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 2006 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26# 27#ident "%Z%%M% %I% %E% SMI" 28 29DIR=/var/tmp/dtest.$$ 30 31mkdir $DIR 32cd $DIR 33 34cat > Makefile <<EOF 35all: main livelib.so deadlib.so 36 37main: main.o prov.o 38 cc -o main main.o 39 40main.o: main.c 41 cc -c main.c 42 43 44livelib.so: livelib.o prov.o 45 cc -z defs -G -o livelib.so livelib.o prov.o -lc 46 47livelib.o: livelib.c prov.h 48 cc -c livelib.c 49 50prov.o: livelib.o prov.d 51 dtrace -G -s prov.d livelib.o 52 53prov.h: prov.d 54 dtrace -h -s prov.d 55 56 57deadlib.so: deadlib.o 58 cc -z defs -G -o deadlib.so deadlib.o -lc 59 60deadlib.o: deadlib.c 61 cc -c deadlib.c 62 63clean: 64 rm -f main.o livelib.o prov.o prov.h deadlib.o 65 66clobber: clean 67 rm -f main livelib.so deadlib.so 68EOF 69 70cat > prov.d <<EOF 71provider test_prov { 72 probe go(); 73}; 74EOF 75 76cat > livelib.c <<EOF 77#include "prov.h" 78 79void 80go(void) 81{ 82 TEST_PROV_GO(); 83} 84EOF 85 86cat > deadlib.c <<EOF 87void 88go(void) 89{ 90} 91EOF 92 93 94cat > main.c <<EOF 95#include <dlfcn.h> 96#include <unistd.h> 97#include <stdio.h> 98 99int 100main(int argc, char **argv) 101{ 102 void *live; 103 104 if ((live = dlopen("./livelib.so", RTLD_LAZY | RTLD_LOCAL)) == NULL) { 105 printf("dlopen of livelib.so failed: %s\n", dlerror()); 106 return (1); 107 } 108 109 (void) dlclose(live); 110 111 pause(); 112 113 return (0); 114} 115EOF 116 117/usr/ccs/bin/make > /dev/null 118if [ $? -ne 0 ]; then 119 print -u2 "failed to build" 120 exit 1 121fi 122 123script() { 124 dtrace -w -c ./main -qs /dev/stdin <<EOF 125 syscall::pause:entry 126 /pid == \$target/ 127 { 128 system("dtrace -l -P test_prov*"); 129 system("kill %d", \$target); 130 exit(0); 131 } 132 133 tick-1s 134 /i++ == 5/ 135 { 136 printf("failed\n"); 137 exit(1); 138 } 139EOF 140} 141 142script 2>&1 143status=$? 144 145cd / 146/usr/bin/rm -rf $DIR 147 148exit $status 149