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