2 * QTest testcase for PV Panic
4 * Copyright (c) 2014 SUSE LINUX Products GmbH
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.
10 #include "qemu/osdep.h"
12 #include "qapi/qmp/qdict.h"
13 #include "hw/misc/pvpanic.h"
15 static void test_panic_nopause(void)
18 QDict
*response
, *data
;
21 qts
= qtest_init("-device pvpanic -action panic=none");
23 val
= qtest_inb(qts
, 0x505);
24 g_assert_cmpuint(val
, ==, PVPANIC_EVENTS
);
26 qtest_outb(qts
, 0x505, 0x1);
28 response
= qtest_qmp_eventwait_ref(qts
, "GUEST_PANICKED");
29 g_assert(qdict_haskey(response
, "data"));
30 data
= qdict_get_qdict(response
, "data");
31 g_assert(qdict_haskey(data
, "action"));
32 g_assert_cmpstr(qdict_get_str(data
, "action"), ==, "run");
33 qobject_unref(response
);
38 static void test_panic(void)
41 QDict
*response
, *data
;
44 qts
= qtest_init("-device pvpanic -action panic=pause");
46 val
= qtest_inb(qts
, 0x505);
47 g_assert_cmpuint(val
, ==, PVPANIC_EVENTS
);
49 qtest_outb(qts
, 0x505, 0x1);
51 response
= qtest_qmp_eventwait_ref(qts
, "GUEST_PANICKED");
52 g_assert(qdict_haskey(response
, "data"));
53 data
= qdict_get_qdict(response
, "data");
54 g_assert(qdict_haskey(data
, "action"));
55 g_assert_cmpstr(qdict_get_str(data
, "action"), ==, "pause");
56 qobject_unref(response
);
61 static void test_pvshutdown(void)
64 QDict
*response
, *data
;
67 qts
= qtest_init("-device pvpanic");
69 val
= qtest_inb(qts
, 0x505);
70 g_assert_cmpuint(val
, ==, PVPANIC_EVENTS
);
72 qtest_outb(qts
, 0x505, PVPANIC_SHUTDOWN
);
74 response
= qtest_qmp_eventwait_ref(qts
, "GUEST_PVSHUTDOWN");
75 qobject_unref(response
);
77 response
= qtest_qmp_eventwait_ref(qts
, "SHUTDOWN");
78 g_assert(qdict_haskey(response
, "data"));
79 data
= qdict_get_qdict(response
, "data");
80 g_assert(qdict_haskey(data
, "guest"));
81 g_assert(qdict_get_bool(data
, "guest"));
82 g_assert(qdict_haskey(data
, "reason"));
83 g_assert_cmpstr(qdict_get_str(data
, "reason"), ==, "guest-shutdown");
84 qobject_unref(response
);
89 int main(int argc
, char **argv
)
91 g_test_init(&argc
, &argv
, NULL
);
92 qtest_add_func("/pvpanic/panic", test_panic
);
93 qtest_add_func("/pvpanic/panic-nopause", test_panic_nopause
);
94 qtest_add_func("/pvpanic/pvshutdown", test_pvshutdown
);