1239385Smm#!/bin/ksh -p
2239385Smm#
3239385Smm# CDDL HEADER START
4239385Smm#
5239385Smm# This file and its contents are supplied under the terms of the
6239385Smm# Common Development and Distribution License ("CDDL"), version 1.0.
7239385Smm# You may only use this file in accordance with the terms of version
8239385Smm# 1.0 of the CDDL.
9239385Smm#
10239385Smm# A full copy of the text of the CDDL should have accompanied this
11239385Smm# source.  A copy of the CDDL is also available via the Internet at
12239385Smm# http://www.illumos.org/license/CDDL.
13239385Smm#
14239385Smm# CDDL HEADER END
15239385Smm#
16239385Smm
17239385Smm#
18239385Smm# Copyright (c) 2012 by Delphix. All rights reserved.
19239385Smm#
20239385Smm
21239385Smm############################################################################
22239385Smm# ASSERTION:
23239385Smm#	temporal option causes output to be sorted, even when some
24239385Smm#	buffers are empty
25239385Smm#
26239385Smm# SECTION: Pragma
27239385Smm#
28239385Smm# NOTES: The temporal option has no effect on a single-CPU system, so
29239385Smm#    this needs to be run on a multi-CPU system to effectively test the
30239385Smm#    temporal option.
31239385Smm#
32239385Smm############################################################################
33239385Smm
34239385Smmif [ $# != 1 ]; then
35239385Smm	echo expected one argument: '<'dtrace-path'>'
36239385Smm	exit 2
37239385Smmfi
38239385Smm
39239385Smmdtrace=$1
40239385Smmfile=/tmp/out.$$
41239385Smm
42239385Smmrm -f $file
43239385Smm
44239385Smm$dtrace -o $file -s /dev/stdin <<EOF
45239385Smm	#pragma D option quiet
46239385Smm	#pragma D option destructive
47239385Smm	#pragma D option temporal
48239385Smm	#pragma D option switchrate=1000hz
49239385Smm
50239385Smm	/*
51239385Smm	 * Use two enablings of the same probe, so that cpu 0 will always
52239385Smm	 * record its data just a little bit before the other cpus.
53239385Smm	 * We don't want to use the chill() action in the same enabling
54239385Smm	 * that we record the timestamp, because chill() causes the
55239385Smm	 * timestamp to be re-read, and thus not match the timestamp
56239385Smm	 * which libdtrace uses to sort the records.
57239385Smm	 */
58239385Smm
59239385Smm	profile-401
60239385Smm	/cpu == 0/
61239385Smm	{
62239385Smm		printf("%d\n", timestamp);
63239385Smm	}
64239385Smm
65239385Smm	profile-401
66239385Smm	/cpu != 0/
67239385Smm	{
68239385Smm		chill(1000); /* one microsecond */
69239385Smm	}
70239385Smm
71239385Smm	profile-401
72239385Smm	/cpu != 0/
73239385Smm	{
74239385Smm		printf("%d\n", timestamp);
75239385Smm	}
76239385Smm
77239385Smm	tick-1s
78239385Smm	/k++ == 10/
79239385Smm	{
80239385Smm		printf("%d\n", timestamp);
81239385Smm		exit(0);
82239385Smm	}
83239385SmmEOF
84239385Smm
85239385Smmstatus=$?
86239385Smmif [ "$status" -ne 0 ]; then
87239385Smm	echo $tst: dtrace failed
88239385Smm	exit $status
89239385Smmfi
90239385Smm
91239385Smm# dtrace outputs a blank line at the end, which will sort to the beginning,
92239385Smm# so use grep to remove the blank line.
93239385Smmhead -n -1 $file > $file.2
94239385Smm
95239385Smmsort -n $file.2 | diff $file.2 -
96239385Smmstatus=$?
97239385Smmif [ "$status" -ne 0 ]; then
98239385Smm	echo $tst: output is not sorted
99239385Smm	exit $status
100239385Smmfi
101239385Smm
102239385Smmexit $status
103