t_kern.c revision 1.1
1/* $NetBSD: t_kern.c,v 1.1 2011/01/06 13:12:52 pooka Exp $ */ 2 3/*- 4 * Copyright (c) 2011 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 17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30#include <sys/types.h> 31#include <sys/signal.h> 32#include <sys/wait.h> 33 34#include <rump/rump.h> 35 36#include <atf-c.h> 37#include <stdio.h> 38#include <stdlib.h> 39#include <unistd.h> 40 41#include "../../h_macros.h" 42#include "../kernspace/kernspace.h" 43 44#define LOCKFUN(_name_, _descr_,_needld_) \ 45 ATF_TC(lockme_##_name_); \ 46 ATF_TC_HEAD(lockme_##_name_, tc) { \ 47 atf_tc_set_md_var(tc, "descr", _descr_); \ 48 } \ 49 ATF_TC_BODY(lockme_##_name_, tc) { \ 50 locktest(tc, LOCKME_##_name_, _needld_); \ 51 } 52 53static void 54locktest(const atf_tc_t *tc, enum locktest lt, int needld) 55{ 56 extern const int rump_lockdebug; 57 int status; 58 59 if (needld && !rump_lockdebug) 60 atf_tc_skip("test requires LOCKDEBUG kernel"); 61 62 switch (fork()) { 63 case 0: 64 rump_init(); 65 rump_schedule(); 66 rumptest_lockme(lt); 67 rump_unschedule(); 68 break; 69 default: 70 RL(wait(&status)); 71 ATF_REQUIRE(WIFSIGNALED(status) && WTERMSIG(status) == SIGABRT); 72 break; 73 case -1: 74 atf_tc_fail("fork"); 75 } 76} 77 78LOCKFUN(DESTROYHELD, "destroy lock while held", 0); 79LOCKFUN(DOUBLEFREE, "free lock twice", 0); 80LOCKFUN(DOUBLEINIT, "init lock twice", 1); 81LOCKFUN(MEMFREE, "free memory active lock is in", 1); 82LOCKFUN(MTX, "locking-against-self mutex", 0); 83LOCKFUN(RWDOUBLEX, "locking-against-self exclusive rwlock", 0); 84LOCKFUN(RWRX, "rw: first shared, then exclusive", 1); 85LOCKFUN(RWXR, "rw: first execusive, then shared", 0); 86 87ATF_TP_ADD_TCS(tp) 88{ 89 90 ATF_TP_ADD_TC(tp, lockme_MTX); 91 ATF_TP_ADD_TC(tp, lockme_RWDOUBLEX); 92 ATF_TP_ADD_TC(tp, lockme_RWRX); 93 ATF_TP_ADD_TC(tp, lockme_RWXR); 94 ATF_TP_ADD_TC(tp, lockme_DOUBLEINIT); 95 ATF_TP_ADD_TC(tp, lockme_DOUBLEFREE); 96 ATF_TP_ADD_TC(tp, lockme_DESTROYHELD); 97 ATF_TP_ADD_TC(tp, lockme_MEMFREE); 98 99 return atf_no_error(); 100} 101