]> granicus.if.org Git - strace/commitdiff
tests: add a test for decoding unix domain socket addresses
authorMasatake YAMATO <yamato@redhat.com>
Wed, 24 Dec 2014 11:59:32 +0000 (20:59 +0900)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 25 Dec 2014 01:01:11 +0000 (01:01 +0000)
* tests/unix-yy-accept.awk: New file.
* tests/unix-yy-connect.awk: New file.
* tests/unix-yy.test: New test.
* tests/Makefile.am (TESTS): Add it.
(EXTRA_DIST): Add unix-yy-accept.awk and unix-yy-connect.awk.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
tests/Makefile.am
tests/unix-yy-accept.awk [new file with mode: 0644]
tests/unix-yy-connect.awk [new file with mode: 0644]
tests/unix-yy.test [new file with mode: 0755]

index 560648b6821e1015c5afcd377f35ac0d852efc2e..f17e8c0f0ca713e459b3c518e5a1ad23a042ace6 100644 (file)
@@ -37,6 +37,7 @@ TESTS = \
        net.test \
        net-fd.test \
        net-yy.test \
+       unix-yy.test \
        uid.test \
        uid16.test \
        uid32.test \
@@ -59,6 +60,8 @@ EXTRA_DIST = init.sh run.sh \
             net-yy-connect.awk \
             sigaction.awk \
             uid.awk \
+            unix-yy-accept.awk \
+            unix-yy-connect.awk \
             $(TESTS)
 
 CLEANFILES = $(TESTS:=.tmp)
diff --git a/tests/unix-yy-accept.awk b/tests/unix-yy-accept.awk
new file mode 100644 (file)
index 0000000..ad1d39e
--- /dev/null
@@ -0,0 +1,65 @@
+BEGIN {
+  lines = 8
+  fail = 0
+
+  inode_listen = "?"
+  inode_accepted = "?"
+  inode_peer = "?"
+
+  r_i = "[1-9][0-9]*"
+  r_bind = "^bind\\(0<UNIX:\\[(" r_i ")\\]>, {sa_family=AF_LOCAL, sun_path=\"local-stream\"}, " r_i "\\) += 0$"
+  r_listen = "^/$"
+  r_getsockname = "^/$"
+  r_accept = "^/$"
+  r_close0 = "^/$"
+  r_close1 = "^/$"
+}
+
+NR == 1 && /^socket\(PF_LOCAL, SOCK_STREAM, 0\) += 0$/ {next}
+
+NR == 2 {
+  if (match($0, r_bind, a)) {
+    inode_listen = a[1]
+    r_listen = "^listen\\(0<UNIX:\\[" inode_listen ",\"local-stream\"\\]>, 5\\) += 0$"
+    r_getsockname = "^getsockname\\(0<UNIX:\\[" inode_listen ",\"local-stream\"\\]>, {sa_family=AF_LOCAL, sun_path=\"local-stream\"}, \\[" r_i "\\]\\) += 0$"
+    r_accept = "^accept\\(0<UNIX:\\[" inode_listen ",\"local-stream\"\\]>, {sa_family=AF_LOCAL, NULL}, \\[" r_i "\\]\\) += 1<UNIX:\\[(" r_i ")->(" r_i "),\"local-stream\"\\]>"
+    next
+  }
+}
+
+NR == 3 {if (match($0, r_listen)) next}
+
+NR == 4 {if (match($0, r_getsockname)) next}
+
+NR == 5 {
+  if (match($0, r_accept, a)) {
+    inode_accepted = a[1]
+    inode_peer = a[2]
+    print inode_accepted
+    r_close0 = "^close\\(0<UNIX:\\[" inode_listen ",\"local-stream\"\\]>\\) += 0$"
+    r_close1 = "^close\\(1<UNIX:\\[" inode_accepted ",\"local-stream\"\\]>\\) += 0$"
+    next
+  }
+}
+
+NR == 6 {if (match($0, r_close0)) next}
+NR == 7 {if (match($0, r_close1)) 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
+  }
+}
diff --git a/tests/unix-yy-connect.awk b/tests/unix-yy-connect.awk
new file mode 100644 (file)
index 0000000..1b41315
--- /dev/null
@@ -0,0 +1,41 @@
+BEGIN {
+  lines = 5
+  fail = 0
+
+  inode = "?"
+
+  r_i = "[1-9][0-9]*"
+  r_close0 = "^close\\(0<UNIX:[" r_i ",\"local-stream\"]>\\) += 0$"
+  r_connect = "^connect\\(1<UNIX:\\[(" r_i ")\\]>, {sa_family=AF_LOCAL, sun_path=\"local-stream\"}, " r_i "\\) += 0$"
+  r_close1 = "^/$"
+}
+
+NR == 1 && /^socket\(PF_LOCAL, SOCK_STREAM, 0\) += 1$/ {next}
+NR == 2 {if (match($0, r_close0)) next}
+NR == 3 {
+  if (match($0, r_connect, a)) {
+    inode = a[1]
+    r_close1 = "^close\\(1<UNIX:\\[(" r_i ")->" r_i "\\]>\\) += 0$"
+    next
+  }
+}
+NR == 4 {if (match($0, r_close1, a) && a[1] == inode) {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
+  }
+}
diff --git a/tests/unix-yy.test b/tests/unix-yy.test
new file mode 100755 (executable)
index 0000000..6e7bd56
--- /dev/null
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+# Check decoding of address information (inode[->peer][,path])
+# associated with unix domain socket descriptors.
+
+. "${srcdir=.}/init.sh"
+
+# strace -yy is implemented using /proc/self/fd
+[ -d /proc/self/fd/ ] ||
+       framework_skip_ '/proc/self/fd/ is not available'
+
+check_prog awk
+check_prog sed
+
+rm -f $LOG.* $LOG-*
+
+./net-accept-connect ||
+       fail_ 'net-accept-connect failed'
+
+./netlink_inet_diag || {
+       if [ $? -eq 77 ]; then
+               framework_skip_ 'NETLINK_INET_DIAG is not available'
+       else
+               fail_ 'netlink_inet_diag failed'
+       fi
+}
+
+args="-tt -ff -yy -o $LOG -eclose,network ./net-accept-connect"
+$STRACE $args ||
+       fail_ "strace $args failed"
+
+"$srcdir"/../strace-log-merge $LOG > $LOG || {
+       cat $LOG
+       fail_ 'strace-log-merge failed'
+}
+rm -f $LOG.*
+
+child="$(sed -rn '/SIGCHLD/ s/^.*, si_pid=([1-9][0-9]*), .*/\1/p' $LOG)"
+[ -n "$child" ] || {
+       cat $LOG
+       fail_ 'failed to find pid of child process'
+}
+
+sed -rn "/^$child"' /!d; / socket\(/,$ s/^[0-9]+ +[^ ]+ (.+)/\1/p' $LOG > $LOG-connect &&
+sed -rn "/^$child"' /d; /SIGCHLD/d; / socket\(/,$ s/^[0-9]+ +[^ ]+ (.+)/\1/p' $LOG > $LOG-accept || {
+       cat $LOG
+       fail_ 'failed to separate logs'
+}
+
+awk -f "$srcdir"/unix-yy-connect.awk $LOG-connect || {
+       cat $LOG-connect
+       fail_ "strace $args failed to decode socket descriptors properly"
+}
+
+awk -f "$srcdir"/unix-yy-accept.awk $LOG-accept || {
+       cat $LOG-accept
+       fail_ "strace $args failed to decode socket descriptors properly"
+}
+
+exit 0