xref: /illumos-gate/usr/src/cmd/dtrace/test/tst/common/ustack/tst.spin.ksh (revision 22a84b8d79248a611e4ba663a268d3c4bed054ac)
1#
2# CDDL HEADER START
3#
4# The contents of this file are subject to the terms of the
5# Common Development and Distribution License (the "License").
6# You may not use this file except in compliance with the License.
7#
8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9# or http://www.opensolaris.org/os/licensing.
10# See the License for the specific language governing permissions
11# and limitations under the License.
12#
13# When distributing Covered Code, include this CDDL HEADER in each
14# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15# If applicable, add the following below this CDDL HEADER, with the
16# fields enclosed by brackets "[]" replaced with your own identifying
17# information: Portions Copyright [yyyy] [name of copyright owner]
18#
19# CDDL HEADER END
20#
21
22#
23# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26#ident	"%Z%%M%	%I%	%E% SMI"
27
28if [ $# != 1 ]; then
29	echo expected one argument: '<'dtrace-path'>'
30	exit 2
31fi
32
33file=out.$$
34dtrace=$1
35
36rm -f $file
37
38dir=`dirname $tst`
39
40$dtrace -o $file -c $dir/tst.spin.exe -s /dev/stdin <<EOF
41
42	#pragma D option quiet
43	#pragma D option destructive
44	#pragma D option evaltime=main
45
46	/*
47	 * Toss out the first 100 samples to wait for the program to enter
48	 * its steady state.
49	 */
50
51	profile-1999
52	/pid == \$target && n++ > 100/
53	{
54		@total = count();
55		@stacks[ustack(4)] = count();
56	}
57
58	tick-1s
59	{
60		secs++;
61	}
62
63	tick-1s
64	/secs > 5/
65	{
66		done = 1;
67	}
68
69	tick-1s
70	/secs > 10/
71	{
72		trace("test timed out");
73		exit(1);
74	}
75
76	profile-1999
77	/pid == \$target && done/
78	{
79		raise(SIGINT);
80		exit(0);
81	}
82
83	END
84	{
85		printa("TOTAL %@u\n", @total);
86		printa("START%kEND\n", @stacks);
87	}
88EOF
89
90status=$?
91if [ "$status" -ne 0 ]; then
92	echo $tst: dtrace failed
93	exit $status
94fi
95
96perl /dev/stdin $file <<EOF
97	\$_ = <>;
98	chomp;
99	die "output problem\n" unless /^TOTAL (\d+)/;
100	\$count = \$1;
101	die "too few samples (\$count)\n" unless \$count >= 1000;
102
103	while (<>) {
104		chomp;
105
106		last if /^$/;
107
108		die "expected START at \$.\n" unless /^START/;
109
110
111		\$_ = <>;
112		chomp;
113		die "expected END at \$.\n" unless /\`baz\+/;
114
115		\$_ = <>;
116		chomp;
117		die "expected END at \$.\n" unless /\`bar\+/;
118
119		\$_ = <>;
120		chomp;
121		die "expected END at \$.\n" unless /\`foo\+/;
122
123		\$_ = <>;
124		chomp;
125		die "expected END at \$.\n" unless /\`main\+/;
126
127		\$_ = <>;
128		chomp;
129		die "expected END at \$.\n" unless /^END\$/;
130	}
131
132EOF
133
134status=$?
135if [ "$status" -eq 0 ]; then
136	rm -f $file
137fi
138
139exit $status
140