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 56279417Smarkj cc -shared -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 69279417Smarkj cc -shared -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> 109277916Smarkj#include <signal.h> 110178476Sjb 111178476Sjbint 112178476Sjbmain(int argc, char **argv) 113178476Sjb{ 114178476Sjb void *live; 115277916Smarkj sigset_t mask; 116178476Sjb 117178476Sjb if ((live = dlopen("./livelib.so", RTLD_LAZY | RTLD_LOCAL)) == NULL) { 118178476Sjb printf("dlopen of livelib.so failed: %s\n", dlerror()); 119178476Sjb return (1); 120178476Sjb } 121178476Sjb 122178476Sjb (void) dlclose(live); 123178476Sjb 124277916Smarkj (void) sigemptyset(&mask); 125277916Smarkj (void) sigsuspend(&mask); 126178476Sjb 127178476Sjb return (0); 128178476Sjb} 129178476SjbEOF 130178476Sjb 131211545Srpaulo/usr/bin/make > /dev/null 132178476Sjbif [ $? -ne 0 ]; then 133178476Sjb print -u2 "failed to build" 134178476Sjb exit 1 135178476Sjbfi 136178476Sjb 137178476Sjbscript() { 138178476Sjb $dtrace -w -x bufsize=1k -c ./main -qs /dev/stdin <<EOF 139277916Smarkj syscall::sigsuspend:entry 140178476Sjb /pid == \$target/ 141178476Sjb { 142178476Sjb system("$dtrace -l -P test_prov*"); 143178476Sjb system("kill %d", \$target); 144178476Sjb exit(0); 145178476Sjb } 146178476Sjb 147178476Sjb tick-1s 148178476Sjb /i++ == 5/ 149178476Sjb { 150178476Sjb printf("failed\n"); 151178476Sjb exit(1); 152178476Sjb } 153178476SjbEOF 154178476Sjb} 155178476Sjb 156178476Sjbscript 2>&1 157178476Sjbstatus=$? 158178476Sjb 159178476Sjbcd / 160211545Srpaulo/bin/rm -rf $DIR 161178476Sjb 162178476Sjbexit $status 163