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