virtio-ccw: support ring size changes
[qemu.git] / tests / q35-test.c
blob812abe54806ecac2c97b50f69a93e9adca060539
1 /*
2 * QTest testcase for Q35 northbridge
4 * Copyright (c) 2015 Red Hat, Inc.
6 * Author: Gerd Hoffmann <kraxel@redhat.com>
8 * This work is licensed under the terms of the GNU GPL, version 2 or later.
9 * See the COPYING file in the top-level directory.
12 #include <glib.h>
13 #include <string.h>
14 #include "libqtest.h"
15 #include "libqos/pci.h"
16 #include "libqos/pci-pc.h"
17 #include "qemu/osdep.h"
18 #include "hw/pci-host/q35.h"
20 static void smram_set_bit(QPCIDevice *pcidev, uint8_t mask, bool enabled)
22 uint8_t smram;
24 smram = qpci_config_readb(pcidev, MCH_HOST_BRIDGE_SMRAM);
25 if (enabled) {
26 smram |= mask;
27 } else {
28 smram &= ~mask;
30 qpci_config_writeb(pcidev, MCH_HOST_BRIDGE_SMRAM, smram);
33 static bool smram_test_bit(QPCIDevice *pcidev, uint8_t mask)
35 uint8_t smram;
37 smram = qpci_config_readb(pcidev, MCH_HOST_BRIDGE_SMRAM);
38 return smram & mask;
41 static void test_smram_lock(void)
43 QPCIBus *pcibus;
44 QPCIDevice *pcidev;
45 QDict *response;
47 pcibus = qpci_init_pc();
48 g_assert(pcibus != NULL);
50 pcidev = qpci_device_find(pcibus, 0);
51 g_assert(pcidev != NULL);
53 /* check open is settable */
54 smram_set_bit(pcidev, MCH_HOST_BRIDGE_SMRAM_D_OPEN, false);
55 g_assert(smram_test_bit(pcidev, MCH_HOST_BRIDGE_SMRAM_D_OPEN) == false);
56 smram_set_bit(pcidev, MCH_HOST_BRIDGE_SMRAM_D_OPEN, true);
57 g_assert(smram_test_bit(pcidev, MCH_HOST_BRIDGE_SMRAM_D_OPEN) == true);
59 /* lock, check open is cleared & not settable */
60 smram_set_bit(pcidev, MCH_HOST_BRIDGE_SMRAM_D_LCK, true);
61 g_assert(smram_test_bit(pcidev, MCH_HOST_BRIDGE_SMRAM_D_OPEN) == false);
62 smram_set_bit(pcidev, MCH_HOST_BRIDGE_SMRAM_D_OPEN, true);
63 g_assert(smram_test_bit(pcidev, MCH_HOST_BRIDGE_SMRAM_D_OPEN) == false);
65 /* reset */
66 response = qmp("{'execute': 'system_reset', 'arguments': {} }");
67 g_assert(response);
68 g_assert(!qdict_haskey(response, "error"));
69 QDECREF(response);
71 /* check open is settable again */
72 smram_set_bit(pcidev, MCH_HOST_BRIDGE_SMRAM_D_OPEN, false);
73 g_assert(smram_test_bit(pcidev, MCH_HOST_BRIDGE_SMRAM_D_OPEN) == false);
74 smram_set_bit(pcidev, MCH_HOST_BRIDGE_SMRAM_D_OPEN, true);
75 g_assert(smram_test_bit(pcidev, MCH_HOST_BRIDGE_SMRAM_D_OPEN) == true);
78 int main(int argc, char **argv)
80 int ret;
82 g_test_init(&argc, &argv, NULL);
84 qtest_add_func("/q35/smram/lock", test_smram_lock);
86 qtest_start("-M q35");
87 ret = g_test_run();
88 qtest_end();
90 return ret;