1178476Sjb#!/bin/ksh -p 2178476Sjb# 3178476Sjb# CDDL HEADER START 4178476Sjb# 5178476Sjb# The contents of this file are subject to the terms of the 6178476Sjb# Common Development and Distribution License (the "License"). 7178476Sjb# You may not use this file except in compliance with the License. 8178476Sjb# 9178476Sjb# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10178476Sjb# or http://www.opensolaris.org/os/licensing. 11178476Sjb# See the License for the specific language governing permissions 12178476Sjb# and limitations under the License. 13178476Sjb# 14178476Sjb# When distributing Covered Code, include this CDDL HEADER in each 15178476Sjb# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16178476Sjb# If applicable, add the following below this CDDL HEADER, with the 17178476Sjb# fields enclosed by brackets "[]" replaced with your own identifying 18178476Sjb# information: Portions Copyright [yyyy] [name of copyright owner] 19178476Sjb# 20178476Sjb# CDDL HEADER END 21178476Sjb# 22178476Sjb 23178476Sjb# 24178476Sjb# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 25178476Sjb# Use is subject to license terms. 26178476Sjb# 27178476Sjb# ident "%Z%%M% %I% %E% SMI" 28178476Sjb 29178476Sjb# 30178476Sjb# This test verifies that USDT providers are removed when its associated 31178476Sjb# load object is closed via dlclose(3dl). 32178476Sjb# 33178476Sjb 34178476Sjbif [ $# != 1 ]; then 35178476Sjb echo expected one argument: '<'dtrace-path'>' 36178476Sjb exit 2 37178476Sjbfi 38178476Sjb 39178476Sjbdtrace=$1 40178476SjbDIR=/var/tmp/dtest.$$ 41178476Sjb 42178476Sjbmkdir $DIR 43178476Sjbcd $DIR 44178476Sjb 45178476Sjbcat > Makefile <<EOF 46178476Sjball: main livelib.so deadlib.so 47178476Sjb 48178476Sjbmain: main.o prov.o 49178476Sjb cc -o main main.o 50178476Sjb 51178476Sjbmain.o: main.c 52178476Sjb cc -c main.c 53178476Sjb 54178476Sjb 55178476Sjblivelib.so: livelib.o prov.o 56178476Sjb cc -z defs -G -o livelib.so livelib.o prov.o -lc 57178476Sjb 58178476Sjblivelib.o: livelib.c prov.h 59178476Sjb cc -c livelib.c 60178476Sjb 61178476Sjbprov.o: livelib.o prov.d 62178476Sjb $dtrace -G -s prov.d livelib.o 63178476Sjb 64178476Sjbprov.h: prov.d 65178476Sjb $dtrace -h -s prov.d 66178476Sjb 67178476Sjb 68178476Sjbdeadlib.so: deadlib.o 69178476Sjb cc -z defs -G -o deadlib.so deadlib.o -lc 70178476Sjb 71178476Sjbdeadlib.o: deadlib.c 72178476Sjb cc -c deadlib.c 73178476Sjb 74178476Sjbclean: 75178476Sjb rm -f main.o livelib.o prov.o prov.h deadlib.o 76178476Sjb 77178476Sjbclobber: clean 78178476Sjb rm -f main livelib.so deadlib.so 79178476SjbEOF 80178476Sjb 81178476Sjbcat > prov.d <<EOF 82178476Sjbprovider test_prov { 83178476Sjb probe go(); 84178476Sjb}; 85178476SjbEOF 86178476Sjb 87178476Sjbcat > livelib.c <<EOF 88178476Sjb#include "prov.h" 89178476Sjb 90178476Sjbvoid 91178476Sjbgo(void) 92178476Sjb{ 93178476Sjb TEST_PROV_GO(); 94178476Sjb} 95178476SjbEOF 96178476Sjb 97178476Sjbcat > deadlib.c <<EOF 98178476Sjbvoid 99178476Sjbgo(void) 100178476Sjb{ 101178476Sjb} 102178476SjbEOF 103178476Sjb 104178476Sjb 105178476Sjbcat > main.c <<EOF 106178476Sjb#include <dlfcn.h> 107178476Sjb#include <unistd.h> 108178476Sjb#include <stdio.h> 109178476Sjb 110178476Sjbint 111178476Sjbmain(int argc, char **argv) 112178476Sjb{ 113178476Sjb void *live; 114178476Sjb 115178476Sjb if ((live = dlopen("./livelib.so", RTLD_LAZY | RTLD_LOCAL)) == NULL) { 116178476Sjb printf("dlopen of livelib.so failed: %s\n", dlerror()); 117178476Sjb return (1); 118178476Sjb } 119178476Sjb 120178476Sjb (void) dlclose(live); 121178476Sjb 122178476Sjb pause(); 123178476Sjb 124178476Sjb return (0); 125178476Sjb} 126178476SjbEOF 127178476Sjb 128211545Srpaulo/usr/bin/make > /dev/null 129178476Sjbif [ $? -ne 0 ]; then 130178476Sjb print -u2 "failed to build" 131178476Sjb exit 1 132178476Sjbfi 133178476Sjb 134178476Sjbscript() { 135178476Sjb $dtrace -w -x bufsize=1k -c ./main -qs /dev/stdin <<EOF 136178476Sjb syscall::pause:entry 137178476Sjb /pid == \$target/ 138178476Sjb { 139178476Sjb system("$dtrace -l -P test_prov*"); 140178476Sjb system("kill %d", \$target); 141178476Sjb exit(0); 142178476Sjb } 143178476Sjb 144178476Sjb tick-1s 145178476Sjb /i++ == 5/ 146178476Sjb { 147178476Sjb printf("failed\n"); 148178476Sjb exit(1); 149178476Sjb } 150178476SjbEOF 151178476Sjb} 152178476Sjb 153178476Sjbscript 2>&1 154178476Sjbstatus=$? 155178476Sjb 156178476Sjbcd / 157211545Srpaulo/bin/rm -rf $DIR 158178476Sjb 159178476Sjbexit $status 160