diff options
| author | Tobias Brunner <tobias@strongswan.org> | 2017-07-12 16:53:13 +0200 |
|---|---|---|
| committer | Tobias Brunner <tobias@strongswan.org> | 2017-08-07 10:44:05 +0200 |
| commit | 99cf64e960eddac09e4d362bc79a5194217ecb87 (patch) | |
| tree | 5bd58fc2f4d62547d7fa359983b31087bc608b51 /testing/do-tests | |
| parent | f9fbcbb1a00d631bbd9d6ee1209251b3ee85dbaf (diff) | |
| download | strongswan-99cf64e960eddac09e4d362bc79a5194217ecb87.tar.bz2 strongswan-99cf64e960eddac09e4d362bc79a5194217ecb87.tar.xz | |
testing: Add support for counting matching lines in tests
Specifying an integer instead of YES in evaltest.dat causes the number to get
compared against the actual number of lines matching the pattern.
This may be used to count matching packets or log lines.
Diffstat (limited to 'testing/do-tests')
| -rwxr-xr-x | testing/do-tests | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/testing/do-tests b/testing/do-tests index 230403b9f..2ebc96ee9 100755 --- a/testing/do-tests +++ b/testing/do-tests @@ -416,29 +416,38 @@ do STATUS="passed" eval `awk -F "::" '{ - host=$1 - command=$2 - pattern=$3 - hit=$4 - if (host !~ /^#.*/ && command != "") - { + host=$1 + command=$2 + pattern=$3 + hit=$4 + if (host ~ /^#.*/ || command == "") + { + next + } if (command == "tcpdump") { - printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host) - printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047 [%s]\"; ", host, pattern, hit) - printf("ssh \044SSHCONF root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"; ", host, pattern) + printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host) + printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047 [%s]\"; ", host, pattern, hit) + printf("cmd_out=\044(ssh \044SSHCONF root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"); ", host, pattern) } else { - printf("echo \"%s# %s | grep \047%s\047 [%s]\"; ", host, command, pattern, hit) - printf("ssh \044SSHCONF root@\044ipv4_%s %s | grep \"%s\"; ", host, command, pattern) + printf("echo \"%s# %s | grep \047%s\047 [%s]\"; ", host, command, pattern, hit) + printf("cmd_out=\044(ssh \044SSHCONF root@\044ipv4_%s %s | grep \"%s\"); ", host, command, pattern) } printf("cmd_exit=\044?; ") + printf("echo \"\044cmd_out\"; ") printf("echo; ") - printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\" ] ", hit) - printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit) + if (hit ~ /^[0-9]+$/) + { + printf("if [ \044(echo \"\044cmd_out\" | wc -l) -ne %d ] ", hit) + } + else + { + printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\" ] ", hit) + printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit) + } printf("; then STATUS=\"failed\"; fi; \n") - } }' $TESTDIR/evaltest.dat` >> $CONSOLE_LOG 2>&1 |
