Home | History | Annotate | Download | only in usdt
      1  2633    ahl #!/bin/ksh -p
      2  2633    ahl #
      3  2633    ahl # CDDL HEADER START
      4  2633    ahl #
      5  2633    ahl # The contents of this file are subject to the terms of the
      6  2633    ahl # Common Development and Distribution License (the "License").
      7  2633    ahl # You may not use this file except in compliance with the License.
      8  2633    ahl #
      9  2633    ahl # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     10  2633    ahl # or http://www.opensolaris.org/os/licensing.
     11  2633    ahl # See the License for the specific language governing permissions
     12  2633    ahl # and limitations under the License.
     13  2633    ahl #
     14  2633    ahl # When distributing Covered Code, include this CDDL HEADER in each
     15  2633    ahl # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     16  2633    ahl # If applicable, add the following below this CDDL HEADER, with the
     17  2633    ahl # fields enclosed by brackets "[]" replaced with your own identifying
     18  2633    ahl # information: Portions Copyright [yyyy] [name of copyright owner]
     19  2633    ahl #
     20  2633    ahl # CDDL HEADER END
     21  2633    ahl #
     22  2633    ahl 
     23  2633    ahl #
     24  4821    ahl # Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
     25  2633    ahl # Use is subject to license terms.
     26  2633    ahl #
     27  4821    ahl # ident	"%Z%%M%	%I%	%E% SMI"
     28  4821    ahl 
     29  4821    ahl #
     30  4821    ahl # This test verifies that USDT providers are removed when its associated
     31  4821    ahl # load object is closed via dlclose(3dl).
     32  4821    ahl #
     33  2633    ahl 
     34  2804  tomee if [ $# != 1 ]; then
     35  2804  tomee 	echo expected one argument: '<'dtrace-path'>'
     36  2804  tomee 	exit 2
     37  2804  tomee fi
     38  2804  tomee 
     39  2804  tomee dtrace=$1
     40  2633    ahl DIR=/var/tmp/dtest.$$
     41  2633    ahl 
     42  2633    ahl mkdir $DIR
     43  2633    ahl cd $DIR
     44  2633    ahl 
     45  2633    ahl cat > Makefile <<EOF
     46  2633    ahl all: main livelib.so deadlib.so
     47  2633    ahl 
     48  2633    ahl main: main.o prov.o
     49  2633    ahl 	cc -o main main.o
     50  2633    ahl 
     51  2633    ahl main.o: main.c
     52  2633    ahl 	cc -c main.c
     53  2633    ahl 
     54  2633    ahl 
     55  2633    ahl livelib.so: livelib.o prov.o
     56  2633    ahl 	cc -z defs -G -o livelib.so livelib.o prov.o -lc
     57  2633    ahl 
     58  2633    ahl livelib.o: livelib.c prov.h
     59  2633    ahl 	cc -c livelib.c
     60  2633    ahl 
     61  2633    ahl prov.o: livelib.o prov.d
     62  2804  tomee 	$dtrace -G -s prov.d livelib.o
     63  2633    ahl 
     64  2633    ahl prov.h: prov.d
     65  2804  tomee 	$dtrace -h -s prov.d
     66  2633    ahl 
     67  2633    ahl 
     68  2633    ahl deadlib.so: deadlib.o
     69  2633    ahl 	cc -z defs -G -o deadlib.so deadlib.o -lc
     70  2633    ahl 
     71  2633    ahl deadlib.o: deadlib.c
     72  2633    ahl 	cc -c deadlib.c
     73  2633    ahl 
     74  2633    ahl clean:
     75  2633    ahl 	rm -f main.o livelib.o prov.o prov.h deadlib.o
     76  2633    ahl 
     77  2633    ahl clobber: clean
     78  2633    ahl 	rm -f main livelib.so deadlib.so
     79  2633    ahl EOF
     80  2633    ahl 
     81  2633    ahl cat > prov.d <<EOF
     82  2633    ahl provider test_prov {
     83  2633    ahl 	probe go();
     84  2633    ahl };
     85  2633    ahl EOF
     86  2633    ahl 
     87  2633    ahl cat > livelib.c <<EOF
     88  2633    ahl #include "prov.h"
     89  2633    ahl 
     90  2633    ahl void
     91  2633    ahl go(void)
     92  2633    ahl {
     93  2633    ahl 	TEST_PROV_GO();
     94  2633    ahl }
     95  2633    ahl EOF
     96  2633    ahl 
     97  2633    ahl cat > deadlib.c <<EOF
     98  2633    ahl void
     99  2633    ahl go(void)
    100  2633    ahl {
    101  2633    ahl }
    102  2633    ahl EOF
    103  2633    ahl 
    104  2633    ahl 
    105  2633    ahl cat > main.c <<EOF
    106  2633    ahl #include <dlfcn.h>
    107  2633    ahl #include <unistd.h>
    108  2633    ahl #include <stdio.h>
    109  2633    ahl 
    110  2633    ahl int
    111  2633    ahl main(int argc, char **argv)
    112  2633    ahl {
    113  2633    ahl 	void *live;
    114  2633    ahl 
    115  2633    ahl 	if ((live = dlopen("./livelib.so", RTLD_LAZY | RTLD_LOCAL)) == NULL) {
    116  2633    ahl 		printf("dlopen of livelib.so failed: %s\n", dlerror());
    117  2633    ahl 		return (1);
    118  2633    ahl 	}
    119  2633    ahl 
    120  2633    ahl 	(void) dlclose(live);
    121  2633    ahl 
    122  2633    ahl 	pause();
    123  2633    ahl 
    124  2633    ahl 	return (0);
    125  2633    ahl }
    126  2633    ahl EOF
    127  2633    ahl 
    128  2633    ahl /usr/ccs/bin/make > /dev/null
    129  2633    ahl if [ $? -ne 0 ]; then
    130  2633    ahl 	print -u2 "failed to build"
    131  2633    ahl 	exit 1
    132  2633    ahl fi
    133  2633    ahl 
    134  2633    ahl script() {
    135  4821    ahl 	$dtrace -w -x bufsize=1k -c ./main -qs /dev/stdin <<EOF
    136  2633    ahl 	syscall::pause:entry
    137  2633    ahl 	/pid == \$target/
    138  2633    ahl 	{
    139  2804  tomee 		system("$dtrace -l -P test_prov*");
    140  2633    ahl 		system("kill %d", \$target);
    141  2633    ahl 		exit(0);
    142  2633    ahl 	}
    143  2633    ahl 
    144  2633    ahl 	tick-1s
    145  2633    ahl 	/i++ == 5/
    146  2633    ahl 	{
    147  2633    ahl 		printf("failed\n");
    148  2633    ahl 		exit(1);
    149  2633    ahl 	}
    150  2633    ahl EOF
    151  2633    ahl }
    152  2633    ahl 
    153  2633    ahl script 2>&1
    154  2633    ahl status=$?
    155  2633    ahl 
    156  2633    ahl cd /
    157  2633    ahl /usr/bin/rm -rf $DIR
    158  2633    ahl 
    159  2633    ahl exit $status
    160