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