3
# Copyright (c) 2011 Peter Pentchev
6
# Redistribution and use in source and binary forms, with or without
7
# modification, are permitted provided that the following conditions
9
# 1. Redistributions of source code must retain the above copyright
10
# notice, this list of conditions and the following disclaimer.
11
# 2. Redistributions in binary form must reproduce the above copyright
12
# notice, this list of conditions and the following disclaimer in the
13
# documentation and/or other materials provided with the distribution.
15
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
[ -z "$TIMELIMIT" ] && TIMELIMIT='./timelimit'
31
echo '# return EX_UNAVAILABLE if subsecond precision not supported'
32
$TIMELIMIT -t 0.5 true 2>/dev/null
34
if [ "$res" = 69 ]; then
35
echo '# Subsecond precision not supported, skipping this test set'
36
for i in 1 2 3 4 5 6 7 8; do
41
if [ "$res" = 0 ]; then echo 'ok 1'; else echo "not ok 1 res is $res"; fi
43
echo '# kill a shell script during the sleep, only execute a single echo'
44
v=`$TIMELIMIT -t 0.7 sh -c 'echo 1; sleep 1; echo 2' 2>/dev/null`
46
if [ "$res" = 143 ]; then echo 'ok 2'; else echo "not ok 2 exit code $res"; fi
47
if expr "x$v" : 'x1' > /dev/null; then echo 'ok 3'; else echo "not ok 3 v is '$v'"; fi
48
if ! expr "x$v" : 'x.*2' > /dev/null; then echo 'ok 4'; else echo "not ok 4 v is '$v'"; fi
50
echo '# catch a signal, kill with a different one'
51
v=`$TIMELIMIT -t 0.7 -s 1 -T 0.8 -S 15 sh -c 'trap "" HUP; echo 1; sleep 1; echo 2; sleep 1; echo 3' 2>/dev/null`
53
if [ "$res" = 143 ]; then echo 'ok 5'; else echo "not ok 5 exit code $res"; fi
54
if expr "x$v" : 'x1' > /dev/null; then echo 'ok 6'; else echo "not ok 6 v is '$v'"; fi
55
if expr "x$v" : 'x.*2' > /dev/null; then echo 'ok 7'; else echo "not ok 7 v is '$v'"; fi
56
if ! expr "x$v" : 'x.*3' > /dev/null; then echo 'ok 8'; else echo "not ok 8 v is '$v'"; fi