xref: /onnv-gate/usr/src/cmd/dtrace/test/tst/common/ustack/tst.spin.ksh (revision 2804:e8e3422f18c2)
12633Sahl#
22633Sahl# CDDL HEADER START
32633Sahl#
42633Sahl# The contents of this file are subject to the terms of the
52633Sahl# Common Development and Distribution License (the "License").
62633Sahl# You may not use this file except in compliance with the License.
72633Sahl#
82633Sahl# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
92633Sahl# or http://www.opensolaris.org/os/licensing.
102633Sahl# See the License for the specific language governing permissions
112633Sahl# and limitations under the License.
122633Sahl#
132633Sahl# When distributing Covered Code, include this CDDL HEADER in each
142633Sahl# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
152633Sahl# If applicable, add the following below this CDDL HEADER, with the
162633Sahl# fields enclosed by brackets "[]" replaced with your own identifying
172633Sahl# information: Portions Copyright [yyyy] [name of copyright owner]
182633Sahl#
192633Sahl# CDDL HEADER END
202633Sahl#
212633Sahl
222633Sahl#
232633Sahl# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
242633Sahl# Use is subject to license terms.
252633Sahl#
262633Sahl#ident	"%Z%%M%	%I%	%E% SMI"
272633Sahl
28*2804Stomeeif [ $# != 1 ]; then
29*2804Stomee	echo expected one argument: '<'dtrace-path'>'
30*2804Stomee	exit 2
31*2804Stomeefi
32*2804Stomee
332633Sahlfile=out.$$
34*2804Stomeedtrace=$1
352633Sahl
362633Sahlrm -f $file
372633Sahl
382633Sahldir=`dirname $tst`
392633Sahl
402633Sahl$dtrace -o $file -c $dir/tst.spin.exe -s /dev/stdin <<EOF
412633Sahl
422633Sahl	#pragma D option quiet
432633Sahl	#pragma D option destructive
442633Sahl	#pragma D option evaltime=main
452633Sahl
462633Sahl	/*
472633Sahl	 * Toss out the first 100 samples to wait for the program to enter
482633Sahl	 * its steady state.
492633Sahl	 */
502633Sahl
512633Sahl	profile-1999
522633Sahl	/pid == \$target && n++ > 100/
532633Sahl	{
542633Sahl		@total = count();
552633Sahl		@stacks[ustack(4)] = count();
562633Sahl	}
572633Sahl
582633Sahl	tick-1s
592633Sahl	{
602633Sahl		secs++;
612633Sahl	}
622633Sahl
632633Sahl	tick-1s
642633Sahl	/secs > 5/
652633Sahl	{
662633Sahl		done = 1;
672633Sahl	}
682633Sahl
692633Sahl	tick-1s
702633Sahl	/secs > 10/
712633Sahl	{
722633Sahl		trace("test timed out");
732633Sahl		exit(1);
742633Sahl	}
752633Sahl
762633Sahl	profile-1999
772633Sahl	/pid == \$target && done/
782633Sahl	{
792633Sahl		raise(SIGINT);
802633Sahl		exit(0);
812633Sahl	}
822633Sahl
832633Sahl	END
842633Sahl	{
852633Sahl		printa("TOTAL %@u\n", @total);
862633Sahl		printa("START%kEND\n", @stacks);
872633Sahl	}
882633SahlEOF
892633Sahl
902633Sahlstatus=$?
912633Sahlif [ "$status" -ne 0 ]; then
922633Sahl	echo $tst: dtrace failed
932633Sahl	exit $status
942633Sahlfi
952633Sahl
962633Sahlperl /dev/stdin $file <<EOF
972633Sahl	\$_ = <>;
982633Sahl	chomp;
992633Sahl	die "output problem\n" unless /^TOTAL (\d+)/;
1002633Sahl	\$count = \$1;
1012633Sahl	die "too few samples (\$count)\n" unless \$count >= 1000;
1022633Sahl
1032633Sahl	while (<>) {
1042633Sahl		chomp;
1052633Sahl
1062633Sahl		last if /^$/;
1072633Sahl
1082633Sahl		die "expected START at \$.\n" unless /^START/;
1092633Sahl
1102633Sahl
1112633Sahl		\$_ = <>;
1122633Sahl		chomp;
1132633Sahl		die "expected END at \$.\n" unless /\`baz\+/;
1142633Sahl
1152633Sahl		\$_ = <>;
1162633Sahl		chomp;
1172633Sahl		die "expected END at \$.\n" unless /\`bar\+/;
1182633Sahl
1192633Sahl		\$_ = <>;
1202633Sahl		chomp;
1212633Sahl		die "expected END at \$.\n" unless /\`foo\+/;
1222633Sahl
1232633Sahl		\$_ = <>;
1242633Sahl		chomp;
1252633Sahl		die "expected END at \$.\n" unless /\`main\+/;
1262633Sahl
1272633Sahl		\$_ = <>;
1282633Sahl		chomp;
1292633Sahl		die "expected END at \$.\n" unless /^END\$/;
1302633Sahl	}
1312633Sahl
1322633SahlEOF
1332633Sahl
1342633Sahlstatus=$?
1352633Sahlif [ "$status" -eq 0 ]; then
1362633Sahl	rm -f $file
1372633Sahlfi
1382633Sahl
1392633Sahlexit $status
140