2 * QTest testcase for PV Panic PCI device
4 * Copyright (C) 2020 Oracle
7 * Mihai Carabas <mihai.carabas@oracle.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
14 #include "qemu/osdep.h"
16 #include "qapi/qmp/qdict.h"
17 #include "libqos/pci.h"
18 #include "libqos/pci-pc.h"
19 #include "hw/pci/pci_regs.h"
21 static void test_panic_nopause(void)
24 QDict
*response
, *data
;
30 qts
= qtest_init("-device pvpanic-pci,addr=04.0 -action panic=none");
31 pcibus
= qpci_new_pc(qts
, NULL
);
32 dev
= qpci_device_find(pcibus
, QPCI_DEVFN(0x4, 0x0));
33 qpci_device_enable(dev
);
34 bar
= qpci_iomap(dev
, 0, NULL
);
36 qpci_memread(dev
, bar
, 0, &val
, sizeof(val
));
37 g_assert_cmpuint(val
, ==, 3);
40 qpci_memwrite(dev
, bar
, 0, &val
, sizeof(val
));
42 response
= qtest_qmp_eventwait_ref(qts
, "GUEST_PANICKED");
43 g_assert(qdict_haskey(response
, "data"));
44 data
= qdict_get_qdict(response
, "data");
45 g_assert(qdict_haskey(data
, "action"));
46 g_assert_cmpstr(qdict_get_str(data
, "action"), ==, "run");
47 qobject_unref(response
);
54 static void test_panic(void)
57 QDict
*response
, *data
;
63 qts
= qtest_init("-device pvpanic-pci,addr=04.0 -action panic=pause");
64 pcibus
= qpci_new_pc(qts
, NULL
);
65 dev
= qpci_device_find(pcibus
, QPCI_DEVFN(0x4, 0x0));
66 qpci_device_enable(dev
);
67 bar
= qpci_iomap(dev
, 0, NULL
);
69 qpci_memread(dev
, bar
, 0, &val
, sizeof(val
));
70 g_assert_cmpuint(val
, ==, 3);
73 qpci_memwrite(dev
, bar
, 0, &val
, sizeof(val
));
75 response
= qtest_qmp_eventwait_ref(qts
, "GUEST_PANICKED");
76 g_assert(qdict_haskey(response
, "data"));
77 data
= qdict_get_qdict(response
, "data");
78 g_assert(qdict_haskey(data
, "action"));
79 g_assert_cmpstr(qdict_get_str(data
, "action"), ==, "pause");
80 qobject_unref(response
);
87 int main(int argc
, char **argv
)
89 g_test_init(&argc
, &argv
, NULL
);
90 qtest_add_func("/pvpanic-pci/panic", test_panic
);
91 qtest_add_func("/pvpanic-pci/panic-nopause", test_panic_nopause
);