]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/pragma/tst.temporal.ksh
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / cddl / contrib / opensolaris / cmd / dtrace / test / tst / common / pragma / tst.temporal.ksh
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
33 if [ $# != 1 ]; then
34         echo expected one argument: '<'dtrace-path'>'
35         exit 2
36 fi
37
38 dtrace=$1
39 file=/tmp/out.$$
40
41 rm -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         }
67 EOF
68
69 status=$?
70 if [ "$status" -ne 0 ]; then
71         echo $tst: dtrace failed
72         exit $status
73 fi
74
75 # dtrace outputs a blank line at the end, which will sort to the beginning,
76 # so use sed to remove the blank line.
77 sed '$d' $file > $file.2
78
79 sort -n $file.2 | diff $file.2 -
80 status=$?
81 if [ "$status" -ne 0 ]; then
82         echo $tst: output is not sorted
83         exit $status
84 fi
85
86 head -n 1 $file.2 | grep begin >/dev/null
87 status=$?
88 if [ "$status" -ne 0 ]; then
89         echo $tst: begin probe did not fire
90         exit $status
91 fi
92
93 tail -n 2 $file.2 | grep end >/dev/null
94 status=$?
95 if [ "$status" -ne 0 ]; then
96         echo $tst: end probe did not fire
97         exit $status
98 fi
99
100 if [ $(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
104 fi
105
106 exit $status