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.
10 #include "qemu/osdep.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"));
21 static QDict
*qmp_get_event(const char *name
)
23 QDict
*event
= qmp("");
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");
39 static QDict
*ib700_program_and_wait(QTestState
*s
)
41 clock_step(NANOSECONDS_PER_SECOND
* 40);
48 clock_step(NANOSECONDS_PER_SECOND
);
53 clock_step(NANOSECONDS_PER_SECOND
);
56 clock_step(3 * NANOSECONDS_PER_SECOND
);
59 /* Enable and let it fire */
61 clock_step(3 * NANOSECONDS_PER_SECOND
);
63 clock_step(2 * NANOSECONDS_PER_SECOND
);
64 return qmp_get_event("WATCHDOG");
68 static void ib700_pause(void)
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"));
76 d
= qmp_get_event("STOP");
81 static void ib700_reset(void)
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"));
89 d
= qmp_get_event("RESET");
94 static void ib700_shutdown(void)
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"));
102 d
= qmp_get_event("SHUTDOWN");
107 static void ib700_none(void)
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"));
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
);