]> git.proxmox.com Git - mirror_qemu.git/blame - tests/wdt_ib700-test.c
tests/boot-sector: Drop dependence on global_qtest
[mirror_qemu.git] / tests / wdt_ib700-test.c
CommitLineData
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"
452fcdbc 12#include "qapi/qmp/qdict.h"
e0cf11f3 13#include "qemu/timer.h"
f52b7687
PB
14
15static void qmp_check_no_event(void)
16{
17 QDict *resp = qmp("{'execute':'query-status'}");
18 g_assert(qdict_haskey(resp, "return"));
19 QDECREF(resp);
20}
21
f52b7687
PB
22static QDict *ib700_program_and_wait(QTestState *s)
23{
2c58c27b
MA
24 QDict *event, *data;
25
13566fe3 26 clock_step(NANOSECONDS_PER_SECOND * 40);
f52b7687
PB
27 qmp_check_no_event();
28
29 /* 2 second limit */
30 outb(0x443, 14);
31
32 /* Ping */
13566fe3 33 clock_step(NANOSECONDS_PER_SECOND);
f52b7687
PB
34 qmp_check_no_event();
35 outb(0x443, 14);
36
37 /* Disable */
13566fe3 38 clock_step(NANOSECONDS_PER_SECOND);
f52b7687
PB
39 qmp_check_no_event();
40 outb(0x441, 1);
13566fe3 41 clock_step(3 * NANOSECONDS_PER_SECOND);
f52b7687
PB
42 qmp_check_no_event();
43
44 /* Enable and let it fire */
45 outb(0x443, 13);
13566fe3 46 clock_step(3 * NANOSECONDS_PER_SECOND);
f52b7687 47 qmp_check_no_event();
13566fe3 48 clock_step(2 * NANOSECONDS_PER_SECOND);
2c58c27b
MA
49 event = qmp_eventwait_ref("WATCHDOG");
50 data = qdict_get_qdict(event, "data");
51 QINCREF(data);
52 QDECREF(event);
53 return data;
f52b7687
PB
54}
55
56
57static void ib700_pause(void)
58{
59 QDict *d;
60 QTestState *s = qtest_start("-watchdog-action pause -device ib700");
61 qtest_irq_intercept_in(s, "ioapic");
62 d = ib700_program_and_wait(s);
63 g_assert(!strcmp(qdict_get_str(d, "action"), "pause"));
64 QDECREF(d);
2c58c27b 65 qmp_eventwait("STOP");
f52b7687
PB
66 qtest_end();
67}
68
69static void ib700_reset(void)
70{
71 QDict *d;
72 QTestState *s = qtest_start("-watchdog-action reset -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"), "reset"));
76 QDECREF(d);
2c58c27b 77 qmp_eventwait("RESET");
f52b7687
PB
78 qtest_end();
79}
80
81static void ib700_shutdown(void)
82{
83 QDict *d;
84 QTestState *s = qtest_start("-watchdog-action reset -no-reboot -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);
2c58c27b 89 qmp_eventwait("SHUTDOWN");
f52b7687
PB
90 qtest_end();
91}
92
93static void ib700_none(void)
94{
95 QDict *d;
96 QTestState *s = qtest_start("-watchdog-action none -device ib700");
97 qtest_irq_intercept_in(s, "ioapic");
98 d = ib700_program_and_wait(s);
99 g_assert(!strcmp(qdict_get_str(d, "action"), "none"));
100 QDECREF(d);
101 qtest_end();
102}
103
104int main(int argc, char **argv)
105{
f52b7687
PB
106 g_test_init(&argc, &argv, NULL);
107 qtest_add_func("/wdt_ib700/pause", ib700_pause);
108 qtest_add_func("/wdt_ib700/reset", ib700_reset);
109 qtest_add_func("/wdt_ib700/shutdown", ib700_shutdown);
110 qtest_add_func("/wdt_ib700/none", ib700_none);
111
9be38598 112 return g_test_run();
f52b7687 113}