diff options
author | 2021-05-09 14:20:58 -0400 | |
---|---|---|
committer | 2021-05-09 14:20:58 -0400 | |
commit | 5fd83771641d15c418f747bd343ba6738d3875f7 (patch) | |
tree | 5abf0f78f680d9837dbd93d4d4c3933bb7509599 /shell_cmds/time/tests/test_time.sh | |
download | apple_cmds-5fd83771641d15c418f747bd343ba6738d3875f7.tar.gz apple_cmds-5fd83771641d15c418f747bd343ba6738d3875f7.tar.zst apple_cmds-5fd83771641d15c418f747bd343ba6738d3875f7.zip |
Import macOS userland
adv_cmds-176
basic_cmds-55
bootstrap_cmds-116.100.1
developer_cmds-66
diskdev_cmds-667.40.1
doc_cmds-53.60.1
file_cmds-321.40.3
mail_cmds-35
misc_cmds-34
network_cmds-606.40.1
patch_cmds-17
remote_cmds-63
shell_cmds-216.60.1
system_cmds-880.60.2
text_cmds-106
Diffstat (limited to 'shell_cmds/time/tests/test_time.sh')
-rwxr-xr-x | shell_cmds/time/tests/test_time.sh | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/shell_cmds/time/tests/test_time.sh b/shell_cmds/time/tests/test_time.sh new file mode 100755 index 0000000..6cf002d --- /dev/null +++ b/shell_cmds/time/tests/test_time.sh @@ -0,0 +1,60 @@ +#!/bin/sh + +set -o nounset + +TIME="${TIME-/usr/bin/time}" +echo "SUITE: time(1)" +what $TIME +echo + +EXIT=0 + +echo TEST: check real time + +TIME_SLEEP=`$TIME 2>&1 sleep 1 | sed -n -E 's/[ ]+([0-9]+).*/\1/p'` +TIME_STATUS=$? + +if [ "$TIME_STATUS" -ne "0" ]; then + echo FAIL: time failed with "$TIME_STATUS" + EXIT=1 +fi + +if [ "$TIME_SLEEP" -lt "0" ]; then + echo FAIL: time mis-timed sleep + EXIT=2 +fi + +MONOTONIC=`sysctl -n kern.monotonic.task_thread_counting` +if [ "$MONOTONIC" -ne "0" ]; then + echo TEST: check instructions retired + + TIME_INSTRS=`$TIME -l 2>&1 sleep 1 | sed -E -n '/instructions/p'` + if [ -z "$TIME_INSTRS" ]; then + echo FAIL: time is not showing instructions retired + EXIT=3 + fi +else + echo SKIP: check instructions retired +fi + +# NB: SIGINT and SIGQUIT work locally, but the automated test harnesses tries to +# handle those signals itself before the fork. + +echo TEST: check child SIGUSR1 + +TIME_USR1=`$TIME 2>&1 sh -c 'kill -USR1 $$ && sleep 5 && true'` +TIME_STATUS=$? +if [ "$TIME_STATUS" -eq "0" ]; then + echo FAIL: time should allow child to receive SIGUSR1 + EXIT=4 +fi + +echo TEST: check non-existent binary +TIME_NONEXIST=`$TIME 2>&1 ./this-wont-exist` +TIME_STATUS=$? +if [ "$TIME_STATUS" -ne "127" ]; then + echo FAIL: time should error when measuring a non-existent command + EXIT=5 +fi + +exit $EXIT |