]> git.saurik.com Git - apple/shell_cmds.git/blob - time/tests/test_time.sh
shell_cmds-216.60.1.tar.gz
[apple/shell_cmds.git] / time / tests / test_time.sh
1 #!/bin/sh
2
3 set -o nounset
4
5 TIME="${TIME-/usr/bin/time}"
6 echo "SUITE: time(1)"
7 what $TIME
8 echo
9
10 EXIT=0
11
12 echo TEST: check real time
13
14 TIME_SLEEP=`$TIME 2>&1 sleep 1 | sed -n -E 's/[ ]+([0-9]+).*/\1/p'`
15 TIME_STATUS=$?
16
17 if [ "$TIME_STATUS" -ne "0" ]; then
18 echo FAIL: time failed with "$TIME_STATUS"
19 EXIT=1
20 fi
21
22 if [ "$TIME_SLEEP" -lt "0" ]; then
23 echo FAIL: time mis-timed sleep
24 EXIT=2
25 fi
26
27 MONOTONIC=`sysctl -n kern.monotonic.task_thread_counting`
28 if [ "$MONOTONIC" -ne "0" ]; then
29 echo TEST: check instructions retired
30
31 TIME_INSTRS=`$TIME -l 2>&1 sleep 1 | sed -E -n '/instructions/p'`
32 if [ -z "$TIME_INSTRS" ]; then
33 echo FAIL: time is not showing instructions retired
34 EXIT=3
35 fi
36 else
37 echo SKIP: check instructions retired
38 fi
39
40 # NB: SIGINT and SIGQUIT work locally, but the automated test harnesses tries to
41 # handle those signals itself before the fork.
42
43 echo TEST: check child SIGUSR1
44
45 TIME_USR1=`$TIME 2>&1 sh -c 'kill -USR1 $$ && sleep 5 && true'`
46 TIME_STATUS=$?
47 if [ "$TIME_STATUS" -eq "0" ]; then
48 echo FAIL: time should allow child to receive SIGUSR1
49 EXIT=4
50 fi
51
52 echo TEST: check non-existent binary
53 TIME_NONEXIST=`$TIME 2>&1 ./this-wont-exist`
54 TIME_STATUS=$?
55 if [ "$TIME_STATUS" -ne "127" ]; then
56 echo FAIL: time should error when measuring a non-existent command
57 EXIT=5
58 fi
59
60 exit $EXIT