1178476Sjb#
2178476Sjb# CDDL HEADER START
3178476Sjb#
4178476Sjb# The contents of this file are subject to the terms of the
5178476Sjb# Common Development and Distribution License (the "License").
6178476Sjb# You may not use this file except in compliance with the License.
7178476Sjb#
8178476Sjb# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9178476Sjb# or http://www.opensolaris.org/os/licensing.
10178476Sjb# See the License for the specific language governing permissions
11178476Sjb# and limitations under the License.
12178476Sjb#
13178476Sjb# When distributing Covered Code, include this CDDL HEADER in each
14178476Sjb# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15178476Sjb# If applicable, add the following below this CDDL HEADER, with the
16178476Sjb# fields enclosed by brackets "[]" replaced with your own identifying
17178476Sjb# information: Portions Copyright [yyyy] [name of copyright owner]
18178476Sjb#
19178476Sjb# CDDL HEADER END
20178476Sjb#
21178476Sjb
22178476Sjb#
23178476Sjb# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24178476Sjb# Use is subject to license terms.
25178476Sjb#
26178476Sjb# ident	"%Z%%M%	%I%	%E% SMI"
27178476Sjb
28178476Sjb#
29178476Sjb# ASSERTION: Make sure USDT probes work as tail-calls on SPARC.
30178476Sjb#
31178476Sjb
32178476Sjbif [ $# != 1 ]; then
33178476Sjb	echo expected one argument: '<'dtrace-path'>'
34178476Sjb	exit 2
35178476Sjbfi
36178476Sjb
37178476Sjbdtrace=$1
38178476SjbDIR=/var/tmp/dtest.$$
39178476Sjb
40178476Sjbmkdir $DIR
41178476Sjbcd $DIR
42178476Sjb
43178476Sjbcat > test.s <<EOF
44178476Sjb#include <sys/asm_linkage.h>
45178476Sjb
46178476Sjb	DGDEF(__fsr_init_value)
47178476Sjb	.word 0
48178476Sjb
49178476Sjb	ENTRY(test)
50178476Sjb	save	%sp, -SA(MINFRAME + 4), %sp
51178476Sjb	mov	9, %i0
52178476Sjb	mov	19, %i1
53178476Sjb	mov	2006, %i2
54178476Sjb	call	__dtrace_test___fire
55178476Sjb	restore
56178476Sjb	SET_SIZE(test)
57178476Sjb
58178476Sjb	ENTRY(main)
59178476Sjb	save	%sp, -SA(MINFRAME + 4), %sp
60178476Sjb
61178476Sjb1:
62178476Sjb	call	test
63178476Sjb	nop
64178476Sjb
65178476Sjb	ba	1b
66178476Sjb	nop
67178476Sjb
68178476Sjb	ret
69178476Sjb	restore	%g0, %g0, %o0
70178476Sjb	SET_SIZE(main)
71178476SjbEOF
72178476Sjb
73178476Sjbcat > prov.d <<EOF
74178476Sjbprovider test {
75178476Sjb	probe fire(int, int, int);
76178476Sjb};
77178476SjbEOF
78178476Sjb
79211545Srpaulo/usr/bin/as -xregsym=no -P -D_ASM -o test.o test.s
80178476Sjbif [ $? -ne 0 ]; then
81178476Sjb	print -u2 "failed to compile test.s"
82178476Sjb	exit 1
83178476Sjbfi
84178476Sjb
85178476Sjb$dtrace -G -32 -s prov.d test.o
86178476Sjbif [ $? -ne 0 ]; then
87178476Sjb	print -u2 "failed to create DOF"
88178476Sjb	exit 1
89178476Sjbfi
90178476Sjb
91178476Sjbcc -o test test.o prov.o
92178476Sjbif [ $? -ne 0 ]; then
93178476Sjb	print -u2 "failed to link final executable"
94178476Sjb	exit 1
95178476Sjbfi
96178476Sjb
97178476Sjb$dtrace -c ./test -s /dev/stdin <<EOF
98178476Sjbtest\$target:::fire
99178476Sjb/arg0 == 9 && arg1 == 19 && arg2 == 2006/
100178476Sjb{
101178476Sjb	printf("%d/%d/%d", arg0, arg1, arg2);
102178476Sjb	exit(0);
103178476Sjb}
104178476Sjb
105178476Sjbtest\$target:::fire
106178476Sjb{
107178476Sjb	printf("%d/%d/%d", arg0, arg1, arg2);
108178476Sjb	exit(1);
109178476Sjb}
110178476Sjb
111178476SjbBEGIN
112178476Sjb{
113178476Sjb	/*
114178476Sjb	 * Let's just do this for 5 seconds.
115178476Sjb	 */
116178476Sjb	timeout = timestamp + 5000000000;
117178476Sjb}
118178476Sjb
119178476Sjbprofile:::tick-4
120178476Sjb/timestamp > timeout/
121178476Sjb{
122178476Sjb	trace("test timed out");
123178476Sjb	exit(1);
124178476Sjb}
125178476SjbEOF
126178476Sjb
127178476Sjbstatus=$?
128178476Sjb
129178476Sjbcd /
130211545Srpaulo/bin/rm -rf $DIR
131178476Sjb
132178476Sjbexit $status
133