]>
Commit | Line | Data |
---|---|---|
f52b7687 PB |
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 | ||
681c28a3 | 10 | #include "qemu/osdep.h" |
f52b7687 | 11 | #include "libqtest.h" |
e0cf11f3 | 12 | #include "qemu/timer.h" |
f52b7687 PB |
13 | |
14 | static void qmp_check_no_event(void) | |
15 | { | |
16 | QDict *resp = qmp("{'execute':'query-status'}"); | |
17 | g_assert(qdict_haskey(resp, "return")); | |
18 | QDECREF(resp); | |
19 | } | |
20 | ||
21 | static QDict *qmp_get_event(const char *name) | |
22 | { | |
23 | QDict *event = qmp(""); | |
24 | QDict *data; | |
25 | g_assert(qdict_haskey(event, "event")); | |
26 | g_assert(!strcmp(qdict_get_str(event, "event"), name)); | |
27 | ||
28 | if (qdict_haskey(event, "data")) { | |
29 | data = qdict_get_qdict(event, "data"); | |
30 | QINCREF(data); | |
31 | } else { | |
32 | data = NULL; | |
33 | } | |
34 | ||
35 | QDECREF(event); | |
36 | return data; | |
37 | } | |
38 | ||
39 | static QDict *ib700_program_and_wait(QTestState *s) | |
40 | { | |
13566fe3 | 41 | clock_step(NANOSECONDS_PER_SECOND * 40); |
f52b7687 PB |
42 | qmp_check_no_event(); |
43 | ||
44 | /* 2 second limit */ | |
45 | outb(0x443, 14); | |
46 | ||
47 | /* Ping */ | |
13566fe3 | 48 | clock_step(NANOSECONDS_PER_SECOND); |
f52b7687 PB |
49 | qmp_check_no_event(); |
50 | outb(0x443, 14); | |
51 | ||
52 | /* Disable */ | |
13566fe3 | 53 | clock_step(NANOSECONDS_PER_SECOND); |
f52b7687 PB |
54 | qmp_check_no_event(); |
55 | outb(0x441, 1); | |
13566fe3 | 56 | clock_step(3 * NANOSECONDS_PER_SECOND); |
f52b7687 PB |
57 | qmp_check_no_event(); |
58 | ||
59 | /* Enable and let it fire */ | |
60 | outb(0x443, 13); | |
13566fe3 | 61 | clock_step(3 * NANOSECONDS_PER_SECOND); |
f52b7687 | 62 | qmp_check_no_event(); |
13566fe3 | 63 | clock_step(2 * NANOSECONDS_PER_SECOND); |
f52b7687 PB |
64 | return qmp_get_event("WATCHDOG"); |
65 | } | |
66 | ||
67 | ||
68 | static void ib700_pause(void) | |
69 | { | |
70 | QDict *d; | |
71 | QTestState *s = qtest_start("-watchdog-action pause -device ib700"); | |
72 | qtest_irq_intercept_in(s, "ioapic"); | |
73 | d = ib700_program_and_wait(s); | |
74 | g_assert(!strcmp(qdict_get_str(d, "action"), "pause")); | |
75 | QDECREF(d); | |
76 | d = qmp_get_event("STOP"); | |
77 | QDECREF(d); | |
78 | qtest_end(); | |
79 | } | |
80 | ||
81 | static void ib700_reset(void) | |
82 | { | |
83 | QDict *d; | |
84 | QTestState *s = qtest_start("-watchdog-action reset -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")); | |
88 | QDECREF(d); | |
89 | d = qmp_get_event("RESET"); | |
90 | QDECREF(d); | |
91 | qtest_end(); | |
92 | } | |
93 | ||
94 | static void ib700_shutdown(void) | |
95 | { | |
96 | QDict *d; | |
97 | QTestState *s = qtest_start("-watchdog-action reset -no-reboot -device ib700"); | |
98 | qtest_irq_intercept_in(s, "ioapic"); | |
99 | d = ib700_program_and_wait(s); | |
100 | g_assert(!strcmp(qdict_get_str(d, "action"), "reset")); | |
101 | QDECREF(d); | |
102 | d = qmp_get_event("SHUTDOWN"); | |
103 | QDECREF(d); | |
104 | qtest_end(); | |
105 | } | |
106 | ||
107 | static void ib700_none(void) | |
108 | { | |
109 | QDict *d; | |
110 | QTestState *s = qtest_start("-watchdog-action none -device ib700"); | |
111 | qtest_irq_intercept_in(s, "ioapic"); | |
112 | d = ib700_program_and_wait(s); | |
113 | g_assert(!strcmp(qdict_get_str(d, "action"), "none")); | |
114 | QDECREF(d); | |
115 | qtest_end(); | |
116 | } | |
117 | ||
118 | int main(int argc, char **argv) | |
119 | { | |
f52b7687 PB |
120 | g_test_init(&argc, &argv, NULL); |
121 | qtest_add_func("/wdt_ib700/pause", ib700_pause); | |
122 | qtest_add_func("/wdt_ib700/reset", ib700_reset); | |
123 | qtest_add_func("/wdt_ib700/shutdown", ib700_shutdown); | |
124 | qtest_add_func("/wdt_ib700/none", ib700_none); | |
125 | ||
9be38598 | 126 | return g_test_run(); |
f52b7687 | 127 | } |