diff options
author | bapt <bapt@FreeBSD.org> | 2014-10-28 10:39:41 +0000 |
---|---|---|
committer | bapt <bapt@FreeBSD.org> | 2014-10-28 10:39:41 +0000 |
commit | 99068e42872b66860995cc4b3b0b80a05b98e376 (patch) | |
tree | 8030d29cd6931e195649216852c510503632cdb3 | |
parent | c5fce01b6c95453cd9dd11a4e4eb67319c505a8b (diff) | |
download | FreeBSD-src-99068e42872b66860995cc4b3b0b80a05b98e376.zip FreeBSD-src-99068e42872b66860995cc4b3b0b80a05b98e376.tar.gz |
Add regression tests for the timeout(1) utility
They are modeled over the regression tests that are provided for the GNU
coreutils timeout(1) utility
-rw-r--r-- | etc/mtree/BSD.tests.dist | 2 | ||||
-rw-r--r-- | usr.bin/timeout/Makefile | 6 | ||||
-rw-r--r-- | usr.bin/timeout/tests/Makefile | 7 | ||||
-rw-r--r-- | usr.bin/timeout/tests/timeout.sh | 215 |
4 files changed, 230 insertions, 0 deletions
diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index 45c2d7c..93ca4df 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -281,6 +281,8 @@ regress.multitest.out .. .. + timeout + .. tr .. truncate diff --git a/usr.bin/timeout/Makefile b/usr.bin/timeout/Makefile index 46ca6e3..c1957ae 100644 --- a/usr.bin/timeout/Makefile +++ b/usr.bin/timeout/Makefile @@ -1,5 +1,11 @@ # $FreeBSD$ +.include <src.opts.mk> + PROG= timeout +.if ${MK_TESTS} != "no" +SUBDIR+= tests +.endif + .include <bsd.prog.mk> diff --git a/usr.bin/timeout/tests/Makefile b/usr.bin/timeout/tests/Makefile new file mode 100644 index 0000000..6303718 --- /dev/null +++ b/usr.bin/timeout/tests/Makefile @@ -0,0 +1,7 @@ +# $FreeBSD$ + +TESTSDIR= ${TESTSBASE}/usr.bin/timeout + +ATF_TESTS_SH= timeout + +.include <bsd.test.mk> diff --git a/usr.bin/timeout/tests/timeout.sh b/usr.bin/timeout/tests/timeout.sh new file mode 100644 index 0000000..e04e6f9 --- /dev/null +++ b/usr.bin/timeout/tests/timeout.sh @@ -0,0 +1,215 @@ +# $FreeBSD$ + +atf_test_case nominal +nominal_head() +{ + atf_set "descr" "Basic tests on timeout(1) utility" +} + +nominal_body() +{ + atf_check \ + -o empty \ + -e empty \ + -s exit:0 \ + -x timeout 5 true +} + +atf_test_case time_unit +time_unit_head() +{ + atf_set "descr" "Test parsing the default time unit" +} + +time_unit_body() +{ + atf_check \ + -o empty \ + -e empty \ + -s exit:0 \ + -x timeout 1d true + + atf_check \ + -o empty \ + -e empty \ + -s exit:0 \ + -x timeout 1h true + + atf_check \ + -o empty \ + -e empty \ + -s exit:0 \ + -x timeout 1m true + + atf_check \ + -o empty \ + -e empty \ + -s exit:0 \ + -x timeout 1s true +} + +atf_test_case no_timeout +no_timeout_head() +{ + atf_set "descr" "Test disabled timeout" +} + +no_timeout_body() +{ + atf_check \ + -o empty \ + -e empty \ + -s exit:0 \ + -x timeout 0 true +} + +atf_test_case exit_numbers +exit_numbers_head() +{ + atf_set "descr" "Test exit numbers" +} + +exit_numbers_body() +{ + atf_check \ + -o empty \ + -e empty \ + -s exit:2 \ + -x timeout 5 sh -c \'exit 2\' + + atf_check \ + -o empty \ + -e empty \ + -s exit:124 \ + -x timeout .1 sleep 1 + + # With preserv status exit shoudl be 128 + TERM aka 143 + atf_check \ + -o empty \ + -e empty \ + -s exit:143 \ + -x timeout --preserve-status .1 sleep 10 + + atf_check \ + -o empty \ + -e empty \ + -s exit:124 \ + -x timeout -s1 -k1 .1 sleep 10 + + atf_check \ + -o empty \ + -e empty \ + -s exit:0 \ + -x sh -c 'trap "" CHLD; exec timeout 10 true' +} + +atf_test_case with_a_child +with_a_child_head() +{ + atf_set "descr" "When starting with a child (coreutils bug#9098)" +} + +with_a_child_body() +{ + out=$(sleep .1 & exec timeout .5 sh -c 'sleep 2; echo foo') + status=$? + test "$out" = "" && test $status = 124 || atf_fail + +} + +atf_test_case invalid_timeout +invalid_timeout_head() +{ + atf_set "descr" "Invalid timeout" +} + +invalid_timeout_body() +{ + atf_check \ + -o empty \ + -e inline:"timeout: invalid duration\n" \ + -s exit:125 \ + -x timeout invalid sleep 0 + + atf_check \ + -o empty \ + -e inline:"timeout: invalid duration\n" \ + -s exit:125 \ + -x timeout --kill-after=invalid 1 sleep 0 + + atf_check \ + -o empty \ + -e inline:"timeout: invalid duration\n" \ + -s exit:125 \ + -x timeout 42D sleep 0 + + atf_check \ + -o empty \ + -e inline:"timeout: invalid duration\n" \ + -s exit:125 \ + -x timeout 999999999999999999999999999999999999999999999999999999999999d sleep 0 + + atf_check \ + -o empty \ + -e inline:"timeout: invalid duration\n" \ + -s exit:125 \ + -x timeout 2.34e+5d sleep 0 +} + +atf_test_case invalid_signal +invalid_signal_head() +{ + atf_set "descr" "Invalid signal" +} + +invalid_signal_body() +{ + atf_check \ + -o empty \ + -e inline:"timeout: invalid signal\n" \ + -s exit:125 \ + -x timeout --signal=invalid 1 sleep 0 +} + +atf_test_case invalid_command +invalid_command_head() +{ + atf_set "descr" "Invalid command" +} + +invalid_command_body() +{ + atf_check \ + -o empty \ + -e inline:"timeout: exec(.): Permission denied\n" \ + -s exit:126 \ + -x timeout 10 . +} + +atf_test_case no_such_command +no_such_command_head() +{ + atf_set "descr" "No such command" +} + +no_such_command_body() +{ + atf_check \ + -o empty \ + -e inline:"timeout: exec(enoexists): No such file or directory\n" \ + -s exit:127 \ + -x timeout 10 enoexists +} + +atf_init_test_cases() +{ + atf_add_test_case nominal + atf_add_test_case time_unit + atf_add_test_case no_timeout + atf_add_test_case exit_numbers + atf_add_test_case with_a_child + atf_add_test_case invalid_timeout + atf_add_test_case invalid_signal + atf_add_test_case invalid_command + atf_add_test_case no_such_command +} |