tst.trapstat.ksh revision 178476
1255570Strasz#/bin/ksh -p
2255570Strasz#
3255570Strasz# CDDL HEADER START
4255570Strasz#
5255570Strasz# The contents of this file are subject to the terms of the
6255570Strasz# Common Development and Distribution License (the "License").
7255570Strasz# You may not use this file except in compliance with the License.
8255570Strasz#
9255570Strasz# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10255570Strasz# or http://www.opensolaris.org/os/licensing.
11255570Strasz# See the License for the specific language governing permissions
12255570Strasz# and limitations under the License.
13255570Strasz#
14255570Strasz# When distributing Covered Code, include this CDDL HEADER in each
15255570Strasz# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16255570Strasz# If applicable, add the following below this CDDL HEADER, with the
17255570Strasz# fields enclosed by brackets "[]" replaced with your own identifying
18255570Strasz# information: Portions Copyright [yyyy] [name of copyright owner]
19255570Strasz#
20255570Strasz# CDDL HEADER END
21255570Strasz#
22255570Strasz
23255570Strasz#
24255570Strasz# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
25255570Strasz# Use is subject to license terms.
26255570Strasz#
27255570Strasz# ident	"%Z%%M%	%I%	%E% SMI"
28255570Strasz
29255570Strasz#
30255570Strasz# This script verifies that user-land stacks can be walked safely
31255570Strasz# when the trapstat(1M) utility is running. An arbitrary program, w(1),
32255570Strasz# is started once a second to ensure stacks can be walked at all stages
33255570Strasz# of the process lifecycle.
34255570Strasz#
35268682Smav
36268682Smavscript()
37268682Smav{
38268682Smav        $dtrace -o $dtraceout -s /dev/stdin <<EOF
39255570Strasz        fbt:::
40255570Strasz        {
41268685Smav                @[ustackdepth] = count();
42255570Strasz        }
43255570StraszEOF
44255570Strasz}
45255570Strasz
46268682Smavrun_commands()
47268682Smav{
48273319Smav	cnt=0
49268682Smav
50255570Strasz	while [ $cnt -lt 10 ]; do
51255570Strasz		w > /dev/null
52255570Strasz		sleep 1
53255570Strasz		cnt=$(($cnt+1))	
54255570Strasz	done
55255570Strasz}
56255570Strasz
57255570Straszif [ $# != 1 ]; then
58255570Strasz        echo expected one argument: '<'dtrace-path'>'
59255570Strasz        exit 2
60273310Smavfi
61276613Smav
62255570Straszdtrace=$1
63255570Straszdtraceout=/tmp/dtrace.out.$$
64255570Straszscript 2>/dev/null &
65255570Strasztimeout=15
66255570Strasz
67255570Strasz#
68255570Strasz# Sleep while the above script fires into life. To guard against dtrace dying
69255570Strasz# and us sleeping forever we allow 15 secs for this to happen. This should be
70255570Strasz# enough for even the slowest systems.
71255570Strasz#
72255570Straszwhile [ ! -f $dtraceout ]; do
73255570Strasz        sleep 1
74255570Strasz        timeout=$(($timeout-1))
75255570Strasz        if [ $timeout -eq 0 ]; then
76255570Strasz                echo "dtrace failed to start. Exiting."
77255570Strasz                exit 1
78255570Strasz        fi
79255570Straszdone
80255570Strasz
81255570Straszrun_commands &
82255570Strasztrapstat -t 1 10
83255570Straszstatus=$?
84255570Strasz
85268258Smavrm $dtraceout
86268691Smav
87255570Straszexit $status
88255570Strasz