1 /* $NetBSD: t_swwdog.c,v 1.7 2017/01/13 21:30:39 christos Exp $ */
4 * Copyright (c) 2010 Antti Kantee. All Rights Reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/types.h>
43 #include <rump/rump.h>
44 #include <rump/rump_syscalls.h>
48 static volatile sig_atomic_t tcount;
54 assert(sig == SIGUSR1);
59 * Since we are testing for swwdog's ability to reboot/panic, we need
60 * to fork and monitor the exit status from the parent and report
61 * something sensible back to atf.
66 char wname[WDOG_NAMESIZE];
73 signal(SIGUSR1, sigcount);
75 switch ((p1 = fork())) {
79 atf_tc_fail_errno("fork");
83 ATF_REQUIRE_EQ(p1, p2);
84 ATF_REQUIRE_EQ(tcount, max);
90 fd = rump_sys_open("/dev/watchdog", O_RDWR);
92 err(1, "open watchdog");
97 if (rump_sys_ioctl(fd, WDOGIOC_GWDOGS, &wc) == -1)
98 err(1, "can't fetch watchdog names");
101 assert(wc.wc_count == 1);
103 strlcpy(wm.wm_name, wc.wc_names, sizeof(wm.wm_name));
104 wm.wm_mode = WDOG_MODE_ETICKLE;
106 if (rump_sys_ioctl(fd, WDOGIOC_SMODE, &wm) == -1)
107 atf_tc_fail_errno("failed to set tickle");
111 rump_sys_ioctl(fd, WDOGIOC_TICKLE);
113 wm.wm_mode = WDOG_MODE_DISARMED;
114 rump_sys_ioctl(fd, WDOGIOC_SMODE, &wm);
116 kill(getppid(), SIGUSR1);
119 printf("staying alive\n");
120 kill(getppid(), SIGUSR1);
124 printf("no watchdog registered!\n");
129 ATF_TC_HEAD(reboot, tc)
132 atf_tc_set_md_var(tc, "descr", "check swwdog reboot capability");
135 ATF_TC_BODY(reboot, tc)
137 extern bool rumpns_swwdog_reboot;
140 /* XXX: should use sysctl */
141 rumpns_swwdog_reboot = true;
142 status = testbody(1);
144 ATF_REQUIRE(WIFEXITED(status));
145 ATF_REQUIRE_EQ(WEXITSTATUS(status), 0);
149 ATF_TC_HEAD(panic, tc)
152 atf_tc_set_md_var(tc, "descr", "check swwdog panic capability");
155 ATF_TC_BODY(panic, tc)
157 extern bool rumpns_swwdog_reboot;
160 /* XXX: should use sysctl */
161 rumpns_swwdog_reboot = false;
162 status = testbody(1);
164 ATF_REQUIRE(WIFSIGNALED(status));
165 ATF_REQUIRE_EQ(WTERMSIG(status), SIGABRT);
169 ATF_TC_HEAD(disarm, tc)
172 atf_tc_set_md_var(tc, "descr", "check swwdog disarm capability");
175 ATF_TC_BODY(disarm, tc)
179 status = testbody(2);
181 ATF_REQUIRE(WIFEXITED(status));
182 ATF_REQUIRE_EQ(WEXITSTATUS(status), 2);
188 ATF_TP_ADD_TC(tp, panic);
189 ATF_TP_ADD_TC(tp, reboot);
190 ATF_TP_ADD_TC(tp, disarm);
192 return atf_no_error();