2 # Validate sleep parameters
4 # Copyright (C) 2016-2025 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 .
"${srcdir=.}/tests/init.sh"; path_prepend_ .
/src
20 print_ver_
sleep printf
24 returns_
1 timeout
10 sleep invalid || fail
=1
25 returns_
1 timeout
10 sleep -- -1 || fail
=1
26 returns_
1 timeout
10 sleep 42D || fail
=1
27 returns_
1 timeout
10 sleep 42d
42day || fail
=1
28 returns_
1 timeout
10 sleep nan || fail
=1
29 returns_
1 timeout
10 sleep '' || fail
=1
30 returns_
1 timeout
10 sleep || fail
=1
32 # subsecond actual sleep
33 timeout
10 sleep 0.001 || fail
=1
34 timeout
10 sleep 0x
.002p1 || fail
=1
36 # Using small timeouts for larger sleeps is racy,
37 # but false positives should be avoided on most systems
38 returns_
124 timeout
0.1 sleep 1d
2h
3m
4s || fail
=1
39 returns_
124 timeout
0.1 sleep inf || fail
=1
40 returns_
124 timeout
0.1 sleep $LDBL_MAX || fail
=1
42 # Test locale decimal handling for printf, sleep, timeout
43 if test "$LOCALE_FR_UTF8" != "none"; then
45 locale_decimal
=$
(LC_ALL
=$f env
printf '%0.3f' 0.001) || fail
=1
46 locale_decimal
=$
(LC_ALL
=$f env
printf '%0.3f' "$locale_decimal") || fail
=1
47 case "$locale_decimal" in
49 LC_ALL
=$f timeout
1$locale_decimal sleep "$locale_decimal" || fail
=1 ;;