spice: remove spice-experimental.h include
[qemu.git] / tests / wdt_ib700-test.c
blob513a53385235dd896ca98379df6b0e8310e999ef
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"
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"));
21 QDECREF(resp);
24 static QDict *qmp_get_event(const char *name)
26 QDict *event = qmp("");
27 QDict *data;
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");
33 QINCREF(data);
34 } else {
35 data = NULL;
38 QDECREF(event);
39 return data;
42 static QDict *ib700_program_and_wait(QTestState *s)
44 clock_step(NS_PER_SEC * 40);
45 qmp_check_no_event();
47 /* 2 second limit */
48 outb(0x443, 14);
50 /* Ping */
51 clock_step(NS_PER_SEC);
52 qmp_check_no_event();
53 outb(0x443, 14);
55 /* Disable */
56 clock_step(NS_PER_SEC);
57 qmp_check_no_event();
58 outb(0x441, 1);
59 clock_step(3 * NS_PER_SEC);
60 qmp_check_no_event();
62 /* Enable and let it fire */
63 outb(0x443, 13);
64 clock_step(3 * NS_PER_SEC);
65 qmp_check_no_event();
66 clock_step(2 * NS_PER_SEC);
67 return qmp_get_event("WATCHDOG");
71 static void ib700_pause(void)
73 QDict *d;
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"));
78 QDECREF(d);
79 d = qmp_get_event("STOP");
80 QDECREF(d);
81 qtest_end();
84 static void ib700_reset(void)
86 QDict *d;
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"));
91 QDECREF(d);
92 d = qmp_get_event("RESET");
93 QDECREF(d);
94 qtest_end();
97 static void ib700_shutdown(void)
99 QDict *d;
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"));
104 QDECREF(d);
105 d = qmp_get_event("SHUTDOWN");
106 QDECREF(d);
107 qtest_end();
110 static void ib700_none(void)
112 QDict *d;
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"));
117 QDECREF(d);
118 qtest_end();
121 int main(int argc, char **argv)
123 int ret;
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);
131 ret = g_test_run();
133 return ret;