1453 dtest should fail if dependencies are missing
[illumos-gate.git] / usr / src / cmd / dtrace / test / tst / common / ip / tst.localtcpstate.ksh
blob9f730754950bf6508216d6af051af6c9d2f7c362
1 #!/usr/bin/ksh
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
20 # CDDL HEADER END
24 # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
28 # Test tcp:::state-change and tcp:::{send,receive} by connecting to
29 # the local ssh service and sending a test message. This should result
30 # in a "Protocol mismatch" response and a close of the connection.
31 # A number of state transition events along with tcp fusion send and
32 # receive events for the message should result.
34 # This may fail due to:
36 # 1. A change to the ip stack breaking expected probe behavior,
37 # which is the reason we are testing.
38 # 2. The lo0 interface missing or not up.
39 # 3. The local ssh service is not online.
40 # 4. An unlikely race causes the unlocked global send/receive
41 # variables to be corrupted.
43 # This test performs a TCP connection to the ssh service (port 22) and
44 # checks that at least the following packet counts were traced:
46 # 3 x ip:::send (2 during the TCP handshake, then a FIN)
47 # 4 x tcp:::send (2 during the TCP handshake, 1 message then a FIN)
48 # 2 x ip:::receive (1 during the TCP handshake, then the FIN ACK)
49 # 3 x tcp:::receive (1 during the TCP handshake, 1 message then the FIN ACK)
51 # The actual ip count tested is 5 each way, since we are tracing both
52 # source and destination events. The actual tcp count tested is 7
53 # each way, since the TCP fusion send/receive events will not reach IP.
55 # For this test to work, we are assuming that the TCP handshake and
56 # TCP close will enter the IP code path and not use tcp fusion.
59 if (( $# != 1 )); then
60 print -u2 "expected one argument: <dtrace-path>"
61 exit 2
64 dtrace=$1
65 local=127.0.0.1
66 tcpport=22
67 DIR=/var/tmp/dtest.$$
69 mkdir $DIR
70 cd $DIR
72 cat > test.pl <<-EOPERL
73 use IO::Socket;
74 my \$s = IO::Socket::INET->new(
75 Proto => "tcp",
76 PeerAddr => "$local",
77 PeerPort => $tcpport,
78 Timeout => 3);
79 die "Could not connect to host $local port $tcpport" unless \$s;
80 print \$s "testing state machine transitions";
81 close \$s;
82 EOPERL
84 $dtrace -c 'perl test.pl' -qs /dev/stdin <<EODTRACE
85 BEGIN
87 ipsend = tcpsend = ipreceive = tcpreceive = 0;
88 connreq = connest = connaccept = 0;
91 ip:::send
92 /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
93 args[4]->ipv4_protocol == IPPROTO_TCP/
95 ipsend++;
98 tcp:::send
99 /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
100 (args[4]->tcp_sport == $tcpport || args[4]->tcp_dport == $tcpport)/
102 tcpsend++;
105 ip:::receive
106 /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
107 args[4]->ipv4_protocol == IPPROTO_TCP/
109 ipreceive++;
112 tcp:::receive
113 /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
114 (args[4]->tcp_sport == $tcpport || args[4]->tcp_dport == $tcpport)/
116 tcpreceive++;
119 tcp:::state-change
121 state_event[args[3]->tcps_state]++;
124 tcp:::connect-request
125 /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
126 args[4]->tcp_dport == $tcpport/
128 connreq++;
131 tcp:::connect-established
132 /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
133 args[4]->tcp_sport == $tcpport/
135 connest++;
138 tcp:::accept-established
139 /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
140 args[4]->tcp_dport == $tcpport/
142 connaccept++;
147 printf("Minimum TCP events seen\n\n");
148 printf("ip:::send - %s\n", ipsend >= 5 ? "yes" : "no");
149 printf("ip:::receive - %s\n", ipreceive >= 5 ? "yes" : "no");
150 printf("tcp:::send - %s\n", tcpsend >= 7 ? "yes" : "no");
151 printf("tcp:::receive - %s\n", tcpreceive >= 7 ? "yes" : "no");
152 printf("tcp:::state-change to syn-sent - %s\n",
153 state_event[TCP_STATE_SYN_SENT] >=1 ? "yes" : "no");
154 printf("tcp:::state-change to syn-received - %s\n",
155 state_event[TCP_STATE_SYN_RECEIVED] >=1 ? "yes" : "no");
156 printf("tcp:::state-change to established - %s\n",
157 state_event[TCP_STATE_ESTABLISHED] >= 2 ? "yes" : "no");
158 printf("tcp:::state-change to fin-wait-1 - %s\n",
159 state_event[TCP_STATE_FIN_WAIT_1] >= 1 ? "yes" : "no");
160 printf("tcp:::state-change to close-wait - %s\n",
161 state_event[TCP_STATE_CLOSE_WAIT] >= 1 ? "yes" : "no");
162 printf("tcp:::state-change to fin-wait-2 - %s\n",
163 state_event[TCP_STATE_FIN_WAIT_2] >= 1 ? "yes" : "no");
164 printf("tcp:::state-change to last-ack - %s\n",
165 state_event[TCP_STATE_LAST_ACK] >= 1 ? "yes" : "no");
166 printf("tcp:::state-change to time-wait - %s\n",
167 state_event[TCP_STATE_TIME_WAIT] >= 1 ? "yes" : "no");
168 printf("tcp:::connect-request - %s\n",
169 connreq >=1 ? "yes" : "no");
170 printf("tcp:::connect-established - %s\n",
171 connest >=1 ? "yes" : "no");
172 printf("tcp:::accept-established - %s\n",
173 connaccept >=1 ? "yes" : "no");
175 EODTRACE
177 status=$?
179 cd /
180 /usr/bin/rm -rf $DIR
182 exit $status