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"
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
*qmp_get_event(const char *name
)
24 QDict
*event
= qmp("");
26 g_assert(qdict_haskey(event
, "event"));
27 g_assert(!strcmp(qdict_get_str(event
, "event"), name
));
29 if (qdict_haskey(event
, "data")) {
30 data
= qdict_get_qdict(event
, "data");
40 static QDict
*ib700_program_and_wait(QTestState
*s
)
42 clock_step(NANOSECONDS_PER_SECOND
* 40);
49 clock_step(NANOSECONDS_PER_SECOND
);
54 clock_step(NANOSECONDS_PER_SECOND
);
57 clock_step(3 * NANOSECONDS_PER_SECOND
);
60 /* Enable and let it fire */
62 clock_step(3 * NANOSECONDS_PER_SECOND
);
64 clock_step(2 * NANOSECONDS_PER_SECOND
);
65 return qmp_get_event("WATCHDOG");
69 static void ib700_pause(void)
72 QTestState
*s
= qtest_start("-watchdog-action pause -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"), "pause"));
77 d
= qmp_get_event("STOP");
82 static void ib700_reset(void)
85 QTestState
*s
= qtest_start("-watchdog-action reset -device ib700");
86 qtest_irq_intercept_in(s
, "ioapic");
87 d
= ib700_program_and_wait(s
);
88 g_assert(!strcmp(qdict_get_str(d
, "action"), "reset"));
90 d
= qmp_get_event("RESET");
95 static void ib700_shutdown(void)
98 QTestState
*s
= qtest_start("-watchdog-action reset -no-reboot -device ib700");
99 qtest_irq_intercept_in(s
, "ioapic");
100 d
= ib700_program_and_wait(s
);
101 g_assert(!strcmp(qdict_get_str(d
, "action"), "reset"));
103 d
= qmp_get_event("SHUTDOWN");
108 static void ib700_none(void)
111 QTestState
*s
= qtest_start("-watchdog-action none -device ib700");
112 qtest_irq_intercept_in(s
, "ioapic");
113 d
= ib700_program_and_wait(s
);
114 g_assert(!strcmp(qdict_get_str(d
, "action"), "none"));
119 int main(int argc
, char **argv
)
123 g_test_init(&argc
, &argv
, NULL
);
124 qtest_add_func("/wdt_ib700/pause", ib700_pause
);
125 qtest_add_func("/wdt_ib700/reset", ib700_reset
);
126 qtest_add_func("/wdt_ib700/shutdown", ib700_shutdown
);
127 qtest_add_func("/wdt_ib700/none", ib700_none
);