xref: /freebsd-src/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/misc/tst.dofmax.ksh (revision 6cec9cad762b6476313fb1f8e931a1647822db6b)
1*ae9f1a18SMark Johnston#
2*ae9f1a18SMark Johnston# CDDL HEADER START
3*ae9f1a18SMark Johnston#
4*ae9f1a18SMark Johnston# The contents of this file are subject to the terms of the
5*ae9f1a18SMark Johnston# Common Development and Distribution License (the "License").
6*ae9f1a18SMark Johnston# You may not use this file except in compliance with the License.
7*ae9f1a18SMark Johnston#
8*ae9f1a18SMark Johnston# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*ae9f1a18SMark Johnston# or http://www.opensolaris.org/os/licensing.
10*ae9f1a18SMark Johnston# See the License for the specific language governing permissions
11*ae9f1a18SMark Johnston# and limitations under the License.
12*ae9f1a18SMark Johnston#
13*ae9f1a18SMark Johnston# When distributing Covered Code, include this CDDL HEADER in each
14*ae9f1a18SMark Johnston# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*ae9f1a18SMark Johnston# If applicable, add the following below this CDDL HEADER, with the
16*ae9f1a18SMark Johnston# fields enclosed by brackets "[]" replaced with your own identifying
17*ae9f1a18SMark Johnston# information: Portions Copyright [yyyy] [name of copyright owner]
18*ae9f1a18SMark Johnston#
19*ae9f1a18SMark Johnston# CDDL HEADER END
20*ae9f1a18SMark Johnston#
21*ae9f1a18SMark Johnston
22*ae9f1a18SMark Johnston#
23*ae9f1a18SMark Johnston# Copyright (c) 2012, Joyent, Inc. All rights reserved.
24*ae9f1a18SMark Johnston#
25*ae9f1a18SMark Johnston
26*ae9f1a18SMark Johnstonlet j=8
27*ae9f1a18SMark Johnston
28*ae9f1a18SMark Johnstonenable()
29*ae9f1a18SMark Johnston{
30*ae9f1a18SMark Johnston	prog=/var/tmp/dtest.$$.d
31*ae9f1a18SMark Johnston	err=/var/tmp/dtest.$$.err
32*ae9f1a18SMark Johnston
33*ae9f1a18SMark Johnston	nawk -v nprobes=$1 'BEGIN { \
34*ae9f1a18SMark Johnston		for (i = 0; i < nprobes - 1; i++) { 		\
35*ae9f1a18SMark Johnston			printf("dtrace:::BEGIN,\n");		\
36*ae9f1a18SMark Johnston		}						\
37*ae9f1a18SMark Johnston								\
38*ae9f1a18SMark Johnston		printf("dtrace:::BEGIN { exit(0); }\n");	\
39*ae9f1a18SMark Johnston	}' /dev/null > $prog
40*ae9f1a18SMark Johnston
41*ae9f1a18SMark Johnston	dtrace -qs $prog > /dev/null 2> $err
42*ae9f1a18SMark Johnston
43*ae9f1a18SMark Johnston	if [[ "$?" -eq 0 ]]; then
44*ae9f1a18SMark Johnston		return 0
45*ae9f1a18SMark Johnston	else
46*ae9f1a18SMark Johnston		if ! grep "DIF program exceeds maximum program size" $err \
47*ae9f1a18SMark Johnston		    1> /dev/null 2>&1 ; then
48*ae9f1a18SMark Johnston			echo "failed to enable $prog: `cat $err`"
49*ae9f1a18SMark Johnston			exit 1
50*ae9f1a18SMark Johnston		fi
51*ae9f1a18SMark Johnston
52*ae9f1a18SMark Johnston		return 1
53*ae9f1a18SMark Johnston	fi
54*ae9f1a18SMark Johnston}
55*ae9f1a18SMark Johnston
56*ae9f1a18SMark Johnston#
57*ae9f1a18SMark Johnston# First, establish an upper bound
58*ae9f1a18SMark Johnston#
59*ae9f1a18SMark Johnstonlet upper=1
60*ae9f1a18SMark Johnston
61*ae9f1a18SMark Johnstonwhile enable $upper ; do
62*ae9f1a18SMark Johnston	let lower=upper
63*ae9f1a18SMark Johnston	let upper=upper+upper
64*ae9f1a18SMark Johnston	echo success at $lower, raised to $upper
65*ae9f1a18SMark Johnstondone
66*ae9f1a18SMark Johnston
67*ae9f1a18SMark Johnston#
68*ae9f1a18SMark Johnston# Now search for the highest value that can be enabled
69*ae9f1a18SMark Johnston#
70*ae9f1a18SMark Johnstonwhile [[ "$lower" -lt "$upper" ]]; do
71*ae9f1a18SMark Johnston	let guess=$(((lower + upper) / 2))
72*ae9f1a18SMark Johnston	echo "lower is $lower; upper is $upper; guess is $guess\c"
73*ae9f1a18SMark Johnston
74*ae9f1a18SMark Johnston	if enable $guess ; then
75*ae9f1a18SMark Johnston		if [[ $((upper - lower)) -le 2 ]]; then
76*ae9f1a18SMark Johnston			let upper=guess
77*ae9f1a18SMark Johnston		fi
78*ae9f1a18SMark Johnston
79*ae9f1a18SMark Johnston		echo " (success)"
80*ae9f1a18SMark Johnston		let lower=guess
81*ae9f1a18SMark Johnston	else
82*ae9f1a18SMark Johnston		echo " (failure)"
83*ae9f1a18SMark Johnston		let upper=guess
84*ae9f1a18SMark Johnston	fi
85*ae9f1a18SMark Johnstondone
86*ae9f1a18SMark Johnston
87*ae9f1a18SMark Johnstonlet expected=10000
88*ae9f1a18SMark Johnston
89*ae9f1a18SMark Johnstonif [[ "$lower" -lt "$expected" ]]; then
90*ae9f1a18SMark Johnston	echo "expected support for enablings of at least $expected probes; \c"
91*ae9f1a18SMark Johnston	echo "found $lower"
92*ae9f1a18SMark Johnston	exit 1
93*ae9f1a18SMark Johnstonfi
94*ae9f1a18SMark Johnston
95*ae9f1a18SMark Johnstonecho "maximum supported enabled probes found to be $lower"
96*ae9f1a18SMark Johnstonexit 0
97*ae9f1a18SMark Johnston
98