tst.provregex3.ksh revision 211545
155714Skris#!/bin/ksh -p
2160814Ssimon#
3238405Sjkim# CDDL HEADER START
4160814Ssimon#
5160814Ssimon# The contents of this file are subject to the terms of the
6160814Ssimon# Common Development and Distribution License (the "License").
7160814Ssimon# You may not use this file except in compliance with the License.
8160814Ssimon#
9160814Ssimon# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10160814Ssimon# or http://www.opensolaris.org/os/licensing.
11160814Ssimon# See the License for the specific language governing permissions
12160814Ssimon# and limitations under the License.
13160814Ssimon#
14160814Ssimon# When distributing Covered Code, include this CDDL HEADER in each
15160814Ssimon# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16160814Ssimon# If applicable, add the following below this CDDL HEADER, with the
17160814Ssimon# fields enclosed by brackets "[]" replaced with your own identifying
18160814Ssimon# information: Portions Copyright [yyyy] [name of copyright owner]
19160814Ssimon#
20160814Ssimon# CDDL HEADER END
21160814Ssimon#
22160814Ssimon
23160814Ssimon#
24160814Ssimon# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
25160814Ssimon# Use is subject to license terms.
26160814Ssimon#
27160814Ssimon# ident	"%Z%%M%	%I%	%E% SMI"
28160814Ssimon
29160814Ssimon#
30160814Ssimon# This test verifies that a regex in the provider name will match
31160814Ssimon# USDT probes as well as pid probes (e.g., p*d$target matches both 
32160814Ssimon# pid$target and pyramid$target.)
33160814Ssimon#
34160814Ssimon
35160814Ssimonif [ $# != 1 ]; then
36160814Ssimon	echo expected one argument: '<'dtrace-path'>'
37160814Ssimon	exit 2
38160814Ssimonfi
39160814Ssimon
40160814Ssimondtrace=$1
41160814SsimonDIR=${TMPDIR:-/tmp}/dtest.$$
42160814Ssimon
43160814Ssimonmkdir $DIR
44160814Ssimoncd $DIR
45160814Ssimon
46160814Ssimoncat > Makefile <<EOF
47160814Ssimon	all: main
48160814Ssimon
49160814Ssimonmain: main.o prov.o
50160814Ssimon	cc -o main main.o prov.o
51160814Ssimon
52160814Ssimonmain.o: main.c prov.h
53160814Ssimon	cc -c main.c
54160814Ssimon
5555714Skrisprov.h: prov.d
5655714Skris	$dtrace -h -s prov.d
5755714Skris
5855714Skrisprov.o: prov.d main.o
5955714Skris	$dtrace -G -32 -s prov.d main.o
6055714SkrisEOF
6155714Skris
6255714Skriscat > prov.d <<EOF
6355714Skrisprovider pyramid {
6455714Skris	probe entry();
6555714Skris};
6655714SkrisEOF
6755714Skris
6855714Skriscat > main.c <<EOF
6955714Skris#include <sys/sdt.h>
7055714Skris#include "prov.h"
7155714Skris
7255714Skrisint
7355714Skrismain(int argc, char **argv)
7455714Skris{
7555714Skris	PYRAMID_ENTRY();
7655714Skris}
7755714SkrisEOF
7855714Skris
7955714Skrismake > /dev/null
8055714Skrisif [ $? -ne 0 ]; then
8155714Skris	print -u2 "failed to build"
8255714Skris	exit 1
8355714Skrisfi
8455714Skris
8555714Skriscat > main.d <<'EOF'
8655714Skrisp*d$target::main:entry
8755714Skris{
8855714Skris	printf("%s:%s:%s\n", probemod, probefunc, probename);
8955714Skris}
9055714SkrisEOF
9155714Skris
9255714Skrisscript() {
9355714Skris	$dtrace -q -s ./main.d -c ./main
9455714Skris}
9555714Skris
9655714Skrisscript
9755714Skrisstatus=$?
9855714Skris
9955714Skriscd /tmp
10055714Skris/bin/rm -rf $DIR
10155714Skris
10255714Skrisexit $status
10355714Skris