1210753Srpaulo#
2210753Srpaulo# CDDL HEADER START
3210753Srpaulo#
4210753Srpaulo# The contents of this file are subject to the terms of the
5210753Srpaulo# Common Development and Distribution License (the "License").
6210753Srpaulo# You may not use this file except in compliance with the License.
7210753Srpaulo#
8210753Srpaulo# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9210753Srpaulo# or http://www.opensolaris.org/os/licensing.
10210753Srpaulo# See the License for the specific language governing permissions
11210753Srpaulo# and limitations under the License.
12210753Srpaulo#
13210753Srpaulo# When distributing Covered Code, include this CDDL HEADER in each
14210753Srpaulo# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15210753Srpaulo# If applicable, add the following below this CDDL HEADER, with the
16210753Srpaulo# fields enclosed by brackets "[]" replaced with your own identifying
17210753Srpaulo# information: Portions Copyright [yyyy] [name of copyright owner]
18210753Srpaulo#
19210753Srpaulo# CDDL HEADER END
20210753Srpaulo#
21210753Srpaulo
22210753Srpaulo#
23210753Srpaulo# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24210753Srpaulo# Use is subject to license terms.
25210753Srpaulo#
26210753Srpaulo#ident	"%Z%%M%	%I%	%E% SMI"
27210753Srpaulo
28210753Srpaulo#
29210753Srpaulo# This test is primarily intended to verify a fix for SPARC, but there's no
30210753Srpaulo# harm in running it on other platforms. Here, we verify that is-enabled
31210753Srpaulo# probes don't interfere with return values from previously invoked functions.
32210753Srpaulo#
33210753Srpaulo
34210753Srpauloif [ $# != 1 ]; then
35210753Srpaulo	echo expected one argument: '<'dtrace-path'>'
36210753Srpaulo	exit 2
37210753Srpaulofi
38210753Srpaulo
39210753Srpaulodtrace=$1
40210753SrpauloDIR=/var/tmp/dtest.$$
41210753Srpaulo
42210753Srpaulomkdir $DIR
43210753Srpaulocd $DIR
44210753Srpaulo
45210753Srpaulocat > prov.d <<EOF
46210753Srpauloprovider test_prov {
47210753Srpaulo	probe go();
48210753Srpaulo};
49210753SrpauloEOF
50210753Srpaulo
51210753Srpaulo$dtrace -h -s prov.d
52210753Srpauloif [ $? -ne 0 ]; then
53210753Srpaulo	print -u2 "failed to generate header file"
54210753Srpaulo	exit 1
55210753Srpaulofi
56210753Srpaulo
57210753Srpaulocat > test.c <<EOF
58210753Srpaulo#include <stdio.h>
59210753Srpaulo#include "prov.h"
60210753Srpaulo
61210753Srpauloint
62210753Srpaulofoo(void)
63210753Srpaulo{
64210753Srpaulo	return (24);
65210753Srpaulo}
66210753Srpaulo
67210753Srpauloint
68210753Srpaulomain(int argc, char **argv)
69210753Srpaulo{
70210753Srpaulo	int a = foo();
71210753Srpaulo	if (TEST_PROV_GO_ENABLED()) {
72210753Srpaulo		TEST_PROV_GO();
73210753Srpaulo	}
74210753Srpaulo	(void) printf("%d %d %d\n", a, a, a);
75210753Srpaulo
76210753Srpaulo	return (0);
77210753Srpaulo}
78210753SrpauloEOF
79210753Srpaulo
80331178Seadlercc -c -O2 test.c
81210753Srpauloif [ $? -ne 0 ]; then
82210753Srpaulo	print -u2 "failed to compile test.c"
83210753Srpaulo	exit 1
84210753Srpaulofi
85288413Smarkj$dtrace -G -s prov.d test.o
86210753Srpauloif [ $? -ne 0 ]; then
87210753Srpaulo	print -u2 "failed to create DOF"
88210753Srpaulo	exit 1
89210753Srpaulofi
90210753Srpaulocc -o test test.o prov.o
91210753Srpauloif [ $? -ne 0 ]; then
92210753Srpaulo	print -u2 "failed to link final executable"
93210753Srpaulo	exit 1
94210753Srpaulofi
95210753Srpaulo
96210753Srpauloscript()
97210753Srpaulo{
98210753Srpaulo	./test
99210753Srpaulo
100210753Srpaulo	$dtrace -c ./test -qs /dev/stdin <<EOF
101210753Srpaulo	test_prov\$target:::
102210753Srpaulo	{
103210753Srpaulo	}
104210753SrpauloEOF
105210753Srpaulo}
106210753Srpaulo
107210753Srpauloscript
108210753Srpaulostatus=$?
109210753Srpaulo
110210753Srpaulocd /
111211545Srpaulo/bin/rm -rf $DIR
112210753Srpaulo
113210753Srpauloexit $status
114