mirror of https://gitee.com/openkylin/qemu.git
tests: virtio-9p: use the synth backend
The purpose of virtio-9p-test is to test the virtio-9p device, especially the 9p server state machine. We don't really care what fsdev backend we're using. Moreover, if we want to be able to test the flush request or a device reset with in-flights I/O, it is close to impossible to achieve with a physical backend because we cannot ask it reliably to put an I/O on hold at a specific point in time. Fortunately, we can do that with the synthetic backend, which allows to register callbacks on read/write accesses to a specific file. This will be used by a later patch to test the 9P flush request. The walk request test is converted to using the synth backend. Signed-off-by: Greg Kurz <groug@kaod.org> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
60b1fa9de1
commit
2893ddd598
|
@ -19,6 +19,7 @@
|
||||||
#include "qemu/rcu.h"
|
#include "qemu/rcu.h"
|
||||||
#include "qemu/rcu_queue.h"
|
#include "qemu/rcu_queue.h"
|
||||||
#include "qemu/cutils.h"
|
#include "qemu/cutils.h"
|
||||||
|
#include "sysemu/qtest.h"
|
||||||
|
|
||||||
/* Root node for synth file system */
|
/* Root node for synth file system */
|
||||||
static V9fsSynthNode synth_root = {
|
static V9fsSynthNode synth_root = {
|
||||||
|
@ -527,6 +528,21 @@ static int synth_init(FsContext *ctx, Error **errp)
|
||||||
|
|
||||||
/* Mark the subsystem is ready for use */
|
/* Mark the subsystem is ready for use */
|
||||||
synth_fs = 1;
|
synth_fs = 1;
|
||||||
|
|
||||||
|
if (qtest_enabled()) {
|
||||||
|
V9fsSynthNode *node = NULL;
|
||||||
|
int i, ret;
|
||||||
|
|
||||||
|
/* Directory hierarchy for WALK test */
|
||||||
|
for (i = 0; i < P9_MAXWELEM; i++) {
|
||||||
|
char *name = g_strdup_printf(QTEST_V9FS_SYNTH_WALK_FILE, i);
|
||||||
|
|
||||||
|
ret = qemu_v9fs_synth_mkdir(node, 0700, name, &node);
|
||||||
|
assert(!ret);
|
||||||
|
g_free(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,4 +49,8 @@ int qemu_v9fs_synth_add_file(V9fsSynthNode *parent, int mode,
|
||||||
const char *name, v9fs_synth_read read,
|
const char *name, v9fs_synth_read read,
|
||||||
v9fs_synth_write write, void *arg);
|
v9fs_synth_write write, void *arg);
|
||||||
|
|
||||||
|
/* qtest stuff */
|
||||||
|
|
||||||
|
#define QTEST_V9FS_SYNTH_WALK_FILE "WALK%d"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "standard-headers/linux/virtio_ids.h"
|
#include "standard-headers/linux/virtio_ids.h"
|
||||||
#include "standard-headers/linux/virtio_pci.h"
|
#include "standard-headers/linux/virtio_pci.h"
|
||||||
#include "hw/9pfs/9p.h"
|
#include "hw/9pfs/9p.h"
|
||||||
|
#include "hw/9pfs/9p-synth.h"
|
||||||
|
|
||||||
#define QVIRTIO_9P_TIMEOUT_US (10 * 1000 * 1000)
|
#define QVIRTIO_9P_TIMEOUT_US (10 * 1000 * 1000)
|
||||||
|
|
||||||
|
@ -26,23 +27,19 @@ typedef struct {
|
||||||
QVirtioDevice *dev;
|
QVirtioDevice *dev;
|
||||||
QOSState *qs;
|
QOSState *qs;
|
||||||
QVirtQueue *vq;
|
QVirtQueue *vq;
|
||||||
char *test_share;
|
|
||||||
} QVirtIO9P;
|
} QVirtIO9P;
|
||||||
|
|
||||||
static QVirtIO9P *qvirtio_9p_start(const char *driver)
|
static QVirtIO9P *qvirtio_9p_start(const char *driver)
|
||||||
{
|
{
|
||||||
const char *arch = qtest_get_arch();
|
const char *arch = qtest_get_arch();
|
||||||
const char *cmd = "-fsdev local,id=fsdev0,security_model=none,path=%s "
|
const char *cmd = "-fsdev synth,id=fsdev0 "
|
||||||
"-device %s,fsdev=fsdev0,mount_tag=%s";
|
"-device %s,fsdev=fsdev0,mount_tag=%s";
|
||||||
QVirtIO9P *v9p = g_new0(QVirtIO9P, 1);
|
QVirtIO9P *v9p = g_new0(QVirtIO9P, 1);
|
||||||
|
|
||||||
v9p->test_share = g_strdup("/tmp/qtest.XXXXXX");
|
|
||||||
g_assert_nonnull(mkdtemp(v9p->test_share));
|
|
||||||
|
|
||||||
if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
|
if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
|
||||||
v9p->qs = qtest_pc_boot(cmd, v9p->test_share, driver, mount_tag);
|
v9p->qs = qtest_pc_boot(cmd, driver, mount_tag);
|
||||||
} else if (strcmp(arch, "ppc64") == 0) {
|
} else if (strcmp(arch, "ppc64") == 0) {
|
||||||
v9p->qs = qtest_spapr_boot(cmd, v9p->test_share, driver, mount_tag);
|
v9p->qs = qtest_spapr_boot(cmd, driver, mount_tag);
|
||||||
} else {
|
} else {
|
||||||
g_printerr("virtio-9p tests are only available on x86 or ppc64\n");
|
g_printerr("virtio-9p tests are only available on x86 or ppc64\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
@ -54,8 +51,6 @@ static QVirtIO9P *qvirtio_9p_start(const char *driver)
|
||||||
static void qvirtio_9p_stop(QVirtIO9P *v9p)
|
static void qvirtio_9p_stop(QVirtIO9P *v9p)
|
||||||
{
|
{
|
||||||
qtest_shutdown(v9p->qs);
|
qtest_shutdown(v9p->qs);
|
||||||
rmdir(v9p->test_share);
|
|
||||||
g_free(v9p->test_share);
|
|
||||||
g_free(v9p);
|
g_free(v9p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,17 +417,14 @@ static void fs_attach(QVirtIO9P *v9p)
|
||||||
|
|
||||||
static void fs_walk(QVirtIO9P *v9p)
|
static void fs_walk(QVirtIO9P *v9p)
|
||||||
{
|
{
|
||||||
char *wnames[P9_MAXWELEM], *paths[P9_MAXWELEM];
|
char *wnames[P9_MAXWELEM];
|
||||||
char *last_path = v9p->test_share;
|
|
||||||
uint16_t nwqid;
|
uint16_t nwqid;
|
||||||
v9fs_qid *wqid;
|
v9fs_qid *wqid;
|
||||||
int i;
|
int i;
|
||||||
P9Req *req;
|
P9Req *req;
|
||||||
|
|
||||||
for (i = 0; i < P9_MAXWELEM; i++) {
|
for (i = 0; i < P9_MAXWELEM; i++) {
|
||||||
wnames[i] = g_strdup_printf("%s%d", __func__, i);
|
wnames[i] = g_strdup_printf(QTEST_V9FS_SYNTH_WALK_FILE, i);
|
||||||
last_path = paths[i] = g_strdup_printf("%s/%s", last_path, wnames[i]);
|
|
||||||
g_assert(!mkdir(paths[i], 0700));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fs_attach(v9p);
|
fs_attach(v9p);
|
||||||
|
@ -443,8 +435,6 @@ static void fs_walk(QVirtIO9P *v9p)
|
||||||
g_assert_cmpint(nwqid, ==, P9_MAXWELEM);
|
g_assert_cmpint(nwqid, ==, P9_MAXWELEM);
|
||||||
|
|
||||||
for (i = 0; i < P9_MAXWELEM; i++) {
|
for (i = 0; i < P9_MAXWELEM; i++) {
|
||||||
rmdir(paths[P9_MAXWELEM - i - 1]);
|
|
||||||
g_free(paths[P9_MAXWELEM - i - 1]);
|
|
||||||
g_free(wnames[i]);
|
g_free(wnames[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue