]> granicus.if.org Git - strace/commitdiff
tests: factor out common awk code
authorDmitry V. Levin <ldv@altlinux.org>
Wed, 18 Mar 2015 19:14:02 +0000 (19:14 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 18 Mar 2015 22:41:17 +0000 (22:41 +0000)
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.

tests/Makefile.am
tests/caps.awk
tests/getdents.awk
tests/getdents.test
tests/getrandom.awk
tests/init.sh
tests/match.awk [new file with mode: 0644]
tests/select.awk
tests/sigaction.awk

index 7f9a11ea4d9fa38cae030499851fe2439f67685f..0acad4df71c666148cd6ae71718c0141a9d0ee98 100644 (file)
@@ -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 \
index 70f314730018c33f6e2e915d863e3c672aa00a81..f2f143d6eacad1695cfeac8d98f98243f6a2c6b5 100644 (file)
@@ -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"
index c230e26734b34c3bda1cdb366f20f691e4d61274..8a00133448773273c8cc1a34ef526da07ae61fec 100644 (file)
@@ -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"
index 5be3e8372924890eccedbd59f8ab8e1f81bd8446..3fa1c8db50d7ec11377817b7d61890f2e6289f19 100755 (executable)
@@ -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
index 4c5f6fc108179e377b28123e2ad7bb06b041f68c..09d2a0f09139684d0c1910eb48b06be6a7f99f75 100644 (file)
@@ -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"
index a3ccd1fa2b5d8e2dd87f6aaf6c80aa8c677e8205..0c5b121f0405ae0e995c5761a3a8443dfbfd2757 100644 (file)
@@ -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 (file)
index 0000000..39af47c
--- /dev/null
@@ -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
+}
index 688cefe4c42644fbb812c363906fe9b9d4d79e87..996d028521401f1c7bfbeb3f75001f30bbc97c1b 100644 (file)
@@ -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"
index 01133d29e8e020b17485827bb7b2bb0b16d00664..df96e4b31da08c51befdb72f7a84eef8ba1096d0 100644 (file)
@@ -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"