KVM: remove support for kernel-irqchip=off
[qemu.git] / tests / qtest / pvpanic-pci-test.c
blob2c05b376ba728382bccbb6f259ad95c93e1989a0
1 /*
2 * QTest testcase for PV Panic PCI device
4 * Copyright (C) 2020 Oracle
6 * Authors:
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"
15 #include "libqtest.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)
23 uint8_t val;
24 QDict *response, *data;
25 QTestState *qts;
26 QPCIBus *pcibus;
27 QPCIDevice *dev;
28 QPCIBar bar;
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);
39 val = 1;
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);
49 g_free(dev);
50 qpci_free_pc(pcibus);
51 qtest_quit(qts);
54 static void test_panic(void)
56 uint8_t val;
57 QDict *response, *data;
58 QTestState *qts;
59 QPCIBus *pcibus;
60 QPCIDevice *dev;
61 QPCIBar bar;
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);
72 val = 1;
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);
82 g_free(dev);
83 qpci_free_pc(pcibus);
84 qtest_quit(qts);
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);
93 return g_test_run();