Skip to content

Commit

Permalink
tests: virtio-9p: add LOPEN operation test
Browse files Browse the repository at this point in the history
Trivial test of a successful open.

Signed-off-by: Greg Kurz <groug@kaod.org>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
  • Loading branch information
gkurz committed Feb 1, 2018
1 parent 2893ddd commit 82469aa
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
5 changes: 5 additions & 0 deletions hw/9pfs/9p-synth.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,11 @@ static int synth_init(FsContext *ctx, Error **errp)
assert(!ret);
g_free(name);
}

/* File for LOPEN test */
ret = qemu_v9fs_synth_add_file(NULL, 0, QTEST_V9FS_SYNTH_LOPEN_FILE,
NULL, NULL, ctx);
assert(!ret);
}

return 0;
Expand Down
1 change: 1 addition & 0 deletions hw/9pfs/9p-synth.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ int qemu_v9fs_synth_add_file(V9fsSynthNode *parent, int mode,
/* qtest stuff */

#define QTEST_V9FS_SYNTH_WALK_FILE "WALK%d"
#define QTEST_V9FS_SYNTH_LOPEN_FILE "LOPEN"

#endif
47 changes: 47 additions & 0 deletions tests/virtio-9p-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ static const char *rmessage_name(uint8_t id)
id == P9_RVERSION ? "RVERSION" :
id == P9_RATTACH ? "RATTACH" :
id == P9_RWALK ? "RWALK" :
id == P9_RLOPEN ? "RLOPEN" :
"<unknown>";
}

Expand Down Expand Up @@ -389,6 +390,34 @@ static void v9fs_rwalk(P9Req *req, uint16_t *nwqid, v9fs_qid **wqid)
v9fs_req_free(req);
}

/* size[4] Tlopen tag[2] fid[4] flags[4] */
static P9Req *v9fs_tlopen(QVirtIO9P *v9p, uint32_t fid, uint32_t flags,
uint16_t tag)
{
P9Req *req;

req = v9fs_req_init(v9p, 4 + 4, P9_TLOPEN, tag);
v9fs_uint32_write(req, fid);
v9fs_uint32_write(req, flags);
v9fs_req_send(req);
return req;
}

/* size[4] Rlopen tag[2] qid[13] iounit[4] */
static void v9fs_rlopen(P9Req *req, v9fs_qid *qid, uint32_t *iounit)
{
v9fs_req_recv(req, P9_RLOPEN);
if (qid) {
v9fs_memread(req, qid, 13);
} else {
v9fs_memskip(req, 13);
}
if (iounit) {
v9fs_uint32_read(req, iounit);
}
v9fs_req_free(req);
}

static void fs_version(QVirtIO9P *v9p)
{
const char *version = "9P2000.L";
Expand Down Expand Up @@ -478,6 +507,23 @@ static void fs_walk_dotdot(QVirtIO9P *v9p)
g_free(wnames[0]);
}

static void fs_lopen(QVirtIO9P *v9p)
{
char *const wnames[] = { g_strdup(QTEST_V9FS_SYNTH_LOPEN_FILE) };
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);

g_free(wnames[0]);
}

typedef void (*v9fs_test_fn)(QVirtIO9P *v9p);

static void v9fs_run_pci_test(gconstpointer data)
Expand Down Expand Up @@ -507,6 +553,7 @@ int main(int argc, char **argv)
v9fs_qtest_pci_add("/virtio/9p/pci/fs/walk/no_slash", fs_walk_no_slash);
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);

return g_test_run();
}

0 comments on commit 82469aa

Please sign in to comment.