xref: /freebsd-src/contrib/netbsd-tests/lib/libc/sys/t_clock_nanosleep.c (revision 3f8455b0905a05552b1155e09165787e1d098060)
1cdebaff8SEnji Cooper /* $NetBSD: t_clock_nanosleep.c,v 1.1 2016/11/11 15:30:44 njoly Exp $ */
2cdebaff8SEnji Cooper 
3cdebaff8SEnji Cooper /*-
4cdebaff8SEnji Cooper  * Copyright (c) 2016 The NetBSD Foundation, Inc.
5cdebaff8SEnji Cooper  * All rights reserved.
6cdebaff8SEnji Cooper  *
7cdebaff8SEnji Cooper  * Redistribution and use in source and binary forms, with or without
8cdebaff8SEnji Cooper  * modification, are permitted provided that the following conditions
9cdebaff8SEnji Cooper  * are met:
10cdebaff8SEnji Cooper  * 1. Redistributions of source code must retain the above copyright
11cdebaff8SEnji Cooper  *    notice, this list of conditions and the following disclaimer.
12cdebaff8SEnji Cooper  * 2. Redistributions in binary form must reproduce the above copyright
13cdebaff8SEnji Cooper  *    notice, this list of conditions and the following disclaimer in the
14cdebaff8SEnji Cooper  *    documentation and/or other materials provided with the distribution.
15cdebaff8SEnji Cooper  *
16cdebaff8SEnji Cooper  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17cdebaff8SEnji Cooper  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18cdebaff8SEnji Cooper  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19cdebaff8SEnji Cooper  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20cdebaff8SEnji Cooper  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21cdebaff8SEnji Cooper  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22cdebaff8SEnji Cooper  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23cdebaff8SEnji Cooper  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24cdebaff8SEnji Cooper  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25cdebaff8SEnji Cooper  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26cdebaff8SEnji Cooper  * POSSIBILITY OF SUCH DAMAGE.
27cdebaff8SEnji Cooper  */
28cdebaff8SEnji Cooper 
29cdebaff8SEnji Cooper #include <sys/cdefs.h>
30cdebaff8SEnji Cooper __RCSID("$NetBSD: t_clock_nanosleep.c,v 1.1 2016/11/11 15:30:44 njoly Exp $");
31cdebaff8SEnji Cooper 
32cdebaff8SEnji Cooper #include <atf-c.h>
33cdebaff8SEnji Cooper #include <time.h>
34cdebaff8SEnji Cooper 
35cdebaff8SEnji Cooper ATF_TC(clock_nanosleep_remain);
ATF_TC_HEAD(clock_nanosleep_remain,tc)36cdebaff8SEnji Cooper ATF_TC_HEAD(clock_nanosleep_remain, tc)
37cdebaff8SEnji Cooper {
38cdebaff8SEnji Cooper 	atf_tc_set_md_var(tc, "descr",
39cdebaff8SEnji Cooper 	    "Check clock_nanosleep(2) remaining time");
40cdebaff8SEnji Cooper }
41cdebaff8SEnji Cooper 
ATF_TC_BODY(clock_nanosleep_remain,tc)42cdebaff8SEnji Cooper ATF_TC_BODY(clock_nanosleep_remain, tc)
43cdebaff8SEnji Cooper {
44cdebaff8SEnji Cooper 	struct timespec rqtp, rmtp;
45cdebaff8SEnji Cooper 
46cdebaff8SEnji Cooper 	rqtp.tv_sec = 0; rqtp.tv_nsec = 0;
47cdebaff8SEnji Cooper 	rmtp.tv_sec = -1; rmtp.tv_nsec = -1;
48cdebaff8SEnji Cooper 	ATF_REQUIRE(clock_nanosleep(CLOCK_REALTIME, 0, &rqtp, &rmtp) == 0);
49*3f8455b0SEric van Gyzen #ifdef __FreeBSD__
50*3f8455b0SEric van Gyzen 	ATF_CHECK(rmtp.tv_sec == -1 && rmtp.tv_nsec == -1);
51*3f8455b0SEric van Gyzen #else
52cdebaff8SEnji Cooper 	ATF_CHECK(rmtp.tv_sec == 0 && rmtp.tv_nsec == 0);
53*3f8455b0SEric van Gyzen #endif
54cdebaff8SEnji Cooper 
55cdebaff8SEnji Cooper 	ATF_REQUIRE(clock_gettime(CLOCK_REALTIME, &rqtp) == 0);
56cdebaff8SEnji Cooper 	rmtp.tv_sec = -1; rmtp.tv_nsec = -1;
57cdebaff8SEnji Cooper 	ATF_REQUIRE(clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &rqtp, &rmtp) == 0);
58cdebaff8SEnji Cooper 	ATF_CHECK(rmtp.tv_sec == -1 && rmtp.tv_nsec == -1);
59cdebaff8SEnji Cooper }
60cdebaff8SEnji Cooper 
ATF_TP_ADD_TCS(tp)61cdebaff8SEnji Cooper ATF_TP_ADD_TCS(tp)
62cdebaff8SEnji Cooper {
63cdebaff8SEnji Cooper 
64cdebaff8SEnji Cooper 	ATF_TP_ADD_TC(tp, clock_nanosleep_remain);
65cdebaff8SEnji Cooper 
66cdebaff8SEnji Cooper 	return atf_no_error();
67cdebaff8SEnji Cooper }
68