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