8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / dtrace / test / tst / common / ip / tst.ipv4localtcp.ksh
blob4527940ebf872ee8bbeb1e5628261059ed04919d
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) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 # Test {ip,tcp}:::{send,receive} of IPv4 TCP to local host.
30 # This may fail due to:
32 # 1. A change to the ip stack breaking expected probe behavior,
33 # which is the reason we are testing.
34 # 2. The lo0 interface missing or not up.
35 # 3. The local ssh service is not online.
36 # 4. An unlikely race causes the unlocked global send/receive
37 # variables to be corrupted.
39 # This test performs a TCP connection and checks that at least the
40 # following packet counts were traced:
42 # 3 x ip:::send (2 during the TCP handshake, then a FIN)
43 # 3 x tcp:::send (2 during the TCP handshake, then a FIN)
44 # 2 x ip:::receive (1 during the TCP handshake, then the FIN ACK)
45 # 2 x tcp:::receive (1 during the TCP handshake, then the FIN ACK)
47 # The actual count tested is 5 each way, since we are tracing both
48 # source and destination events.
50 # For this test to work, we are assuming that the TCP handshake and
51 # TCP close will enter the IP code path and not use tcp fusion.
54 if (( $# != 1 )); then
55 print -u2 "expected one argument: <dtrace-path>"
56 exit 2
59 dtrace=$1
60 local=127.0.0.1
61 tcpport=22
62 DIR=/var/tmp/dtest.$$
64 mkdir $DIR
65 cd $DIR
67 cat > test.pl <<-EOPERL
68 use IO::Socket;
69 my \$s = IO::Socket::INET->new(
70 Proto => "tcp",
71 PeerAddr => "$local",
72 PeerPort => $tcpport,
73 Timeout => 3);
74 die "Could not connect to host $local port $tcpport" unless \$s;
75 close \$s;
76 EOPERL
78 $dtrace -c 'perl test.pl' -qs /dev/stdin <<EODTRACE
79 BEGIN
81 ipsend = tcpsend = ipreceive = tcpreceive = 0;
84 ip:::send
85 /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
86 args[4]->ipv4_protocol == IPPROTO_TCP/
88 ipsend++;
91 tcp:::send
92 /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local"/
94 tcpsend++;
97 ip:::receive
98 /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local" &&
99 args[4]->ipv4_protocol == IPPROTO_TCP/
101 ipreceive++;
104 tcp:::receive
105 /args[2]->ip_saddr == "$local" && args[2]->ip_daddr == "$local"/
107 tcpreceive++;
112 printf("Minimum TCP events seen\n\n");
113 printf("ip:::send - %s\n", ipsend >= 5 ? "yes" : "no");
114 printf("ip:::receive - %s\n", ipreceive >= 5 ? "yes" : "no");
115 printf("tcp:::send - %s\n", tcpsend >= 5 ? "yes" : "no");
116 printf("tcp:::receive - %s\n", tcpreceive >= 5 ? "yes" : "no");
118 EODTRACE
120 status=$?
122 cd /
123 /usr/bin/rm -rf $DIR
125 exit $status