xref: /freebsd-src/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/cpc/err.cputrackfailtostart.ksh (revision 1670a1c2a47d10ecccd001970b859caf93cd3b6e)
1*1670a1c2SRui Paulo#!/bin/ksh
2*1670a1c2SRui Paulo#
3*1670a1c2SRui Paulo# CDDL HEADER START
4*1670a1c2SRui Paulo#
5*1670a1c2SRui Paulo# The contents of this file are subject to the terms of the
6*1670a1c2SRui Paulo# Common Development and Distribution License (the "License").
7*1670a1c2SRui Paulo# You may not use this file except in compliance with the License.
8*1670a1c2SRui Paulo#
9*1670a1c2SRui Paulo# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*1670a1c2SRui Paulo# or http://www.opensolaris.org/os/licensing.
11*1670a1c2SRui Paulo# See the License for the specific language governing permissions
12*1670a1c2SRui Paulo# and limitations under the License.
13*1670a1c2SRui Paulo#
14*1670a1c2SRui Paulo# When distributing Covered Code, include this CDDL HEADER in each
15*1670a1c2SRui Paulo# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*1670a1c2SRui Paulo# If applicable, add the following below this CDDL HEADER, with the
17*1670a1c2SRui Paulo# fields enclosed by brackets "[]" replaced with your own identifying
18*1670a1c2SRui Paulo# information: Portions Copyright [yyyy] [name of copyright owner]
19*1670a1c2SRui Paulo#
20*1670a1c2SRui Paulo# CDDL HEADER END
21*1670a1c2SRui Paulo#
22*1670a1c2SRui Paulo
23*1670a1c2SRui Paulo#
24*1670a1c2SRui Paulo# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25*1670a1c2SRui Paulo# Use is subject to license terms.
26*1670a1c2SRui Paulo
27*1670a1c2SRui Paulo#
28*1670a1c2SRui Paulo# This script ensures that cputrack(1M) will fail to start when the cpc
29*1670a1c2SRui Paulo# provider has active enablings.
30*1670a1c2SRui Paulo#
31*1670a1c2SRui Paulo# The script will fail if:
32*1670a1c2SRui Paulo#	1) The system under test does not define the 'PAPI_tot_ins' event.
33*1670a1c2SRui Paulo#
34*1670a1c2SRui Paulo
35*1670a1c2SRui Pauloscript()
36*1670a1c2SRui Paulo{
37*1670a1c2SRui Paulo        $dtrace -o $dtraceout -s /dev/stdin <<EOF
38*1670a1c2SRui Paulo        #pragma D option bufsize=128k
39*1670a1c2SRui Paulo
40*1670a1c2SRui Paulo        cpc:::PAPI_tot_ins-all-10000
41*1670a1c2SRui Paulo        {
42*1670a1c2SRui Paulo                @[probename] = count();
43*1670a1c2SRui Paulo        }
44*1670a1c2SRui PauloEOF
45*1670a1c2SRui Paulo}
46*1670a1c2SRui Paulo
47*1670a1c2SRui Paulo
48*1670a1c2SRui Pauloif [ $# != 1 ]; then
49*1670a1c2SRui Paulo        echo expected one argument: '<'dtrace-path'>'
50*1670a1c2SRui Paulo        exit 2
51*1670a1c2SRui Paulofi
52*1670a1c2SRui Paulo
53*1670a1c2SRui Paulodtrace=$1
54*1670a1c2SRui Paulodtraceout=/tmp/dtrace.out.$$
55*1670a1c2SRui Pauloscript 2>/dev/null &
56*1670a1c2SRui Paulotimeout=15
57*1670a1c2SRui Paulo
58*1670a1c2SRui Paulo#
59*1670a1c2SRui Paulo# Sleep while the above script fires into life. To guard against dtrace dying
60*1670a1c2SRui Paulo# and us sleeping forever we allow 15 secs for this to happen. This should be
61*1670a1c2SRui Paulo# enough for even the slowest systems.
62*1670a1c2SRui Paulo#
63*1670a1c2SRui Paulowhile [ ! -f $dtraceout ]; do
64*1670a1c2SRui Paulo        sleep 1
65*1670a1c2SRui Paulo        timeout=$(($timeout-1))
66*1670a1c2SRui Paulo        if [ $timeout -eq 0 ]; then
67*1670a1c2SRui Paulo                echo "dtrace failed to start. Exiting."
68*1670a1c2SRui Paulo                exit 1
69*1670a1c2SRui Paulo        fi
70*1670a1c2SRui Paulodone
71*1670a1c2SRui Paulo
72*1670a1c2SRui Paulocputrack -c PAPI_tot_ins sleep 10
73*1670a1c2SRui Paulostatus=$?
74*1670a1c2SRui Paulo
75*1670a1c2SRui Paulorm $dtraceout
76*1670a1c2SRui Paulo
77*1670a1c2SRui Pauloexit $status
78