pseries: fix TCG migration
[qemu/ar7.git] / tests / megasas-test.c
blobce960e7f8192720db58489088e9e60ed164bd0ae
1 /*
2 * QTest testcase for LSI MegaRAID
4 * Copyright (c) 2017 Red Hat Inc.
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 "libqtest.h"
12 #include "qemu/bswap.h"
13 #include "libqos/libqos-pc.h"
14 #include "libqos/libqos-spapr.h"
16 static QOSState *qmegasas_start(const char *extra_opts)
18 const char *arch = qtest_get_arch();
19 const char *cmd = "-drive id=hd0,if=none,file=null-co://,format=raw "
20 "-device megasas,id=scsi0,addr=04.0 "
21 "-device scsi-hd,bus=scsi0.0,drive=hd0 %s";
23 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
24 return qtest_pc_boot(cmd, extra_opts ? : "");
27 g_printerr("virtio-scsi tests are only available on x86 or ppc64\n");
28 exit(EXIT_FAILURE);
31 static void qmegasas_stop(QOSState *qs)
33 qtest_shutdown(qs);
36 /* Tests only initialization so far. TODO: Replace with functional tests */
37 static void pci_nop(void)
39 QOSState *qs;
41 qs = qmegasas_start(NULL);
42 qmegasas_stop(qs);
45 /* This used to cause a NULL pointer dereference. */
46 static void megasas_pd_get_info_fuzz(void)
48 QPCIDevice *dev;
49 QOSState *qs;
50 QPCIBar bar;
51 uint32_t context[256];
52 uint64_t context_pa;
53 int i;
55 qs = qmegasas_start(NULL);
56 dev = qpci_device_find(qs->pcibus, QPCI_DEVFN(4,0));
57 g_assert(dev != NULL);
59 qpci_device_enable(dev);
60 bar = qpci_iomap(dev, 0, NULL);
62 memset(context, 0, sizeof(context));
63 context[0] = cpu_to_le32(0x05050505);
64 context[1] = cpu_to_le32(0x01010101);
65 for (i = 2; i < ARRAY_SIZE(context); i++) {
66 context[i] = cpu_to_le32(0x41414141);
68 context[6] = cpu_to_le32(0x02020000);
69 context[7] = cpu_to_le32(0);
71 context_pa = qmalloc(qs, sizeof(context));
72 memwrite(context_pa, context, sizeof(context));
73 qpci_io_writel(dev, bar, 0x40, context_pa);
75 g_free(dev);
76 qmegasas_stop(qs);
79 int main(int argc, char **argv)
81 g_test_init(&argc, &argv, NULL);
82 qtest_add_func("/megasas/pci/nop", pci_nop);
83 qtest_add_func("/megasas/dcmd/pd-get-info/fuzz", megasas_pd_get_info_fuzz);
85 return g_test_run();