MAINTAINERS: update s390 file patterns
[qemu/ar7.git] / tests / wdt_ib700-test.c
blob82ca597252720f73d1eaa03e9669e3b5900bd732
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 <glib.h>
11 #include <string.h>
12 #include "libqtest.h"
13 #include "qemu/osdep.h"
14 #include "qemu/timer.h"
16 static void qmp_check_no_event(void)
18 QDict *resp = qmp("{'execute':'query-status'}");
19 g_assert(qdict_haskey(resp, "return"));
20 QDECREF(resp);
23 static QDict *qmp_get_event(const char *name)
25 QDict *event = qmp("");
26 QDict *data;
27 g_assert(qdict_haskey(event, "event"));
28 g_assert(!strcmp(qdict_get_str(event, "event"), name));
30 if (qdict_haskey(event, "data")) {
31 data = qdict_get_qdict(event, "data");
32 QINCREF(data);
33 } else {
34 data = NULL;
37 QDECREF(event);
38 return data;
41 static QDict *ib700_program_and_wait(QTestState *s)
43 clock_step(NANOSECONDS_PER_SECOND * 40);
44 qmp_check_no_event();
46 /* 2 second limit */
47 outb(0x443, 14);
49 /* Ping */
50 clock_step(NANOSECONDS_PER_SECOND);
51 qmp_check_no_event();
52 outb(0x443, 14);
54 /* Disable */
55 clock_step(NANOSECONDS_PER_SECOND);
56 qmp_check_no_event();
57 outb(0x441, 1);
58 clock_step(3 * NANOSECONDS_PER_SECOND);
59 qmp_check_no_event();
61 /* Enable and let it fire */
62 outb(0x443, 13);
63 clock_step(3 * NANOSECONDS_PER_SECOND);
64 qmp_check_no_event();
65 clock_step(2 * NANOSECONDS_PER_SECOND);
66 return qmp_get_event("WATCHDOG");
70 static void ib700_pause(void)
72 QDict *d;
73 QTestState *s = qtest_start("-watchdog-action pause -device ib700");
74 qtest_irq_intercept_in(s, "ioapic");
75 d = ib700_program_and_wait(s);
76 g_assert(!strcmp(qdict_get_str(d, "action"), "pause"));
77 QDECREF(d);
78 d = qmp_get_event("STOP");
79 QDECREF(d);
80 qtest_end();
83 static void ib700_reset(void)
85 QDict *d;
86 QTestState *s = qtest_start("-watchdog-action reset -device ib700");
87 qtest_irq_intercept_in(s, "ioapic");
88 d = ib700_program_and_wait(s);
89 g_assert(!strcmp(qdict_get_str(d, "action"), "reset"));
90 QDECREF(d);
91 d = qmp_get_event("RESET");
92 QDECREF(d);
93 qtest_end();
96 static void ib700_shutdown(void)
98 QDict *d;
99 QTestState *s = qtest_start("-watchdog-action reset -no-reboot -device ib700");
100 qtest_irq_intercept_in(s, "ioapic");
101 d = ib700_program_and_wait(s);
102 g_assert(!strcmp(qdict_get_str(d, "action"), "reset"));
103 QDECREF(d);
104 d = qmp_get_event("SHUTDOWN");
105 QDECREF(d);
106 qtest_end();
109 static void ib700_none(void)
111 QDict *d;
112 QTestState *s = qtest_start("-watchdog-action none -device ib700");
113 qtest_irq_intercept_in(s, "ioapic");
114 d = ib700_program_and_wait(s);
115 g_assert(!strcmp(qdict_get_str(d, "action"), "none"));
116 QDECREF(d);
117 qtest_end();
120 int main(int argc, char **argv)
122 int ret;
124 g_test_init(&argc, &argv, NULL);
125 qtest_add_func("/wdt_ib700/pause", ib700_pause);
126 qtest_add_func("/wdt_ib700/reset", ib700_reset);
127 qtest_add_func("/wdt_ib700/shutdown", ib700_shutdown);
128 qtest_add_func("/wdt_ib700/none", ib700_none);
130 ret = g_test_run();
132 return ret;