]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/usdt/tst.dlclose2.ksh
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / cddl / contrib / opensolaris / cmd / dtrace / test / tst / common / usdt / tst.dlclose2.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 2006 Sun Microsystems, Inc.  All rights reserved.
25 # Use is subject to license terms.
26 #
27 #ident  "%Z%%M% %I%     %E% SMI"
28
29 if [ $# != 1 ]; then
30         echo expected one argument: '<'dtrace-path'>'
31         exit 2
32 fi
33
34 dtrace=$1
35 DIR=/var/tmp/dtest.$$
36
37 mkdir $DIR
38 cd $DIR
39
40 cat > Makefile <<EOF
41 all: main livelib.so deadlib.so
42
43 main: main.o prov.o
44         cc -o main main.o
45
46 main.o: main.c
47         cc -c main.c
48
49
50 livelib.so: livelib.o prov.o
51         cc -z defs -G -o livelib.so livelib.o prov.o -lc
52
53 livelib.o: livelib.c prov.h
54         cc -c livelib.c
55
56 prov.o: livelib.o prov.d
57         $dtrace -G -s prov.d livelib.o
58
59 prov.h: prov.d
60         $dtrace -h -s prov.d
61
62
63 deadlib.so: deadlib.o
64         cc -z defs -G -o deadlib.so deadlib.o -lc
65
66 deadlib.o: deadlib.c
67         cc -c deadlib.c
68
69 clean:
70         rm -f main.o livelib.o prov.o prov.h deadlib.o
71
72 clobber: clean
73         rm -f main livelib.so deadlib.so
74 EOF
75
76 cat > prov.d <<EOF
77 provider test_prov {
78         probe go();
79 };
80 EOF
81
82 cat > livelib.c <<EOF
83 #include "prov.h"
84
85 void
86 go(void)
87 {
88         TEST_PROV_GO();
89 }
90 EOF
91
92 cat > deadlib.c <<EOF
93 void
94 go(void)
95 {
96 }
97 EOF
98
99
100 cat > main.c <<EOF
101 #include <dlfcn.h>
102 #include <unistd.h>
103 #include <stdio.h>
104
105 int
106 main(int argc, char **argv)
107 {
108         void *live, *dead;
109         void *go;
110
111         if ((live = dlopen("./livelib.so", RTLD_LAZY | RTLD_LOCAL)) == NULL) {
112                 printf("dlopen of livelib.so failed: %s\n", dlerror());
113                 return (1);
114         }
115
116         (void) dlclose(live);
117
118         if ((dead = dlopen("./deadlib.so", RTLD_LAZY | RTLD_LOCAL)) == NULL) {
119                 printf("dlopen of deadlib.so failed: %s\n", dlerror());
120                 return (1);
121         }
122
123         if ((live = dlopen("./livelib.so", RTLD_LAZY | RTLD_LOCAL)) == NULL) {
124                 printf("dlopen of livelib.so failed: %s\n", dlerror());
125                 return (1);
126         }
127
128         if ((go = dlsym(live, "go")) == NULL) {
129                 printf("failed to lookup 'go' in livelib.so\n");
130                 return (1);
131         }
132
133         ((void (*)(void))go)();
134
135         return (0);
136 }
137 EOF
138
139 /usr/bin/make > /dev/null
140 if [ $? -ne 0 ]; then
141         print -u2 "failed to build"
142         exit 1
143 fi
144
145 script() {
146         $dtrace -w -c ./main -Zqs /dev/stdin <<EOF
147         test_prov*:::
148         {
149                 printf("%s:%s:%s\n", probemod, probefunc, probename);
150         }
151 EOF
152 }
153
154 script
155 status=$?
156
157 cd /
158 /bin/rm -rf $DIR
159
160 exit $status