2 * QTest testcase for VirtIO 9P
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.
10 #include "qemu/osdep.h"
12 #include "qemu-common.h"
13 #include "libqos/libqos-pc.h"
14 #include "libqos/libqos-spapr.h"
15 #include "libqos/virtio.h"
16 #include "libqos/virtio-pci.h"
17 #include "standard-headers/linux/virtio_ids.h"
18 #include "standard-headers/linux/virtio_pci.h"
20 static const char mount_tag
[] = "qtest";
21 static char *test_share
;
24 static QOSState
*qvirtio_9p_start(void)
26 const char *arch
= qtest_get_arch();
27 const char *cmd
= "-fsdev local,id=fsdev0,security_model=none,path=%s "
28 "-device virtio-9p-pci,fsdev=fsdev0,mount_tag=%s";
30 test_share
= g_strdup("/tmp/qtest.XXXXXX");
31 g_assert_nonnull(mkdtemp(test_share
));
33 if (strcmp(arch
, "i386") == 0 || strcmp(arch
, "x86_64") == 0) {
34 return qtest_pc_boot(cmd
, test_share
, mount_tag
);
36 if (strcmp(arch
, "ppc64") == 0) {
37 return qtest_spapr_boot(cmd
, test_share
, mount_tag
);
40 g_printerr("virtio-9p tests are only available on x86 or ppc64\n");
44 static void qvirtio_9p_stop(QOSState
*qs
)
51 static void pci_nop(void)
55 qs
= qvirtio_9p_start();
65 static QVirtIO9P
*qvirtio_9p_pci_init(QOSState
*qs
)
68 QVirtioPCIDevice
*dev
;
70 v9p
= g_new0(QVirtIO9P
, 1);
73 dev
= qvirtio_pci_device_find(v9p
->qs
->pcibus
, VIRTIO_ID_9P
);
74 g_assert_nonnull(dev
);
75 g_assert_cmphex(dev
->vdev
.device_type
, ==, VIRTIO_ID_9P
);
76 v9p
->dev
= (QVirtioDevice
*) dev
;
78 qvirtio_pci_device_enable(dev
);
79 qvirtio_reset(v9p
->dev
);
80 qvirtio_set_acknowledge(v9p
->dev
);
81 qvirtio_set_driver(v9p
->dev
);
83 v9p
->vq
= qvirtqueue_setup(v9p
->dev
, v9p
->qs
->alloc
, 0);
87 static void qvirtio_9p_pci_free(QVirtIO9P
*v9p
)
89 qvirtqueue_cleanup(v9p
->dev
->bus
, v9p
->vq
, v9p
->qs
->alloc
);
90 qvirtio_pci_device_disable(container_of(v9p
->dev
, QVirtioPCIDevice
, vdev
));
95 static void pci_basic_config(void)
103 qs
= qvirtio_9p_start();
104 v9p
= qvirtio_9p_pci_init(qs
);
106 tag_len
= qvirtio_config_readw(v9p
->dev
, 0);
107 g_assert_cmpint(tag_len
, ==, strlen(mount_tag
));
109 tag
= g_malloc(tag_len
);
110 for (i
= 0; i
< tag_len
; i
++) {
111 tag
[i
] = qvirtio_config_readb(v9p
->dev
, i
+ 2);
113 g_assert_cmpmem(tag
, tag_len
, mount_tag
, tag_len
);
116 qvirtio_9p_pci_free(v9p
);
120 int main(int argc
, char **argv
)
122 g_test_init(&argc
, &argv
, NULL
);
123 qtest_add_func("/virtio/9p/pci/nop", pci_nop
);
124 qtest_add_func("/virtio/9p/pci/basic/configuration", pci_basic_config
);