]> git.proxmox.com Git - mirror_qemu.git/blame - tests/q35-test.c
tests/q35-test: push down qtest_start / qtest_end to test case(s)
[mirror_qemu.git] / tests / q35-test.c
CommitLineData
66e2ec24
GH
1/*
2 * QTest testcase for Q35 northbridge
3 *
4 * Copyright (c) 2015 Red Hat, Inc.
5 *
6 * Author: Gerd Hoffmann <kraxel@redhat.com>
7 *
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.
10 */
11
681c28a3 12#include "qemu/osdep.h"
66e2ec24
GH
13#include "libqtest.h"
14#include "libqos/pci.h"
15#include "libqos/pci-pc.h"
66e2ec24
GH
16#include "hw/pci-host/q35.h"
17
18static void smram_set_bit(QPCIDevice *pcidev, uint8_t mask, bool enabled)
19{
20 uint8_t smram;
21
22 smram = qpci_config_readb(pcidev, MCH_HOST_BRIDGE_SMRAM);
23 if (enabled) {
24 smram |= mask;
25 } else {
26 smram &= ~mask;
27 }
28 qpci_config_writeb(pcidev, MCH_HOST_BRIDGE_SMRAM, smram);
29}
30
31static bool smram_test_bit(QPCIDevice *pcidev, uint8_t mask)
32{
33 uint8_t smram;
34
35 smram = qpci_config_readb(pcidev, MCH_HOST_BRIDGE_SMRAM);
36 return smram & mask;
37}
38
39static void test_smram_lock(void)
40{
41 QPCIBus *pcibus;
42 QPCIDevice *pcidev;
43 QDict *response;
44
8bbf4aa9
LE
45 qtest_start("-M q35");
46
2ecd7e2f 47 pcibus = qpci_init_pc(NULL);
66e2ec24
GH
48 g_assert(pcibus != NULL);
49
50 pcidev = qpci_device_find(pcibus, 0);
51 g_assert(pcidev != NULL);
52
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);
58
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);
64
65 /* reset */
66 response = qmp("{'execute': 'system_reset', 'arguments': {} }");
67 g_assert(response);
68 g_assert(!qdict_haskey(response, "error"));
69 QDECREF(response);
70
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);
fb6faea8
MAL
76
77 g_free(pcidev);
78 qpci_free_pc(pcibus);
8bbf4aa9
LE
79
80 qtest_end();
66e2ec24
GH
81}
82
83int main(int argc, char **argv)
84{
66e2ec24
GH
85 g_test_init(&argc, &argv, NULL);
86
87 qtest_add_func("/q35/smram/lock", test_smram_lock);
88
8bbf4aa9 89 return g_test_run();
66e2ec24 90}