dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / dtrace / test / tst / common / usdt / tst.dlclose2.ksh
blob328db12cc1cce4552ef9f5a53a7c8c8c6ad3d7e0
1 #!/bin/ksh -p
3 # CDDL HEADER START
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.
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.
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]
20 # CDDL HEADER END
24 # Copyright 2006 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
28 if [ $# != 1 ]; then
29 echo expected one argument: '<'dtrace-path'>'
30 exit 2
33 dtrace=$1
34 DIR=/var/tmp/dtest.$$
36 mkdir $DIR
37 cd $DIR
39 cat > Makefile <<EOF
40 all: main livelib.so deadlib.so
42 main: main.o prov.o
43 gcc -m32 -o main main.o
45 main.o: main.c
46 gcc -m32 -c main.c
49 livelib.so: livelib.o prov.o
50 gcc -m32 -shared -o livelib.so livelib.o prov.o -lc
52 livelib.o: livelib.c prov.h
53 gcc -m32 -fPIC -c livelib.c
55 prov.o: livelib.o prov.d
56 $dtrace -G -s prov.d livelib.o
58 prov.h: prov.d
59 $dtrace -h -s prov.d
62 deadlib.so: deadlib.o
63 gcc -m32 -shared -o deadlib.so deadlib.o -lc
65 deadlib.o: deadlib.c
66 gcc -m32 -fPIC -c deadlib.c
68 clean:
69 rm -f main.o livelib.o prov.o prov.h deadlib.o
71 clobber: clean
72 rm -f main livelib.so deadlib.so
73 EOF
75 cat > prov.d <<EOF
76 provider test_prov {
77 probe go();
79 EOF
81 cat > livelib.c <<EOF
82 #include "prov.h"
84 void
85 go(void)
87 TEST_PROV_GO();
89 EOF
91 cat > deadlib.c <<EOF
92 void
93 go(void)
96 EOF
99 cat > main.c <<EOF
100 #include <dlfcn.h>
101 #include <unistd.h>
102 #include <stdio.h>
105 main(int argc, char **argv)
107 void *live, *dead;
108 void *go;
110 if ((live = dlopen("./livelib.so", RTLD_LAZY | RTLD_LOCAL)) == NULL) {
111 printf("dlopen of livelib.so failed: %s\n", dlerror());
112 return (1);
115 (void) dlclose(live);
117 if ((dead = dlopen("./deadlib.so", RTLD_LAZY | RTLD_LOCAL)) == NULL) {
118 printf("dlopen of deadlib.so failed: %s\n", dlerror());
119 return (1);
122 if ((live = dlopen("./livelib.so", RTLD_LAZY | RTLD_LOCAL)) == NULL) {
123 printf("dlopen of livelib.so failed: %s\n", dlerror());
124 return (1);
127 if ((go = dlsym(live, "go")) == NULL) {
128 printf("failed to lookup 'go' in livelib.so\n");
129 return (1);
132 ((void (*)(void))go)();
134 return (0);
138 make > /dev/null
139 if [ $? -ne 0 ]; then
140 print -u2 "failed to build"
141 exit 1
144 script() {
145 $dtrace -w -c ./main -Zqs /dev/stdin <<EOF
146 test_prov*:::
148 printf("%s:%s:%s\n", probemod, probefunc, probename);
153 script
154 status=$?
156 cd /
157 /usr/bin/rm -rf $DIR
159 exit $status