]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/usdt/tst.dlclose1.ksh
Merge ^/vendor/compiler-rt/dist up to its last change, and resolve conflicts.
[FreeBSD/FreeBSD.git] / cddl / contrib / opensolaris / cmd / dtrace / test / tst / common / usdt / tst.dlclose1.ksh
1 #!/bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
25 # Use is subject to license terms.
26 #
27 # ident "%Z%%M% %I%     %E% SMI"
28
29 #
30 # This test verifies that USDT providers are removed when its associated
31 # load object is closed via dlclose(3dl).
32 #
33
34 if [ $# != 1 ]; then
35         echo expected one argument: '<'dtrace-path'>'
36         exit 2
37 fi
38
39 dtrace=$1
40 DIR=/var/tmp/dtest.$$
41
42 mkdir $DIR
43 cd $DIR
44
45 cat > Makefile <<EOF
46 all: main livelib.so deadlib.so
47
48 main: main.o prov.o
49         cc -o main main.o
50
51 main.o: main.c
52         cc -c main.c
53
54
55 livelib.so: livelib.o prov.o
56         cc -shared -o livelib.so livelib.o prov.o -lc
57
58 livelib.o: livelib.c prov.h
59         cc -c livelib.c
60
61 prov.o: livelib.o prov.d
62         $dtrace -G -s prov.d livelib.o
63
64 prov.h: prov.d
65         $dtrace -h -s prov.d
66
67
68 deadlib.so: deadlib.o
69         cc -shared -o deadlib.so deadlib.o -lc
70
71 deadlib.o: deadlib.c
72         cc -c deadlib.c
73
74 clean:
75         rm -f main.o livelib.o prov.o prov.h deadlib.o
76
77 clobber: clean
78         rm -f main livelib.so deadlib.so
79 EOF
80
81 cat > prov.d <<EOF
82 provider test_prov {
83         probe go();
84 };
85 EOF
86
87 cat > livelib.c <<EOF
88 #include "prov.h"
89
90 void
91 go(void)
92 {
93         TEST_PROV_GO();
94 }
95 EOF
96
97 cat > deadlib.c <<EOF
98 void
99 go(void)
100 {
101 }
102 EOF
103
104
105 cat > main.c <<EOF
106 #include <dlfcn.h>
107 #include <unistd.h>
108 #include <stdio.h>
109 #include <signal.h>
110
111 int
112 main(int argc, char **argv)
113 {
114         void *live;
115         sigset_t mask;
116
117         if ((live = dlopen("./livelib.so", RTLD_LAZY | RTLD_LOCAL)) == NULL) {
118                 printf("dlopen of livelib.so failed: %s\n", dlerror());
119                 return (1);
120         }
121
122         (void) dlclose(live);
123
124         (void) sigemptyset(&mask);
125         (void) sigsuspend(&mask);
126
127         return (0);
128 }
129 EOF
130
131 /usr/bin/make > /dev/null
132 if [ $? -ne 0 ]; then
133         print -u2 "failed to build"
134         exit 1
135 fi
136
137 script() {
138         $dtrace -w -x bufsize=1k -c ./main -qs /dev/stdin <<EOF
139         syscall::sigsuspend:entry
140         /pid == \$target/
141         {
142                 system("$dtrace -l -P test_prov*");
143                 system("kill %d", \$target);
144                 exit(0);
145         }
146
147         tick-1s
148         /i++ == 5/
149         {
150                 printf("failed\n");
151                 exit(1);
152         }
153 EOF
154 }
155
156 script 2>&1
157 status=$?
158
159 cd /
160 /bin/rm -rf $DIR
161
162 exit $status