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 USDT probes will be picked up after a dlopen(3C) 306e0bee74Sjhaslam# when a regex in the provider name matches both USDT probes and pid probes 316e0bee74Sjhaslam# (e.g., p*d$target matches both pid$target and pyramid$target.) 326e0bee74Sjhaslam# 336e0bee74Sjhaslam 346e0bee74Sjhaslamif [ $# != 1 ]; then 356e0bee74Sjhaslam echo expected one argument: '<'dtrace-path'>' 366e0bee74Sjhaslam exit 2 376e0bee74Sjhaslamfi 386e0bee74Sjhaslam 396e0bee74Sjhaslamdtrace=$1 406e0bee74SjhaslamDIR=${TMPDIR:-/tmp}/dtest.$$ 416e0bee74Sjhaslam 426e0bee74Sjhaslammkdir $DIR 436e0bee74Sjhaslamcd $DIR 446e0bee74Sjhaslam 456e0bee74Sjhaslamcat > Makefile <<EOF 466e0bee74Sjhaslamall: main altlib.so 476e0bee74Sjhaslam 486e0bee74Sjhaslammain: main.o provmain.o 49*a386cc11SRobert Mustacchi gcc -m32 -o main main.o provmain.o 506e0bee74Sjhaslam 516e0bee74Sjhaslammain.o: main.c prov.h 52*a386cc11SRobert Mustacchi gcc -m32 -c main.c 536e0bee74Sjhaslam 546e0bee74Sjhaslamprov.h: prov.d 556e0bee74Sjhaslam $dtrace -h -s prov.d 566e0bee74Sjhaslam 576e0bee74Sjhaslamprovmain.o: prov.d main.o 586e0bee74Sjhaslam $dtrace -G -32 -o provmain.o -s prov.d main.o 596e0bee74Sjhaslam 606e0bee74Sjhaslamaltlib.so: altlib.o provalt.o 61*a386cc11SRobert Mustacchi gcc -m32 -shared -o altlib.so altlib.o provalt.o -lc 626e0bee74Sjhaslam 636e0bee74Sjhaslamaltlib.o: altlib.c prov.h 64*a386cc11SRobert Mustacchi gcc -m32 -c altlib.c 656e0bee74Sjhaslam 666e0bee74Sjhaslamprovalt.o: prov.d altlib.o 676e0bee74Sjhaslam $dtrace -G -32 -o provalt.o -s prov.d altlib.o 686e0bee74SjhaslamEOF 696e0bee74Sjhaslam 706e0bee74Sjhaslamcat > prov.d <<EOF 716e0bee74Sjhaslamprovider pyramid { 726e0bee74Sjhaslam probe entry(); 736e0bee74Sjhaslam}; 746e0bee74SjhaslamEOF 756e0bee74Sjhaslam 766e0bee74Sjhaslamcat > altlib.c <<EOF 776e0bee74Sjhaslam#include <sys/sdt.h> 786e0bee74Sjhaslam#include "prov.h" 796e0bee74Sjhaslam 806e0bee74Sjhaslamvoid 816e0bee74Sjhaslamgo(void) 826e0bee74Sjhaslam{ 836e0bee74Sjhaslam PYRAMID_ENTRY(); 846e0bee74Sjhaslam} 856e0bee74SjhaslamEOF 866e0bee74Sjhaslam 876e0bee74Sjhaslamcat > main.c <<EOF 886e0bee74Sjhaslam#include <dlfcn.h> 896e0bee74Sjhaslam#include <unistd.h> 906e0bee74Sjhaslam#include <stdio.h> 916e0bee74Sjhaslam#include <sys/sdt.h> 926e0bee74Sjhaslam#include "prov.h" 936e0bee74Sjhaslam 946e0bee74Sjhaslamvoid 956e0bee74Sjhaslamgo(void) 966e0bee74Sjhaslam{ 976e0bee74Sjhaslam PYRAMID_ENTRY(); 986e0bee74Sjhaslam} 996e0bee74Sjhaslam 1006e0bee74Sjhaslamint 1016e0bee74Sjhaslammain(int argc, char **argv) 1026e0bee74Sjhaslam{ 1036e0bee74Sjhaslam void *alt; 1046e0bee74Sjhaslam void *alt_go; 1056e0bee74Sjhaslam 1066e0bee74Sjhaslam go(); 1076e0bee74Sjhaslam 1086e0bee74Sjhaslam if ((alt = dlopen("./altlib.so", RTLD_LAZY | RTLD_LOCAL)) 1096e0bee74Sjhaslam == NULL) { 1106e0bee74Sjhaslam printf("dlopen of altlib.so failed: %s\n", dlerror()); 1116e0bee74Sjhaslam return (1); 1126e0bee74Sjhaslam } 1136e0bee74Sjhaslam 1146e0bee74Sjhaslam if ((alt_go = dlsym(alt, "go")) == NULL) { 1156e0bee74Sjhaslam printf("failed to lookup 'go' in altlib.so\n"); 1166e0bee74Sjhaslam return (1); 1176e0bee74Sjhaslam } 1186e0bee74Sjhaslam 1196e0bee74Sjhaslam ((void (*)(void))alt_go)(); 1206e0bee74Sjhaslam 1216e0bee74Sjhaslam return (0); 1226e0bee74Sjhaslam} 1236e0bee74SjhaslamEOF 1246e0bee74Sjhaslam 1256e0bee74Sjhaslammake > /dev/null 1266e0bee74Sjhaslamif [ $? -ne 0 ]; then 1276e0bee74Sjhaslam print -u2 "failed to build" 1286e0bee74Sjhaslam exit 1 1296e0bee74Sjhaslamfi 1306e0bee74Sjhaslam 1316e0bee74Sjhaslamcat > main.d <<'EOF' 1326e0bee74Sjhaslamp*d$target::go:entry 1336e0bee74Sjhaslam{ 1346e0bee74Sjhaslam @foo[probemod, probefunc, probename] = count(); 1356e0bee74Sjhaslam} 1366e0bee74Sjhaslam 1376e0bee74SjhaslamEND 1386e0bee74Sjhaslam{ 1396e0bee74Sjhaslam printa("%s:%s:%s %@u\n",@foo); 1406e0bee74Sjhaslam} 1416e0bee74SjhaslamEOF 1426e0bee74Sjhaslam 1436e0bee74Sjhaslamscript() { 1446e0bee74Sjhaslam $dtrace -q -s ./main.d -c ./main 1456e0bee74Sjhaslam} 1466e0bee74Sjhaslam 1476e0bee74Sjhaslamscript 1486e0bee74Sjhaslamstatus=$? 1496e0bee74Sjhaslam 1506e0bee74Sjhaslamcd /tmp 1516e0bee74Sjhaslam/usr/bin/rm -rf $DIR 1526e0bee74Sjhaslam 1536e0bee74Sjhaslamexit $status 154