tst.enabled2.ksh revision 288413
1166124Srafan#
250276Speter# CDDL HEADER START
3166124Srafan#
4166124Srafan# The contents of this file are subject to the terms of the
5166124Srafan# Common Development and Distribution License (the "License").
6166124Srafan# You may not use this file except in compliance with the License.
750276Speter#
862449Speter# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9166124Srafan# or http://www.opensolaris.org/os/licensing.
10166124Srafan# See the License for the specific language governing permissions
11166124Srafan# and limitations under the License.
1262449Speter#
13166124Srafan# When distributing Covered Code, include this CDDL HEADER in each
14166124Srafan# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15166124Srafan# If applicable, add the following below this CDDL HEADER, with the
16166124Srafan# fields enclosed by brackets "[]" replaced with your own identifying
1762449Speter# information: Portions Copyright [yyyy] [name of copyright owner]
1850276Speter#
19166124Srafan# CDDL HEADER END
20166124Srafan#
2150276Speter
2262449Speter#
23166124Srafan# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24166124Srafan# Use is subject to license terms.
25166124Srafan#
2662449Speter#ident	"%Z%%M%	%I%	%E% SMI"
2750276Speter
2862449Speter#
29166124Srafan# This test is primarily intended to verify a fix for SPARC, but there's no
30166124Srafan# harm in running it on other platforms. Here, we verify that is-enabled
31166124Srafan# probes don't interfere with return values from previously invoked functions.
32166124Srafan#
3362449Speter
3450276Speterif [ $# != 1 ]; then
35166124Srafan	echo expected one argument: '<'dtrace-path'>'
36166124Srafan	exit 2
37166124Srafanfi
38166124Srafan
39166124Srafandtrace=$1
4062449SpeterDIR=/var/tmp/dtest.$$
4176726Speter
42166124Srafanmkdir $DIR
43166124Srafancd $DIR
44166124Srafan
45166124Srafancat > prov.d <<EOF
46166124Srafanprovider test_prov {
47166124Srafan	probe go();
48166124Srafan};
49166124SrafanEOF
50166124Srafan
51166124Srafan$dtrace -h -s prov.d
52166124Srafanif [ $? -ne 0 ]; then
53166124Srafan	print -u2 "failed to generate header file"
54166124Srafan	exit 1
55166124Srafanfi
56166124Srafan
57166124Srafancat > test.c <<EOF
58166124Srafan#include <stdio.h>
59166124Srafan#include "prov.h"
60166124Srafan
61166124Srafanint
62166124Srafanfoo(void)
63166124Srafan{
64166124Srafan	return (24);
65166124Srafan}
66166124Srafan
67166124Srafanint
68166124Srafanmain(int argc, char **argv)
69166124Srafan{
70166124Srafan	int a = foo();
71166124Srafan	if (TEST_PROV_GO_ENABLED()) {
72166124Srafan		TEST_PROV_GO();
73166124Srafan	}
74166124Srafan	(void) printf("%d %d %d\n", a, a, a);
75166124Srafan
76166124Srafan	return (0);
77166124Srafan}
78166124SrafanEOF
79166124Srafan
80166124Srafancc -c -xO2 test.c
81166124Srafanif [ $? -ne 0 ]; then
82166124Srafan	print -u2 "failed to compile test.c"
83166124Srafan	exit 1
84166124Srafanfi
85166124Srafan$dtrace -G -s prov.d test.o
86166124Srafanif [ $? -ne 0 ]; then
87166124Srafan	print -u2 "failed to create DOF"
88166124Srafan	exit 1
89166124Srafanfi
90166124Srafancc -o test test.o prov.o
91166124Srafanif [ $? -ne 0 ]; then
92166124Srafan	print -u2 "failed to link final executable"
93166124Srafan	exit 1
94166124Srafanfi
95166124Srafan
96166124Srafanscript()
97166124Srafan{
98166124Srafan	./test
99166124Srafan
100166124Srafan	$dtrace -c ./test -qs /dev/stdin <<EOF
101166124Srafan	test_prov\$target:::
102166124Srafan	{
103166124Srafan	}
104166124SrafanEOF
105166124Srafan}
106166124Srafan
107166124Srafanscript
108166124Srafanstatus=$?
109166124Srafan
110166124Srafancd /
111166124Srafan/bin/rm -rf $DIR
11262449Speter
11350276Speterexit $status
114166124Srafan