target/arm: Reset btype for direct branches
[qemu/ar7.git] / tests / nvme-test.c
blob2700ba838aaa3f75bb90e8529a65f481355f38da
1 /*
2 * QTest testcase for NVMe
4 * Copyright (c) 2014 SUSE LINUX Products GmbH
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 */
10 #include "qemu/osdep.h"
11 #include "qemu/units.h"
12 #include "libqtest.h"
13 #include "libqos/libqos-pc.h"
15 static QOSState *qnvme_start(const char *extra_opts)
17 QOSState *qs;
18 const char *arch = qtest_get_arch();
19 const char *cmd = "-drive id=drv0,if=none,file=null-co://,format=raw "
20 "-device nvme,addr=0x4.0,serial=foo,drive=drv0 %s";
22 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
23 qs = qtest_pc_boot(cmd, extra_opts ? : "");
24 global_qtest = qs->qts;
25 return qs;
28 g_printerr("nvme tests are only available on x86\n");
29 exit(EXIT_FAILURE);
32 static void qnvme_stop(QOSState *qs)
34 qtest_shutdown(qs);
37 static void nop(void)
39 QOSState *qs;
41 qs = qnvme_start(NULL);
42 qnvme_stop(qs);
45 static void nvmetest_cmb_test(void)
47 const int cmb_bar_size = 2 * MiB;
48 QOSState *qs;
49 QPCIDevice *pdev;
50 QPCIBar bar;
52 qs = qnvme_start("-global nvme.cmb_size_mb=2");
53 pdev = qpci_device_find(qs->pcibus, QPCI_DEVFN(4,0));
54 g_assert(pdev != NULL);
56 qpci_device_enable(pdev);
57 bar = qpci_iomap(pdev, 2, NULL);
59 qpci_io_writel(pdev, bar, 0, 0xccbbaa99);
60 g_assert_cmpint(qpci_io_readb(pdev, bar, 0), ==, 0x99);
61 g_assert_cmpint(qpci_io_readw(pdev, bar, 0), ==, 0xaa99);
63 /* Test partially out-of-bounds accesses. */
64 qpci_io_writel(pdev, bar, cmb_bar_size - 1, 0x44332211);
65 g_assert_cmpint(qpci_io_readb(pdev, bar, cmb_bar_size - 1), ==, 0x11);
66 g_assert_cmpint(qpci_io_readw(pdev, bar, cmb_bar_size - 1), !=, 0x2211);
67 g_assert_cmpint(qpci_io_readl(pdev, bar, cmb_bar_size - 1), !=, 0x44332211);
68 g_free(pdev);
70 qnvme_stop(qs);
73 int main(int argc, char **argv)
75 g_test_init(&argc, &argv, NULL);
76 qtest_add_func("/nvme/nop", nop);
77 qtest_add_func("/nvme/cmb_test", nvmetest_cmb_test);
79 return g_test_run();