[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 5/7] tests: virtio-9p: add WRITE operation test
From: |
Greg Kurz |
Subject: |
[Qemu-devel] [PATCH 5/7] tests: virtio-9p: add WRITE operation test |
Date: |
Wed, 24 Jan 2018 00:39:23 +0100 |
User-agent: |
StGit/0.17.1-46-g6855-dirty |
Trivial test of a successful write.
Signed-off-by: Greg Kurz <address@hidden>
---
hw/9pfs/9p-synth.c | 11 +++++++++
hw/9pfs/9p-synth.h | 1 +
tests/virtio-9p-test.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 71 insertions(+)
diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c
index f17b74f44461..f2d59a90a670 100644
--- a/hw/9pfs/9p-synth.c
+++ b/hw/9pfs/9p-synth.c
@@ -515,6 +515,12 @@ static int synth_unlinkat(FsContext *ctx, V9fsPath *dir,
return -1;
}
+static ssize_t v9fs_synth_qtest_write(void *buf, int len, off_t offset,
+ void *arg)
+{
+ return len;
+}
+
static int synth_init(FsContext *ctx, Error **errp)
{
QLIST_INIT(&synth_root.child);
@@ -546,6 +552,11 @@ static int synth_init(FsContext *ctx, Error **errp)
ret = qemu_v9fs_synth_add_file(NULL, 0, QTEST_V9FS_SYNTH_LOPEN_FILE,
NULL, NULL, ctx);
assert(!ret);
+
+ /* File for WRITE test */
+ ret = qemu_v9fs_synth_add_file(NULL, 0, QTEST_V9FS_SYNTH_WRITE_FILE,
+ NULL, v9fs_synth_qtest_write, ctx);
+ assert(!ret);
}
return 0;
diff --git a/hw/9pfs/9p-synth.h b/hw/9pfs/9p-synth.h
index 2a8d6fd00d69..a74032d7bd9a 100644
--- a/hw/9pfs/9p-synth.h
+++ b/hw/9pfs/9p-synth.h
@@ -53,5 +53,6 @@ int qemu_v9fs_synth_add_file(V9fsSynthNode *parent, int mode,
#define QTEST_V9FS_SYNTH_WALK_FILE "WALK%d"
#define QTEST_V9FS_SYNTH_LOPEN_FILE "LOPEN"
+#define QTEST_V9FS_SYNTH_WRITE_FILE "WRITE"
#endif
diff --git a/tests/virtio-9p-test.c b/tests/virtio-9p-test.c
index 6ba782e24f3a..5871a16dac73 100644
--- a/tests/virtio-9p-test.c
+++ b/tests/virtio-9p-test.c
@@ -150,6 +150,13 @@ static void v9fs_uint32_write(P9Req *req, uint32_t val)
v9fs_memwrite(req, &le_val, 4);
}
+static void v9fs_uint64_write(P9Req *req, uint64_t val)
+{
+ uint64_t le_val = cpu_to_le64(val);
+
+ v9fs_memwrite(req, &le_val, 8);
+}
+
static void v9fs_uint32_read(P9Req *req, uint32_t *val)
{
v9fs_memread(req, val, 4);
@@ -239,6 +246,7 @@ static const char *rmessage_name(uint8_t id)
id == P9_RATTACH ? "RATTACH" :
id == P9_RWALK ? "RWALK" :
id == P9_RLOPEN ? "RLOPEN" :
+ id == P9_RWRITE ? "RWRITE" :
"<unknown>";
}
@@ -418,6 +426,31 @@ static void v9fs_rlopen(P9Req *req, v9fs_qid *qid,
uint32_t *iounit)
v9fs_req_free(req);
}
+/* size[4] Twrite tag[2] fid[4] offset[8] count[4] data[count] */
+static P9Req *v9fs_twrite(QVirtIO9P *v9p, uint32_t fid, uint64_t offset,
+ uint32_t count, const void *data, uint16_t tag)
+{
+ P9Req *req;
+
+ req = v9fs_req_init(v9p, 4 + 8 + 4 + count, P9_TWRITE, tag);
+ v9fs_uint32_write(req, fid);
+ v9fs_uint64_write(req, offset);
+ v9fs_uint32_write(req, count);
+ v9fs_memwrite(req, data, count);
+ v9fs_req_send(req);
+ return req;
+}
+
+/* size[4] Rwrite tag[2] count[4] */
+static void v9fs_rwrite(P9Req *req, uint32_t *count)
+{
+ v9fs_req_recv(req, P9_RWRITE);
+ if (count) {
+ v9fs_uint32_read(req, count);
+ }
+ v9fs_req_free(req);
+}
+
static void fs_version(QVirtIO9P *v9p)
{
const char *version = "9P2000.L";
@@ -524,6 +557,31 @@ static void fs_lopen(QVirtIO9P *v9p)
g_free(wnames[0]);
}
+static void fs_write(QVirtIO9P *v9p)
+{
+ static const uint32_t write_count = P9_MAX_SIZE / 2;
+ char *const wnames[] = { g_strdup(QTEST_V9FS_SYNTH_WRITE_FILE) };
+ char *buf = g_malloc(write_count);
+ uint32_t count;
+ P9Req *req;
+
+ fs_attach(v9p);
+ req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0);
+ v9fs_req_wait_for_reply(req);
+ v9fs_rwalk(req, NULL, NULL);
+
+ req = v9fs_tlopen(v9p, 1, O_WRONLY, 0);
+ v9fs_req_wait_for_reply(req);
+ v9fs_rlopen(req, NULL, NULL);
+
+ req = v9fs_twrite(v9p, 1, 0, write_count, buf, 0);
+ v9fs_req_wait_for_reply(req);
+ v9fs_rwrite(req, &count);
+ g_assert_cmpint(count, ==, write_count);
+
+ g_free(wnames[0]);
+}
+
typedef void (*v9fs_test_fn)(QVirtIO9P *v9p);
static void v9fs_run_pci_test(gconstpointer data)
@@ -554,6 +612,7 @@ int main(int argc, char **argv)
v9fs_qtest_pci_add("/virtio/9p/pci/fs/walk/dotdot_from_root",
fs_walk_dotdot);
v9fs_qtest_pci_add("/virtio/9p/pci/fs/lopen/basic", fs_lopen);
+ v9fs_qtest_pci_add("/virtio/9p/pci/fs/write/basic", fs_write);
return g_test_run();
}
- [Qemu-devel] [PATCH 0/7] tests: virtio-9p: test request cancellation, Greg Kurz, 2018/01/23
- [Qemu-devel] [PATCH 1/7] tests: virtio-9p: move request tag to the test functions, Greg Kurz, 2018/01/23
- [Qemu-devel] [PATCH 2/7] tests: virtio-9p: wait for completion in the test code, Greg Kurz, 2018/01/23
- [Qemu-devel] [PATCH 3/7] tests: virtio-9p: use the synth backend, Greg Kurz, 2018/01/23
- [Qemu-devel] [PATCH 4/7] tests: virtio-9p: add LOPEN operation test, Greg Kurz, 2018/01/23
- [Qemu-devel] [PATCH 5/7] tests: virtio-9p: add WRITE operation test,
Greg Kurz <=
- [Qemu-devel] [PATCH 6/7] libqos/virtio: return length written into used descriptor, Greg Kurz, 2018/01/23
- [Qemu-devel] [PATCH 7/7] tests: virtio-9p: add FLUSH operation test, Greg Kurz, 2018/01/23
- Re: [Qemu-devel] [PATCH 0/7] tests: virtio-9p: test request cancellation, Stefan Hajnoczi, 2018/01/29