Debian Codegraph @

doc/SystemTap_Beginners_Guide/testsuite/systemtap.base/ipaddr.exp

raw
1 set TEST_NAME_BASE "ipaddr"
2 if {![installtest_p]} { untested $TEST_NAME_BASE; return }
3
4 # nc server management variables
5 set IPV4_ONLY -1
6 set nc_pipe 0
7
8 # Start an 'nc' server. To start an IPv4 server, pass 1 as the
9 # argument. To start an IPv6 server, pass 0 as the argument.
10 proc start_nc_server { IPV4 } {
11 global TEST_NAME IPV4_ONLY nc_pipe
12 if {$IPV4_ONLY < 0} {
13 # First, does 'nc' exist on this system?
14 if {[catch { exec which nc } res]} {
15 fail "$TEST_NAME find 'nc'"
16 return -1
17 }
18 pass "$TEST_NAME find 'nc'"
19
20 # Older versions of 'nc' (on RHEL4 for instance) don't support
21 # IPv6. Does this 'nc' support IPv6?
22 set IPV4_ONLY 0
23 if {[catch { exec sh -c "nc -h 2>&1 | grep -qi IPv6" } res]} {
24 # If we're here, 'nc' doesn't support IPv6. So, it
25 # supports IPv4 only.
26 set IPV4_ONLY 1
27 }
28 }
29
30 # Figure out the 'nc' command line.
31 if {$IPV4} {
32 if {$IPV4_ONLY} {
33 set nc_cmd "| nc -l localhost -p 8079"
34 } else {
35 set nc_cmd "| nc -l -4 localhost 8079"
36 }
37 } else {
38 if {$IPV4_ONLY} {
39 untested "$TEST_NAME starting IPv6 nc server"
40 return -1
41 }
42 set nc_cmd "| nc -l -6 localhost6 8079"
43 }
44
45 # Actually start the 'nc' server.
46 verbose -log "starting $nc_cmd"
47 if {[catch {open $nc_cmd} nc_pipe]} {
48 verbose -log "nc command failed: $fl"
49 fail "$TEST_NAME nc server start"
50 return -1
51 }
52
53 pass "$TEST_NAME nc server start"
54 return 0
55 }
56
57 # Stop the nc server.
58 proc stop_nc_server {} {
59 global TEST_NAME nc_pipe
60
61 kill -INT [pid $nc_pipe] 5
62 catch { close $nc_pipe } res
63 pass "$TEST_NAME nc server stop"
64 return
65 }
66
67 # "load" generation function for stap_run. It runs a client version
68 # of 'nc' and sends some IPv4 data through it.
69 proc run_ipv4_client {} {
70 global srcdir subdir
71 global IPV4_ONLY
72
73 catch {
74 exec bash -c "cat $srcdir/$subdir/ipaddr.txt > /dev/tcp/127.0.0.1/8079"
75 }
76 return 0
77 }
78
79 # "load" generation function for stap_run. It runs a client version
80 # of 'nc' and sends some IPv6 data through it.
81 proc run_ipv6_client {} {
82 global srcdir subdir
83 global IPV4_ONLY
84
85 if {$IPV4_ONLY} {
86 verbose -log "error: nc only supports IPv4"
87 return 1
88 }
89 catch {
90 exec bash -c "cat $srcdir/$subdir/ipaddr.txt > /dev/tcp/::1/8079"
91 }
92 return 0
93 }
94
95 # Start the 1st IPv4 test
96 set TEST_NAME "${TEST_NAME_BASE}_IPv4_recvmsg"
97 if {[start_nc_server 1]} {
98 # If we couldn't start the server, we're done.
99 return
100 }
101 set script_output "packets = \[0-9\]+\r\naddress errors = 0\r\nbad family errors = 0\r\n"
102 stap_run $TEST_NAME run_ipv4_client $script_output $srcdir/$subdir/ipaddr1.stp
103
104 # Stop/cleanup the IPv4 server.
105 stop_nc_server
106
107 # Start the 2nd IPv4 test
108 set TEST_NAME "${TEST_NAME_BASE}_IPv4_receive"
109 if {[start_nc_server 1]} {
110 # If we couldn't start the server, we're done.
111 return
112 }
113 stap_run $TEST_NAME run_ipv4_client $script_output $srcdir/$subdir/ipaddr2.stp
114
115 # Stop/cleanup the IPv4 server
116 stop_nc_server
117
118 # Start the 1st IPv6 test
119 set TEST_NAME "${TEST_NAME_BASE}_IPv6_recvmsg"
120 if {[start_nc_server 0]} {
121 # If we couldn't start the server, we're done.
122 return
123 }
124 stap_run $TEST_NAME run_ipv6_client $script_output $srcdir/$subdir/ipaddr1.stp
125
126 # Stop/cleanup the IPv6 server.
127 stop_nc_server
128
129 # Start the 2nd IPv6 test
130 set TEST_NAME "${TEST_NAME_BASE}_IPv6_receive"
131 if {[start_nc_server 0]} {
132 # If we couldn't start the server, we're done.
133 return
134 }
135 stap_run $TEST_NAME run_ipv6_client $script_output $srcdir/$subdir/ipaddr2.stp
136
137 # Stop/cleanup the IPv6 server.
138 stop_nc_server