xref: /openbmc/qemu/tests/qtest/wdt_ib700-test.c (revision 883f2c59)
1 /*
2  * QTest testcase for the IB700 watchdog
3  *
4  * Copyright (c) 2014 Red Hat, Inc.
5  *
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.
8  */
9 
10 #include "qemu/osdep.h"
11 #include "libqtest.h"
12 #include "qapi/qmp/qdict.h"
13 #include "qemu/timer.h"
14 
15 static void qmp_check_no_event(QTestState *s)
16 {
17     QDict *resp = qtest_qmp(s, "{'execute':'query-status'}");
18     g_assert(qdict_haskey(resp, "return"));
19     qobject_unref(resp);
20 }
21 
22 static QDict *ib700_program_and_wait(QTestState *s)
23 {
24     QDict *event, *data;
25 
26     qtest_clock_step(s, NANOSECONDS_PER_SECOND * 40);
27     qmp_check_no_event(s);
28 
29     /* 2 second limit */
30     qtest_outb(s, 0x443, 14);
31 
32     /* Ping */
33     qtest_clock_step(s, NANOSECONDS_PER_SECOND);
34     qmp_check_no_event(s);
35     qtest_outb(s, 0x443, 14);
36 
37     /* Disable */
38     qtest_clock_step(s, NANOSECONDS_PER_SECOND);
39     qmp_check_no_event(s);
40     qtest_outb(s, 0x441, 1);
41     qtest_clock_step(s, 3 * NANOSECONDS_PER_SECOND);
42     qmp_check_no_event(s);
43 
44     /* Enable and let it fire */
45     qtest_outb(s, 0x443, 13);
46     qtest_clock_step(s, 3 * NANOSECONDS_PER_SECOND);
47     qmp_check_no_event(s);
48     qtest_clock_step(s, 2 * NANOSECONDS_PER_SECOND);
49     event = qtest_qmp_eventwait_ref(s, "WATCHDOG");
50     data = qdict_get_qdict(event, "data");
51     qobject_ref(data);
52     qobject_unref(event);
53     return data;
54 }
55 
56 
57 static void ib700_pause(void)
58 {
59     QDict *d;
60     QTestState *s = qtest_init("-watchdog-action pause -device ib700");
61 
62     qtest_irq_intercept_in(s, "ioapic");
63     d = ib700_program_and_wait(s);
64     g_assert(!strcmp(qdict_get_str(d, "action"), "pause"));
65     qobject_unref(d);
66     qtest_qmp_eventwait(s, "STOP");
67     qtest_quit(s);
68 }
69 
70 static void ib700_reset(void)
71 {
72     QDict *d;
73     QTestState *s = qtest_init("-watchdog-action reset -device ib700");
74 
75     qtest_irq_intercept_in(s, "ioapic");
76     d = ib700_program_and_wait(s);
77     g_assert(!strcmp(qdict_get_str(d, "action"), "reset"));
78     qobject_unref(d);
79     qtest_qmp_eventwait(s, "RESET");
80     qtest_quit(s);
81 }
82 
83 static void ib700_shutdown(void)
84 {
85     QDict *d;
86     QTestState *s;
87 
88     s = qtest_init("-watchdog-action reset -no-reboot -device ib700");
89     qtest_irq_intercept_in(s, "ioapic");
90     d = ib700_program_and_wait(s);
91     g_assert(!strcmp(qdict_get_str(d, "action"), "reset"));
92     qobject_unref(d);
93     qtest_qmp_eventwait(s, "SHUTDOWN");
94     qtest_quit(s);
95 }
96 
97 static void ib700_none(void)
98 {
99     QDict *d;
100     QTestState *s = qtest_init("-watchdog-action none -device ib700");
101 
102     qtest_irq_intercept_in(s, "ioapic");
103     d = ib700_program_and_wait(s);
104     g_assert(!strcmp(qdict_get_str(d, "action"), "none"));
105     qobject_unref(d);
106     qtest_quit(s);
107 }
108 
109 int main(int argc, char **argv)
110 {
111     g_test_init(&argc, &argv, NULL);
112     qtest_add_func("/wdt_ib700/pause", ib700_pause);
113     qtest_add_func("/wdt_ib700/reset", ib700_reset);
114     qtest_add_func("/wdt_ib700/shutdown", ib700_shutdown);
115     qtest_add_func("/wdt_ib700/none", ib700_none);
116 
117     return g_test_run();
118 }
119