libqos: Use explicit QTestState for ahci operations
[qemu.git] / tests / wdt_ib700-test.c
blobd777f3212e9b691a53239bdf12f042d4f19b5f02
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(void)
17 QDict *resp = qmp("{'execute':'query-status'}");
18 g_assert(qdict_haskey(resp, "return"));
19 QDECREF(resp);
22 static QDict *ib700_program_and_wait(QTestState *s)
24 QDict *event, *data;
26 clock_step(NANOSECONDS_PER_SECOND * 40);
27 qmp_check_no_event();
29 /* 2 second limit */
30 outb(0x443, 14);
32 /* Ping */
33 clock_step(NANOSECONDS_PER_SECOND);
34 qmp_check_no_event();
35 outb(0x443, 14);
37 /* Disable */
38 clock_step(NANOSECONDS_PER_SECOND);
39 qmp_check_no_event();
40 outb(0x441, 1);
41 clock_step(3 * NANOSECONDS_PER_SECOND);
42 qmp_check_no_event();
44 /* Enable and let it fire */
45 outb(0x443, 13);
46 clock_step(3 * NANOSECONDS_PER_SECOND);
47 qmp_check_no_event();
48 clock_step(2 * NANOSECONDS_PER_SECOND);
49 event = qmp_eventwait_ref("WATCHDOG");
50 data = qdict_get_qdict(event, "data");
51 QINCREF(data);
52 QDECREF(event);
53 return data;
57 static void ib700_pause(void)
59 QDict *d;
60 QTestState *s = qtest_start("-watchdog-action pause -device ib700");
61 qtest_irq_intercept_in(s, "ioapic");
62 d = ib700_program_and_wait(s);
63 g_assert(!strcmp(qdict_get_str(d, "action"), "pause"));
64 QDECREF(d);
65 qmp_eventwait("STOP");
66 qtest_end();
69 static void ib700_reset(void)
71 QDict *d;
72 QTestState *s = qtest_start("-watchdog-action reset -device ib700");
73 qtest_irq_intercept_in(s, "ioapic");
74 d = ib700_program_and_wait(s);
75 g_assert(!strcmp(qdict_get_str(d, "action"), "reset"));
76 QDECREF(d);
77 qmp_eventwait("RESET");
78 qtest_end();
81 static void ib700_shutdown(void)
83 QDict *d;
84 QTestState *s = qtest_start("-watchdog-action reset -no-reboot -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 qmp_eventwait("SHUTDOWN");
90 qtest_end();
93 static void ib700_none(void)
95 QDict *d;
96 QTestState *s = qtest_start("-watchdog-action none -device ib700");
97 qtest_irq_intercept_in(s, "ioapic");
98 d = ib700_program_and_wait(s);
99 g_assert(!strcmp(qdict_get_str(d, "action"), "none"));
100 QDECREF(d);
101 qtest_end();
104 int main(int argc, char **argv)
106 g_test_init(&argc, &argv, NULL);
107 qtest_add_func("/wdt_ib700/pause", ib700_pause);
108 qtest_add_func("/wdt_ib700/reset", ib700_reset);
109 qtest_add_func("/wdt_ib700/shutdown", ib700_shutdown);
110 qtest_add_func("/wdt_ib700/none", ib700_none);
112 return g_test_run();