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.
10 #include "qemu/osdep.h"
11 #include "libqos/libqtest.h"
12 #include "qapi/qmp/qdict.h"
13 #include "qemu/timer.h"
15 static void qmp_check_no_event(QTestState
*s
)
17 QDict
*resp
= qtest_qmp(s
, "{'execute':'query-status'}");
18 g_assert(qdict_haskey(resp
, "return"));
22 static QDict
*ib700_program_and_wait(QTestState
*s
)
26 qtest_clock_step(s
, NANOSECONDS_PER_SECOND
* 40);
27 qmp_check_no_event(s
);
30 qtest_outb(s
, 0x443, 14);
33 qtest_clock_step(s
, NANOSECONDS_PER_SECOND
);
34 qmp_check_no_event(s
);
35 qtest_outb(s
, 0x443, 14);
38 qtest_clock_step(s
, NANOSECONDS_PER_SECOND
);
39 qmp_check_no_event(s
);
40 qtest_outb(s
, 0x441, 1);
41 qtest_clock_step(s
, 3 * NANOSECONDS_PER_SECOND
);
42 qmp_check_no_event(s
);
44 /* Enable and let it fire */
45 qtest_outb(s
, 0x443, 13);
46 qtest_clock_step(s
, 3 * NANOSECONDS_PER_SECOND
);
47 qmp_check_no_event(s
);
48 qtest_clock_step(s
, 2 * NANOSECONDS_PER_SECOND
);
49 event
= qtest_qmp_eventwait_ref(s
, "WATCHDOG");
50 data
= qdict_get_qdict(event
, "data");
57 static void ib700_pause(void)
60 QTestState
*s
= qtest_init("-watchdog-action pause -device ib700");
62 qtest_irq_intercept_in(s
, "ioapic");
63 d
= ib700_program_and_wait(s
);
64 g_assert(!strcmp(qdict_get_str(d
, "action"), "pause"));
66 qtest_qmp_eventwait(s
, "STOP");
70 static void ib700_reset(void)
73 QTestState
*s
= qtest_init("-watchdog-action reset -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"), "reset"));
79 qtest_qmp_eventwait(s
, "RESET");
83 static void ib700_shutdown(void)
88 s
= qtest_init("-watchdog-action reset -no-reboot -device ib700");
89 qtest_irq_intercept_in(s
, "ioapic");
90 d
= ib700_program_and_wait(s
);
91 g_assert(!strcmp(qdict_get_str(d
, "action"), "reset"));
93 qtest_qmp_eventwait(s
, "SHUTDOWN");
97 static void ib700_none(void)
100 QTestState
*s
= qtest_init("-watchdog-action none -device ib700");
102 qtest_irq_intercept_in(s
, "ioapic");
103 d
= ib700_program_and_wait(s
);
104 g_assert(!strcmp(qdict_get_str(d
, "action"), "none"));
109 int main(int argc
, char **argv
)
111 g_test_init(&argc
, &argv
, NULL
);
112 qtest_add_func("/wdt_ib700/pause", ib700_pause
);
113 qtest_add_func("/wdt_ib700/reset", ib700_reset
);
114 qtest_add_func("/wdt_ib700/shutdown", ib700_shutdown
);
115 qtest_add_func("/wdt_ib700/none", ib700_none
);