[PATCH 3/3] tests: add a test for decoding the address of unix socket
Masatake YAMATO
yamato at redhat.com
Sat Dec 6 21:56:15 UTC 2014
* tests/Makefile.am: Add unix-yy.test to TESTS.
Add unix-yy-accept.awk and unix-yy-connect.awk to EXTRA_DIST.
* tests/unix-yy-accept.awk: New file.
* tests/unix-yy-connect.awk: New file.
* tests/unix-yy.test: New file.
Signed-off-by: Masatake YAMATO <yamato at redhat.com>
---
tests/Makefile.am | 5 +++-
tests/unix-yy-accept.awk | 65 +++++++++++++++++++++++++++++++++++++++++++++++
tests/unix-yy-connect.awk | 41 ++++++++++++++++++++++++++++++
tests/unix-yy.test | 59 ++++++++++++++++++++++++++++++++++++++++++
4 files changed, 169 insertions(+), 1 deletion(-)
create mode 100644 tests/unix-yy-accept.awk
create mode 100644 tests/unix-yy-connect.awk
create mode 100755 tests/unix-yy.test
diff --git a/tests/Makefile.am b/tests/Makefile.am
index aef6a56..096babc 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -37,7 +37,8 @@ TESTS = \
detach-sleeping.test \
detach-stopped.test \
detach-running.test \
- strace-k.test
+ strace-k.test \
+ unix-yy.test
net-fd.log: net.log
@@ -49,6 +50,8 @@ EXTRA_DIST = init.sh run.sh \
net-yy-accept.awk \
net-yy-connect.awk \
sigaction.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
index 0000000..1ead7ae
--- /dev/null
+++ b/tests/unix-yy-accept.awk
@@ -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<local-stream," inode_listen ">, 5\\) += 0$"
+ r_getsockname = "^getsockname\\(0<local-stream," inode_listen ">, {sa_family=AF_LOCAL, sun_path=\"local-stream\"}, \\[" r_i "\\]\\) += 0$"
+ r_accept = "^accept\\(0<local-stream," inode_listen ">, {sa_family=AF_LOCAL, NULL}, \\[" r_i "\\]\\) += 1<local-stream,(" r_i ")->(" r_i ")>"
+ 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<local-stream," inode_listen ">\\) += 0$"
+ r_close1 = "^close\\(1<local-stream," inode_accepted ">\\) += 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
index 0000000..897b635
--- /dev/null
+++ b/tests/unix-yy-connect.awk
@@ -0,0 +1,41 @@
+BEGIN {
+ lines = 5
+ fail = 0
+
+ inode = "?"
+
+ r_i = "[1-9][0-9]*"
+ r_close0 = "^close\\(0<local-stream," r_i ">\\) += 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<(" 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
index 0000000..d910932
--- /dev/null
+++ b/tests/unix-yy.test
@@ -0,0 +1,59 @@
+#!/bin/sh
+
+# Check decoding of address information ([path,]inode[->peer]) associated with unix 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
--
1.9.3
More information about the Strace-devel
mailing list