xref: /illumos-gate/usr/src/cmd/dtrace/test/tst/common/usdt/tst.sameprovmulti.ksh (revision 45ede40b2394db7967e59f19288fae9b62efd4aa)
1#
2# This file and its contents are supplied under the terms of the
3# Common Development and Distribution License ("CDDL"), version 1.0.
4# You may only use this file in accordance with the terms of version
5# 1.0 of the CDDL.
6#
7# A full copy of the text of the CDDL should have accompanied this
8# source.  A copy of the CDDL is also available via the Internet at
9# http://www.illumos.org/license/CDDL.
10#
11
12#
13# Copyright (c) 2015, Joyent, Inc. All rights reserved.
14#
15
16#
17# This test assures that we can have the same provider name across multiple
18# probe definitions, and that the result will be the union of those
19# definitions.  In particular, libusdt depends on this when (for example)
20# node modules that create a provider are loaded multiple times due to
21# being included by different modules.
22#
23
24if [ $# != 1 ]; then
25	echo expected one argument: '<'dtrace-path'>'
26	exit 2
27fi
28
29dtrace=$1
30DIR=/var/tmp/dtest.$$
31
32mkdir $DIR
33cd $DIR
34
35cat > test.c <<EOF
36#include <unistd.h>
37
38void
39main()
40{
41EOF
42
43objs=
44
45for oogle in bagnoogle stalloogle cockoogle; do
46	cat > $oogle.c <<EOF
47#include <sys/sdt.h>
48
49void
50$oogle()
51{
52	DTRACE_PROBE(doogle, $oogle);
53}
54EOF
55
56	cat > $oogle.d <<EOF
57provider doogle {
58	probe $oogle();
59};
60EOF
61
62	gcc -m32 -c $oogle.c
63
64	if [ $? -ne 0 ]; then
65		print -u2 "failed to compile $oogle.c"
66		exit 1
67	fi
68
69	$dtrace -G -32 -s $oogle.d $oogle.o -o $oogle.d.o
70
71	if [ $? -ne 0 ]; then
72		print -u2 "failed to process $oogle.d"
73		exit 1
74	fi
75
76	objs="$objs $oogle.o $oogle.d.o"
77	echo $oogle'();' >> test.c
78done
79
80echo "}" >> test.c
81
82gcc -m32 -o test test.c $objs
83
84if [ $? -ne 0 ]; then
85	print -u2 "failed to compile test.c"
86	exit 1
87fi
88
89$dtrace -n 'doogle$target:::{@[probename] = count()}' \
90    -n 'END{printa("%-10s %@d\n", @)}' -x quiet -x aggsortkey -Zc ./test
91
92if [ $? -ne 0 ]; then
93	print -u2 "failed to execute test"
94	exit 1
95fi
96
97cd /
98/usr/bin/rm -rf $DIR
99exit 0
100