diff options
author | Dmitry V. Levin <ldv@altlinux.org> | 2015-03-18 19:14:02 +0000 |
---|---|---|
committer | Dmitry V. Levin <ldv@altlinux.org> | 2015-03-18 22:41:17 +0000 |
commit | 226bf1c21b8f04f7fa1655979fe00adee1e68b5e (patch) | |
tree | 5253a2ed5659fd2a2d010224471f74b8a5e56ee7 | |
parent | 6add1b09d656887e282947f1ee129ee9003530c6 (diff) | |
download | android_external_strace-226bf1c21b8f04f7fa1655979fe00adee1e68b5e.tar.gz android_external_strace-226bf1c21b8f04f7fa1655979fe00adee1e68b5e.tar.bz2 android_external_strace-226bf1c21b8f04f7fa1655979fe00adee1e68b5e.zip |
tests: factor out common awk code
Factor out awk code used in several tests to match.awk.
* tests/match.awk: New file.
* tests/Makefile.am (EXTRA_DIST): Add it.
* tests/caps.awk: Use it.
* tests/getdents.awk: Likewise.
* tests/getrandom.awk: Likewise.
* tests/select.awk: Likewise.
* tests/sigaction.awk: Likewise.
* tests/init.sh (match_awk): Use gawk not awk. Define AWKPATH.
* tests/getdents.test: Likewise.
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/caps.awk | 31 | ||||
-rw-r--r-- | tests/getdents.awk | 113 | ||||
-rwxr-xr-x | tests/getdents.test | 6 | ||||
-rw-r--r-- | tests/getrandom.awk | 21 | ||||
-rw-r--r-- | tests/init.sh | 7 | ||||
-rw-r--r-- | tests/match.awk | 26 | ||||
-rw-r--r-- | tests/select.awk | 21 | ||||
-rw-r--r-- | tests/sigaction.awk | 74 |
9 files changed, 124 insertions, 177 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 7f9a11ea..0acad4df 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -84,7 +84,7 @@ net-fd.log: net.log TEST_LOG_COMPILER = $(srcdir)/run.sh -EXTRA_DIST = init.sh run.sh \ +EXTRA_DIST = init.sh run.sh match.awk \ caps.awk \ dumpio.expected \ fanotify_mark.expected \ diff --git a/tests/caps.awk b/tests/caps.awk index 70f31473..f2f143d6 100644 --- a/tests/caps.awk +++ b/tests/caps.awk @@ -1,25 +1,12 @@ BEGIN { - fail = 0 - lines = 3 - cap = "(0|CAP_[A-Z_]+(\\|CAP_[A-Z_]+)*|CAP_[A-Z_]+(\\|CAP_[A-Z_]+){37}\\|0xffffffc0)" - capget = "^capget\\(\\{_LINUX_CAPABILITY_VERSION_3, 0\\}, \\{" cap ", " cap ", " cap "\\}\\) = 0$" + cap = "(0|CAP_[A-Z_]+(\\|CAP_[A-Z_]+)*|CAP_[A-Z_]+(\\|CAP_[A-Z_]+){37}\\|0xffffffc0)" + r[1] = "^capget\\(\\{_LINUX_CAPABILITY_VERSION_3, 0\\}, \\{" cap ", " cap ", " cap "\\}\\) = 0$" + capset_data = "{CAP_DAC_OVERRIDE|CAP_WAKE_ALARM, CAP_DAC_READ_SEARCH|CAP_BLOCK_SUSPEND, 0}" + s[2] = "capset({_LINUX_CAPABILITY_VERSION_3, 0}, " capset_data ") = -1 EPERM (Operation not permitted)" + s[3] = "+++ exited with 0 +++" + + lines = 3 + fail = 0 } -NR == 1 {if (match($0, capget)) next} - -NR == 2 && $0 == "capset({_LINUX_CAPABILITY_VERSION_3, 0}, {CAP_DAC_OVERRIDE|CAP_WAKE_ALARM, CAP_DAC_READ_SEARCH|CAP_BLOCK_SUSPEND, 0}) = -1 EPERM (Operation not permitted)" {next} - -NR == lines && $0 == "+++ exited with 0 +++" {next} - -{ - print "Line " NR " does not match." - fail = 1 - exit 1 -} - -END { - if (fail == 0 && NR != lines) { - print "Expected " lines " lines, found " NR " line(s)." - exit 1 - } -} +@include "match.awk" diff --git a/tests/getdents.awk b/tests/getdents.awk index c230e267..8a001334 100644 --- a/tests/getdents.awk +++ b/tests/getdents.awk @@ -1,68 +1,51 @@ BEGIN { - lines = 3 - fail = 0 - - i = "[0-9]+" - len = "[1-9]" i - - d_ino = "d_ino=" i - d_off = "d_off=" i - d_reclen = "d_reclen=" len - d_name_1 = "d_name=\"\\.\"" - d_name_2 = "d_name=\"\\.\\.\"" - d_name_3 = "d_name=\"(A\\\\n){127}Z\"" - # Some older systems might not pass back d_type at all like Alpha. - d_type_dir = "d_type=DT_(DIR|UNKNOWN)" - d_type_reg = "d_type=DT_(REG|UNKNOWN)" - - dirent_1 = "\\{" d_ino ", " d_off ", " d_reclen ", " d_name_1 ", " d_type_dir "\\}" - dirent_2 = "\\{" d_ino ", " d_off ", " d_reclen ", " d_name_2 ", " d_type_dir "\\}" - dirent_3 = "\\{" d_ino ", " d_off ", " d_reclen ", " d_name_3 ", " d_type_reg "\\}" - - dirent64_1 = "\\{" d_ino ", " d_off ", " d_reclen ", " d_type_dir ", " d_name_1 "\\}" - dirent64_2 = "\\{" d_ino ", " d_off ", " d_reclen ", " d_type_dir ", " d_name_2 "\\}" - dirent64_3 = "\\{" d_ino ", " d_off ", " d_reclen ", " d_type_reg ", " d_name_3 "\\}" - - d_123 = dirent_1 " " dirent_2 " " dirent_3 - d_213 = dirent_2 " " dirent_1 " " dirent_3 - d_132 = dirent_1 " " dirent_3 " " dirent_2 - d_321 = dirent_3 " " dirent_2 " " dirent_1 - d_231 = dirent_2 " " dirent_3 " " dirent_1 - d_312 = dirent_3 " " dirent_1 " " dirent_2 - - d64_123 = dirent64_1 " " dirent64_2 " " dirent64_3 - d64_213 = dirent64_2 " " dirent64_1 " " dirent64_3 - d64_132 = dirent64_1 " " dirent64_3 " " dirent64_2 - d64_321 = dirent64_3 " " dirent64_2 " " dirent64_1 - d64_231 = dirent64_2 " " dirent64_3 " " dirent64_1 - d64_312 = dirent64_3 " " dirent64_1 " " dirent64_2 - - dents = "\\{(" d_123 "|" d_213 "|" d_132 "|" d_321 "|" d_231 "|" d_312 ")\\}" - dents64 = "\\{(" d64_123 "|" d64_213 "|" d64_132 "|" d64_321 "|" d64_231 "|" d64_312 ")\\}" - - getdents = "^getdents\\(" i ", " dents ", " len "\\) += " len "$" - getdents64 = "^getdents64\\(" i ", " dents64 ", " len "\\) += " len "$" + i = "[0-9]+" + len = "[1-9]" i + + d_ino = "d_ino=" i + d_off = "d_off=" i + d_reclen = "d_reclen=" len + d_name_1 = "d_name=\"\\.\"" + d_name_2 = "d_name=\"\\.\\.\"" + d_name_3 = "d_name=\"(A\\\\n){127}Z\"" + # Some older systems might not pass back d_type at all like Alpha. + d_type_dir = "d_type=DT_(DIR|UNKNOWN)" + d_type_reg = "d_type=DT_(REG|UNKNOWN)" + + dirent_1 = "\\{" d_ino ", " d_off ", " d_reclen ", " d_name_1 ", " d_type_dir "\\}" + dirent_2 = "\\{" d_ino ", " d_off ", " d_reclen ", " d_name_2 ", " d_type_dir "\\}" + dirent_3 = "\\{" d_ino ", " d_off ", " d_reclen ", " d_name_3 ", " d_type_reg "\\}" + + dirent64_1 = "\\{" d_ino ", " d_off ", " d_reclen ", " d_type_dir ", " d_name_1 "\\}" + dirent64_2 = "\\{" d_ino ", " d_off ", " d_reclen ", " d_type_dir ", " d_name_2 "\\}" + dirent64_3 = "\\{" d_ino ", " d_off ", " d_reclen ", " d_type_reg ", " d_name_3 "\\}" + + d_123 = dirent_1 " " dirent_2 " " dirent_3 + d_213 = dirent_2 " " dirent_1 " " dirent_3 + d_132 = dirent_1 " " dirent_3 " " dirent_2 + d_321 = dirent_3 " " dirent_2 " " dirent_1 + d_231 = dirent_2 " " dirent_3 " " dirent_1 + d_312 = dirent_3 " " dirent_1 " " dirent_2 + + d64_123 = dirent64_1 " " dirent64_2 " " dirent64_3 + d64_213 = dirent64_2 " " dirent64_1 " " dirent64_3 + d64_132 = dirent64_1 " " dirent64_3 " " dirent64_2 + d64_321 = dirent64_3 " " dirent64_2 " " dirent64_1 + d64_231 = dirent64_2 " " dirent64_3 " " dirent64_1 + d64_312 = dirent64_3 " " dirent64_1 " " dirent64_2 + + dents = "\\{(" d_123 "|" d_213 "|" d_132 "|" d_321 "|" d_231 "|" d_312 ")\\}" + dents64 = "\\{(" d64_123 "|" d64_213 "|" d64_132 "|" d64_321 "|" d64_231 "|" d64_312 ")\\}" + + getdents = "getdents\\(" i ", " dents ", " len "\\)" + getdents64 = "getdents64\\(" i ", " dents64 ", " len "\\)" + + r[1] = "^(" getdents "|" getdents64 ") += " len "$" + r[2] = "^getdents(64)?\\([0-9]+, \\{\\}, [1-9][0-9]+\\) += 0$" + s[3] = "+++ exited with 0 +++" + + lines = 3 + fail = 0 } -NR == 1 {if (match($0, getdents) || match($0, getdents64)) next} - -NR == 2 && /^getdents(64)?\([0-9]+, \{\}, [1-9][0-9]+\) += 0$/ {next} - -NR == lines && /^\+\+\+ exited with 0 \+\+\+$/ {next} - -{ - print "Line " NR " does not match: " $0 - fail=1 -} - -END { - if (NR != lines) { - print "Expected " lines " lines, found " NR " line(s)." - print "" - exit 1 - } - if (fail) { - print "" - exit 1 - } -} +@include "match.awk" diff --git a/tests/getdents.test b/tests/getdents.test index 5be3e837..3fa1c8db 100755 --- a/tests/getdents.test +++ b/tests/getdents.test @@ -4,9 +4,9 @@ . "${srcdir=.}/init.sh" -check_prog awk -awk -f "$srcdir"/getdents.awk "$srcdir"/getdents.out || - framework_skip_ 'awk does not work properly' +check_prog gawk +AWKPATH="$srcdir" gawk -f "$srcdir"/getdents.awk "$srcdir"/getdents.out || + framework_skip_ 'gawk does not work properly' check_prog ls check_prog mkdir diff --git a/tests/getrandom.awk b/tests/getrandom.awk index 4c5f6fc1..09d2a0f0 100644 --- a/tests/getrandom.awk +++ b/tests/getrandom.awk @@ -2,25 +2,10 @@ BEGIN { r[1] = "^getrandom\\(\"(\\\\x[0-9a-f][0-9a-f]){3}\", 3, 0\\) += 3$" r[2] = "^getrandom\\(\"(\\\\x[0-9a-f][0-9a-f]){3}\"\\.\\.\\., 4, GRND_NONBLOCK\\) += 4$" r[3] = "^getrandom\\(0x[[0-9a-f]+, 4, GRND_NONBLOCK\\|GRND_RANDOM\\|0x3000\\) += -1 " - r[4] = "^\\+\\+\\+ exited with 0 \\+\\+\\+$" + s[4] = "+++ exited with 0 +++" + lines = 4 fail = 0 } -NR > lines { exit 1 } - -{ - if (match($0, r[NR])) - next - - print "Line " NR " does not match." - fail = 1 -} - -END { - if (fail == 0 && NR != lines) { - fail = 1 - print "Expected " lines " lines, found " NR " line(s)." - } - exit fail -} +@include "match.awk" diff --git a/tests/init.sh b/tests/init.sh index a3ccd1fa..0c5b121f 100644 --- a/tests/init.sh +++ b/tests/init.sh @@ -66,7 +66,7 @@ run_strace_merge() # dump both files and fail with ERROR_MESSAGE. match_awk() { - local output program error awk + local output program error if [ $# -eq 0 ]; then output="$LOG" else @@ -82,11 +82,10 @@ match_awk() else error="$1"; shift fi - awk=${AWK:-awk} - check_prog "$awk" + check_prog gawk - "$awk" -f "$program" "$@" < "$output" || { + AWKPATH="$srcdir" gawk -f "$program" "$@" < "$output" || { cat < "$output" fail_ "$error" } diff --git a/tests/match.awk b/tests/match.awk new file mode 100644 index 00000000..39af47ce --- /dev/null +++ b/tests/match.awk @@ -0,0 +1,26 @@ +# s[] is array of match strings +# r[] is array of match patterns + +NR > lines { next } + +{ + if (s[NR]) { + if ($0 == s[NR]) + next + print "Line " NR " does not match expected string: " s[NR] + } else { + if (match($0, r[NR])) + next + print "Line " NR " does not match expected pattern: " r[NR] + } + + fail = 1 +} + +END { + if (fail == 0 && NR != lines) { + fail = 1 + print "Expected " lines " lines, found " NR " line(s)." + } + exit fail +} diff --git a/tests/select.awk b/tests/select.awk index 688cefe4..996d0285 100644 --- a/tests/select.awk +++ b/tests/select.awk @@ -2,25 +2,10 @@ BEGIN { r[1] = "^p?select6?\\(2, \\[0 1\\], \\[0 1\\], \\[0 1\\], NULL(, 0)?\\) += 1 \\(\\)$" r[2] = "^p?select6?\\(-1, NULL, 0x[0-9a-f]+, NULL, NULL(, 0)?\\) += -1 " r[3] = "^p?select6?\\(1025, \\[0\\], \\[\\], NULL, \\{0, 100(000)?\\}(, 0)?\\) += 0 \\(Timeout\\)$" - r[4] = "^\\+\\+\\+ exited with 0 \\+\\+\\+$" + s[4] = "+++ exited with 0 +++" + lines = 4 fail = 0 } -NR > lines { exit 1 } - -{ - if (match($0, r[NR])) - next - - print "Line " NR " does not match." - fail = 1 -} - -END { - if (fail == 0 && NR != lines) { - fail = 1 - print "Expected " lines " lines, found " NR " line(s)." - } - exit fail -} +@include "match.awk" diff --git a/tests/sigaction.awk b/tests/sigaction.awk index 01133d29..df96e4b3 100644 --- a/tests/sigaction.awk +++ b/tests/sigaction.awk @@ -1,55 +1,37 @@ -# rt_sigaction on ALPHA has 5 args: sig, act, oact, sigsetsize, restorer. -# rt_sigaction on SPARC has 5 args: sig, act, oact, restorer, sigsetsize. -# rt_sigaction on other architectures has 4 args: sig, act, oact, sigsetsize. -# Some architectures have SA_RESTORER, some don't; -# in particular, SPARC has and ALPHA hasn't. -# -# There are two regexps for each test: -# the 1st is for any architecture with SA_RESTORER, including SPARC; -# the 2nd is for any architecture without SA_RESTORER, including ALPHA; -# the 3rd is for any architecture without SA_RESTORER and swapped args. - BEGIN { - lines = 5 - fail = 0 -} + n1[1] = "SIG_IGN, \\[HUP INT\\], SA_RESTORER\\|SA_RESTART, 0x[0-9a-f]+" + n2[1] = "SIG_IGN, \\[HUP INT\\], SA_RESTART" -# Test 1. -NR == 1 && /^rt_sigaction\(SIGUSR2, \{SIG_IGN, \[HUP INT\], SA_RESTORER\|SA_RESTART, 0x[0-9a-f]+\}, \{SIG_DFL, \[\], 0\}, (0x[0-9a-f]+, )?(4|8|16)\) = 0$/ {next} -NR == 1 && /^rt_sigaction\(SIGUSR2, \{SIG_IGN, \[HUP INT\], SA_RESTART\}, \{SIG_DFL, \[\], 0\}, (4|8|16)(, 0x[0-9a-f]+)?\) = 0$/ {next} -NR == 1 && /^rt_sigaction\(SIGUSR2, \{SIG_IGN, \[HUP INT\], SA_RESTART\}, \{SIG_DFL, \[\], 0\}, 0x[0-9a-f]+, (4|8|16)\) = 0$/ {next} + n1[2] = "0x[0-9a-f]+, \\[QUIT TERM\\], SA_RESTORER\\|SA_SIGINFO, 0x[0-9a-f]+" + n2[2] = "0x[0-9a-f]+, \\[QUIT TERM\\], SA_SIGINFO" -# Test 2. -NR == 2 && /^rt_sigaction\(SIGUSR2, \{0x[0-9a-f]+, \[QUIT TERM\], SA_RESTORER\|SA_SIGINFO, 0x[0-9a-f]+\}, \{SIG_IGN, \[HUP INT\], SA_RESTORER\|SA_RESTART, 0x[0-9a-f]+\}, (0x[0-9a-f]+, )?(4|8|16)\) = 0$/ {next} -NR == 2 && /^rt_sigaction\(SIGUSR2, \{0x[0-9a-f]+, \[QUIT TERM\], SA_SIGINFO\}, \{SIG_IGN, \[HUP INT\], SA_RESTART\}, (4|8|16)(, 0x[0-9a-f]+)?\) = 0$/ {next} -NR == 2 && /^rt_sigaction\(SIGUSR2, \{0x[0-9a-f]+, \[QUIT TERM\], SA_SIGINFO\}, \{SIG_IGN, \[HUP INT\], SA_RESTART\}, 0x[0-9a-f]+, (4|8|16)\) = 0$/ {next} + n1[3] = "SIG_DFL, \\[\\], SA_RESTORER, 0x[0-9a-f]+" + n2[3] = "SIG_DFL, \\[\\], 0" -# Test 3. -NR == 3 && /^rt_sigaction\(SIGUSR2, \{SIG_DFL, \[\], SA_RESTORER, 0x[0-9a-f]+\}, \{0x[0-9a-f]+, \[QUIT TERM\], SA_RESTORER\|SA_SIGINFO, 0x[0-9a-f]+\}, (0x[0-9a-f]+, )?(4|8|16)\) = 0$/ {next} -NR == 3 && /^rt_sigaction\(SIGUSR2, \{SIG_DFL, \[\], 0\}, \{0x[0-9a-f]+, \[QUIT TERM\], SA_SIGINFO\}, (4|8|16)(, 0x[0-9a-f]+)?\) = 0$/ {next} -NR == 3 && /^rt_sigaction\(SIGUSR2, \{SIG_DFL, \[\], 0\}, \{0x[0-9a-f]+, \[QUIT TERM\], SA_SIGINFO\}, 0x[0-9a-f]+, (4|8|16)\) = 0$/ {next} + n1[4] = "SIG_DFL, ~\\[HUP( ((RT|SIGRT)[^] ]+|[3-9][0-9]|1[0-9][0-9]))*\\], SA_RESTORER, 0x[0-9a-f]+" + n2[4] = "SIG_DFL, ~\\[HUP( ((RT|SIGRT)[^] ]+|[3-9][0-9]|1[0-9][0-9]))*\\], 0" -# Test 4. -NR == 4 && /^rt_sigaction\(SIGUSR2, \{SIG_DFL, ~\[HUP( ((RT|SIGRT)[^] ]+|[3-9][0-9]|1[0-9][0-9]))*\], SA_RESTORER, 0x[0-9a-f]+\}, \{SIG_DFL, \[\], SA_RESTORER, 0x[0-9a-f]+\}, (0x[0-9a-f]+, )?(4|8|16)\) = 0$/ {next} -NR == 4 && /^rt_sigaction\(SIGUSR2, \{SIG_DFL, ~\[HUP( ((RT|SIGRT)[^] ]+|[3-9][0-9]|1[0-9][0-9]))*\], 0\}, \{SIG_DFL, \[\], 0\}, (4|8|16)(, 0x[0-9a-f]+)?\) = 0$/ {next} -NR == 4 && /^rt_sigaction\(SIGUSR2, \{SIG_DFL, ~\[HUP( ((RT|SIGRT)[^] ]+|[3-9][0-9]|1[0-9][0-9]))*\], 0\}, \{SIG_DFL, \[\], 0\}, 0x[0-9a-f]+, (4|8|16)\) = 0$/ {next} + o1[1] = o2[1] = "SIG_DFL, \\[\\], 0" -# The last line. -NR == lines && /^\+\+\+ exited with 0 \+\+\+$/ {next} + for (i = 2; i < 5; i++) { + o1[i] = n1[i - 1] + o2[i] = n2[i - 1] + } -{ - print "Line " NR " does not match: " $0 - fail=1 -} + a1 = "(0x[0-9a-f]+, )?(4|8|16)" + a2 = "(4|8|16)(, 0x[0-9a-f]+)?" + a3 = "0x[0-9a-f]+, (4|8|16)" -END { - if (NR != lines) { - print "Expected " lines " lines, found " NR " line(s)." - print "" - exit 1 - } - if (fail) { - print "" - exit 1 - } + for (i = 1; i < 5; i++) { + r[i] = "^rt_sigaction\\(SIGUSR2, (" \ + "\\{" n1[i] "\\}, \\{" o1[i] "\\}, " a1 "|" \ + "\\{" n2[i] "\\}, \\{" o2[i] "\\}, " a2 "|" \ + "\\{" n2[i] "\\}, \\{" o2[i] "\\}, " a3 ")\\) = 0$" + } + s[5] = "+++ exited with 0 +++" + + lines = 5 + fail = 0 } + +@include "match.awk" |