Home | History | Annotate | Line # | Download | only in sys
t_sigtimedwait.c revision 1.2.10.2
      1  1.2.10.2  yamt /* $NetBSD: t_sigtimedwait.c,v 1.2.10.2 2014/05/22 11:42:21 yamt Exp $ */
      2  1.2.10.2  yamt 
      3  1.2.10.2  yamt /*-
      4  1.2.10.2  yamt  * Copyright (c) 2011 The NetBSD Foundation, Inc.
      5  1.2.10.2  yamt  * All rights reserved.
      6  1.2.10.2  yamt  *
      7  1.2.10.2  yamt  * Redistribution and use in source and binary forms, with or without
      8  1.2.10.2  yamt  * modification, are permitted provided that the following conditions
      9  1.2.10.2  yamt  * are met:
     10  1.2.10.2  yamt  * 1. Redistributions of source code must retain the above copyright
     11  1.2.10.2  yamt  *    notice, this list of conditions and the following disclaimer.
     12  1.2.10.2  yamt  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.2.10.2  yamt  *    notice, this list of conditions and the following disclaimer in the
     14  1.2.10.2  yamt  *    documentation and/or other materials provided with the distribution.
     15  1.2.10.2  yamt  *
     16  1.2.10.2  yamt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  1.2.10.2  yamt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  1.2.10.2  yamt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  1.2.10.2  yamt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  1.2.10.2  yamt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  1.2.10.2  yamt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  1.2.10.2  yamt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  1.2.10.2  yamt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  1.2.10.2  yamt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  1.2.10.2  yamt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  1.2.10.2  yamt  * POSSIBILITY OF SUCH DAMAGE.
     27  1.2.10.2  yamt  */
     28  1.2.10.2  yamt 
     29  1.2.10.2  yamt #include <sys/cdefs.h>
     30  1.2.10.2  yamt __RCSID("$NetBSD: t_sigtimedwait.c,v 1.2.10.2 2014/05/22 11:42:21 yamt Exp $");
     31  1.2.10.2  yamt 
     32  1.2.10.2  yamt #include <sys/time.h>
     33  1.2.10.2  yamt #include <errno.h>
     34  1.2.10.2  yamt #include <signal.h>
     35  1.2.10.2  yamt #include <stdio.h>
     36  1.2.10.2  yamt #include <string.h>
     37  1.2.10.2  yamt #include <atf-c.h>
     38  1.2.10.2  yamt 
     39  1.2.10.2  yamt 
     40  1.2.10.2  yamt ATF_TC(sigtimedwait_all0timeout);
     41  1.2.10.2  yamt 
     42  1.2.10.2  yamt ATF_TC_HEAD(sigtimedwait_all0timeout, tc)
     43  1.2.10.2  yamt {
     44  1.2.10.2  yamt 	atf_tc_set_md_var(tc, "timeout", "10");
     45  1.2.10.2  yamt 	atf_tc_set_md_var(tc, "descr", "Test for PR kern/47625: sigtimedwait"
     46  1.2.10.2  yamt 	    " with a timeout value of all zero should return imediately");
     47  1.2.10.2  yamt }
     48  1.2.10.2  yamt 
     49  1.2.10.2  yamt ATF_TC_BODY(sigtimedwait_all0timeout, tc)
     50  1.2.10.2  yamt {
     51  1.2.10.2  yamt 	sigset_t block;
     52  1.2.10.2  yamt 	struct timespec ts, before, after, len;
     53  1.2.10.2  yamt 	siginfo_t info;
     54  1.2.10.2  yamt 	int r;
     55  1.2.10.2  yamt 
     56  1.2.10.2  yamt 	sigemptyset(&block);
     57  1.2.10.2  yamt 	ts.tv_sec = 0;
     58  1.2.10.2  yamt 	ts.tv_nsec = 0;
     59  1.2.10.2  yamt 	clock_gettime(CLOCK_MONOTONIC, &before);
     60  1.2.10.2  yamt 	r = sigtimedwait(&block, &info, &ts);
     61  1.2.10.2  yamt 	clock_gettime(CLOCK_MONOTONIC, &after);
     62  1.2.10.2  yamt 	ATF_REQUIRE(r == -1);
     63  1.2.10.2  yamt 	ATF_REQUIRE_ERRNO(EAGAIN, errno);
     64  1.2.10.2  yamt 	timespecsub(&after, &before, &len);
     65  1.2.10.2  yamt 	ATF_REQUIRE(len.tv_sec < 1);
     66  1.2.10.2  yamt }
     67  1.2.10.2  yamt 
     68  1.2.10.2  yamt ATF_TC(sigtimedwait_NULL_timeout);
     69  1.2.10.2  yamt 
     70  1.2.10.2  yamt ATF_TC_HEAD(sigtimedwait_NULL_timeout, tc)
     71  1.2.10.2  yamt {
     72  1.2.10.2  yamt 	atf_tc_set_md_var(tc, "timeout", "10");
     73  1.2.10.2  yamt 	atf_tc_set_md_var(tc, "descr", "Test sigtimedwait() without timeout");
     74  1.2.10.2  yamt }
     75  1.2.10.2  yamt 
     76  1.2.10.2  yamt ATF_TC_BODY(sigtimedwait_NULL_timeout, tc)
     77  1.2.10.2  yamt {
     78  1.2.10.2  yamt 	sigset_t sig;
     79  1.2.10.2  yamt 	siginfo_t info;
     80  1.2.10.2  yamt 	struct itimerval it;
     81  1.2.10.2  yamt 	int r;
     82  1.2.10.2  yamt 
     83  1.2.10.2  yamt 	/* arrange for a SIGALRM signal in a few seconds */
     84  1.2.10.2  yamt 	memset(&it, 0, sizeof it);
     85  1.2.10.2  yamt 	it.it_value.tv_sec = 5;
     86  1.2.10.2  yamt 	ATF_REQUIRE(setitimer(ITIMER_REAL, &it, NULL) == 0);
     87  1.2.10.2  yamt 
     88  1.2.10.2  yamt 	/* wait without timeout */
     89  1.2.10.2  yamt 	sigemptyset(&sig);
     90  1.2.10.2  yamt 	sigaddset(&sig, SIGALRM);
     91  1.2.10.2  yamt 	r = sigtimedwait(&sig, &info, NULL);
     92  1.2.10.2  yamt 	ATF_REQUIRE(r == SIGALRM);
     93  1.2.10.2  yamt }
     94  1.2.10.2  yamt 
     95  1.2.10.2  yamt ATF_TC(sigtimedwait_small_timeout);
     96  1.2.10.2  yamt 
     97  1.2.10.2  yamt ATF_TC_HEAD(sigtimedwait_small_timeout, tc)
     98  1.2.10.2  yamt {
     99  1.2.10.2  yamt 	atf_tc_set_md_var(tc, "timeout", "15");
    100  1.2.10.2  yamt 	atf_tc_set_md_var(tc, "descr", "Test sigtimedwait with a small "
    101  1.2.10.2  yamt 	    "timeout");
    102  1.2.10.2  yamt }
    103  1.2.10.2  yamt 
    104  1.2.10.2  yamt ATF_TC_BODY(sigtimedwait_small_timeout, tc)
    105  1.2.10.2  yamt {
    106  1.2.10.2  yamt 	sigset_t block;
    107  1.2.10.2  yamt 	struct timespec ts;
    108  1.2.10.2  yamt 	siginfo_t info;
    109  1.2.10.2  yamt 	int r;
    110  1.2.10.2  yamt 
    111  1.2.10.2  yamt 	sigemptyset(&block);
    112  1.2.10.2  yamt 	ts.tv_sec = 5;
    113  1.2.10.2  yamt 	ts.tv_nsec = 0;
    114  1.2.10.2  yamt 	r = sigtimedwait(&block, &info, &ts);
    115  1.2.10.2  yamt 	ATF_REQUIRE(r == -1);
    116  1.2.10.2  yamt 	ATF_REQUIRE_ERRNO(EAGAIN, errno);
    117  1.2.10.2  yamt }
    118  1.2.10.2  yamt 
    119  1.2.10.2  yamt ATF_TP_ADD_TCS(tp)
    120  1.2.10.2  yamt {
    121  1.2.10.2  yamt 	ATF_TP_ADD_TC(tp, sigtimedwait_all0timeout);
    122  1.2.10.2  yamt 	ATF_TP_ADD_TC(tp, sigtimedwait_NULL_timeout);
    123  1.2.10.2  yamt 	ATF_TP_ADD_TC(tp, sigtimedwait_small_timeout);
    124  1.2.10.2  yamt 
    125  1.2.10.2  yamt 	return atf_no_error();
    126  1.2.10.2  yamt }
    127