From e77a02882e380e9b6f031b1b79da395a1c89f600 Mon Sep 17 00:00:00 2001 From: Michael Rash Date: Mon, 21 Oct 2013 20:34:22 -0400 Subject: [PATCH] [test suite] Add support for Test::Valgrind against the perl FKO module When --enable-valgrind is used, this commit adds support for running the perl FKO built-in tests (in the t/ directory) under the CPAN Test::Valgrind module. A check is performed to see whether Test::Valgrind is install before attempting to use it. Any 'fko_' function that shows up under the test output is flagged and causes the test-suite test to fail. --- test/test-fwknop.pl | 51 +++++++++++++++++++++++++++++++++++ test/tests/perl_FKO_module.pl | 8 ++++++ 2 files changed, 59 insertions(+) diff --git a/test/test-fwknop.pl b/test/test-fwknop.pl index 83b74d91..2e135c79 100755 --- a/test/test-fwknop.pl +++ b/test/test-fwknop.pl @@ -276,6 +276,7 @@ my $server_test_file = ''; my $enable_valgrind = 0; my $disable_valgrind = 0; our $valgrind_str = ''; +my $cpan_valgrind_mod = 'Test::Valgrina'; my %prev_valgrind_cov = (); my %prev_valgrind_file_titles = (); my $fko_wrapper_dir = 'fko-wrapper'; @@ -1747,6 +1748,45 @@ sub perl_fko_module_make_test() { return $rv; } +sub perl_fko_module_make_test_valgrind() { + my $test_hr = shift; + + my $rv = 1; + + my $curr_pwd = cwd() or die $!; + + chdir '../perl/FKO' or die $!; + + &run_cmd("prove --exec 'perl -Iblib/lib -Iblib/arch -M$cpan_valgrind_mod' t/*.t", + $cmd_out_tmp, "../../test/$curr_test_file"); + + chdir $curr_pwd or die $!; + + if ($test_hr->{'positive_output_matches'}) { + unless (&file_find_regex( + $test_hr->{'positive_output_matches'}, + $MATCH_ALL, $APPEND_RESULTS, $curr_test_file)) { + &write_test_file( + "[-] positive_output_matches not met, setting rv=0\n", + $curr_test_file); + $rv = 0; + } + } + + if ($test_hr->{'negative_output_matches'}) { + if (&file_find_regex( + $test_hr->{'negative_output_matches'}, + $MATCH_ANY, $APPEND_RESULTS, $curr_test_file)) { + &write_test_file( + "[-] negative_output_matches not met, setting rv=0\n", + $curr_test_file); + $rv = 0; + } + } + + return $rv; +} + sub perl_fko_module_new_object() { my $test_hr = shift; @@ -5317,6 +5357,7 @@ sub init() { unless ($valgrind_path) { print "[-] --enable-valgrind mode requested ", "but valgrind not found, disabling.\n"; + push @tests_to_exclude, qr/$cpan_valgrind_mod/; $enable_valgrind = 0; } } @@ -5349,6 +5390,16 @@ sub init() { } } close F; + + ### check to see if the Test::Valgrind module is installed + if ($enable_valgrind and $valgrind_path) { + unless (&run_cmd("perl -e 'use $cpan_valgrind_mod'", + $cmd_out_tmp, $curr_test_file) and &find_command('prove')) { + push @tests_to_exclude, qr/$cpan_valgrind_mod/; + } + } else { + push @tests_to_exclude, qr/$cpan_valgrind_mod/; + } } else { push @tests_to_exclude, qr/perl FKO module/; } diff --git a/test/tests/perl_FKO_module.pl b/test/tests/perl_FKO_module.pl index 3cbe9b30..2ab35b67 100644 --- a/test/tests/perl_FKO_module.pl +++ b/test/tests/perl_FKO_module.pl @@ -15,6 +15,14 @@ 'positive_output_matches' => [qr/All\stests\ssuccessful/i], 'fatal' => $NO }, + { + 'category' => 'perl FKO module', + 'subcategory' => 'make test', + 'detail' => 'Test::Valgrind', + 'function' => \&perl_fko_module_make_test_valgrind, + 'negative_output_matches' => [qr/fko_/i], + 'fatal' => $NO + }, { 'category' => 'perl FKO module',