scsi: esp: check TI buffer index before read/write
[qemu/kevin.git] / tests / wdt_ib700-test.c
blobefe3370453996a3bb2e7564fa67fd225064170bc
1 /*
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.
8 */
10 #include "qemu/osdep.h"
11 #include <glib.h>
12 #include "libqtest.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"));
19 QDECREF(resp);
22 static QDict *qmp_get_event(const char *name)
24 QDict *event = qmp("");
25 QDict *data;
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");
31 QINCREF(data);
32 } else {
33 data = NULL;
36 QDECREF(event);
37 return data;
40 static QDict *ib700_program_and_wait(QTestState *s)
42 clock_step(NANOSECONDS_PER_SECOND * 40);
43 qmp_check_no_event();
45 /* 2 second limit */
46 outb(0x443, 14);
48 /* Ping */
49 clock_step(NANOSECONDS_PER_SECOND);
50 qmp_check_no_event();
51 outb(0x443, 14);
53 /* Disable */
54 clock_step(NANOSECONDS_PER_SECOND);
55 qmp_check_no_event();
56 outb(0x441, 1);
57 clock_step(3 * NANOSECONDS_PER_SECOND);
58 qmp_check_no_event();
60 /* Enable and let it fire */
61 outb(0x443, 13);
62 clock_step(3 * NANOSECONDS_PER_SECOND);
63 qmp_check_no_event();
64 clock_step(2 * NANOSECONDS_PER_SECOND);
65 return qmp_get_event("WATCHDOG");
69 static void ib700_pause(void)
71 QDict *d;
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"));
76 QDECREF(d);
77 d = qmp_get_event("STOP");
78 QDECREF(d);
79 qtest_end();
82 static void ib700_reset(void)
84 QDict *d;
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"));
89 QDECREF(d);
90 d = qmp_get_event("RESET");
91 QDECREF(d);
92 qtest_end();
95 static void ib700_shutdown(void)
97 QDict *d;
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"));
102 QDECREF(d);
103 d = qmp_get_event("SHUTDOWN");
104 QDECREF(d);
105 qtest_end();
108 static void ib700_none(void)
110 QDict *d;
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"));
115 QDECREF(d);
116 qtest_end();
119 int main(int argc, char **argv)
121 int ret;
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);
129 ret = g_test_run();
131 return ret;