diff options
Diffstat (limited to 'tests/monitor/run-tests.sh')
-rwxr-xr-x | tests/monitor/run-tests.sh | 73 |
1 files changed, 50 insertions, 23 deletions
diff --git a/tests/monitor/run-tests.sh b/tests/monitor/run-tests.sh index 1fe613c7..f1ac790a 100755 --- a/tests/monitor/run-tests.sh +++ b/tests/monitor/run-tests.sh @@ -9,15 +9,22 @@ mydiff() { diff -w -I '^# ' "$@" } -if [ "$(id -u)" != "0" ] ; then - echo "this requires root!" +err() { + echo "$*" >&2 +} + +die() { + err "$*" exit 1 +} + +if [ "$(id -u)" != "0" ] ; then + die "this requires root!" fi testdir=$(mktemp -d) if [ ! -d $testdir ]; then - echo "Failed to create test directory" >&2 - exit 1 + die "Failed to create test directory" fi trap 'rm -rf $testdir; $nft flush ruleset' EXIT @@ -56,6 +63,7 @@ monitor_run_test() { monitor_output=$(mktemp -p $testdir) monitor_args="" $test_json && monitor_args="vm json" + local rc=0 $nft -nn monitor $monitor_args >$monitor_output & monitor_pid=$! @@ -66,46 +74,50 @@ monitor_run_test() { echo "command file:" cat $command_file } - $nft -f $command_file || { - echo "nft command failed!" - kill $monitor_pid - wait >/dev/null 2>&1 - exit 1 + $nft -f - <$command_file || { + err "nft command failed!" + rc=1 } sleep 0.5 kill $monitor_pid wait >/dev/null 2>&1 $test_json && json_output_filter $monitor_output - if ! mydiff -q $monitor_output $output_file >/dev/null 2>&1; then - echo "monitor output differs!" - mydiff -u $output_file $monitor_output - exit 1 + mydiff -q $monitor_output $output_file >/dev/null 2>&1 + if [[ $rc == 0 && $? != 0 ]]; then + err "monitor output differs!" + mydiff -u $output_file $monitor_output >&2 + rc=1 fi rm $command_file rm $output_file touch $command_file touch $output_file + return $rc } echo_run_test() { echo_output=$(mktemp -p $testdir) + local rc=0 + $debug && { echo "command file:" cat $command_file } - $nft -nn -e -f $command_file >$echo_output || { - echo "nft command failed!" - exit 1 + $nft -nn -e -f - <$command_file >$echo_output || { + err "nft command failed!" + rc=1 } - if ! mydiff -q $echo_output $output_file >/dev/null 2>&1; then - echo "echo output differs!" - mydiff -u $output_file $echo_output - exit 1 + mydiff -q $echo_output $output_file >/dev/null 2>&1 + if [[ $rc == 0 && $? != 0 ]]; then + err "echo output differs!" + mydiff -u $output_file $echo_output >&2 + rc=1 fi rm $command_file rm $output_file touch $command_file touch $output_file + return $rc } testcases="" @@ -143,12 +155,16 @@ else variants="monitor echo" fi +rc=0 for variant in $variants; do run_test=${variant}_run_test output_append=${variant}_output_append for testcase in ${testcases:-testcases/*.t}; do - echo "$variant: running tests from file $(basename $testcase)" + filename=$(basename $testcase) + echo "$variant: running tests from file $filename" + rc_start=$rc + # files are like this: # # I add table ip t @@ -162,7 +178,10 @@ for variant in $variants; do while read dir line; do case $dir in I) - $input_complete && $run_test + $input_complete && { + $run_test + let "rc += $?" + } input_complete=false cmd_append "$line" ;; @@ -179,6 +198,14 @@ for variant in $variants; do ;; esac done <$testcase - $input_complete && $run_test + $input_complete && { + $run_test + let "rc += $?" + } + + let "rc_diff = rc - rc_start" + [[ $rc_diff -ne 0 ]] && \ + echo "$variant: $rc_diff tests from file $filename failed" done done +exit $rc |