Home | History | Annotate | Line # | Download | only in rumpkern
t_signals.c revision 1.1.2.1
      1      1.1   pooka /*	$NetBSD: t_signals.c,v 1.1.2.1 2011/03/05 15:10:56 bouyer Exp $	*/
      2      1.1   pooka 
      3      1.1   pooka /*-
      4      1.1   pooka  * Copyright (c) 2011 The NetBSD Foundation, Inc.
      5      1.1   pooka  * All rights reserved.
      6      1.1   pooka  *
      7      1.1   pooka  * Redistribution and use in source and binary forms, with or without
      8      1.1   pooka  * modification, are permitted provided that the following conditions
      9      1.1   pooka  * are met:
     10      1.1   pooka  * 1. Redistributions of source code must retain the above copyright
     11      1.1   pooka  *    notice, this list of conditions and the following disclaimer.
     12      1.1   pooka  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1   pooka  *    notice, this list of conditions and the following disclaimer in the
     14      1.1   pooka  *    documentation and/or other materials provided with the distribution.
     15      1.1   pooka  *
     16      1.1   pooka  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
     17      1.1   pooka  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
     18      1.1   pooka  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     19      1.1   pooka  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20      1.1   pooka  * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
     21      1.1   pooka  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     22      1.1   pooka  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     23      1.1   pooka  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     24      1.1   pooka  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
     25      1.1   pooka  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     26      1.1   pooka  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
     27      1.1   pooka  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28      1.1   pooka  */
     29      1.1   pooka 
     30      1.1   pooka #include <sys/types.h>
     31      1.1   pooka #include <sys/wait.h>
     32      1.1   pooka 
     33      1.1   pooka #include <atf-c.h>
     34      1.1   pooka #include <errno.h>
     35      1.1   pooka #include <string.h>
     36      1.1   pooka #include <signal.h>
     37      1.1   pooka #include <unistd.h>
     38      1.1   pooka 
     39      1.1   pooka #include <rump/rump.h>
     40      1.1   pooka 
     41      1.1   pooka #include "../kernspace/kernspace.h"
     42      1.1   pooka #include "../../h_macros.h"
     43      1.1   pooka 
     44      1.1   pooka ATF_TC(sigraise);
     45      1.1   pooka ATF_TC_HEAD(sigraise, tc)
     46      1.1   pooka {
     47      1.1   pooka 
     48      1.1   pooka 	atf_tc_set_md_var(tc, "descr", "RUMP_SIGMODEL_RAISE");
     49      1.1   pooka }
     50      1.1   pooka 
     51      1.1   pooka ATF_TC(sigignore);
     52      1.1   pooka ATF_TC_HEAD(sigignore, tc)
     53      1.1   pooka {
     54      1.1   pooka 
     55      1.1   pooka 	atf_tc_set_md_var(tc, "descr", "RUMP_SIGMODEL_IGNORE");
     56      1.1   pooka }
     57      1.1   pooka 
     58      1.1   pooka ATF_TC(sigpanic);
     59      1.1   pooka ATF_TC_HEAD(sigpanic, tc)
     60      1.1   pooka {
     61      1.1   pooka 
     62      1.1   pooka 	atf_tc_set_md_var(tc, "descr", "RUMP_SIGMODEL_PANIC");
     63      1.1   pooka }
     64      1.1   pooka 
     65      1.1   pooka static volatile sig_atomic_t sigcnt;
     66      1.1   pooka static void
     67      1.1   pooka thehand(int sig)
     68      1.1   pooka {
     69      1.1   pooka 
     70      1.1   pooka 	sigcnt++;
     71      1.1   pooka }
     72      1.1   pooka 
     73      1.1   pooka ATF_TC_BODY(sigraise, tc)
     74      1.1   pooka {
     75      1.1   pooka 
     76      1.1   pooka 	signal(SIGUSR2, thehand);
     77      1.1   pooka 	rump_boot_setsigmodel(RUMP_SIGMODEL_RAISE);
     78      1.1   pooka 
     79      1.1   pooka 	rump_init();
     80      1.1   pooka 	rump_schedule();
     81      1.1   pooka 	rumptest_localsig(SIGUSR2);
     82      1.1   pooka 	rump_unschedule();
     83      1.1   pooka 	ATF_REQUIRE_EQ(sigcnt, 1);
     84      1.1   pooka }
     85      1.1   pooka 
     86      1.1   pooka ATF_TC_BODY(sigignore, tc)
     87      1.1   pooka {
     88      1.1   pooka 
     89      1.1   pooka 	rump_boot_setsigmodel(RUMP_SIGMODEL_IGNORE);
     90      1.1   pooka 
     91      1.1   pooka 	rump_init();
     92      1.1   pooka 	rump_schedule();
     93      1.1   pooka 	rumptest_localsig(SIGKILL);
     94      1.1   pooka 	rump_unschedule();
     95      1.1   pooka }
     96      1.1   pooka 
     97      1.1   pooka ATF_TC_BODY(sigpanic, tc)
     98      1.1   pooka {
     99      1.1   pooka 	int status;
    100      1.1   pooka 
    101  1.1.2.1  bouyer 	rump_boot_setsigmodel(RUMP_SIGMODEL_PANIC);
    102  1.1.2.1  bouyer 
    103      1.1   pooka 	switch (fork()) {
    104      1.1   pooka 	case 0:
    105      1.1   pooka 		rump_init();
    106      1.1   pooka 		rump_schedule();
    107      1.1   pooka 		rumptest_localsig(SIGCONT);
    108      1.1   pooka 		/* NOTREACHED */
    109      1.1   pooka 		exit(1);
    110      1.1   pooka 	default:
    111      1.1   pooka 		wait(&status);
    112      1.1   pooka 		ATF_REQUIRE(WIFSIGNALED(status) && WTERMSIG(status) == SIGABRT);
    113      1.1   pooka 		break;
    114      1.1   pooka 	case -1:
    115      1.1   pooka 		atf_tc_fail_errno("fork");
    116      1.1   pooka 	}
    117      1.1   pooka }
    118      1.1   pooka 
    119      1.1   pooka ATF_TP_ADD_TCS(tp)
    120      1.1   pooka {
    121      1.1   pooka 
    122      1.1   pooka 	ATF_TP_ADD_TC(tp, sigraise);
    123      1.1   pooka 	ATF_TP_ADD_TC(tp, sigignore);
    124      1.1   pooka 	ATF_TP_ADD_TC(tp, sigpanic);
    125      1.1   pooka 
    126      1.1   pooka 	return atf_no_error();
    127      1.1   pooka }
    128