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	"@(#)tst.spin.ksh	1.1	06/08/28 SMI"
27
28file=out.$$
29dtrace=/usr/sbin/dtrace
30
31rm -f $file
32
33if [ -f /usr/lib/dtrace/darwin.d ]; then
34dir=`pwd`
35evt=preinit
36else
37dir=`dirname $tst`
38evt=main
39fi
40
41$dtrace -o $file -c $dir/tst.spin.exe -s /dev/stdin <<EOF
42
43	#pragma D option quiet
44	#pragma D option destructive
45	#pragma D option evaltime=$evt
46
47	/*
48	 * Toss out the first 100 samples to wait for the program to enter
49	 * its steady state.
50	 */
51
52	profile-1999
53	/pid == \$target && n++ > 100/
54	{
55		@total = count();
56		@stacks[ustack(4)] = count();
57	}
58
59	tick-1s
60	{
61		secs++;
62	}
63
64	tick-1s
65	/secs > 5/
66	{
67		done = 1;
68	}
69
70	tick-1s
71	/secs > 10/
72	{
73		trace("test timed out");
74		exit(1);
75	}
76
77	profile-1999
78	/pid == \$target && done/
79	{
80		raise(SIGINT);
81		exit(0);
82	}
83
84	END
85	{
86		printa("TOTAL %@u\n", @total);
87		printa("START%kEND\n", @stacks);
88	}
89EOF
90
91status=$?
92if [ "$status" -ne 0 ]; then
93	echo $tst: dtrace failed
94	exit $status
95fi
96
97perl /dev/stdin $file <<EOF
98	\$_ = <>;
99	chomp;
100	die "output problem\n" unless /^TOTAL (\d+)/;
101	\$count = \$1;
102	die "too few samples (\$count)\n" unless \$count >= 1000;
103
104	while (<>) {
105		chomp;
106
107		last if /^$/;
108
109		die "expected START at \$.\n" unless /^START/;
110
111
112		\$_ = <>;
113		chomp;
114		die "expected END at \$.\n" unless /\`baz\+/;
115
116		\$_ = <>;
117		chomp;
118		die "expected END at \$.\n" unless /\`bar\+/;
119
120		\$_ = <>;
121		chomp;
122		die "expected END at \$.\n" unless /\`foo\+/;
123
124		\$_ = <>;
125		chomp;
126		die "expected END at \$.\n" unless /\`main\+/;
127
128		\$_ = <>;
129		chomp;
130		die "expected END at \$.\n" unless /^END\$/;
131	}
132
133EOF
134
135status=$?
136if [ "$status" -eq 0 ]; then
137	rm -f $file
138fi
139
140exit $status
141