1130561Sobrien#
2130561Sobrien# This file and its contents are supplied under the terms of the
3130561Sobrien# Common Development and Distribution License ("CDDL"), version 1.0.
4130561Sobrien# You may only use this file in accordance with the terms of version
5130561Sobrien# 1.0 of the CDDL.
6130561Sobrien#
7130561Sobrien# A full copy of the text of the CDDL should have accompanied this
8130561Sobrien# source.  A copy of the CDDL is also available via the Internet at
9130561Sobrien# http://www.illumos.org/license/CDDL.
10130561Sobrien#
11130561Sobrien
12130561Sobrien#
13130561Sobrien# Copyright (c) 2015, Joyent, Inc. All rights reserved.
14130561Sobrien#
15130561Sobrien
16130561Sobrien#
17130561Sobrien# This test assures that we can have the same provider name across multiple
18130561Sobrien# probe definitions, and that the result will be the union of those
19130561Sobrien# definitions.  In particular, libusdt depends on this when (for example)
20130561Sobrien# node modules that create a provider are loaded multiple times due to
21130561Sobrien# being included by different modules.
22130561Sobrien#
23130561Sobrien
24130561Sobrienif [ $# != 1 ]; then
25130561Sobrien	echo expected one argument: '<'dtrace-path'>'
26130561Sobrien	exit 2
27130561Sobrienfi
28130561Sobrien
29130561Sobriendtrace=$1
30130561SobrienDIR=/var/tmp/dtest.$$
31130561Sobrien
32130561Sobrienmkdir $DIR
33130561Sobriencd $DIR
34130561Sobrien
35130561Sobriencat > test.c <<EOF
36130561Sobrien#include <unistd.h>
37130561Sobrien
38130561Sobrienvoid
39130561Sobrienmain()
40130561Sobrien{
41130561SobrienEOF
42130561Sobrien
43130561Sobrienobjs=
44130561Sobrien
45130561Sobrienfor oogle in bagnoogle stalloogle cockoogle; do
46130561Sobrien	cat > $oogle.c <<EOF
47130561Sobrien#include <sys/sdt.h>
48130561Sobrien
49130561Sobrienvoid
50130561Sobrien$oogle()
51130561Sobrien{
52130561Sobrien	DTRACE_PROBE(doogle, $oogle);
53130561Sobrien}
54130561SobrienEOF
55130561Sobrien
56130561Sobrien	cat > $oogle.d <<EOF
57130561Sobrienprovider doogle {
58130561Sobrien	probe $oogle();
59130561Sobrien};
60130561SobrienEOF
61130561Sobrien
62130561Sobrien	cc -c $oogle.c
63130561Sobrien
64130561Sobrien	if [ $? -ne 0 ]; then
65130561Sobrien		print -u2 "failed to compile $oogle.c"
66130561Sobrien		exit 1
67130561Sobrien	fi
68130561Sobrien
69130561Sobrien	$dtrace -G -s $oogle.d $oogle.o -o $oogle.d.o
70130561Sobrien
71130561Sobrien	if [ $? -ne 0 ]; then
72130561Sobrien		print -u2 "failed to process $oogle.d"
73130561Sobrien		exit 1
74130561Sobrien	fi
75130561Sobrien
76130561Sobrien	objs="$objs $oogle.o $oogle.d.o"
77130561Sobrien	echo $oogle'();' >> test.c
78130561Sobriendone
79130561Sobrien
80130561Sobrienecho "}" >> test.c
81130561Sobrien
82130561Sobriencc -o test test.c $objs
83130561Sobrien
84130561Sobrienif [ $? -ne 0 ]; then
85130561Sobrien	print -u2 "failed to compile test.c"
86130561Sobrien	exit 1
87130561Sobrienfi
88130561Sobrien
89130561Sobrien$dtrace -n 'doogle$target:::{@[probename] = count()}' \
90130561Sobrien    -n 'END{printa("%-10s %@d\n", @)}' -x quiet -x aggsortkey -Zc ./test
91130561Sobrien
92130561Sobrienif [ $? -ne 0 ]; then
93130561Sobrien	print -u2 "failed to execute test"
94130561Sobrien	exit 1
95130561Sobrienfi
96130561Sobrien
97130561Sobriencd /
98130561Sobrienrm -rf $DIR
99130561Sobrienexit 0
100130561Sobrien