xref: /openbmc/qemu/tests/qtest/pvpanic-test.c (revision ab1b2ba9)
1 /*
2  * QTest testcase for PV Panic
3  *
4  * Copyright (c) 2014 SUSE LINUX Products GmbH
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 "qemu/osdep.h"
11 #include "libqtest.h"
12 #include "qapi/qmp/qdict.h"
13 
14 static void test_panic_nopause(void)
15 {
16     uint8_t val;
17     QDict *response, *data;
18     QTestState *qts;
19 
20     qts = qtest_init("-device pvpanic -action panic=none");
21 
22     val = qtest_inb(qts, 0x505);
23     g_assert_cmpuint(val, ==, 3);
24 
25     qtest_outb(qts, 0x505, 0x1);
26 
27     response = qtest_qmp_eventwait_ref(qts, "GUEST_PANICKED");
28     g_assert(qdict_haskey(response, "data"));
29     data = qdict_get_qdict(response, "data");
30     g_assert(qdict_haskey(data, "action"));
31     g_assert_cmpstr(qdict_get_str(data, "action"), ==, "run");
32     qobject_unref(response);
33 
34     qtest_quit(qts);
35 }
36 
37 static void test_panic(void)
38 {
39     uint8_t val;
40     QDict *response, *data;
41     QTestState *qts;
42 
43     qts = qtest_init("-device pvpanic -action panic=pause");
44 
45     val = qtest_inb(qts, 0x505);
46     g_assert_cmpuint(val, ==, 3);
47 
48     qtest_outb(qts, 0x505, 0x1);
49 
50     response = qtest_qmp_eventwait_ref(qts, "GUEST_PANICKED");
51     g_assert(qdict_haskey(response, "data"));
52     data = qdict_get_qdict(response, "data");
53     g_assert(qdict_haskey(data, "action"));
54     g_assert_cmpstr(qdict_get_str(data, "action"), ==, "pause");
55     qobject_unref(response);
56 
57     qtest_quit(qts);
58 }
59 
60 int main(int argc, char **argv)
61 {
62     int ret;
63 
64     g_test_init(&argc, &argv, NULL);
65     qtest_add_func("/pvpanic/panic", test_panic);
66     qtest_add_func("/pvpanic/panic-nopause", test_panic_nopause);
67 
68     ret = g_test_run();
69 
70     return ret;
71 }
72