]> Git Repo - qemu.git/blob - tests/wdt_ib700-test.c
image-fuzzer: Fuzzing functions for qcow2 images
[qemu.git] / tests / wdt_ib700-test.c
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 <glib.h>
11 #include <string.h>
12 #include "libqtest.h"
13 #include "qemu/osdep.h"
14
15 #define NS_PER_SEC 1000000000ULL
16
17 static void qmp_check_no_event(void)
18 {
19     QDict *resp = qmp("{'execute':'query-status'}");
20     g_assert(qdict_haskey(resp, "return"));
21     QDECREF(resp);
22 }
23
24 static QDict *qmp_get_event(const char *name)
25 {
26     QDict *event = qmp("");
27     QDict *data;
28     g_assert(qdict_haskey(event, "event"));
29     g_assert(!strcmp(qdict_get_str(event, "event"), name));
30
31     if (qdict_haskey(event, "data")) {
32         data = qdict_get_qdict(event, "data");
33         QINCREF(data);
34     } else {
35         data = NULL;
36     }
37
38     QDECREF(event);
39     return data;
40 }
41
42 static QDict *ib700_program_and_wait(QTestState *s)
43 {
44     clock_step(NS_PER_SEC * 40);
45     qmp_check_no_event();
46
47     /* 2 second limit */
48     outb(0x443, 14);
49
50     /* Ping */
51     clock_step(NS_PER_SEC);
52     qmp_check_no_event();
53     outb(0x443, 14);
54
55     /* Disable */
56     clock_step(NS_PER_SEC);
57     qmp_check_no_event();
58     outb(0x441, 1);
59     clock_step(3 * NS_PER_SEC);
60     qmp_check_no_event();
61
62     /* Enable and let it fire */
63     outb(0x443, 13);
64     clock_step(3 * NS_PER_SEC);
65     qmp_check_no_event();
66     clock_step(2 * NS_PER_SEC);
67     return qmp_get_event("WATCHDOG");
68 }
69
70
71 static void ib700_pause(void)
72 {
73     QDict *d;
74     QTestState *s = qtest_start("-watchdog-action pause -device ib700");
75     qtest_irq_intercept_in(s, "ioapic");
76     d = ib700_program_and_wait(s);
77     g_assert(!strcmp(qdict_get_str(d, "action"), "pause"));
78     QDECREF(d);
79     d = qmp_get_event("STOP");
80     QDECREF(d);
81     qtest_end();
82 }
83
84 static void ib700_reset(void)
85 {
86     QDict *d;
87     QTestState *s = qtest_start("-watchdog-action reset -device ib700");
88     qtest_irq_intercept_in(s, "ioapic");
89     d = ib700_program_and_wait(s);
90     g_assert(!strcmp(qdict_get_str(d, "action"), "reset"));
91     QDECREF(d);
92     d = qmp_get_event("RESET");
93     QDECREF(d);
94     qtest_end();
95 }
96
97 static void ib700_shutdown(void)
98 {
99     QDict *d;
100     QTestState *s = qtest_start("-watchdog-action reset -no-reboot -device ib700");
101     qtest_irq_intercept_in(s, "ioapic");
102     d = ib700_program_and_wait(s);
103     g_assert(!strcmp(qdict_get_str(d, "action"), "reset"));
104     QDECREF(d);
105     d = qmp_get_event("SHUTDOWN");
106     QDECREF(d);
107     qtest_end();
108 }
109
110 static void ib700_none(void)
111 {
112     QDict *d;
113     QTestState *s = qtest_start("-watchdog-action none -device ib700");
114     qtest_irq_intercept_in(s, "ioapic");
115     d = ib700_program_and_wait(s);
116     g_assert(!strcmp(qdict_get_str(d, "action"), "none"));
117     QDECREF(d);
118     qtest_end();
119 }
120
121 int main(int argc, char **argv)
122 {
123     int ret;
124
125     g_test_init(&argc, &argv, NULL);
126     qtest_add_func("/wdt_ib700/pause", ib700_pause);
127     qtest_add_func("/wdt_ib700/reset", ib700_reset);
128     qtest_add_func("/wdt_ib700/shutdown", ib700_shutdown);
129     qtest_add_func("/wdt_ib700/none", ib700_none);
130
131     ret = g_test_run();
132
133     return ret;
134 }
This page took 0.032003 seconds and 4 git commands to generate.