From owner-svn-src-head@FreeBSD.ORG Tue Oct 28 10:39:43 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 13BD4341; Tue, 28 Oct 2014 10:39:43 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id DA2686D4; Tue, 28 Oct 2014 10:39:42 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s9SAdgCZ071722; Tue, 28 Oct 2014 10:39:42 GMT (envelope-from bapt@FreeBSD.org) Received: (from bapt@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s9SAdfvq071716; Tue, 28 Oct 2014 10:39:41 GMT (envelope-from bapt@FreeBSD.org) Message-Id: <201410281039.s9SAdfvq071716@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: bapt set sender to bapt@FreeBSD.org using -f From: Baptiste Daroussin Date: Tue, 28 Oct 2014 10:39:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r273771 - in head: etc/mtree usr.bin/timeout usr.bin/timeout/tests X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Oct 2014 10:39:43 -0000 Author: bapt Date: Tue Oct 28 10:39:41 2014 New Revision: 273771 URL: https://svnweb.freebsd.org/changeset/base/273771 Log: 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 Added: head/usr.bin/timeout/tests/ head/usr.bin/timeout/tests/Makefile (contents, props changed) head/usr.bin/timeout/tests/timeout.sh (contents, props changed) Modified: head/etc/mtree/BSD.tests.dist head/usr.bin/timeout/Makefile Modified: head/etc/mtree/BSD.tests.dist ============================================================================== --- head/etc/mtree/BSD.tests.dist Tue Oct 28 10:39:29 2014 (r273770) +++ head/etc/mtree/BSD.tests.dist Tue Oct 28 10:39:41 2014 (r273771) @@ -281,6 +281,8 @@ regress.multitest.out .. .. + timeout + .. tr .. truncate Modified: head/usr.bin/timeout/Makefile ============================================================================== --- head/usr.bin/timeout/Makefile Tue Oct 28 10:39:29 2014 (r273770) +++ head/usr.bin/timeout/Makefile Tue Oct 28 10:39:41 2014 (r273771) @@ -1,5 +1,11 @@ # $FreeBSD$ +.include + PROG= timeout +.if ${MK_TESTS} != "no" +SUBDIR+= tests +.endif + .include Added: head/usr.bin/timeout/tests/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.bin/timeout/tests/Makefile Tue Oct 28 10:39:41 2014 (r273771) @@ -0,0 +1,7 @@ +# $FreeBSD$ + +TESTSDIR= ${TESTSBASE}/usr.bin/timeout + +ATF_TESTS_SH= timeout + +.include Added: head/usr.bin/timeout/tests/timeout.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.bin/timeout/tests/timeout.sh Tue Oct 28 10:39:41 2014 (r273771) @@ -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 +}