xref: /openbmc/qemu/tests/qtest/wdt_ib700-test.c (revision 2e3408b3cc7de4e87a9adafc8c19bfce3abec947)
11e8a1faeSThomas Huth /*
21e8a1faeSThomas Huth  * QTest testcase for the IB700 watchdog
31e8a1faeSThomas Huth  *
41e8a1faeSThomas Huth  * Copyright (c) 2014 Red Hat, Inc.
51e8a1faeSThomas Huth  *
61e8a1faeSThomas Huth  * This work is licensed under the terms of the GNU GPL, version 2 or later.
71e8a1faeSThomas Huth  * See the COPYING file in the top-level directory.
81e8a1faeSThomas Huth  */
91e8a1faeSThomas Huth 
101e8a1faeSThomas Huth #include "qemu/osdep.h"
11*907b5105SMarc-André Lureau #include "libqtest.h"
121e8a1faeSThomas Huth #include "qapi/qmp/qdict.h"
131e8a1faeSThomas Huth #include "qemu/timer.h"
141e8a1faeSThomas Huth 
qmp_check_no_event(QTestState * s)151e8a1faeSThomas Huth static void qmp_check_no_event(QTestState *s)
161e8a1faeSThomas Huth {
171e8a1faeSThomas Huth     QDict *resp = qtest_qmp(s, "{'execute':'query-status'}");
181e8a1faeSThomas Huth     g_assert(qdict_haskey(resp, "return"));
191e8a1faeSThomas Huth     qobject_unref(resp);
201e8a1faeSThomas Huth }
211e8a1faeSThomas Huth 
ib700_program_and_wait(QTestState * s)221e8a1faeSThomas Huth static QDict *ib700_program_and_wait(QTestState *s)
231e8a1faeSThomas Huth {
241e8a1faeSThomas Huth     QDict *event, *data;
251e8a1faeSThomas Huth 
261e8a1faeSThomas Huth     qtest_clock_step(s, NANOSECONDS_PER_SECOND * 40);
271e8a1faeSThomas Huth     qmp_check_no_event(s);
281e8a1faeSThomas Huth 
291e8a1faeSThomas Huth     /* 2 second limit */
301e8a1faeSThomas Huth     qtest_outb(s, 0x443, 14);
311e8a1faeSThomas Huth 
321e8a1faeSThomas Huth     /* Ping */
331e8a1faeSThomas Huth     qtest_clock_step(s, NANOSECONDS_PER_SECOND);
341e8a1faeSThomas Huth     qmp_check_no_event(s);
351e8a1faeSThomas Huth     qtest_outb(s, 0x443, 14);
361e8a1faeSThomas Huth 
371e8a1faeSThomas Huth     /* Disable */
381e8a1faeSThomas Huth     qtest_clock_step(s, NANOSECONDS_PER_SECOND);
391e8a1faeSThomas Huth     qmp_check_no_event(s);
401e8a1faeSThomas Huth     qtest_outb(s, 0x441, 1);
411e8a1faeSThomas Huth     qtest_clock_step(s, 3 * NANOSECONDS_PER_SECOND);
421e8a1faeSThomas Huth     qmp_check_no_event(s);
431e8a1faeSThomas Huth 
441e8a1faeSThomas Huth     /* Enable and let it fire */
451e8a1faeSThomas Huth     qtest_outb(s, 0x443, 13);
461e8a1faeSThomas Huth     qtest_clock_step(s, 3 * NANOSECONDS_PER_SECOND);
471e8a1faeSThomas Huth     qmp_check_no_event(s);
481e8a1faeSThomas Huth     qtest_clock_step(s, 2 * NANOSECONDS_PER_SECOND);
491e8a1faeSThomas Huth     event = qtest_qmp_eventwait_ref(s, "WATCHDOG");
501e8a1faeSThomas Huth     data = qdict_get_qdict(event, "data");
511e8a1faeSThomas Huth     qobject_ref(data);
521e8a1faeSThomas Huth     qobject_unref(event);
531e8a1faeSThomas Huth     return data;
541e8a1faeSThomas Huth }
551e8a1faeSThomas Huth 
561e8a1faeSThomas Huth 
ib700_pause(void)571e8a1faeSThomas Huth static void ib700_pause(void)
581e8a1faeSThomas Huth {
591e8a1faeSThomas Huth     QDict *d;
601e8a1faeSThomas Huth     QTestState *s = qtest_init("-watchdog-action pause -device ib700");
611e8a1faeSThomas Huth 
621e8a1faeSThomas Huth     qtest_irq_intercept_in(s, "ioapic");
631e8a1faeSThomas Huth     d = ib700_program_and_wait(s);
641e8a1faeSThomas Huth     g_assert(!strcmp(qdict_get_str(d, "action"), "pause"));
651e8a1faeSThomas Huth     qobject_unref(d);
661e8a1faeSThomas Huth     qtest_qmp_eventwait(s, "STOP");
671e8a1faeSThomas Huth     qtest_quit(s);
681e8a1faeSThomas Huth }
691e8a1faeSThomas Huth 
ib700_reset(void)701e8a1faeSThomas Huth static void ib700_reset(void)
711e8a1faeSThomas Huth {
721e8a1faeSThomas Huth     QDict *d;
731e8a1faeSThomas Huth     QTestState *s = qtest_init("-watchdog-action reset -device ib700");
741e8a1faeSThomas Huth 
751e8a1faeSThomas Huth     qtest_irq_intercept_in(s, "ioapic");
761e8a1faeSThomas Huth     d = ib700_program_and_wait(s);
771e8a1faeSThomas Huth     g_assert(!strcmp(qdict_get_str(d, "action"), "reset"));
781e8a1faeSThomas Huth     qobject_unref(d);
791e8a1faeSThomas Huth     qtest_qmp_eventwait(s, "RESET");
801e8a1faeSThomas Huth     qtest_quit(s);
811e8a1faeSThomas Huth }
821e8a1faeSThomas Huth 
ib700_shutdown(void)831e8a1faeSThomas Huth static void ib700_shutdown(void)
841e8a1faeSThomas Huth {
851e8a1faeSThomas Huth     QDict *d;
861e8a1faeSThomas Huth     QTestState *s;
871e8a1faeSThomas Huth 
881e8a1faeSThomas Huth     s = qtest_init("-watchdog-action reset -no-reboot -device ib700");
891e8a1faeSThomas Huth     qtest_irq_intercept_in(s, "ioapic");
901e8a1faeSThomas Huth     d = ib700_program_and_wait(s);
911e8a1faeSThomas Huth     g_assert(!strcmp(qdict_get_str(d, "action"), "reset"));
921e8a1faeSThomas Huth     qobject_unref(d);
931e8a1faeSThomas Huth     qtest_qmp_eventwait(s, "SHUTDOWN");
941e8a1faeSThomas Huth     qtest_quit(s);
951e8a1faeSThomas Huth }
961e8a1faeSThomas Huth 
ib700_none(void)971e8a1faeSThomas Huth static void ib700_none(void)
981e8a1faeSThomas Huth {
991e8a1faeSThomas Huth     QDict *d;
1001e8a1faeSThomas Huth     QTestState *s = qtest_init("-watchdog-action none -device ib700");
1011e8a1faeSThomas Huth 
1021e8a1faeSThomas Huth     qtest_irq_intercept_in(s, "ioapic");
1031e8a1faeSThomas Huth     d = ib700_program_and_wait(s);
1041e8a1faeSThomas Huth     g_assert(!strcmp(qdict_get_str(d, "action"), "none"));
1051e8a1faeSThomas Huth     qobject_unref(d);
1061e8a1faeSThomas Huth     qtest_quit(s);
1071e8a1faeSThomas Huth }
1081e8a1faeSThomas Huth 
main(int argc,char ** argv)1091e8a1faeSThomas Huth int main(int argc, char **argv)
1101e8a1faeSThomas Huth {
1111e8a1faeSThomas Huth     g_test_init(&argc, &argv, NULL);
1121e8a1faeSThomas Huth     qtest_add_func("/wdt_ib700/pause", ib700_pause);
1131e8a1faeSThomas Huth     qtest_add_func("/wdt_ib700/reset", ib700_reset);
1141e8a1faeSThomas Huth     qtest_add_func("/wdt_ib700/shutdown", ib700_shutdown);
1151e8a1faeSThomas Huth     qtest_add_func("/wdt_ib700/none", ib700_none);
1161e8a1faeSThomas Huth 
1171e8a1faeSThomas Huth     return g_test_run();
1181e8a1faeSThomas Huth }
119