From cbf751e8ddd513ed953d2f8fd64864e6c3211d98 Mon Sep 17 00:00:00 2001 From: Michael Rash Date: Fri, 12 Apr 2013 21:50:47 -0400 Subject: [PATCH] [test suite] check for fwknopd ready to receive packets This commit was inspired through conversations with George Herlin. --- test/test-fwknop.pl | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/test/test-fwknop.pl b/test/test-fwknop.pl index 8da5acd7..dd9f3b3e 100755 --- a/test/test-fwknop.pl +++ b/test/test-fwknop.pl @@ -631,7 +631,7 @@ sub run_test() { } } - if ($enable_valgrind) { + if ($enable_valgrind and &is_valgrind_running()) { if ($killall_path and $pgrep_path) { for my $cmd ('memcheck', 'valgrind') { system "$pgrep_path > /dev/null $cmd " . @@ -4451,9 +4451,7 @@ sub specs() { sub time_for_valgrind() { my $ctr = 0; - while (&run_cmd("ps axuww | grep LD_LIBRARY_PATH | " . - "grep valgrind |grep -v perl | grep -v grep", - $cmd_out_tmp, $curr_test_file)) { + while (&is_valgrind_running()) { $ctr++; last if $ctr == 5; sleep 1; @@ -4461,6 +4459,12 @@ sub time_for_valgrind() { return; } +sub is_valgrind_running() { + return &run_cmd("ps axuww | grep LD_LIBRARY_PATH | " . + "grep valgrind |grep -v perl | grep -v grep", + $cmd_out_tmp, $curr_test_file); +} + sub anonymize_results() { my $rv = 0; die "[*] $output_dir does not exist" unless -d $output_dir; @@ -4540,6 +4544,17 @@ sub start_fwknopd() { exit &run_cmd($test_hr->{'fwknopd_cmdline'}, $server_cmd_tmp, $server_test_file); } + + ### look for 'fwknopd main event loop' as the indicator that fwknopd + ### is ready to receive packets + my $tries = 0; + while (not &file_find_regex([qr/fwknopd\smain\sevent\sloop/], + $MATCH_ALL, $server_cmd_tmp)) { + $tries++; + last if $tries == 10; ### shouldn't reasonably get here + sleep 1; + } + return $pid; } @@ -5206,6 +5221,22 @@ sub stop_fwknopd() { sleep 1; } + ### open the pid file and send signal manually if -K didn't work + if (-e $default_pid_file) { + open F, "< $default_pid_file" + or die "[*] Could not open $default_pid_file: $!"; + my $pid = ; + close F; + chomp $pid; + my $tries = 0; + while (kill 0, $pid) { + kill 9, $pid unless kill 15, $pid; + $tries++; + last if $tries == 3; + sleep 1; + } + } + return; }