1266988Smarkj#
2266988Smarkj# CDDL HEADER START
3266988Smarkj#
4266988Smarkj# The contents of this file are subject to the terms of the
5266988Smarkj# Common Development and Distribution License (the "License").
6266988Smarkj# You may not use this file except in compliance with the License.
7266988Smarkj#
8266988Smarkj# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9266988Smarkj# or http://www.opensolaris.org/os/licensing.
10266988Smarkj# See the License for the specific language governing permissions
11266988Smarkj# and limitations under the License.
12266988Smarkj#
13266988Smarkj# When distributing Covered Code, include this CDDL HEADER in each
14266988Smarkj# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15266988Smarkj# If applicable, add the following below this CDDL HEADER, with the
16266988Smarkj# fields enclosed by brackets "[]" replaced with your own identifying
17266988Smarkj# information: Portions Copyright [yyyy] [name of copyright owner]
18266988Smarkj#
19266988Smarkj# CDDL HEADER END
20266988Smarkj#
21266988Smarkj
22266988Smarkj#
23266988Smarkj# Copyright (c) 2013, Joyent, Inc. All rights reserved.
24266988Smarkj#
25266988Smarkj
26266988Smarkjif [ $# != 1 ]; then
27266988Smarkj	echo expected one argument: '<'dtrace-path'>'
28266988Smarkj	exit 2
29266988Smarkjfi
30266988Smarkj
31266988Smarkjdtrace=$1
32266988SmarkjDIR=/var/tmp/dtest.$$
33266988Smarkj
34266988Smarkjmkdir $DIR
35266988Smarkjcd $DIR
36266988Smarkj
37266988Smarkjecho '#pragma D option quiet' > test.d
38266988Smarkjecho '#pragma D option aggsortkey' >> test.d
39266988Smarkj
40266988Smarkjcat > test.c <<EOF
41266988Smarkj#include <unistd.h>
42266988Smarkj
43266988Smarkjvoid
44266988Smarkjmain()
45266988Smarkj{
46266988SmarkjEOF
47266988Smarkj
48266988Smarkjobjs=
49266988Smarkj
50266988Smarkjfor oogle in doogle bagnoogle; do
51266988Smarkj	cat > $oogle.c <<EOF
52266988Smarkj#include <sys/sdt.h>
53266988Smarkj
54266988Smarkjvoid
55266988Smarkj$oogle()
56266988Smarkj{
57266988Smarkj	DTRACE_PROBE($oogle, knows);
58266988Smarkj}
59266988SmarkjEOF
60266988Smarkj
61266988Smarkj	cat > $oogle.d <<EOF
62266988Smarkjprovider $oogle {
63266988Smarkj	probe knows();
64266988Smarkj};
65266988SmarkjEOF
66266988Smarkj
67266988Smarkj	cc -c $oogle.c
68266988Smarkj
69266988Smarkj	if [ $? -ne 0 ]; then
70266988Smarkj		print -u2 "failed to compile $oogle.c"
71266988Smarkj		exit 1
72266988Smarkj	fi
73266988Smarkj
74288413Smarkj	$dtrace -G -s $oogle.d $oogle.o -o $oogle.d.o
75266988Smarkj
76266988Smarkj	if [ $? -ne 0 ]; then
77266988Smarkj		print -u2 "failed to process $oogle.d"
78266988Smarkj		exit 1
79266988Smarkj	fi
80266988Smarkj
81266988Smarkj	objs="$objs $oogle.o $oogle.d.o"
82266988Smarkj	echo $oogle'();' >> test.c
83266988Smarkj	echo $oogle'$target:::{@[probefunc] = count()}' >> test.d
84266988Smarkjdone
85266988Smarkj
86266988Smarkjecho "}" >> test.c
87266988Smarkj
88266988Smarkjecho 'END{printa("%-10s %@d\\n", @)}' >> test.d
89266988Smarkj
90266988Smarkjcc -o test test.c $objs
91266988Smarkj
92266988Smarkjif [ $? -ne 0 ]; then
93266988Smarkj	print -u2 "failed to compile test.c"
94266988Smarkj	exit 1
95266988Smarkjfi
96266988Smarkj
97266988Smarkj$dtrace -s ./test.d -Zc ./test
98266988Smarkj
99266988Smarkjif [ $? -ne 0 ]; then
100266988Smarkj	print -u2 "failed to execute test"
101266988Smarkj	exit 1
102266988Smarkjfi
103266988Smarkj
104266988Smarkjcd /
105279414Smarkjrm -rf $DIR
106266988Smarkjexit 0
107