1ac20c57jhaslam#/bin/ksh -p
2ac20c57jhaslam#
3ac20c57jhaslam# CDDL HEADER START
4ac20c57jhaslam#
5ac20c57jhaslam# The contents of this file are subject to the terms of the
6ac20c57jhaslam# Common Development and Distribution License (the "License").
7ac20c57jhaslam# You may not use this file except in compliance with the License.
8ac20c57jhaslam#
9ac20c57jhaslam# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10ac20c57jhaslam# or http://www.opensolaris.org/os/licensing.
11ac20c57jhaslam# See the License for the specific language governing permissions
12ac20c57jhaslam# and limitations under the License.
13ac20c57jhaslam#
14ac20c57jhaslam# When distributing Covered Code, include this CDDL HEADER in each
15ac20c57jhaslam# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16ac20c57jhaslam# If applicable, add the following below this CDDL HEADER, with the
17ac20c57jhaslam# fields enclosed by brackets "[]" replaced with your own identifying
18ac20c57jhaslam# information: Portions Copyright [yyyy] [name of copyright owner]
19ac20c57jhaslam#
20ac20c57jhaslam# CDDL HEADER END
21ac20c57jhaslam#
22ac20c57jhaslam
23ac20c57jhaslam#
24ac20c57jhaslam# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
25ac20c57jhaslam# Use is subject to license terms.
26ac20c57jhaslam#
27ac20c57jhaslam# ident	"%Z%%M%	%I%	%E% SMI"
28ac20c57jhaslam
29ac20c57jhaslam#
30ac20c57jhaslam# This script verifies that user-land stacks can be walked safely
31ac20c57jhaslam# when the trapstat(1M) utility is running. An arbitrary program, w(1),
32ac20c57jhaslam# is started once a second to ensure stacks can be walked at all stages
33ac20c57jhaslam# of the process lifecycle.
34ac20c57jhaslam#
35ac20c57jhaslam
36ac20c57jhaslamscript()
37ac20c57jhaslam{
38ac20c57jhaslam        $dtrace -o $dtraceout -s /dev/stdin <<EOF
39ac20c57jhaslam        fbt:::
40ac20c57jhaslam        {
41ac20c57jhaslam                @[ustackdepth] = count();
42ac20c57jhaslam        }
43ac20c57jhaslamEOF
44ac20c57jhaslam}
45ac20c57jhaslam
46ac20c57jhaslamrun_commands()
47ac20c57jhaslam{
48ac20c57jhaslam	cnt=0
49ac20c57jhaslam
50ac20c57jhaslam	while [ $cnt -lt 10 ]; do
51ac20c57jhaslam		w > /dev/null
52ac20c57jhaslam		sleep 1
53ac20c57jhaslam		cnt=$(($cnt+1))	
54ac20c57jhaslam	done
55ac20c57jhaslam}
56ac20c57jhaslam
57ac20c57jhaslamif [ $# != 1 ]; then
58ac20c57jhaslam        echo expected one argument: '<'dtrace-path'>'
59ac20c57jhaslam        exit 2
60ac20c57jhaslamfi
61ac20c57jhaslam
62ac20c57jhaslamdtrace=$1
63ac20c57jhaslamdtraceout=/tmp/dtrace.out.$$
64ac20c57jhaslamscript 2>/dev/null &
65ac20c57jhaslamtimeout=15
66ac20c57jhaslam
67ac20c57jhaslam#
68ac20c57jhaslam# Sleep while the above script fires into life. To guard against dtrace dying
69ac20c57jhaslam# and us sleeping forever we allow 15 secs for this to happen. This should be
70ac20c57jhaslam# enough for even the slowest systems.
71ac20c57jhaslam#
72ac20c57jhaslamwhile [ ! -f $dtraceout ]; do
73ac20c57jhaslam        sleep 1
74ac20c57jhaslam        timeout=$(($timeout-1))
75ac20c57jhaslam        if [ $timeout -eq 0 ]; then
76ac20c57jhaslam                echo "dtrace failed to start. Exiting."
77ac20c57jhaslam                exit 1
78ac20c57jhaslam        fi
79ac20c57jhaslamdone
80ac20c57jhaslam
81ac20c57jhaslamrun_commands &
82ac20c57jhaslamtrapstat -t 1 10
83ac20c57jhaslamstatus=$?
84ac20c57jhaslam
85ac20c57jhaslamrm $dtraceout
86ac20c57jhaslam
87ac20c57jhaslamexit $status
88