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 "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"));
22 static QDict
*ib700_program_and_wait(QTestState
*s
)
26 clock_step(NANOSECONDS_PER_SECOND
* 40);
33 clock_step(NANOSECONDS_PER_SECOND
);
38 clock_step(NANOSECONDS_PER_SECOND
);
41 clock_step(3 * NANOSECONDS_PER_SECOND
);
44 /* Enable and let it fire */
46 clock_step(3 * NANOSECONDS_PER_SECOND
);
48 clock_step(2 * NANOSECONDS_PER_SECOND
);
49 event
= qmp_eventwait_ref("WATCHDOG");
50 data
= qdict_get_qdict(event
, "data");
57 static void ib700_pause(void)
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"));
65 qmp_eventwait("STOP");
69 static void ib700_reset(void)
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"));
77 qmp_eventwait("RESET");
81 static void ib700_shutdown(void)
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"));
89 qmp_eventwait("SHUTDOWN");
93 static void ib700_none(void)
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"));
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
);