migration: Remove unneeded includes of migration/vmstate.h
[qemu/ar7.git] / tests / wdt_ib700-test.c
blob49f4f0c2216f07a45746fc162599c9f90078404c
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 "qemu/timer.h"
14 static void qmp_check_no_event(void)
16 QDict *resp = qmp("{'execute':'query-status'}");
17 g_assert(qdict_haskey(resp, "return"));
18 QDECREF(resp);
21 static QDict *qmp_get_event(const char *name)
23 QDict *event = qmp("");
24 QDict *data;
25 g_assert(qdict_haskey(event, "event"));
26 g_assert(!strcmp(qdict_get_str(event, "event"), name));
28 if (qdict_haskey(event, "data")) {
29 data = qdict_get_qdict(event, "data");
30 QINCREF(data);
31 } else {
32 data = NULL;
35 QDECREF(event);
36 return data;
39 static QDict *ib700_program_and_wait(QTestState *s)
41 clock_step(NANOSECONDS_PER_SECOND * 40);
42 qmp_check_no_event();
44 /* 2 second limit */
45 outb(0x443, 14);
47 /* Ping */
48 clock_step(NANOSECONDS_PER_SECOND);
49 qmp_check_no_event();
50 outb(0x443, 14);
52 /* Disable */
53 clock_step(NANOSECONDS_PER_SECOND);
54 qmp_check_no_event();
55 outb(0x441, 1);
56 clock_step(3 * NANOSECONDS_PER_SECOND);
57 qmp_check_no_event();
59 /* Enable and let it fire */
60 outb(0x443, 13);
61 clock_step(3 * NANOSECONDS_PER_SECOND);
62 qmp_check_no_event();
63 clock_step(2 * NANOSECONDS_PER_SECOND);
64 return qmp_get_event("WATCHDOG");
68 static void ib700_pause(void)
70 QDict *d;
71 QTestState *s = qtest_start("-watchdog-action pause -device ib700");
72 qtest_irq_intercept_in(s, "ioapic");
73 d = ib700_program_and_wait(s);
74 g_assert(!strcmp(qdict_get_str(d, "action"), "pause"));
75 QDECREF(d);
76 d = qmp_get_event("STOP");
77 QDECREF(d);
78 qtest_end();
81 static void ib700_reset(void)
83 QDict *d;
84 QTestState *s = qtest_start("-watchdog-action reset -device ib700");
85 qtest_irq_intercept_in(s, "ioapic");
86 d = ib700_program_and_wait(s);
87 g_assert(!strcmp(qdict_get_str(d, "action"), "reset"));
88 QDECREF(d);
89 d = qmp_get_event("RESET");
90 QDECREF(d);
91 qtest_end();
94 static void ib700_shutdown(void)
96 QDict *d;
97 QTestState *s = qtest_start("-watchdog-action reset -no-reboot -device ib700");
98 qtest_irq_intercept_in(s, "ioapic");
99 d = ib700_program_and_wait(s);
100 g_assert(!strcmp(qdict_get_str(d, "action"), "reset"));
101 QDECREF(d);
102 d = qmp_get_event("SHUTDOWN");
103 QDECREF(d);
104 qtest_end();
107 static void ib700_none(void)
109 QDict *d;
110 QTestState *s = qtest_start("-watchdog-action none -device ib700");
111 qtest_irq_intercept_in(s, "ioapic");
112 d = ib700_program_and_wait(s);
113 g_assert(!strcmp(qdict_get_str(d, "action"), "none"));
114 QDECREF(d);
115 qtest_end();
118 int main(int argc, char **argv)
120 g_test_init(&argc, &argv, NULL);
121 qtest_add_func("/wdt_ib700/pause", ib700_pause);
122 qtest_add_func("/wdt_ib700/reset", ib700_reset);
123 qtest_add_func("/wdt_ib700/shutdown", ib700_shutdown);
124 qtest_add_func("/wdt_ib700/none", ib700_none);
126 return g_test_run();