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.
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"));
23 static QDict
*qmp_get_event(const char *name
)
25 QDict
*event
= qmp("");
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");
41 static QDict
*ib700_program_and_wait(QTestState
*s
)
43 clock_step(NANOSECONDS_PER_SECOND
* 40);
50 clock_step(NANOSECONDS_PER_SECOND
);
55 clock_step(NANOSECONDS_PER_SECOND
);
58 clock_step(3 * NANOSECONDS_PER_SECOND
);
61 /* Enable and let it fire */
63 clock_step(3 * NANOSECONDS_PER_SECOND
);
65 clock_step(2 * NANOSECONDS_PER_SECOND
);
66 return qmp_get_event("WATCHDOG");
70 static void ib700_pause(void)
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"));
78 d
= qmp_get_event("STOP");
83 static void ib700_reset(void)
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"));
91 d
= qmp_get_event("RESET");
96 static void ib700_shutdown(void)
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"));
104 d
= qmp_get_event("SHUTDOWN");
109 static void ib700_none(void)
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"));
120 int main(int argc
, char **argv
)
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
);