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