1 /* $NetBSD: t_swwdog.c,v 1.5 2011/06/26 12:14:59 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>
46 #include "../../h_macros.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
);
128 ATF_TC_HEAD(reboot
, tc
)
131 atf_tc_set_md_var(tc
, "descr", "check swwdog reboot capability");
134 ATF_TC_BODY(reboot
, tc
)
136 extern bool rumpns_swwdog_reboot
;
139 /* XXX: should use sysctl */
140 rumpns_swwdog_reboot
= true;
141 status
= testbody(1);
143 ATF_REQUIRE(WIFEXITED(status
));
144 ATF_REQUIRE_EQ(WEXITSTATUS(status
), 0);
148 ATF_TC_HEAD(panic
, tc
)
151 atf_tc_set_md_var(tc
, "descr", "check swwdog panic capability");
154 ATF_TC_BODY(panic
, tc
)
156 extern bool rumpns_swwdog_reboot
;
159 /* XXX: should use sysctl */
160 rumpns_swwdog_reboot
= false;
161 status
= testbody(1);
163 ATF_REQUIRE(WIFSIGNALED(status
));
164 ATF_REQUIRE_EQ(WTERMSIG(status
), SIGABRT
);
168 ATF_TC_HEAD(disarm
, tc
)
171 atf_tc_set_md_var(tc
, "descr", "check swwdog disarm capability");
174 ATF_TC_BODY(disarm
, tc
)
178 status
= testbody(2);
180 ATF_REQUIRE(WIFEXITED(status
));
181 ATF_REQUIRE_EQ(WEXITSTATUS(status
), 2);
187 ATF_TP_ADD_TC(tp
, panic
);
188 ATF_TP_ADD_TC(tp
, reboot
);
189 ATF_TP_ADD_TC(tp
, disarm
);
191 return atf_no_error();