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