xref: /illumos-gate/usr/src/cmd/dtrace/test/tst/common/usdt/tst.entryreturn.ksh (revision 581cede61ac9c14d8d4ea452562a567189eead78)
1#
2# CDDL HEADER START
3#
4# The contents of this file are subject to the terms of the
5# Common Development and Distribution License (the "License").
6# You may not use this file except in compliance with the License.
7#
8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9# or http://www.opensolaris.org/os/licensing.
10# See the License for the specific language governing permissions
11# and limitations under the License.
12#
13# When distributing Covered Code, include this CDDL HEADER in each
14# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15# If applicable, add the following below this CDDL HEADER, with the
16# fields enclosed by brackets "[]" replaced with your own identifying
17# information: Portions Copyright [yyyy] [name of copyright owner]
18#
19# CDDL HEADER END
20#
21
22#
23# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26# ident	"%Z%%M%	%I%	%E% SMI"
27
28if [ $# != 1 ]; then
29	echo expected one argument: '<'dtrace-path'>'
30	exit 2
31fi
32
33dtrace=$1
34DIR=/var/tmp/dtest.$$
35
36mkdir $DIR
37cd $DIR
38
39cat > test.c <<EOF
40#include <sys/sdt.h>
41
42int
43main(int argc, char **argv)
44{
45	DTRACE_PROBE(test_prov, entry);
46	DTRACE_PROBE(test_prov, __entry);
47	DTRACE_PROBE(test_prov, foo__entry);
48	DTRACE_PROBE(test_prov, carpentry);
49	DTRACE_PROBE(test_prov, miniatureturn);
50	DTRACE_PROBE(test_prov, foo__return);
51	DTRACE_PROBE(test_prov, __return);
52	/*
53	 * Unfortunately, a "return" probe is not currently possible due to
54	 * the conflict with a reserved word.
55	 */
56	DTRACE_PROBE(test_prov, done);
57}
58EOF
59
60cat > prov.d <<EOF
61provider test_prov {
62	probe entry();
63	probe __entry();
64	probe foo__entry();
65	probe carpentry();
66	probe miniatureturn();
67	probe foo__return();
68	probe __return();
69	probe done();
70};
71EOF
72
73cc -c test.c
74if [ $? -ne 0 ]; then
75	print -u2 "failed to compile test.c"
76	exit 1
77fi
78$dtrace -G -32 -s prov.d test.o
79if [ $? -ne 0 ]; then
80	print -u2 "failed to create DOF"
81	exit 1
82fi
83cc -o test test.o prov.o
84if [ $? -ne 0 ]; then
85	print -u2 "failed to link final executable"
86	exit 1
87fi
88
89script()
90{
91	$dtrace -wqZFs /dev/stdin <<EOF
92	BEGIN
93	{
94		system("$DIR/test");
95		printf("\n");
96	}
97
98	test_prov*:::done
99	/progenyof(\$pid)/
100	{
101		exit(0);
102	}
103
104	test_prov*:::
105	/progenyof(\$pid)/
106	{
107		printf("\n");
108	}
109EOF
110}
111
112script | cut -c5-
113status=$?
114
115cd /
116/usr/bin/rm -rf $DIR
117
118exit $status
119