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# 24038dc6b3Sahl# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 259512fe85Sahl# Use is subject to license terms. 269512fe85Sahl# 27038dc6b3Sahl 28038dc6b3Sahl# 29038dc6b3Sahl# This test verifies that USDT providers are removed when its associated 30038dc6b3Sahl# load object is closed via dlclose(3dl). 31038dc6b3Sahl# 329512fe85Sahl 3323b5c241Stomeeif [ $# != 1 ]; then 3423b5c241Stomee echo expected one argument: '<'dtrace-path'>' 3523b5c241Stomee exit 2 3623b5c241Stomeefi 3723b5c241Stomee 3823b5c241Stomeedtrace=$1 399512fe85SahlDIR=/var/tmp/dtest.$$ 409512fe85Sahl 419512fe85Sahlmkdir $DIR 429512fe85Sahlcd $DIR 439512fe85Sahl 449512fe85Sahlcat > Makefile <<EOF 459512fe85Sahlall: main livelib.so deadlib.so 469512fe85Sahl 479512fe85Sahlmain: main.o prov.o 48*a386cc11SRobert Mustacchi gcc -m32 -o main main.o 499512fe85Sahl 509512fe85Sahlmain.o: main.c 51*a386cc11SRobert Mustacchi gcc -m32 -c main.c 529512fe85Sahl 539512fe85Sahl 549512fe85Sahllivelib.so: livelib.o prov.o 55*a386cc11SRobert Mustacchi gcc -m32 -shared -o livelib.so livelib.o prov.o -lc 569512fe85Sahl 579512fe85Sahllivelib.o: livelib.c prov.h 58*a386cc11SRobert Mustacchi gcc -m32 -fPIC -c livelib.c 599512fe85Sahl 609512fe85Sahlprov.o: livelib.o prov.d 6123b5c241Stomee $dtrace -G -s prov.d livelib.o 629512fe85Sahl 639512fe85Sahlprov.h: prov.d 6423b5c241Stomee $dtrace -h -s prov.d 659512fe85Sahl 669512fe85Sahl 679512fe85Sahldeadlib.so: deadlib.o 68*a386cc11SRobert Mustacchi gcc -m32 -shared -o deadlib.so deadlib.o -lc 699512fe85Sahl 709512fe85Sahldeadlib.o: deadlib.c 71*a386cc11SRobert Mustacchi gcc -m32 -fPIC -c deadlib.c 729512fe85Sahl 739512fe85Sahlclean: 749512fe85Sahl rm -f main.o livelib.o prov.o prov.h deadlib.o 759512fe85Sahl 769512fe85Sahlclobber: clean 779512fe85Sahl rm -f main livelib.so deadlib.so 789512fe85SahlEOF 799512fe85Sahl 809512fe85Sahlcat > prov.d <<EOF 819512fe85Sahlprovider test_prov { 829512fe85Sahl probe go(); 839512fe85Sahl}; 849512fe85SahlEOF 859512fe85Sahl 869512fe85Sahlcat > livelib.c <<EOF 879512fe85Sahl#include "prov.h" 889512fe85Sahl 899512fe85Sahlvoid 909512fe85Sahlgo(void) 919512fe85Sahl{ 929512fe85Sahl TEST_PROV_GO(); 939512fe85Sahl} 949512fe85SahlEOF 959512fe85Sahl 969512fe85Sahlcat > deadlib.c <<EOF 979512fe85Sahlvoid 989512fe85Sahlgo(void) 999512fe85Sahl{ 1009512fe85Sahl} 1019512fe85SahlEOF 1029512fe85Sahl 1039512fe85Sahl 1049512fe85Sahlcat > main.c <<EOF 1059512fe85Sahl#include <dlfcn.h> 1069512fe85Sahl#include <unistd.h> 1079512fe85Sahl#include <stdio.h> 1089512fe85Sahl 1099512fe85Sahlint 1109512fe85Sahlmain(int argc, char **argv) 1119512fe85Sahl{ 1129512fe85Sahl void *live; 1139512fe85Sahl 1149512fe85Sahl if ((live = dlopen("./livelib.so", RTLD_LAZY | RTLD_LOCAL)) == NULL) { 1159512fe85Sahl printf("dlopen of livelib.so failed: %s\n", dlerror()); 1169512fe85Sahl return (1); 1179512fe85Sahl } 1189512fe85Sahl 1199512fe85Sahl (void) dlclose(live); 1209512fe85Sahl 1219512fe85Sahl pause(); 1229512fe85Sahl 1239512fe85Sahl return (0); 1249512fe85Sahl} 1259512fe85SahlEOF 1269512fe85Sahl 127c090e5dfSBryan Cantrillmake > /dev/null 1289512fe85Sahlif [ $? -ne 0 ]; then 1299512fe85Sahl print -u2 "failed to build" 1309512fe85Sahl exit 1 1319512fe85Sahlfi 1329512fe85Sahl 1339512fe85Sahlscript() { 134038dc6b3Sahl $dtrace -w -x bufsize=1k -c ./main -qs /dev/stdin <<EOF 1359512fe85Sahl syscall::pause:entry 1369512fe85Sahl /pid == \$target/ 1379512fe85Sahl { 13823b5c241Stomee system("$dtrace -l -P test_prov*"); 1399512fe85Sahl system("kill %d", \$target); 1409512fe85Sahl exit(0); 1419512fe85Sahl } 1429512fe85Sahl 1439512fe85Sahl tick-1s 1449512fe85Sahl /i++ == 5/ 1459512fe85Sahl { 1469512fe85Sahl printf("failed\n"); 1479512fe85Sahl exit(1); 1489512fe85Sahl } 1499512fe85SahlEOF 1509512fe85Sahl} 1519512fe85Sahl 1529512fe85Sahlscript 2>&1 1539512fe85Sahlstatus=$? 1549512fe85Sahl 1559512fe85Sahlcd / 1569512fe85Sahl/usr/bin/rm -rf $DIR 1579512fe85Sahl 1589512fe85Sahlexit $status 159