xref: /illumos-gate/usr/src/cmd/dtrace/test/tst/common/usdt/tst.dlclose2.ksh (revision a386cc11a86ecb60f5a48078d22c1500e2ad003e)
19512fe85Sahl#!/bin/ksh -p
29512fe85Sahl#
39512fe85Sahl# CDDL HEADER START
49512fe85Sahl#
59512fe85Sahl# The contents of this file are subject to the terms of the
69512fe85Sahl# Common Development and Distribution License (the "License").
79512fe85Sahl# You may not use this file except in compliance with the License.
89512fe85Sahl#
99512fe85Sahl# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
109512fe85Sahl# or http://www.opensolaris.org/os/licensing.
119512fe85Sahl# See the License for the specific language governing permissions
129512fe85Sahl# and limitations under the License.
139512fe85Sahl#
149512fe85Sahl# When distributing Covered Code, include this CDDL HEADER in each
159512fe85Sahl# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
169512fe85Sahl# If applicable, add the following below this CDDL HEADER, with the
179512fe85Sahl# fields enclosed by brackets "[]" replaced with your own identifying
189512fe85Sahl# information: Portions Copyright [yyyy] [name of copyright owner]
199512fe85Sahl#
209512fe85Sahl# CDDL HEADER END
219512fe85Sahl#
229512fe85Sahl
239512fe85Sahl#
249512fe85Sahl# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
259512fe85Sahl# Use is subject to license terms.
269512fe85Sahl#
279512fe85Sahl
2823b5c241Stomeeif [ $# != 1 ]; then
2923b5c241Stomee	echo expected one argument: '<'dtrace-path'>'
3023b5c241Stomee	exit 2
3123b5c241Stomeefi
3223b5c241Stomee
3323b5c241Stomeedtrace=$1
349512fe85SahlDIR=/var/tmp/dtest.$$
359512fe85Sahl
369512fe85Sahlmkdir $DIR
379512fe85Sahlcd $DIR
389512fe85Sahl
399512fe85Sahlcat > Makefile <<EOF
409512fe85Sahlall: main livelib.so deadlib.so
419512fe85Sahl
429512fe85Sahlmain: main.o prov.o
43*a386cc11SRobert Mustacchi	gcc -m32 -o main main.o
449512fe85Sahl
459512fe85Sahlmain.o: main.c
46*a386cc11SRobert Mustacchi	gcc -m32 -c main.c
479512fe85Sahl
489512fe85Sahl
499512fe85Sahllivelib.so: livelib.o prov.o
50*a386cc11SRobert Mustacchi	gcc -m32 -shared -o livelib.so livelib.o prov.o -lc
519512fe85Sahl
529512fe85Sahllivelib.o: livelib.c prov.h
53*a386cc11SRobert Mustacchi	gcc -m32 -fPIC -c livelib.c
549512fe85Sahl
559512fe85Sahlprov.o: livelib.o prov.d
5623b5c241Stomee	$dtrace -G -s prov.d livelib.o
579512fe85Sahl
589512fe85Sahlprov.h: prov.d
5923b5c241Stomee	$dtrace -h -s prov.d
609512fe85Sahl
619512fe85Sahl
629512fe85Sahldeadlib.so: deadlib.o
63*a386cc11SRobert Mustacchi	gcc -m32 -shared -o deadlib.so deadlib.o -lc
649512fe85Sahl
659512fe85Sahldeadlib.o: deadlib.c
66*a386cc11SRobert Mustacchi	gcc -m32 -fPIC -c deadlib.c
679512fe85Sahl
689512fe85Sahlclean:
699512fe85Sahl	rm -f main.o livelib.o prov.o prov.h deadlib.o
709512fe85Sahl
719512fe85Sahlclobber: clean
729512fe85Sahl	rm -f main livelib.so deadlib.so
739512fe85SahlEOF
749512fe85Sahl
759512fe85Sahlcat > prov.d <<EOF
769512fe85Sahlprovider test_prov {
779512fe85Sahl	probe go();
789512fe85Sahl};
799512fe85SahlEOF
809512fe85Sahl
819512fe85Sahlcat > livelib.c <<EOF
829512fe85Sahl#include "prov.h"
839512fe85Sahl
849512fe85Sahlvoid
859512fe85Sahlgo(void)
869512fe85Sahl{
879512fe85Sahl	TEST_PROV_GO();
889512fe85Sahl}
899512fe85SahlEOF
909512fe85Sahl
919512fe85Sahlcat > deadlib.c <<EOF
929512fe85Sahlvoid
939512fe85Sahlgo(void)
949512fe85Sahl{
959512fe85Sahl}
969512fe85SahlEOF
979512fe85Sahl
989512fe85Sahl
999512fe85Sahlcat > main.c <<EOF
1009512fe85Sahl#include <dlfcn.h>
1019512fe85Sahl#include <unistd.h>
1029512fe85Sahl#include <stdio.h>
1039512fe85Sahl
1049512fe85Sahlint
1059512fe85Sahlmain(int argc, char **argv)
1069512fe85Sahl{
1079512fe85Sahl	void *live, *dead;
1089512fe85Sahl	void *go;
1099512fe85Sahl
1109512fe85Sahl	if ((live = dlopen("./livelib.so", RTLD_LAZY | RTLD_LOCAL)) == NULL) {
1119512fe85Sahl		printf("dlopen of livelib.so failed: %s\n", dlerror());
1129512fe85Sahl		return (1);
1139512fe85Sahl	}
1149512fe85Sahl
1159512fe85Sahl	(void) dlclose(live);
1169512fe85Sahl
1179512fe85Sahl	if ((dead = dlopen("./deadlib.so", RTLD_LAZY | RTLD_LOCAL)) == NULL) {
1189512fe85Sahl		printf("dlopen of deadlib.so failed: %s\n", dlerror());
1199512fe85Sahl		return (1);
1209512fe85Sahl	}
1219512fe85Sahl
1229512fe85Sahl	if ((live = dlopen("./livelib.so", RTLD_LAZY | RTLD_LOCAL)) == NULL) {
1239512fe85Sahl		printf("dlopen of livelib.so failed: %s\n", dlerror());
1249512fe85Sahl		return (1);
1259512fe85Sahl	}
1269512fe85Sahl
1279512fe85Sahl	if ((go = dlsym(live, "go")) == NULL) {
1289512fe85Sahl		printf("failed to lookup 'go' in livelib.so\n");
1299512fe85Sahl		return (1);
1309512fe85Sahl	}
1319512fe85Sahl
1329512fe85Sahl	((void (*)(void))go)();
1339512fe85Sahl
1349512fe85Sahl	return (0);
1359512fe85Sahl}
1369512fe85SahlEOF
1379512fe85Sahl
138c090e5dfSBryan Cantrillmake > /dev/null
1399512fe85Sahlif [ $? -ne 0 ]; then
1409512fe85Sahl	print -u2 "failed to build"
1419512fe85Sahl	exit 1
1429512fe85Sahlfi
1439512fe85Sahl
1449512fe85Sahlscript() {
14523b5c241Stomee	$dtrace -w -c ./main -Zqs /dev/stdin <<EOF
1469512fe85Sahl	test_prov*:::
1479512fe85Sahl	{
1489512fe85Sahl		printf("%s:%s:%s\n", probemod, probefunc, probename);
1499512fe85Sahl	}
1509512fe85SahlEOF
1519512fe85Sahl}
1529512fe85Sahl
1539512fe85Sahlscript
1549512fe85Sahlstatus=$?
1559512fe85Sahl
1569512fe85Sahlcd /
1579512fe85Sahl/usr/bin/rm -rf $DIR
1589512fe85Sahl
1599512fe85Sahlexit $status
160