12be1a816SJohn Birrell#
22be1a816SJohn Birrell# CDDL HEADER START
32be1a816SJohn Birrell#
42be1a816SJohn Birrell# The contents of this file are subject to the terms of the
52be1a816SJohn Birrell# Common Development and Distribution License (the "License").
62be1a816SJohn Birrell# You may not use this file except in compliance with the License.
72be1a816SJohn Birrell#
82be1a816SJohn Birrell# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
92be1a816SJohn Birrell# or http://www.opensolaris.org/os/licensing.
102be1a816SJohn Birrell# See the License for the specific language governing permissions
112be1a816SJohn Birrell# and limitations under the License.
122be1a816SJohn Birrell#
132be1a816SJohn Birrell# When distributing Covered Code, include this CDDL HEADER in each
142be1a816SJohn Birrell# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
152be1a816SJohn Birrell# If applicable, add the following below this CDDL HEADER, with the
162be1a816SJohn Birrell# fields enclosed by brackets "[]" replaced with your own identifying
172be1a816SJohn Birrell# information: Portions Copyright [yyyy] [name of copyright owner]
182be1a816SJohn Birrell#
192be1a816SJohn Birrell# CDDL HEADER END
202be1a816SJohn Birrell#
212be1a816SJohn Birrell
222be1a816SJohn Birrell#
232be1a816SJohn Birrell# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
242be1a816SJohn Birrell# Use is subject to license terms.
252be1a816SJohn Birrell#
262be1a816SJohn Birrell# ident	"%Z%%M%	%I%	%E% SMI"
272be1a816SJohn Birrell
282be1a816SJohn Birrellif [ $# != 1 ]; then
292be1a816SJohn Birrell	echo expected one argument: '<'dtrace-path'>'
302be1a816SJohn Birrell	exit 2
312be1a816SJohn Birrellfi
322be1a816SJohn Birrell
332be1a816SJohn Birrelldtrace=$1
342be1a816SJohn BirrellDIR=/var/tmp/dtest.$$
352be1a816SJohn Birrell
362be1a816SJohn Birrellmkdir $DIR
372be1a816SJohn Birrellcd $DIR
382be1a816SJohn Birrell
392be1a816SJohn Birrellcat > test.c <<EOF
402be1a816SJohn Birrell#include <sys/sdt.h>
412be1a816SJohn Birrell
422be1a816SJohn Birrellint
432be1a816SJohn Birrellmain(int argc, char **argv)
442be1a816SJohn Birrell{
452be1a816SJohn Birrell	DTRACE_PROBE(test_prov, entry);
462be1a816SJohn Birrell	DTRACE_PROBE(test_prov, __entry);
472be1a816SJohn Birrell	DTRACE_PROBE(test_prov, foo__entry);
482be1a816SJohn Birrell	DTRACE_PROBE(test_prov, carpentry);
492be1a816SJohn Birrell	DTRACE_PROBE(test_prov, miniatureturn);
502be1a816SJohn Birrell	DTRACE_PROBE(test_prov, foo__return);
512be1a816SJohn Birrell	DTRACE_PROBE(test_prov, __return);
522be1a816SJohn Birrell	/*
532be1a816SJohn Birrell	 * Unfortunately, a "return" probe is not currently possible due to
542be1a816SJohn Birrell	 * the conflict with a reserved word.
552be1a816SJohn Birrell	 */
562be1a816SJohn Birrell	DTRACE_PROBE(test_prov, done);
572be1a816SJohn Birrell}
582be1a816SJohn BirrellEOF
592be1a816SJohn Birrell
602be1a816SJohn Birrellcat > prov.d <<EOF
612be1a816SJohn Birrellprovider test_prov {
622be1a816SJohn Birrell	probe entry();
632be1a816SJohn Birrell	probe __entry();
642be1a816SJohn Birrell	probe foo__entry();
652be1a816SJohn Birrell	probe carpentry();
662be1a816SJohn Birrell	probe miniatureturn();
672be1a816SJohn Birrell	probe foo__return();
682be1a816SJohn Birrell	probe __return();
692be1a816SJohn Birrell	probe done();
702be1a816SJohn Birrell};
712be1a816SJohn BirrellEOF
722be1a816SJohn Birrell
732be1a816SJohn Birrellcc -c test.c
742be1a816SJohn Birrellif [ $? -ne 0 ]; then
752be1a816SJohn Birrell	print -u2 "failed to compile test.c"
762be1a816SJohn Birrell	exit 1
772be1a816SJohn Birrellfi
78c5af5adaSMark Johnston$dtrace -G -s prov.d test.o
792be1a816SJohn Birrellif [ $? -ne 0 ]; then
802be1a816SJohn Birrell	print -u2 "failed to create DOF"
812be1a816SJohn Birrell	exit 1
822be1a816SJohn Birrellfi
832be1a816SJohn Birrellcc -o test test.o prov.o
842be1a816SJohn Birrellif [ $? -ne 0 ]; then
852be1a816SJohn Birrell	print -u2 "failed to link final executable"
862be1a816SJohn Birrell	exit 1
872be1a816SJohn Birrellfi
882be1a816SJohn Birrell
892be1a816SJohn Birrellscript()
902be1a816SJohn Birrell{
912be1a816SJohn Birrell	$dtrace -wqZFs /dev/stdin <<EOF
922be1a816SJohn Birrell	BEGIN
932be1a816SJohn Birrell	{
942be1a816SJohn Birrell		system("$DIR/test");
952be1a816SJohn Birrell		printf("\n");
962be1a816SJohn Birrell	}
972be1a816SJohn Birrell
982be1a816SJohn Birrell	test_prov*:::done
992be1a816SJohn Birrell	/progenyof(\$pid)/
1002be1a816SJohn Birrell	{
1012be1a816SJohn Birrell		exit(0);
1022be1a816SJohn Birrell	}
1032be1a816SJohn Birrell
1042be1a816SJohn Birrell	test_prov*:::
1052be1a816SJohn Birrell	/progenyof(\$pid)/
1062be1a816SJohn Birrell	{
1072be1a816SJohn Birrell		printf("\n");
1082be1a816SJohn Birrell	}
1092be1a816SJohn BirrellEOF
1102be1a816SJohn Birrell}
1112be1a816SJohn Birrell
1122be1a816SJohn Birrellscript | cut -c5-
1132be1a816SJohn Birrellstatus=$?
1142be1a816SJohn Birrell
1152be1a816SJohn Birrellcd /
116b2db7608SRui Paulo/bin/rm -rf $DIR
1172be1a816SJohn Birrell
1182be1a816SJohn Birrellexit $status
119