Remove building with NOCRYPTO option
[minix.git] / tests / lib / libc / sys / t_sigtimedwait.c
blob64b68d9a0607e382dcb941dd22c4c525057324f8
1 /* $NetBSD: t_sigtimedwait.c,v 1.2 2013/03/08 23:18:00 martin Exp $ */
3 /*-
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 * All rights reserved.
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.
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.
29 #include <sys/cdefs.h>
30 __RCSID("$NetBSD: t_sigtimedwait.c,v 1.2 2013/03/08 23:18:00 martin Exp $");
32 #include <sys/time.h>
33 #include <errno.h>
34 #include <signal.h>
35 #include <stdio.h>
36 #include <string.h>
37 #include <atf-c.h>
40 ATF_TC(sigtimedwait_all0timeout);
42 ATF_TC_HEAD(sigtimedwait_all0timeout, tc)
44 atf_tc_set_md_var(tc, "timeout", "10");
45 atf_tc_set_md_var(tc, "descr", "Test for PR kern/47625: sigtimedwait"
46 " with a timeout value of all zero should return imediately");
49 ATF_TC_BODY(sigtimedwait_all0timeout, tc)
51 sigset_t block;
52 struct timespec ts, before, after, len;
53 siginfo_t info;
54 int r;
56 sigemptyset(&block);
57 ts.tv_sec = 0;
58 ts.tv_nsec = 0;
59 clock_gettime(CLOCK_MONOTONIC, &before);
60 r = sigtimedwait(&block, &info, &ts);
61 clock_gettime(CLOCK_MONOTONIC, &after);
62 ATF_REQUIRE(r == -1);
63 ATF_REQUIRE_ERRNO(EAGAIN, errno);
64 timespecsub(&after, &before, &len);
65 ATF_REQUIRE(len.tv_sec < 1);
68 ATF_TC(sigtimedwait_NULL_timeout);
70 ATF_TC_HEAD(sigtimedwait_NULL_timeout, tc)
72 atf_tc_set_md_var(tc, "timeout", "10");
73 atf_tc_set_md_var(tc, "descr", "Test sigtimedwait() without timeout");
76 ATF_TC_BODY(sigtimedwait_NULL_timeout, tc)
78 sigset_t sig;
79 siginfo_t info;
80 struct itimerval it;
81 int r;
83 /* arrange for a SIGALRM signal in a few seconds */
84 memset(&it, 0, sizeof it);
85 it.it_value.tv_sec = 5;
86 ATF_REQUIRE(setitimer(ITIMER_REAL, &it, NULL) == 0);
88 /* wait without timeout */
89 sigemptyset(&sig);
90 sigaddset(&sig, SIGALRM);
91 r = sigtimedwait(&sig, &info, NULL);
92 ATF_REQUIRE(r == SIGALRM);
95 ATF_TC(sigtimedwait_small_timeout);
97 ATF_TC_HEAD(sigtimedwait_small_timeout, tc)
99 atf_tc_set_md_var(tc, "timeout", "15");
100 atf_tc_set_md_var(tc, "descr", "Test sigtimedwait with a small "
101 "timeout");
104 ATF_TC_BODY(sigtimedwait_small_timeout, tc)
106 sigset_t block;
107 struct timespec ts;
108 siginfo_t info;
109 int r;
111 sigemptyset(&block);
112 ts.tv_sec = 5;
113 ts.tv_nsec = 0;
114 r = sigtimedwait(&block, &info, &ts);
115 ATF_REQUIRE(r == -1);
116 ATF_REQUIRE_ERRNO(EAGAIN, errno);
119 ATF_TP_ADD_TCS(tp)
121 ATF_TP_ADD_TC(tp, sigtimedwait_all0timeout);
122 ATF_TP_ADD_TC(tp, sigtimedwait_NULL_timeout);
123 ATF_TP_ADD_TC(tp, sigtimedwait_small_timeout);
125 return atf_no_error();