Home | History | Annotate | Download | only in pid
      1 #!/bin/ksh -p
      2 #
      3 # CDDL HEADER START
      4 #
      5 # The contents of this file are subject to the terms of the
      6 # Common Development and Distribution License (the "License").
      7 # You may not use this file except in compliance with the License.
      8 #
      9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     10 # or http://www.opensolaris.org/os/licensing.
     11 # See the License for the specific language governing permissions
     12 # and limitations under the License.
     13 #
     14 # When distributing Covered Code, include this CDDL HEADER in each
     15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     16 # If applicable, add the following below this CDDL HEADER, with the
     17 # fields enclosed by brackets "[]" replaced with your own identifying
     18 # information: Portions Copyright [yyyy] [name of copyright owner]
     19 #
     20 # CDDL HEADER END
     21 #
     22 
     23 #
     24 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
     25 # Use is subject to license terms.
     26 #
     27 # ident	"%Z%%M%	%I%	%E% SMI"
     28 
     29 #
     30 # This test verifies that probes will be picked up after a dlopen(3C)
     31 # when the pid provider is specified as a glob (e.g., p*d$target.)
     32 #
     33 
     34 if [ $# != 1 ]; then
     35 	echo expected one argument: '<'dtrace-path'>'
     36 	exit 2
     37 fi
     38 
     39 dtrace=$1
     40 DIR=${TMPDIR:-/tmp}/dtest.$$
     41 
     42 mkdir $DIR
     43 cd $DIR
     44 
     45 cat > Makefile <<EOF
     46 all: main altlib.so
     47 
     48 main: main.o
     49 	cc -o main main.o
     50 
     51 main.o: main.c
     52 	cc -c main.c
     53 
     54 altlib.so: altlib.o
     55 	cc -z defs -G -o altlib.so altlib.o -lc
     56 
     57 altlib.o: altlib.c
     58 	cc -c altlib.c
     59 EOF
     60 
     61 cat > altlib.c <<EOF
     62 void
     63 go(void)
     64 {
     65 }
     66 EOF
     67 
     68 cat > main.c <<EOF
     69 #include <dlfcn.h>
     70 #include <unistd.h>
     71 #include <stdio.h>
     72 
     73 void
     74 go(void)
     75 {
     76 }
     77 
     78 int
     79 main(int argc, char **argv)
     80 {
     81 	void *alt;
     82 	void *alt_go;
     83 
     84 	go();
     85 
     86 	if ((alt = dlopen("./altlib.so", RTLD_LAZY | RTLD_LOCAL)) 
     87 	    == NULL) {
     88 		printf("dlopen of altlib.so failed: %s\n", dlerror());
     89 		return (1);
     90 	}
     91 
     92 	if ((alt_go = dlsym(alt, "go")) == NULL) {
     93 		printf("failed to lookup 'go' in altlib.so\n");
     94 		return (1);
     95 	}
     96 
     97 	((void (*)(void))alt_go)();
     98 
     99 	return (0);
    100 }
    101 EOF
    102 
    103 make > /dev/null
    104 if [ $? -ne 0 ]; then
    105 	print -u2 "failed to build"
    106 	exit 1
    107 fi
    108 
    109 cat > main.d <<'EOF'
    110 p*d$target::go:entry
    111 {
    112 	@foo[probemod, probefunc, probename] = count();
    113 }
    114 
    115 END
    116 {
    117 	printa("%s:%s:%s %@u\n",@foo);
    118 }
    119 EOF
    120 
    121 script() {
    122 	$dtrace -q -s ./main.d -c ./main
    123 }
    124 
    125 script
    126 status=$?
    127 
    128 cd /tmp
    129 /usr/bin/rm -rf $DIR
    130 
    131 exit $status
    132