xref: /illumos-gate/usr/src/cmd/dtrace/test/tst/common/usdt/tst.dlclose2.ksh (revision 34a0f871d192b33b865455a8812a3d34c1866315)
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
29if [ $# != 1 ]; then
30	echo expected one argument: '<'dtrace-path'>'
31	exit 2
32fi
33
34dtrace=$1
35DIR=/var/tmp/dtest.$$
36
37mkdir $DIR
38cd $DIR
39
40cat > Makefile <<EOF
41all: main livelib.so deadlib.so
42
43main: main.o prov.o
44	cc -o main main.o
45
46main.o: main.c
47	cc -c main.c
48
49
50livelib.so: livelib.o prov.o
51	cc -z defs -G -o livelib.so livelib.o prov.o -lc
52
53livelib.o: livelib.c prov.h
54	cc -c livelib.c
55
56prov.o: livelib.o prov.d
57	$dtrace -G -s prov.d livelib.o
58
59prov.h: prov.d
60	$dtrace -h -s prov.d
61
62
63deadlib.so: deadlib.o
64	cc -z defs -G -o deadlib.so deadlib.o -lc
65
66deadlib.o: deadlib.c
67	cc -c deadlib.c
68
69clean:
70	rm -f main.o livelib.o prov.o prov.h deadlib.o
71
72clobber: clean
73	rm -f main livelib.so deadlib.so
74EOF
75
76cat > prov.d <<EOF
77provider test_prov {
78	probe go();
79};
80EOF
81
82cat > livelib.c <<EOF
83#include "prov.h"
84
85void
86go(void)
87{
88	TEST_PROV_GO();
89}
90EOF
91
92cat > deadlib.c <<EOF
93void
94go(void)
95{
96}
97EOF
98
99
100cat > main.c <<EOF
101#include <dlfcn.h>
102#include <unistd.h>
103#include <stdio.h>
104
105int
106main(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}
137EOF
138
139/usr/ccs/bin/make > /dev/null
140if [ $? -ne 0 ]; then
141	print -u2 "failed to build"
142	exit 1
143fi
144
145script() {
146	$dtrace -w -c ./main -Zqs /dev/stdin <<EOF
147	test_prov*:::
148	{
149		printf("%s:%s:%s\n", probemod, probefunc, probename);
150	}
151EOF
152}
153
154script
155status=$?
156
157cd /
158/usr/bin/rm -rf $DIR
159
160exit $status
161