diff options
Diffstat (limited to 'tests/monitor/run-tests.sh')
-rwxr-xr-x | tests/monitor/run-tests.sh | 107 |
1 files changed, 76 insertions, 31 deletions
diff --git a/tests/monitor/run-tests.sh b/tests/monitor/run-tests.sh index 9fd0e504..23d4e212 100755 --- a/tests/monitor/run-tests.sh +++ b/tests/monitor/run-tests.sh @@ -1,8 +1,9 @@ #!/bin/bash cd $(dirname $0) - nft=../../src/nft +debug=false + mydiff() { diff -w -I '^# ' "$@" } @@ -20,20 +21,38 @@ output_file=$(mktemp -p $testdir) cmd_append() { echo "$*" >>$command_file } -output_append() { +monitor_output_append() { [[ "$*" == '-' ]] && { cat $command_file >>$output_file return } echo "$*" >>$output_file } -run_test() { +echo_output_append() { + # this is a bit tricky: for replace commands, nft prints a delete + # command - so in case there is a replace command in $command_file, + # just assume any other commands in the same file are sane + grep -q '^replace' $command_file >/dev/null 2>&1 && { + monitor_output_append "$*" + return + } + [[ "$*" == '-' ]] && { + grep '^\(add\|replace\|insert\)' $command_file >>$output_file + return + } + [[ "$*" =~ ^add|replace|insert ]] && echo "$*" >>$output_file +} +monitor_run_test() { monitor_output=$(mktemp -p $testdir) - $nft monitor >$monitor_output & + $nft -nn monitor >$monitor_output & monitor_pid=$! sleep 0.5 + $debug && { + echo "command file:" + cat $command_file + } $nft -f $command_file || { echo "nft command failed!" kill $monitor_pid @@ -54,33 +73,59 @@ run_test() { touch $output_file } -for testcase in testcases/*.t; do - echo "running tests from file $(basename $testcase)" - # files are like this: - # - # I add table ip t - # O add table ip t - # I add chain ip t c - # O add chain ip t c +echo_run_test() { + echo_output=$(mktemp -p $testdir) + $debug && { + echo "command file:" + cat $command_file + } + $nft -nn -e -f $command_file >$echo_output || { + echo "nft command failed!" + exit 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 + fi + rm $command_file + rm $output_file + touch $command_file + touch $output_file +} + +for variant in monitor echo; do + run_test=${variant}_run_test + output_append=${variant}_output_append + + for testcase in testcases/*.t; do + echo "$variant: running tests from file $(basename $testcase)" + # files are like this: + # + # I add table ip t + # O add table ip t + # I add chain ip t c + # O add chain ip t c - $nft flush ruleset + $nft flush ruleset - input_complete=false - while read dir line; do - case $dir in - I) - $input_complete && run_test - input_complete=false - cmd_append "$line" - ;; - O) - input_complete=true - output_append "$line" - ;; - '#'|'') - # ignore comments and empty lines - ;; - esac - done <$testcase - $input_complete && run_test + input_complete=false + while read dir line; do + case $dir in + I) + $input_complete && $run_test + input_complete=false + cmd_append "$line" + ;; + O) + input_complete=true + $output_append "$line" + ;; + '#'|'') + # ignore comments and empty lines + ;; + esac + done <$testcase + $input_complete && $run_test + done done |