hw/arm/iotkit: Wire up MPC interrupt lines
[qemu/ar7.git] / tests / wdt_ib700-test.c
blob797288d939fac2fb51f7200bfc3119e824bd29d0
1 /*
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.
8 */
10 #include "qemu/osdep.h"
11 #include "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"));
19 qobject_unref(resp);
22 static QDict *ib700_program_and_wait(QTestState *s)
24 QDict *event, *data;
26 qtest_clock_step(s, NANOSECONDS_PER_SECOND * 40);
27 qmp_check_no_event(s);
29 /* 2 second limit */
30 qtest_outb(s, 0x443, 14);
32 /* Ping */
33 qtest_clock_step(s, NANOSECONDS_PER_SECOND);
34 qmp_check_no_event(s);
35 qtest_outb(s, 0x443, 14);
37 /* Disable */
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");
51 qobject_ref(data);
52 qobject_unref(event);
53 return data;
57 static void ib700_pause(void)
59 QDict *d;
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"));
65 qobject_unref(d);
66 qtest_qmp_eventwait(s, "STOP");
67 qtest_quit(s);
70 static void ib700_reset(void)
72 QDict *d;
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"));
78 qobject_unref(d);
79 qtest_qmp_eventwait(s, "RESET");
80 qtest_quit(s);
83 static void ib700_shutdown(void)
85 QDict *d;
86 QTestState *s;
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"));
92 qobject_unref(d);
93 qtest_qmp_eventwait(s, "SHUTDOWN");
94 qtest_quit(s);
97 static void ib700_none(void)
99 QDict *d;
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"));
105 qobject_unref(d);
106 qtest_quit(s);
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);
117 return g_test_run();