1*e5803b76SAdam H. Leventhal#!/bin/ksh -p
2*e5803b76SAdam H. Leventhal#
3*e5803b76SAdam H. Leventhal# CDDL HEADER START
4*e5803b76SAdam H. Leventhal#
5*e5803b76SAdam H. Leventhal# This file and its contents are supplied under the terms of the
6*e5803b76SAdam H. Leventhal# Common Development and Distribution License ("CDDL"), version 1.0.
7*e5803b76SAdam H. Leventhal# You may only use this file in accordance with the terms of version
8*e5803b76SAdam H. Leventhal# 1.0 of the CDDL.
9*e5803b76SAdam H. Leventhal#
10*e5803b76SAdam H. Leventhal# A full copy of the text of the CDDL should have accompanied this
11*e5803b76SAdam H. Leventhal# source.  A copy of the CDDL is also available via the Internet at
12*e5803b76SAdam H. Leventhal# http://www.illumos.org/license/CDDL.
13*e5803b76SAdam H. Leventhal#
14*e5803b76SAdam H. Leventhal# CDDL HEADER END
15*e5803b76SAdam H. Leventhal#
16*e5803b76SAdam H. Leventhal
17*e5803b76SAdam H. Leventhal#
18*e5803b76SAdam H. Leventhal# Copyright (c) 2012 by Delphix. All rights reserved.
19*e5803b76SAdam H. Leventhal#
20*e5803b76SAdam H. Leventhal
21*e5803b76SAdam H. Leventhal############################################################################
22*e5803b76SAdam H. Leventhal# ASSERTION:
23*e5803b76SAdam H. Leventhal#	temporal option causes output to be sorted
24*e5803b76SAdam H. Leventhal#
25*e5803b76SAdam H. Leventhal# SECTION: Pragma
26*e5803b76SAdam H. Leventhal#
27*e5803b76SAdam H. Leventhal# NOTES: The temporal option has no effect on a single-CPU system, so
28*e5803b76SAdam H. Leventhal#    this needs to be run on a multi-CPU system to effectively test the
29*e5803b76SAdam H. Leventhal#    temporal option.
30*e5803b76SAdam H. Leventhal#
31*e5803b76SAdam H. Leventhal############################################################################
32*e5803b76SAdam H. Leventhal
33*e5803b76SAdam H. Leventhalif [ $# != 1 ]; then
34*e5803b76SAdam H. Leventhal	echo expected one argument: '<'dtrace-path'>'
35*e5803b76SAdam H. Leventhal	exit 2
36*e5803b76SAdam H. Leventhalfi
37*e5803b76SAdam H. Leventhal
38*e5803b76SAdam H. Leventhaldtrace=$1
39*e5803b76SAdam H. Leventhalfile=/tmp/out.$$
40*e5803b76SAdam H. Leventhal
41*e5803b76SAdam H. Leventhalrm -f $file
42*e5803b76SAdam H. Leventhal
43*e5803b76SAdam H. Leventhal$dtrace -o $file -c 'sleep 3' -s /dev/stdin <<EOF
44*e5803b76SAdam H. Leventhal	#pragma D option quiet
45*e5803b76SAdam H. Leventhal	#pragma D option temporal
46*e5803b76SAdam H. Leventhal
47*e5803b76SAdam H. Leventhal	BEGIN
48*e5803b76SAdam H. Leventhal	{
49*e5803b76SAdam H. Leventhal		@lines = count();
50*e5803b76SAdam H. Leventhal		printf("0 begin\n");
51*e5803b76SAdam H. Leventhal	}
52*e5803b76SAdam H. Leventhal
53*e5803b76SAdam H. Leventhal	END
54*e5803b76SAdam H. Leventhal	{
55*e5803b76SAdam H. Leventhal		/* Bump @lines every time we print a line. */
56*e5803b76SAdam H. Leventhal		@lines = count();
57*e5803b76SAdam H. Leventhal		printf("%u end\n", timestamp);
58*e5803b76SAdam H. Leventhal		@lines = count();
59*e5803b76SAdam H. Leventhal		printa("99999999999999999 lines %@u\n", @lines);
60*e5803b76SAdam H. Leventhal	}
61*e5803b76SAdam H. Leventhal
62*e5803b76SAdam H. Leventhal	profile-97hz
63*e5803b76SAdam H. Leventhal	{
64*e5803b76SAdam H. Leventhal		@lines = count();
65*e5803b76SAdam H. Leventhal		printf("%u\n", timestamp);
66*e5803b76SAdam H. Leventhal	}
67*e5803b76SAdam H. LeventhalEOF
68*e5803b76SAdam H. Leventhal
69*e5803b76SAdam H. Leventhalstatus=$?
70*e5803b76SAdam H. Leventhalif [ "$status" -ne 0 ]; then
71*e5803b76SAdam H. Leventhal	echo $tst: dtrace failed
72*e5803b76SAdam H. Leventhal	exit $status
73*e5803b76SAdam H. Leventhalfi
74*e5803b76SAdam H. Leventhal
75*e5803b76SAdam H. Leventhal# dtrace outputs a blank line at the end, which will sort to the beginning,
76*e5803b76SAdam H. Leventhal# so use head to remove the blank line.
77*e5803b76SAdam H. Leventhalhead -n -1 $file > $file.2
78*e5803b76SAdam H. Leventhal
79*e5803b76SAdam H. Leventhalsort -n $file.2 | diff $file.2 -
80*e5803b76SAdam H. Leventhalstatus=$?
81*e5803b76SAdam H. Leventhalif [ "$status" -ne 0 ]; then
82*e5803b76SAdam H. Leventhal	echo $tst: output is not sorted
83*e5803b76SAdam H. Leventhal	exit $status
84*e5803b76SAdam H. Leventhalfi
85*e5803b76SAdam H. Leventhal
86*e5803b76SAdam H. Leventhalhead -n 1 $file.2 | grep begin >/dev/null
87*e5803b76SAdam H. Leventhalstatus=$?
88*e5803b76SAdam H. Leventhalif [ "$status" -ne 0 ]; then
89*e5803b76SAdam H. Leventhal	echo $tst: begin probe did not fire
90*e5803b76SAdam H. Leventhal	exit $status
91*e5803b76SAdam H. Leventhalfi
92*e5803b76SAdam H. Leventhal
93*e5803b76SAdam H. Leventhaltail -n 2 $file.2 | grep end >/dev/null
94*e5803b76SAdam H. Leventhalstatus=$?
95*e5803b76SAdam H. Leventhalif [ "$status" -ne 0 ]; then
96*e5803b76SAdam H. Leventhal	echo $tst: end probe did not fire
97*e5803b76SAdam H. Leventhal	exit $status
98*e5803b76SAdam H. Leventhalfi
99*e5803b76SAdam H. Leventhal
100*e5803b76SAdam H. Leventhalif [ $(tail -n 1 $file.2 | cut -f3 -d ' ') -ne \
101*e5803b76SAdam H. Leventhal    $(wc -l $file.2) ]; then
102*e5803b76SAdam H. Leventhal	echo $tst: incorrect number of lines output
103*e5803b76SAdam H. Leventhal	exit 1
104*e5803b76SAdam H. Leventhalfi
105*e5803b76SAdam H. Leventhal
106*e5803b76SAdam H. Leventhalexit $status
107