xref: /netbsd-src/tests/bin/sleep/t_sleep.sh (revision 15320a4ac20e8346de7d70fa6e01d02c843b3a99)
1*15320a4aSkre# $NetBSD: t_sleep.sh,v 1.2 2019/01/21 13:19:18 kre Exp $
247dea51eSjruoho#
347dea51eSjruoho# Copyright (c) 2012 The NetBSD Foundation, Inc.
447dea51eSjruoho# All rights reserved.
547dea51eSjruoho#
647dea51eSjruoho# This code is derived from software contributed to The NetBSD Foundation
747dea51eSjruoho# by Jukka Ruohonen.
847dea51eSjruoho#
947dea51eSjruoho# Redistribution and use in source and binary forms, with or without
1047dea51eSjruoho# modification, are permitted provided that the following conditions
1147dea51eSjruoho# are met:
1247dea51eSjruoho# 1. Redistributions of source code must retain the above copyright
1347dea51eSjruoho#    notice, this list of conditions and the following disclaimer.
1447dea51eSjruoho# 2. Redistributions in binary form must reproduce the above copyright
1547dea51eSjruoho#    notice, this list of conditions and the following disclaimer in the
1647dea51eSjruoho#    documentation and/or other materials provided with the distribution.
1747dea51eSjruoho#
1847dea51eSjruoho# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1947dea51eSjruoho# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2047dea51eSjruoho# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2147dea51eSjruoho# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2247dea51eSjruoho# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2347dea51eSjruoho# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2447dea51eSjruoho# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2547dea51eSjruoho# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2647dea51eSjruoho# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2747dea51eSjruoho# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2847dea51eSjruoho# POSSIBILITY OF SUCH DAMAGE.
2947dea51eSjruoho#
3047dea51eSjruoho
3147dea51eSjruohoatf_test_case fraction
3247dea51eSjruohofraction_head() {
3347dea51eSjruoho	atf_set "descr" "Test that sleep(1) handles " \
3447dea51eSjruoho			"fractions of a second (PR bin/3914)"
3547dea51eSjruoho}
3647dea51eSjruoho
3747dea51eSjruohofraction_body() {
3847dea51eSjruoho
3947dea51eSjruoho	atf_check -s exit:0 -o empty -e empty -x "sleep 0.1"
4047dea51eSjruoho	atf_check -s exit:0 -o empty -e empty -x "sleep 0.2"
4147dea51eSjruoho	atf_check -s exit:0 -o empty -e empty -x "sleep 0.3"
42*15320a4aSkre
43*15320a4aSkre	# check that '.' as the radix works, even when the
44*15320a4aSkre	# locale is one which uses something different
45*15320a4aSkre	atf_check -s exit:0 -o empty -e empty -x "LC_ALL=ru_RU.UTF-8 sleep 0.2"
46*15320a4aSkre
47*15320a4aSkre	# and that it is possible to use the locale's radix char (',' here)
48*15320a4aSkre	atf_check -s exit:0 -o empty -e empty -x "LC_ALL=ru_RU.UTF-8 sleep 0,2"
4947dea51eSjruoho}
5047dea51eSjruoho
5147dea51eSjruohoatf_test_case hex
5247dea51eSjruohohex_head() {
5347dea51eSjruoho	atf_set "descr" "Test that sleep(1) handles hexadecimal arguments"
5447dea51eSjruoho}
5547dea51eSjruoho
5647dea51eSjruohohex_body() {
5747dea51eSjruoho
5847dea51eSjruoho	atf_check -s exit:0 -o empty -e empty -x "sleep 0x01"
59*15320a4aSkre	atf_check -s exit:0 -o empty -e empty -x "sleep 0x0.F"
60*15320a4aSkre	atf_check -s exit:0 -o empty -e empty -x "sleep 0x.B"
6147dea51eSjruoho}
6247dea51eSjruoho
6347dea51eSjruohoatf_test_case nonnumeric
6447dea51eSjruohononnumeric_head() {
6547dea51eSjruoho	atf_set "descr" "Test that sleep(1) errors out with " \
6647dea51eSjruoho			"non-numeric argument (PR bin/27140)"
6747dea51eSjruoho}
6847dea51eSjruoho
6947dea51eSjruohononnumeric_body() {
7047dea51eSjruoho
7147dea51eSjruoho	atf_check -s not-exit:0 -o empty -e not-empty -x "sleep xyz"
7247dea51eSjruoho	atf_check -s not-exit:0 -o empty -e not-empty -x "sleep x21"
7347dea51eSjruoho	atf_check -s not-exit:0 -o empty -e not-empty -x "sleep  /3"
74*15320a4aSkre	atf_check -s not-exit:0 -o empty -e not-empty -x "sleep 3+1"
75*15320a4aSkre	atf_check -s not-exit:0 -o empty -e not-empty -x "sleep 0xFG"
76*15320a4aSkre
77*15320a4aSkre	# This includes using an invalid radix char for the locale in use
78*15320a4aSkre	atf_check -s not-exit:0 -o empty -e not-empty -x "LC_ALL=C sleep 3,1"
79*15320a4aSkre
80*15320a4aSkre	# no arg at all (that's non-numeric, right?)
81*15320a4aSkre	atf_check -s not-exit:0 -o empty -e not-empty -x "sleep"
82*15320a4aSkre
83*15320a4aSkre	# and giving 2 or more args is also invalid, even if they are numeric
84*15320a4aSkre	atf_check -s not-exit:0 -o empty -e not-empty -x "sleep 1 2"
8547dea51eSjruoho}
8647dea51eSjruoho
8747dea51eSjruohoatf_init_test_cases() {
8847dea51eSjruoho
8947dea51eSjruoho	atf_add_test_case fraction
9047dea51eSjruoho	atf_add_test_case hex
9147dea51eSjruoho	atf_add_test_case nonnumeric
9247dea51eSjruoho}
93