tst.provregex2.ksh revision 279417
11849Swollman#!/bin/ksh -p
21849Swollman#
31849Swollman# CDDL HEADER START
41849Swollman#
51849Swollman# The contents of this file are subject to the terms of the
61849Swollman# Common Development and Distribution License (the "License").
71849Swollman# You may not use this file except in compliance with the License.
81849Swollman#
91849Swollman# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
101849Swollman# or http://www.opensolaris.org/os/licensing.
111849Swollman# See the License for the specific language governing permissions
121849Swollman# and limitations under the License.
131849Swollman#
141849Swollman# When distributing Covered Code, include this CDDL HEADER in each
151849Swollman# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
161849Swollman# If applicable, add the following below this CDDL HEADER, with the
171849Swollman# fields enclosed by brackets "[]" replaced with your own identifying
181849Swollman# information: Portions Copyright [yyyy] [name of copyright owner]
191849Swollman#
201849Swollman# CDDL HEADER END
211849Swollman#
221849Swollman
231849Swollman#
241849Swollman# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
251849Swollman# Use is subject to license terms.
261849Swollman#
271849Swollman# ident	"%Z%%M%	%I%	%E% SMI"
281849Swollman
291849Swollman#
301849Swollman# This test verifies that probes will be picked up after a dlopen(3C)
311849Swollman# when the pid provider is specified as a glob (e.g., p*d$target.)
321849Swollman#
3350476Speter
341849Swollmanif [ $# != 1 ]; then
351849Swollman	echo expected one argument: '<'dtrace-path'>'
3685437Speter	exit 2
371849Swollmanfi
381849Swollman
391849Swollmandtrace=$1
401849SwollmanDIR=${TMPDIR:-/tmp}/dtest.$$
411849Swollman
421849Swollmanmkdir $DIR
431849Swollmancd $DIR
441849Swollman
451849Swollmancat > Makefile <<EOF
46all: main altlib.so
47
48main: main.o
49	cc -o main main.o
50
51main.o: main.c
52	cc -c main.c
53
54altlib.so: altlib.o
55	cc -shared -o altlib.so altlib.o -lc
56
57altlib.o: altlib.c
58	cc -c altlib.c
59EOF
60
61cat > altlib.c <<EOF
62void
63go(void)
64{
65}
66EOF
67
68cat > main.c <<EOF
69#include <dlfcn.h>
70#include <unistd.h>
71#include <stdio.h>
72
73void
74go(void)
75{
76}
77
78int
79main(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}
101EOF
102
103make > /dev/null
104if [ $? -ne 0 ]; then
105	print -u2 "failed to build"
106	exit 1
107fi
108
109cat > main.d <<'EOF'
110p*d$target::go:entry
111{
112	@foo[probemod, probefunc, probename] = count();
113}
114
115END
116{
117	printa("%s:%s:%s %@u\n",@foo);
118}
119EOF
120
121script() {
122	$dtrace -q -s ./main.d -c ./main
123}
124
125script
126status=$?
127
128cd /tmp
129/bin/rm -rf $DIR
130
131exit $status
132