aboutsummaryrefslogtreecommitdiff
path: root/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/pragma/tst.temporal.ksh
blob: f09c71fa59c78cc95fb665dcef29c094a06448e1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/ksh -p
#
# CDDL HEADER START
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source.  A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
# CDDL HEADER END
#

#
# Copyright (c) 2012 by Delphix. All rights reserved.
#

############################################################################
# ASSERTION:
#	temporal option causes output to be sorted
#
# SECTION: Pragma
#
# NOTES: The temporal option has no effect on a single-CPU system, so
#    this needs to be run on a multi-CPU system to effectively test the
#    temporal option.
#
############################################################################

if [ $# != 1 ]; then
	echo expected one argument: '<'dtrace-path'>'
	exit 2
fi

dtrace=$1
file=/tmp/out.$$

rm -f $file

$dtrace -o $file -c 'sleep 3' -s /dev/stdin <<EOF
	#pragma D option quiet
	#pragma D option temporal

	BEGIN
	{
		@lines = count();
		printf("0 begin\n");
	}

	END
	{
		/* Bump @lines every time we print a line. */
		@lines = count();
		printf("%u end\n", timestamp);
		@lines = count();
		printa("99999999999999999 lines %@u\n", @lines);
	}

	profile-97hz
	{
		@lines = count();
		printf("%u\n", timestamp);
	}
EOF

status=$?
if [ "$status" -ne 0 ]; then
	echo $tst: dtrace failed
	exit $status
fi

# dtrace outputs a blank line at the end, which will sort to the beginning,
# so use sed to remove the blank line.
sed '$d' $file > $file.2

sort -n $file.2 | diff $file.2 -
status=$?
if [ "$status" -ne 0 ]; then
	echo $tst: output is not sorted
	exit $status
fi

head -n 1 $file.2 | grep begin >/dev/null
status=$?
if [ "$status" -ne 0 ]; then
	echo $tst: begin probe did not fire
	exit $status
fi

tail -n 2 $file.2 | grep end >/dev/null
status=$?
if [ "$status" -ne 0 ]; then
	echo $tst: end probe did not fire
	exit $status
fi

if [ $(tail -n 1 $file.2 | cut -f3 -d ' ') -ne \
    $(wc -l $file.2) ]; then
	echo $tst: incorrect number of lines output
	exit 1
fi

exit $status