1 /* $NetBSD: t_kern.c,v 1.3 2012/01/30 13:05:52 njoly Exp $ */
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
30 #include <sys/types.h>
31 #include <sys/signal.h>
34 #include <rump/rump.h>
41 #include "../../h_macros.h"
42 #include "../kernspace/kernspace.h"
44 #define LOCKFUN(_name_, _descr_,_needld_, _expect_) \
45 ATF_TC(lockme_##_name_); \
46 ATF_TC_HEAD(lockme_##_name_, tc) { \
47 atf_tc_set_md_var(tc, "descr", _descr_); \
49 ATF_TC_BODY(lockme_##_name_, tc) { \
50 locktest(tc, LOCKME_##_name_, _needld_, _expect_); \
54 locktest(const atf_tc_t
*tc
, enum locktest lt
, int needld
, const char *expect
)
56 extern const int rump_lockdebug
;
60 if (needld
&& !rump_lockdebug
)
61 atf_tc_skip("test requires LOCKDEBUG kernel");
66 RL(dup2(pipetti
[1], STDOUT_FILENO
));
67 RL(dup2(pipetti
[1], STDOUT_FILENO
));
75 ATF_REQUIRE(WIFSIGNALED(status
) && WTERMSIG(status
) == SIGABRT
);
79 ATF_REQUIRE(read(pipetti
[0], buf
, sizeof(buf
)) > 0);
80 if (strncmp(buf
, expect
, strlen(expect
)) != 0)
81 atf_tc_fail("unexpected output");
89 LOCKFUN(DESTROYHELD
, "destroy lock while held", 0,
90 "mutex error: lockdebug_free: is locked or in use");
91 LOCKFUN(DOUBLEFREE
, "free lock twice", 0,
92 "panic: lockdebug_lookup: uninitialized lock");
93 LOCKFUN(DOUBLEINIT
, "init lock twice", 1,
94 "mutex error: lockdebug_alloc: already initialized");
95 LOCKFUN(MEMFREE
, "free memory active lock is in", 1,
96 "mutex error: kmem_intr_free: allocation contains active lock");
97 LOCKFUN(MTX
, "locking-against-self mutex", 0,
98 "mutex error: lockdebug_wantlock: locking against myself");
99 LOCKFUN(RWDOUBLEX
, "locking-against-self exclusive rwlock", 0,
100 "rwlock error: lockdebug_wantlock: locking against myself");
101 LOCKFUN(RWRX
, "rw: first shared, then exclusive", 1,
102 "rwlock error: lockdebug_wantlock: locking against myself");
103 LOCKFUN(RWXR
, "rw: first execusive, then shared", 0,
104 "rwlock error: lockdebug_wantlock: locking against myself");
109 ATF_TP_ADD_TC(tp
, lockme_MTX
);
110 ATF_TP_ADD_TC(tp
, lockme_RWDOUBLEX
);
111 ATF_TP_ADD_TC(tp
, lockme_RWRX
);
112 ATF_TP_ADD_TC(tp
, lockme_RWXR
);
113 ATF_TP_ADD_TC(tp
, lockme_DOUBLEINIT
);
114 ATF_TP_ADD_TC(tp
, lockme_DOUBLEFREE
);
115 ATF_TP_ADD_TC(tp
, lockme_DESTROYHELD
);
116 ATF_TP_ADD_TC(tp
, lockme_MEMFREE
);
118 return atf_no_error();