xref: /illumos-gate/usr/src/cmd/dtrace/test/tst/common/usdt/tst.dlclose1.ksh (revision f48205be61a214698b763ff550ab9e657525104c)
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;
109
110	if ((live = dlopen("./livelib.so", RTLD_LAZY | RTLD_LOCAL)) == NULL) {
111		printf("dlopen of livelib.so failed: %s\n", dlerror());
112		return (1);
113	}
114
115	(void) dlclose(live);
116
117	pause();
118
119	return (0);
120}
121EOF
122
123/usr/ccs/bin/make > /dev/null
124if [ $? -ne 0 ]; then
125	print -u2 "failed to build"
126	exit 1
127fi
128
129script() {
130	$dtrace -w -c ./main -qs /dev/stdin <<EOF
131	syscall::pause:entry
132	/pid == \$target/
133	{
134		system("$dtrace -l -P test_prov*");
135		system("kill %d", \$target);
136		exit(0);
137	}
138
139	tick-1s
140	/i++ == 5/
141	{
142		printf("failed\n");
143		exit(1);
144	}
145EOF
146}
147
148script 2>&1
149status=$?
150
151cd /
152/usr/bin/rm -rf $DIR
153
154exit $status
155