2 * QTest testcase for the IB700 watchdog
4 * Copyright (c) 2014 Red Hat, Inc.
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
13 #include "qemu/osdep.h"
15 #define NS_PER_SEC 1000000000ULL
17 static void qmp_check_no_event(void)
19 QDict *resp = qmp("{'execute':'query-status'}");
20 g_assert(qdict_haskey(resp, "return"));
24 static QDict *qmp_get_event(const char *name)
26 QDict *event = qmp("");
28 g_assert(qdict_haskey(event, "event"));
29 g_assert(!strcmp(qdict_get_str(event, "event"), name));
31 if (qdict_haskey(event, "data")) {
32 data = qdict_get_qdict(event, "data");
42 static QDict *ib700_program_and_wait(QTestState *s)
44 clock_step(NS_PER_SEC * 40);
51 clock_step(NS_PER_SEC);
56 clock_step(NS_PER_SEC);
59 clock_step(3 * NS_PER_SEC);
62 /* Enable and let it fire */
64 clock_step(3 * NS_PER_SEC);
66 clock_step(2 * NS_PER_SEC);
67 return qmp_get_event("WATCHDOG");
71 static void ib700_pause(void)
74 QTestState *s = qtest_start("-watchdog-action pause -device ib700");
75 qtest_irq_intercept_in(s, "ioapic");
76 d = ib700_program_and_wait(s);
77 g_assert(!strcmp(qdict_get_str(d, "action"), "pause"));
79 d = qmp_get_event("STOP");
84 static void ib700_reset(void)
87 QTestState *s = qtest_start("-watchdog-action reset -device ib700");
88 qtest_irq_intercept_in(s, "ioapic");
89 d = ib700_program_and_wait(s);
90 g_assert(!strcmp(qdict_get_str(d, "action"), "reset"));
92 d = qmp_get_event("RESET");
97 static void ib700_shutdown(void)
100 QTestState *s = qtest_start("-watchdog-action reset -no-reboot -device ib700");
101 qtest_irq_intercept_in(s, "ioapic");
102 d = ib700_program_and_wait(s);
103 g_assert(!strcmp(qdict_get_str(d, "action"), "reset"));
105 d = qmp_get_event("SHUTDOWN");
110 static void ib700_none(void)
113 QTestState *s = qtest_start("-watchdog-action none -device ib700");
114 qtest_irq_intercept_in(s, "ioapic");
115 d = ib700_program_and_wait(s);
116 g_assert(!strcmp(qdict_get_str(d, "action"), "none"));
121 int main(int argc, char **argv)
125 g_test_init(&argc, &argv, NULL);
126 qtest_add_func("/wdt_ib700/pause", ib700_pause);
127 qtest_add_func("/wdt_ib700/reset", ib700_reset);
128 qtest_add_func("/wdt_ib700/shutdown", ib700_shutdown);
129 qtest_add_func("/wdt_ib700/none", ib700_none);