net-fd.test revision 5dec78d0c2663930cd1bbcecbbcee47f68bc52f3
1#!/bin/sh
2
3# Check how network syscalls are traced when decoding socket descriptors
4
5. "${srcdir=.}/init.sh"
6
7# strace -y is implemented using /proc/self/fd
8[ -d /proc/self/fd/ ] ||
9	framework_skip_ '/proc/self/fd/ is not available'
10
11check_prog grep
12check_prog rm
13
14rm -f $LOG.*
15
16./net-accept-connect ||
17	fail_ 'net-accept-connect failed'
18
19# using -y to test socket descriptors 'paths' decoding
20args="-tt -ff -y -o $LOG -enetwork ./net-accept-connect"
21$STRACE $args ||
22	fail_ "strace $args failed"
23
24"$srcdir"/../strace-log-merge $LOG > $LOG || {
25	cat $LOG
26	fail_ 'strace-log-merge failed'
27}
28
29rm -f $LOG.*
30
31grep_log()
32{
33	local syscall="$1"; shift
34	local prefix='[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +'
35
36	LC_ALL=C grep -E -x "$prefix$syscall$@" $LOG > /dev/null || {
37		cat $LOG
38		fail_ "strace -enetwork failed to trace \"$syscall\" properly"
39	}
40}
41grep_log bind '\(0<socket:\[[0-9]+\]>, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="local-stream"\}, 15\) += 0'
42grep_log listen '\(0<socket:\[[0-9]+\]>, 5\) += 0'
43grep_log getsockname '\(0<socket:\[[0-9]+\]>, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="local-stream"\}, \[15\]\) += 0'
44grep_log accept '\(0<socket:\[[0-9]+\]>, \{sa_family=AF_(LOCAL|UNIX|FILE), NULL\}, \[2\]\) += 1'
45grep_log connect '\(1<socket:\[[0-9]+\]>, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="local-stream"\}, 15\) += 0'
46
47exit 0
48