xref: /illumos-gate/usr/src/test/util-tests/tests/sleep/sleep.d (revision c686756220120076a07be0dcce54be698101a3d1)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2019 Robert Mustacchi
14  */
15 
16 /*
17  * This is a companion DTrace script that is used by the sleep test. It
18  * checks if the executed program asks to sleep for the right amount of
19  * time and then exits in a way to indicate this. At the same time, it
20  * always uses the SIGALRM feature of sleep(1) to make sure that sleep
21  * doesn't continue executing (and also to make sure that the feature
22  * works).
23  *
24  * We expect the number of seconds in $1 and the number of nanoseconds
25  * in $2. This script should be invoked as dtrace -s sleep.d -c
26  * '/usr/bin/sleep <waittime>' <seconds> <nanoseconds>.
27  */
28 pid$target::nanosleep:entry
29 /args[0]->tv_sec == $1 && args[0]->tv_nsec == $2/
30 {
31 	raise(SIGALRM);
32 	exit(0);
33 }
34 
35 pid$target::nanosleep:entry
36 {
37 	print(*args[0]);
38 	raise(SIGALRM);
39 	exit(1);
40 }
41