xref: /illumos-gate/usr/src/cmd/dtrace/test/tst/common/pid/tst.provregex2.ksh (revision a386cc11a86ecb60f5a48078d22c1500e2ad003e)
16e0bee74Sjhaslam#!/bin/ksh -p
26e0bee74Sjhaslam#
36e0bee74Sjhaslam# CDDL HEADER START
46e0bee74Sjhaslam#
56e0bee74Sjhaslam# The contents of this file are subject to the terms of the
66e0bee74Sjhaslam# Common Development and Distribution License (the "License").
76e0bee74Sjhaslam# You may not use this file except in compliance with the License.
86e0bee74Sjhaslam#
96e0bee74Sjhaslam# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
106e0bee74Sjhaslam# or http://www.opensolaris.org/os/licensing.
116e0bee74Sjhaslam# See the License for the specific language governing permissions
126e0bee74Sjhaslam# and limitations under the License.
136e0bee74Sjhaslam#
146e0bee74Sjhaslam# When distributing Covered Code, include this CDDL HEADER in each
156e0bee74Sjhaslam# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
166e0bee74Sjhaslam# If applicable, add the following below this CDDL HEADER, with the
176e0bee74Sjhaslam# fields enclosed by brackets "[]" replaced with your own identifying
186e0bee74Sjhaslam# information: Portions Copyright [yyyy] [name of copyright owner]
196e0bee74Sjhaslam#
206e0bee74Sjhaslam# CDDL HEADER END
216e0bee74Sjhaslam#
226e0bee74Sjhaslam
236e0bee74Sjhaslam#
246e0bee74Sjhaslam# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
256e0bee74Sjhaslam# Use is subject to license terms.
266e0bee74Sjhaslam#
276e0bee74Sjhaslam
286e0bee74Sjhaslam#
296e0bee74Sjhaslam# This test verifies that probes will be picked up after a dlopen(3C)
306e0bee74Sjhaslam# when the pid provider is specified as a glob (e.g., p*d$target.)
316e0bee74Sjhaslam#
326e0bee74Sjhaslam
336e0bee74Sjhaslamif [ $# != 1 ]; then
346e0bee74Sjhaslam	echo expected one argument: '<'dtrace-path'>'
356e0bee74Sjhaslam	exit 2
366e0bee74Sjhaslamfi
376e0bee74Sjhaslam
386e0bee74Sjhaslamdtrace=$1
396e0bee74SjhaslamDIR=${TMPDIR:-/tmp}/dtest.$$
406e0bee74Sjhaslam
416e0bee74Sjhaslammkdir $DIR
426e0bee74Sjhaslamcd $DIR
436e0bee74Sjhaslam
446e0bee74Sjhaslamcat > Makefile <<EOF
456e0bee74Sjhaslamall: main altlib.so
466e0bee74Sjhaslam
476e0bee74Sjhaslammain: main.o
48*a386cc11SRobert Mustacchi	gcc -m32 -o main main.o
496e0bee74Sjhaslam
506e0bee74Sjhaslammain.o: main.c
51*a386cc11SRobert Mustacchi	gcc -m32 -c main.c
526e0bee74Sjhaslam
536e0bee74Sjhaslamaltlib.so: altlib.o
54*a386cc11SRobert Mustacchi	gcc -m32 -shared -o altlib.so altlib.o -lc
556e0bee74Sjhaslam
566e0bee74Sjhaslamaltlib.o: altlib.c
57*a386cc11SRobert Mustacchi	gcc -m32 -fPIC -c altlib.c
586e0bee74SjhaslamEOF
596e0bee74Sjhaslam
606e0bee74Sjhaslamcat > altlib.c <<EOF
616e0bee74Sjhaslamvoid
626e0bee74Sjhaslamgo(void)
636e0bee74Sjhaslam{
646e0bee74Sjhaslam}
656e0bee74SjhaslamEOF
666e0bee74Sjhaslam
676e0bee74Sjhaslamcat > main.c <<EOF
686e0bee74Sjhaslam#include <dlfcn.h>
696e0bee74Sjhaslam#include <unistd.h>
706e0bee74Sjhaslam#include <stdio.h>
716e0bee74Sjhaslam
726e0bee74Sjhaslamvoid
736e0bee74Sjhaslamgo(void)
746e0bee74Sjhaslam{
756e0bee74Sjhaslam}
766e0bee74Sjhaslam
776e0bee74Sjhaslamint
786e0bee74Sjhaslammain(int argc, char **argv)
796e0bee74Sjhaslam{
806e0bee74Sjhaslam	void *alt;
816e0bee74Sjhaslam	void *alt_go;
826e0bee74Sjhaslam
836e0bee74Sjhaslam	go();
846e0bee74Sjhaslam
856e0bee74Sjhaslam	if ((alt = dlopen("./altlib.so", RTLD_LAZY | RTLD_LOCAL)) 
866e0bee74Sjhaslam	    == NULL) {
876e0bee74Sjhaslam		printf("dlopen of altlib.so failed: %s\n", dlerror());
886e0bee74Sjhaslam		return (1);
896e0bee74Sjhaslam	}
906e0bee74Sjhaslam
916e0bee74Sjhaslam	if ((alt_go = dlsym(alt, "go")) == NULL) {
926e0bee74Sjhaslam		printf("failed to lookup 'go' in altlib.so\n");
936e0bee74Sjhaslam		return (1);
946e0bee74Sjhaslam	}
956e0bee74Sjhaslam
966e0bee74Sjhaslam	((void (*)(void))alt_go)();
976e0bee74Sjhaslam
986e0bee74Sjhaslam	return (0);
996e0bee74Sjhaslam}
1006e0bee74SjhaslamEOF
1016e0bee74Sjhaslam
1026e0bee74Sjhaslammake > /dev/null
1036e0bee74Sjhaslamif [ $? -ne 0 ]; then
1046e0bee74Sjhaslam	print -u2 "failed to build"
1056e0bee74Sjhaslam	exit 1
1066e0bee74Sjhaslamfi
1076e0bee74Sjhaslam
1086e0bee74Sjhaslamcat > main.d <<'EOF'
1096e0bee74Sjhaslamp*d$target::go:entry
1106e0bee74Sjhaslam{
1116e0bee74Sjhaslam	@foo[probemod, probefunc, probename] = count();
1126e0bee74Sjhaslam}
1136e0bee74Sjhaslam
1146e0bee74SjhaslamEND
1156e0bee74Sjhaslam{
1166e0bee74Sjhaslam	printa("%s:%s:%s %@u\n",@foo);
1176e0bee74Sjhaslam}
1186e0bee74SjhaslamEOF
1196e0bee74Sjhaslam
1206e0bee74Sjhaslamscript() {
1216e0bee74Sjhaslam	$dtrace -q -s ./main.d -c ./main
1226e0bee74Sjhaslam}
1236e0bee74Sjhaslam
1246e0bee74Sjhaslamscript
1256e0bee74Sjhaslamstatus=$?
1266e0bee74Sjhaslam
1276e0bee74Sjhaslamcd /tmp
1286e0bee74Sjhaslam/usr/bin/rm -rf $DIR
1296e0bee74Sjhaslam
1306e0bee74Sjhaslamexit $status
131