hw/sd: sd: Bypass the RCA check for CMD13 in SPI mode
[qemu/ar7.git] / tests / qtest / virtio-9p-test.c
blob92a498f249257cb0a69a6b8fe6082a38b3a3ae36
1 /*
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.
8 */
10 #include "qemu/osdep.h"
11 #include "libqtest-single.h"
12 #include "qemu/module.h"
13 #include "hw/9pfs/9p.h"
14 #include "hw/9pfs/9p-synth.h"
15 #include "libqos/virtio-9p.h"
16 #include "libqos/qgraph.h"
18 #define QVIRTIO_9P_TIMEOUT_US (10 * 1000 * 1000)
19 static QGuestAllocator *alloc;
22 * Used to auto generate new fids. Start with arbitrary high value to avoid
23 * collision with hard coded fids in basic test code.
25 static uint32_t fid_generator = 1000;
27 static uint32_t genfid(void)
29 return fid_generator++;
32 /**
33 * Splits the @a in string by @a delim into individual (non empty) strings
34 * and outputs them to @a out. The output array @a out is NULL terminated.
36 * Output array @a out must be freed by calling split_free().
38 * @returns number of individual elements in output array @a out (without the
39 * final NULL terminating element)
41 static int split(const char *in, const char *delim, char ***out)
43 int n = 0, i = 0;
44 char *tmp, *p;
46 tmp = g_strdup(in);
47 for (p = strtok(tmp, delim); p != NULL; p = strtok(NULL, delim)) {
48 if (strlen(p) > 0) {
49 ++n;
52 g_free(tmp);
54 *out = g_new0(char *, n + 1); /* last element NULL delimiter */
56 tmp = g_strdup(in);
57 for (p = strtok(tmp, delim); p != NULL; p = strtok(NULL, delim)) {
58 if (strlen(p) > 0) {
59 (*out)[i++] = g_strdup(p);
62 g_free(tmp);
64 return n;
67 static void split_free(char ***out)
69 int i;
70 for (i = 0; (*out)[i]; ++i) {
71 g_free((*out)[i]);
73 g_free(*out);
74 *out = NULL;
77 static void pci_config(void *obj, void *data, QGuestAllocator *t_alloc)
79 QVirtio9P *v9p = obj;
80 alloc = t_alloc;
81 size_t tag_len = qvirtio_config_readw(v9p->vdev, 0);
82 char *tag;
83 int i;
85 g_assert_cmpint(tag_len, ==, strlen(MOUNT_TAG));
87 tag = g_malloc(tag_len);
88 for (i = 0; i < tag_len; i++) {
89 tag[i] = qvirtio_config_readb(v9p->vdev, i + 2);
91 g_assert_cmpmem(tag, tag_len, MOUNT_TAG, tag_len);
92 g_free(tag);
95 #define P9_MAX_SIZE 4096 /* Max size of a T-message or R-message */
97 typedef struct {
98 QTestState *qts;
99 QVirtio9P *v9p;
100 uint16_t tag;
101 uint64_t t_msg;
102 uint32_t t_size;
103 uint64_t r_msg;
104 /* No r_size, it is hardcoded to P9_MAX_SIZE */
105 size_t t_off;
106 size_t r_off;
107 uint32_t free_head;
108 } P9Req;
110 static void v9fs_memwrite(P9Req *req, const void *addr, size_t len)
112 qtest_memwrite(req->qts, req->t_msg + req->t_off, addr, len);
113 req->t_off += len;
116 static void v9fs_memskip(P9Req *req, size_t len)
118 req->r_off += len;
121 static void v9fs_memread(P9Req *req, void *addr, size_t len)
123 qtest_memread(req->qts, req->r_msg + req->r_off, addr, len);
124 req->r_off += len;
127 static void v9fs_uint8_read(P9Req *req, uint8_t *val)
129 v9fs_memread(req, val, 1);
132 static void v9fs_uint16_write(P9Req *req, uint16_t val)
134 uint16_t le_val = cpu_to_le16(val);
136 v9fs_memwrite(req, &le_val, 2);
139 static void v9fs_uint16_read(P9Req *req, uint16_t *val)
141 v9fs_memread(req, val, 2);
142 le16_to_cpus(val);
145 static void v9fs_uint32_write(P9Req *req, uint32_t val)
147 uint32_t le_val = cpu_to_le32(val);
149 v9fs_memwrite(req, &le_val, 4);
152 static void v9fs_uint64_write(P9Req *req, uint64_t val)
154 uint64_t le_val = cpu_to_le64(val);
156 v9fs_memwrite(req, &le_val, 8);
159 static void v9fs_uint32_read(P9Req *req, uint32_t *val)
161 v9fs_memread(req, val, 4);
162 le32_to_cpus(val);
165 static void v9fs_uint64_read(P9Req *req, uint64_t *val)
167 v9fs_memread(req, val, 8);
168 le64_to_cpus(val);
171 /* len[2] string[len] */
172 static uint16_t v9fs_string_size(const char *string)
174 size_t len = strlen(string);
176 g_assert_cmpint(len, <=, UINT16_MAX - 2);
178 return 2 + len;
181 static void v9fs_string_write(P9Req *req, const char *string)
183 int len = strlen(string);
185 g_assert_cmpint(len, <=, UINT16_MAX);
187 v9fs_uint16_write(req, (uint16_t) len);
188 v9fs_memwrite(req, string, len);
191 static void v9fs_string_read(P9Req *req, uint16_t *len, char **string)
193 uint16_t local_len;
195 v9fs_uint16_read(req, &local_len);
196 if (len) {
197 *len = local_len;
199 if (string) {
200 *string = g_malloc(local_len + 1);
201 v9fs_memread(req, *string, local_len);
202 (*string)[local_len] = 0;
203 } else {
204 v9fs_memskip(req, local_len);
208 typedef struct {
209 uint32_t size;
210 uint8_t id;
211 uint16_t tag;
212 } QEMU_PACKED P9Hdr;
214 static P9Req *v9fs_req_init(QVirtio9P *v9p, uint32_t size, uint8_t id,
215 uint16_t tag)
217 P9Req *req = g_new0(P9Req, 1);
218 uint32_t total_size = 7; /* 9P header has well-known size of 7 bytes */
219 P9Hdr hdr = {
220 .id = id,
221 .tag = cpu_to_le16(tag)
224 g_assert_cmpint(total_size, <=, UINT32_MAX - size);
225 total_size += size;
226 hdr.size = cpu_to_le32(total_size);
228 g_assert_cmpint(total_size, <=, P9_MAX_SIZE);
230 req->qts = global_qtest;
231 req->v9p = v9p;
232 req->t_size = total_size;
233 req->t_msg = guest_alloc(alloc, req->t_size);
234 v9fs_memwrite(req, &hdr, 7);
235 req->tag = tag;
236 return req;
239 static void v9fs_req_send(P9Req *req)
241 QVirtio9P *v9p = req->v9p;
243 req->r_msg = guest_alloc(alloc, P9_MAX_SIZE);
244 req->free_head = qvirtqueue_add(req->qts, v9p->vq, req->t_msg, req->t_size,
245 false, true);
246 qvirtqueue_add(req->qts, v9p->vq, req->r_msg, P9_MAX_SIZE, true, false);
247 qvirtqueue_kick(req->qts, v9p->vdev, v9p->vq, req->free_head);
248 req->t_off = 0;
251 static const char *rmessage_name(uint8_t id)
253 return
254 id == P9_RLERROR ? "RLERROR" :
255 id == P9_RVERSION ? "RVERSION" :
256 id == P9_RATTACH ? "RATTACH" :
257 id == P9_RWALK ? "RWALK" :
258 id == P9_RLOPEN ? "RLOPEN" :
259 id == P9_RWRITE ? "RWRITE" :
260 id == P9_RMKDIR ? "RMKDIR" :
261 id == P9_RLCREATE ? "RLCREATE" :
262 id == P9_RSYMLINK ? "RSYMLINK" :
263 id == P9_RLINK ? "RLINK" :
264 id == P9_RUNLINKAT ? "RUNLINKAT" :
265 id == P9_RFLUSH ? "RFLUSH" :
266 id == P9_RREADDIR ? "READDIR" :
267 "<unknown>";
270 static void v9fs_req_wait_for_reply(P9Req *req, uint32_t *len)
272 QVirtio9P *v9p = req->v9p;
274 qvirtio_wait_used_elem(req->qts, v9p->vdev, v9p->vq, req->free_head, len,
275 QVIRTIO_9P_TIMEOUT_US);
278 static void v9fs_req_recv(P9Req *req, uint8_t id)
280 P9Hdr hdr;
282 v9fs_memread(req, &hdr, 7);
283 hdr.size = ldl_le_p(&hdr.size);
284 hdr.tag = lduw_le_p(&hdr.tag);
286 g_assert_cmpint(hdr.size, >=, 7);
287 g_assert_cmpint(hdr.size, <=, P9_MAX_SIZE);
288 g_assert_cmpint(hdr.tag, ==, req->tag);
290 if (hdr.id != id) {
291 g_printerr("Received response %d (%s) instead of %d (%s)\n",
292 hdr.id, rmessage_name(hdr.id), id, rmessage_name(id));
294 if (hdr.id == P9_RLERROR) {
295 uint32_t err;
296 v9fs_uint32_read(req, &err);
297 g_printerr("Rlerror has errno %d (%s)\n", err, strerror(err));
300 g_assert_cmpint(hdr.id, ==, id);
303 static void v9fs_req_free(P9Req *req)
305 guest_free(alloc, req->t_msg);
306 guest_free(alloc, req->r_msg);
307 g_free(req);
310 /* size[4] Rlerror tag[2] ecode[4] */
311 static void v9fs_rlerror(P9Req *req, uint32_t *err)
313 v9fs_req_recv(req, P9_RLERROR);
314 v9fs_uint32_read(req, err);
315 v9fs_req_free(req);
318 /* size[4] Tversion tag[2] msize[4] version[s] */
319 static P9Req *v9fs_tversion(QVirtio9P *v9p, uint32_t msize, const char *version,
320 uint16_t tag)
322 P9Req *req;
323 uint32_t body_size = 4;
324 uint16_t string_size = v9fs_string_size(version);
326 g_assert_cmpint(body_size, <=, UINT32_MAX - string_size);
327 body_size += string_size;
328 req = v9fs_req_init(v9p, body_size, P9_TVERSION, tag);
330 v9fs_uint32_write(req, msize);
331 v9fs_string_write(req, version);
332 v9fs_req_send(req);
333 return req;
336 /* size[4] Rversion tag[2] msize[4] version[s] */
337 static void v9fs_rversion(P9Req *req, uint16_t *len, char **version)
339 uint32_t msize;
341 v9fs_req_recv(req, P9_RVERSION);
342 v9fs_uint32_read(req, &msize);
344 g_assert_cmpint(msize, ==, P9_MAX_SIZE);
346 if (len || version) {
347 v9fs_string_read(req, len, version);
350 v9fs_req_free(req);
353 /* size[4] Tattach tag[2] fid[4] afid[4] uname[s] aname[s] n_uname[4] */
354 static P9Req *v9fs_tattach(QVirtio9P *v9p, uint32_t fid, uint32_t n_uname,
355 uint16_t tag)
357 const char *uname = ""; /* ignored by QEMU */
358 const char *aname = ""; /* ignored by QEMU */
359 P9Req *req = v9fs_req_init(v9p, 4 + 4 + 2 + 2 + 4, P9_TATTACH, tag);
361 v9fs_uint32_write(req, fid);
362 v9fs_uint32_write(req, P9_NOFID);
363 v9fs_string_write(req, uname);
364 v9fs_string_write(req, aname);
365 v9fs_uint32_write(req, n_uname);
366 v9fs_req_send(req);
367 return req;
370 typedef char v9fs_qid[13];
372 /* size[4] Rattach tag[2] qid[13] */
373 static void v9fs_rattach(P9Req *req, v9fs_qid *qid)
375 v9fs_req_recv(req, P9_RATTACH);
376 if (qid) {
377 v9fs_memread(req, qid, 13);
379 v9fs_req_free(req);
382 /* size[4] Twalk tag[2] fid[4] newfid[4] nwname[2] nwname*(wname[s]) */
383 static P9Req *v9fs_twalk(QVirtio9P *v9p, uint32_t fid, uint32_t newfid,
384 uint16_t nwname, char *const wnames[], uint16_t tag)
386 P9Req *req;
387 int i;
388 uint32_t body_size = 4 + 4 + 2;
390 for (i = 0; i < nwname; i++) {
391 uint16_t wname_size = v9fs_string_size(wnames[i]);
393 g_assert_cmpint(body_size, <=, UINT32_MAX - wname_size);
394 body_size += wname_size;
396 req = v9fs_req_init(v9p, body_size, P9_TWALK, tag);
397 v9fs_uint32_write(req, fid);
398 v9fs_uint32_write(req, newfid);
399 v9fs_uint16_write(req, nwname);
400 for (i = 0; i < nwname; i++) {
401 v9fs_string_write(req, wnames[i]);
403 v9fs_req_send(req);
404 return req;
407 /* size[4] Rwalk tag[2] nwqid[2] nwqid*(wqid[13]) */
408 static void v9fs_rwalk(P9Req *req, uint16_t *nwqid, v9fs_qid **wqid)
410 uint16_t local_nwqid;
412 v9fs_req_recv(req, P9_RWALK);
413 v9fs_uint16_read(req, &local_nwqid);
414 if (nwqid) {
415 *nwqid = local_nwqid;
417 if (wqid) {
418 *wqid = g_malloc(local_nwqid * 13);
419 v9fs_memread(req, *wqid, local_nwqid * 13);
421 v9fs_req_free(req);
424 /* size[4] Treaddir tag[2] fid[4] offset[8] count[4] */
425 static P9Req *v9fs_treaddir(QVirtio9P *v9p, uint32_t fid, uint64_t offset,
426 uint32_t count, uint16_t tag)
428 P9Req *req;
430 req = v9fs_req_init(v9p, 4 + 8 + 4, P9_TREADDIR, tag);
431 v9fs_uint32_write(req, fid);
432 v9fs_uint64_write(req, offset);
433 v9fs_uint32_write(req, count);
434 v9fs_req_send(req);
435 return req;
438 struct V9fsDirent {
439 v9fs_qid qid;
440 uint64_t offset;
441 uint8_t type;
442 char *name;
443 struct V9fsDirent *next;
446 /* size[4] Rreaddir tag[2] count[4] data[count] */
447 static void v9fs_rreaddir(P9Req *req, uint32_t *count, uint32_t *nentries,
448 struct V9fsDirent **entries)
450 uint32_t local_count;
451 struct V9fsDirent *e = NULL;
452 uint16_t slen;
453 uint32_t n = 0;
455 v9fs_req_recv(req, P9_RREADDIR);
456 v9fs_uint32_read(req, &local_count);
458 if (count) {
459 *count = local_count;
462 for (int32_t togo = (int32_t)local_count;
463 togo >= 13 + 8 + 1 + 2;
464 togo -= 13 + 8 + 1 + 2 + slen, ++n)
466 if (!e) {
467 e = g_malloc(sizeof(struct V9fsDirent));
468 if (entries) {
469 *entries = e;
471 } else {
472 e = e->next = g_malloc(sizeof(struct V9fsDirent));
474 e->next = NULL;
475 /* qid[13] offset[8] type[1] name[s] */
476 v9fs_memread(req, &e->qid, 13);
477 v9fs_uint64_read(req, &e->offset);
478 v9fs_uint8_read(req, &e->type);
479 v9fs_string_read(req, &slen, &e->name);
482 if (nentries) {
483 *nentries = n;
486 v9fs_req_free(req);
489 static void v9fs_free_dirents(struct V9fsDirent *e)
491 struct V9fsDirent *next = NULL;
493 for (; e; e = next) {
494 next = e->next;
495 g_free(e->name);
496 g_free(e);
500 /* size[4] Tlopen tag[2] fid[4] flags[4] */
501 static P9Req *v9fs_tlopen(QVirtio9P *v9p, uint32_t fid, uint32_t flags,
502 uint16_t tag)
504 P9Req *req;
506 req = v9fs_req_init(v9p, 4 + 4, P9_TLOPEN, tag);
507 v9fs_uint32_write(req, fid);
508 v9fs_uint32_write(req, flags);
509 v9fs_req_send(req);
510 return req;
513 /* size[4] Rlopen tag[2] qid[13] iounit[4] */
514 static void v9fs_rlopen(P9Req *req, v9fs_qid *qid, uint32_t *iounit)
516 v9fs_req_recv(req, P9_RLOPEN);
517 if (qid) {
518 v9fs_memread(req, qid, 13);
519 } else {
520 v9fs_memskip(req, 13);
522 if (iounit) {
523 v9fs_uint32_read(req, iounit);
525 v9fs_req_free(req);
528 /* size[4] Twrite tag[2] fid[4] offset[8] count[4] data[count] */
529 static P9Req *v9fs_twrite(QVirtio9P *v9p, uint32_t fid, uint64_t offset,
530 uint32_t count, const void *data, uint16_t tag)
532 P9Req *req;
533 uint32_t body_size = 4 + 8 + 4;
535 g_assert_cmpint(body_size, <=, UINT32_MAX - count);
536 body_size += count;
537 req = v9fs_req_init(v9p, body_size, P9_TWRITE, tag);
538 v9fs_uint32_write(req, fid);
539 v9fs_uint64_write(req, offset);
540 v9fs_uint32_write(req, count);
541 v9fs_memwrite(req, data, count);
542 v9fs_req_send(req);
543 return req;
546 /* size[4] Rwrite tag[2] count[4] */
547 static void v9fs_rwrite(P9Req *req, uint32_t *count)
549 v9fs_req_recv(req, P9_RWRITE);
550 if (count) {
551 v9fs_uint32_read(req, count);
553 v9fs_req_free(req);
556 /* size[4] Tflush tag[2] oldtag[2] */
557 static P9Req *v9fs_tflush(QVirtio9P *v9p, uint16_t oldtag, uint16_t tag)
559 P9Req *req;
561 req = v9fs_req_init(v9p, 2, P9_TFLUSH, tag);
562 v9fs_uint32_write(req, oldtag);
563 v9fs_req_send(req);
564 return req;
567 /* size[4] Rflush tag[2] */
568 static void v9fs_rflush(P9Req *req)
570 v9fs_req_recv(req, P9_RFLUSH);
571 v9fs_req_free(req);
574 static void do_version(QVirtio9P *v9p)
576 const char *version = "9P2000.L";
577 uint16_t server_len;
578 char *server_version;
579 P9Req *req;
581 req = v9fs_tversion(v9p, P9_MAX_SIZE, version, P9_NOTAG);
582 v9fs_req_wait_for_reply(req, NULL);
583 v9fs_rversion(req, &server_len, &server_version);
585 g_assert_cmpmem(server_version, server_len, version, strlen(version));
587 g_free(server_version);
590 /* utility function: walk to requested dir and return fid for that dir */
591 static uint32_t do_walk(QVirtio9P *v9p, const char *path)
593 char **wnames;
594 P9Req *req;
595 const uint32_t fid = genfid();
597 int nwnames = split(path, "/", &wnames);
599 req = v9fs_twalk(v9p, 0, fid, nwnames, wnames, 0);
600 v9fs_req_wait_for_reply(req, NULL);
601 v9fs_rwalk(req, NULL, NULL);
603 split_free(&wnames);
604 return fid;
607 static void fs_version(void *obj, void *data, QGuestAllocator *t_alloc)
609 alloc = t_alloc;
610 do_version(obj);
613 static void do_attach(QVirtio9P *v9p)
615 P9Req *req;
617 do_version(v9p);
618 req = v9fs_tattach(v9p, 0, getuid(), 0);
619 v9fs_req_wait_for_reply(req, NULL);
620 v9fs_rattach(req, NULL);
623 static void fs_attach(void *obj, void *data, QGuestAllocator *t_alloc)
625 alloc = t_alloc;
626 do_attach(obj);
629 static void fs_walk(void *obj, void *data, QGuestAllocator *t_alloc)
631 QVirtio9P *v9p = obj;
632 alloc = t_alloc;
633 char *wnames[P9_MAXWELEM];
634 uint16_t nwqid;
635 v9fs_qid *wqid;
636 int i;
637 P9Req *req;
639 for (i = 0; i < P9_MAXWELEM; i++) {
640 wnames[i] = g_strdup_printf(QTEST_V9FS_SYNTH_WALK_FILE, i);
643 do_attach(v9p);
644 req = v9fs_twalk(v9p, 0, 1, P9_MAXWELEM, wnames, 0);
645 v9fs_req_wait_for_reply(req, NULL);
646 v9fs_rwalk(req, &nwqid, &wqid);
648 g_assert_cmpint(nwqid, ==, P9_MAXWELEM);
650 for (i = 0; i < P9_MAXWELEM; i++) {
651 g_free(wnames[i]);
654 g_free(wqid);
657 static bool fs_dirents_contain_name(struct V9fsDirent *e, const char* name)
659 for (; e; e = e->next) {
660 if (!strcmp(e->name, name)) {
661 return true;
664 return false;
667 /* size[4] Tmkdir tag[2] dfid[4] name[s] mode[4] gid[4] */
668 static P9Req *v9fs_tmkdir(QVirtio9P *v9p, uint32_t dfid, const char *name,
669 uint32_t mode, uint32_t gid, uint16_t tag)
671 P9Req *req;
673 uint32_t body_size = 4 + 4 + 4;
674 uint16_t string_size = v9fs_string_size(name);
676 g_assert_cmpint(body_size, <=, UINT32_MAX - string_size);
677 body_size += string_size;
679 req = v9fs_req_init(v9p, body_size, P9_TMKDIR, tag);
680 v9fs_uint32_write(req, dfid);
681 v9fs_string_write(req, name);
682 v9fs_uint32_write(req, mode);
683 v9fs_uint32_write(req, gid);
684 v9fs_req_send(req);
685 return req;
688 /* size[4] Rmkdir tag[2] qid[13] */
689 static void v9fs_rmkdir(P9Req *req, v9fs_qid *qid)
691 v9fs_req_recv(req, P9_RMKDIR);
692 if (qid) {
693 v9fs_memread(req, qid, 13);
694 } else {
695 v9fs_memskip(req, 13);
697 v9fs_req_free(req);
700 /* size[4] Tlcreate tag[2] fid[4] name[s] flags[4] mode[4] gid[4] */
701 static P9Req *v9fs_tlcreate(QVirtio9P *v9p, uint32_t fid, const char *name,
702 uint32_t flags, uint32_t mode, uint32_t gid,
703 uint16_t tag)
705 P9Req *req;
707 uint32_t body_size = 4 + 4 + 4 + 4;
708 uint16_t string_size = v9fs_string_size(name);
710 g_assert_cmpint(body_size, <=, UINT32_MAX - string_size);
711 body_size += string_size;
713 req = v9fs_req_init(v9p, body_size, P9_TLCREATE, tag);
714 v9fs_uint32_write(req, fid);
715 v9fs_string_write(req, name);
716 v9fs_uint32_write(req, flags);
717 v9fs_uint32_write(req, mode);
718 v9fs_uint32_write(req, gid);
719 v9fs_req_send(req);
720 return req;
723 /* size[4] Rlcreate tag[2] qid[13] iounit[4] */
724 static void v9fs_rlcreate(P9Req *req, v9fs_qid *qid, uint32_t *iounit)
726 v9fs_req_recv(req, P9_RLCREATE);
727 if (qid) {
728 v9fs_memread(req, qid, 13);
729 } else {
730 v9fs_memskip(req, 13);
732 if (iounit) {
733 v9fs_uint32_read(req, iounit);
735 v9fs_req_free(req);
738 /* size[4] Tsymlink tag[2] fid[4] name[s] symtgt[s] gid[4] */
739 static P9Req *v9fs_tsymlink(QVirtio9P *v9p, uint32_t fid, const char *name,
740 const char *symtgt, uint32_t gid, uint16_t tag)
742 P9Req *req;
744 uint32_t body_size = 4 + 4;
745 uint16_t string_size = v9fs_string_size(name) + v9fs_string_size(symtgt);
747 g_assert_cmpint(body_size, <=, UINT32_MAX - string_size);
748 body_size += string_size;
750 req = v9fs_req_init(v9p, body_size, P9_TSYMLINK, tag);
751 v9fs_uint32_write(req, fid);
752 v9fs_string_write(req, name);
753 v9fs_string_write(req, symtgt);
754 v9fs_uint32_write(req, gid);
755 v9fs_req_send(req);
756 return req;
759 /* size[4] Rsymlink tag[2] qid[13] */
760 static void v9fs_rsymlink(P9Req *req, v9fs_qid *qid)
762 v9fs_req_recv(req, P9_RSYMLINK);
763 if (qid) {
764 v9fs_memread(req, qid, 13);
765 } else {
766 v9fs_memskip(req, 13);
768 v9fs_req_free(req);
771 /* size[4] Tlink tag[2] dfid[4] fid[4] name[s] */
772 static P9Req *v9fs_tlink(QVirtio9P *v9p, uint32_t dfid, uint32_t fid,
773 const char *name, uint16_t tag)
775 P9Req *req;
777 uint32_t body_size = 4 + 4;
778 uint16_t string_size = v9fs_string_size(name);
780 g_assert_cmpint(body_size, <=, UINT32_MAX - string_size);
781 body_size += string_size;
783 req = v9fs_req_init(v9p, body_size, P9_TLINK, tag);
784 v9fs_uint32_write(req, dfid);
785 v9fs_uint32_write(req, fid);
786 v9fs_string_write(req, name);
787 v9fs_req_send(req);
788 return req;
791 /* size[4] Rlink tag[2] */
792 static void v9fs_rlink(P9Req *req)
794 v9fs_req_recv(req, P9_RLINK);
795 v9fs_req_free(req);
798 /* size[4] Tunlinkat tag[2] dirfd[4] name[s] flags[4] */
799 static P9Req *v9fs_tunlinkat(QVirtio9P *v9p, uint32_t dirfd, const char *name,
800 uint32_t flags, uint16_t tag)
802 P9Req *req;
804 uint32_t body_size = 4 + 4;
805 uint16_t string_size = v9fs_string_size(name);
807 g_assert_cmpint(body_size, <=, UINT32_MAX - string_size);
808 body_size += string_size;
810 req = v9fs_req_init(v9p, body_size, P9_TUNLINKAT, tag);
811 v9fs_uint32_write(req, dirfd);
812 v9fs_string_write(req, name);
813 v9fs_uint32_write(req, flags);
814 v9fs_req_send(req);
815 return req;
818 /* size[4] Runlinkat tag[2] */
819 static void v9fs_runlinkat(P9Req *req)
821 v9fs_req_recv(req, P9_RUNLINKAT);
822 v9fs_req_free(req);
825 /* basic readdir test where reply fits into a single response message */
826 static void fs_readdir(void *obj, void *data, QGuestAllocator *t_alloc)
828 QVirtio9P *v9p = obj;
829 alloc = t_alloc;
830 char *const wnames[] = { g_strdup(QTEST_V9FS_SYNTH_READDIR_DIR) };
831 uint16_t nqid;
832 v9fs_qid qid;
833 uint32_t count, nentries;
834 struct V9fsDirent *entries = NULL;
835 P9Req *req;
837 do_attach(v9p);
838 req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0);
839 v9fs_req_wait_for_reply(req, NULL);
840 v9fs_rwalk(req, &nqid, NULL);
841 g_assert_cmpint(nqid, ==, 1);
843 req = v9fs_tlopen(v9p, 1, O_DIRECTORY, 0);
844 v9fs_req_wait_for_reply(req, NULL);
845 v9fs_rlopen(req, &qid, NULL);
848 * submit count = msize - 11, because 11 is the header size of Rreaddir
850 req = v9fs_treaddir(v9p, 1, 0, P9_MAX_SIZE - 11, 0);
851 v9fs_req_wait_for_reply(req, NULL);
852 v9fs_rreaddir(req, &count, &nentries, &entries);
855 * Assuming msize (P9_MAX_SIZE) is large enough so we can retrieve all
856 * dir entries with only one readdir request.
858 g_assert_cmpint(
859 nentries, ==,
860 QTEST_V9FS_SYNTH_READDIR_NFILES + 2 /* "." and ".." */
864 * Check all file names exist in returned entries, ignore their order
865 * though.
867 g_assert_cmpint(fs_dirents_contain_name(entries, "."), ==, true);
868 g_assert_cmpint(fs_dirents_contain_name(entries, ".."), ==, true);
869 for (int i = 0; i < QTEST_V9FS_SYNTH_READDIR_NFILES; ++i) {
870 char *name = g_strdup_printf(QTEST_V9FS_SYNTH_READDIR_FILE, i);
871 g_assert_cmpint(fs_dirents_contain_name(entries, name), ==, true);
872 g_free(name);
875 v9fs_free_dirents(entries);
876 g_free(wnames[0]);
879 /* readdir test where overall request is split over several messages */
880 static void do_readdir_split(QVirtio9P *v9p, uint32_t count)
882 char *const wnames[] = { g_strdup(QTEST_V9FS_SYNTH_READDIR_DIR) };
883 uint16_t nqid;
884 v9fs_qid qid;
885 uint32_t nentries, npartialentries;
886 struct V9fsDirent *entries, *tail, *partialentries;
887 P9Req *req;
888 int fid;
889 uint64_t offset;
891 do_attach(v9p);
893 fid = 1;
894 offset = 0;
895 entries = NULL;
896 nentries = 0;
897 tail = NULL;
899 req = v9fs_twalk(v9p, 0, fid, 1, wnames, 0);
900 v9fs_req_wait_for_reply(req, NULL);
901 v9fs_rwalk(req, &nqid, NULL);
902 g_assert_cmpint(nqid, ==, 1);
904 req = v9fs_tlopen(v9p, fid, O_DIRECTORY, 0);
905 v9fs_req_wait_for_reply(req, NULL);
906 v9fs_rlopen(req, &qid, NULL);
909 * send as many Treaddir requests as required to get all directory
910 * entries
912 while (true) {
913 npartialentries = 0;
914 partialentries = NULL;
916 req = v9fs_treaddir(v9p, fid, offset, count, 0);
917 v9fs_req_wait_for_reply(req, NULL);
918 v9fs_rreaddir(req, &count, &npartialentries, &partialentries);
919 if (npartialentries > 0 && partialentries) {
920 if (!entries) {
921 entries = partialentries;
922 nentries = npartialentries;
923 tail = partialentries;
924 } else {
925 tail->next = partialentries;
926 nentries += npartialentries;
928 while (tail->next) {
929 tail = tail->next;
931 offset = tail->offset;
932 } else {
933 break;
937 g_assert_cmpint(
938 nentries, ==,
939 QTEST_V9FS_SYNTH_READDIR_NFILES + 2 /* "." and ".." */
943 * Check all file names exist in returned entries, ignore their order
944 * though.
946 g_assert_cmpint(fs_dirents_contain_name(entries, "."), ==, true);
947 g_assert_cmpint(fs_dirents_contain_name(entries, ".."), ==, true);
948 for (int i = 0; i < QTEST_V9FS_SYNTH_READDIR_NFILES; ++i) {
949 char *name = g_strdup_printf(QTEST_V9FS_SYNTH_READDIR_FILE, i);
950 g_assert_cmpint(fs_dirents_contain_name(entries, name), ==, true);
951 g_free(name);
954 v9fs_free_dirents(entries);
956 g_free(wnames[0]);
959 static void fs_walk_no_slash(void *obj, void *data, QGuestAllocator *t_alloc)
961 QVirtio9P *v9p = obj;
962 alloc = t_alloc;
963 char *const wnames[] = { g_strdup(" /") };
964 P9Req *req;
965 uint32_t err;
967 do_attach(v9p);
968 req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0);
969 v9fs_req_wait_for_reply(req, NULL);
970 v9fs_rlerror(req, &err);
972 g_assert_cmpint(err, ==, ENOENT);
974 g_free(wnames[0]);
977 static void fs_walk_dotdot(void *obj, void *data, QGuestAllocator *t_alloc)
979 QVirtio9P *v9p = obj;
980 alloc = t_alloc;
981 char *const wnames[] = { g_strdup("..") };
982 v9fs_qid root_qid, *wqid;
983 P9Req *req;
985 do_version(v9p);
986 req = v9fs_tattach(v9p, 0, getuid(), 0);
987 v9fs_req_wait_for_reply(req, NULL);
988 v9fs_rattach(req, &root_qid);
990 req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0);
991 v9fs_req_wait_for_reply(req, NULL);
992 v9fs_rwalk(req, NULL, &wqid); /* We now we'll get one qid */
994 g_assert_cmpmem(&root_qid, 13, wqid[0], 13);
996 g_free(wqid);
997 g_free(wnames[0]);
1000 static void fs_lopen(void *obj, void *data, QGuestAllocator *t_alloc)
1002 QVirtio9P *v9p = obj;
1003 alloc = t_alloc;
1004 char *const wnames[] = { g_strdup(QTEST_V9FS_SYNTH_LOPEN_FILE) };
1005 P9Req *req;
1007 do_attach(v9p);
1008 req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0);
1009 v9fs_req_wait_for_reply(req, NULL);
1010 v9fs_rwalk(req, NULL, NULL);
1012 req = v9fs_tlopen(v9p, 1, O_WRONLY, 0);
1013 v9fs_req_wait_for_reply(req, NULL);
1014 v9fs_rlopen(req, NULL, NULL);
1016 g_free(wnames[0]);
1019 static void fs_write(void *obj, void *data, QGuestAllocator *t_alloc)
1021 QVirtio9P *v9p = obj;
1022 alloc = t_alloc;
1023 static const uint32_t write_count = P9_MAX_SIZE / 2;
1024 char *const wnames[] = { g_strdup(QTEST_V9FS_SYNTH_WRITE_FILE) };
1025 char *buf = g_malloc0(write_count);
1026 uint32_t count;
1027 P9Req *req;
1029 do_attach(v9p);
1030 req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0);
1031 v9fs_req_wait_for_reply(req, NULL);
1032 v9fs_rwalk(req, NULL, NULL);
1034 req = v9fs_tlopen(v9p, 1, O_WRONLY, 0);
1035 v9fs_req_wait_for_reply(req, NULL);
1036 v9fs_rlopen(req, NULL, NULL);
1038 req = v9fs_twrite(v9p, 1, 0, write_count, buf, 0);
1039 v9fs_req_wait_for_reply(req, NULL);
1040 v9fs_rwrite(req, &count);
1041 g_assert_cmpint(count, ==, write_count);
1043 g_free(buf);
1044 g_free(wnames[0]);
1047 static void fs_flush_success(void *obj, void *data, QGuestAllocator *t_alloc)
1049 QVirtio9P *v9p = obj;
1050 alloc = t_alloc;
1051 char *const wnames[] = { g_strdup(QTEST_V9FS_SYNTH_FLUSH_FILE) };
1052 P9Req *req, *flush_req;
1053 uint32_t reply_len;
1054 uint8_t should_block;
1056 do_attach(v9p);
1057 req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0);
1058 v9fs_req_wait_for_reply(req, NULL);
1059 v9fs_rwalk(req, NULL, NULL);
1061 req = v9fs_tlopen(v9p, 1, O_WRONLY, 0);
1062 v9fs_req_wait_for_reply(req, NULL);
1063 v9fs_rlopen(req, NULL, NULL);
1065 /* This will cause the 9p server to try to write data to the backend,
1066 * until the write request gets cancelled.
1068 should_block = 1;
1069 req = v9fs_twrite(v9p, 1, 0, sizeof(should_block), &should_block, 0);
1071 flush_req = v9fs_tflush(v9p, req->tag, 1);
1073 /* The write request is supposed to be flushed: the server should just
1074 * mark the write request as used and reply to the flush request.
1076 v9fs_req_wait_for_reply(req, &reply_len);
1077 g_assert_cmpint(reply_len, ==, 0);
1078 v9fs_req_free(req);
1079 v9fs_rflush(flush_req);
1081 g_free(wnames[0]);
1084 static void fs_flush_ignored(void *obj, void *data, QGuestAllocator *t_alloc)
1086 QVirtio9P *v9p = obj;
1087 alloc = t_alloc;
1088 char *const wnames[] = { g_strdup(QTEST_V9FS_SYNTH_FLUSH_FILE) };
1089 P9Req *req, *flush_req;
1090 uint32_t count;
1091 uint8_t should_block;
1093 do_attach(v9p);
1094 req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0);
1095 v9fs_req_wait_for_reply(req, NULL);
1096 v9fs_rwalk(req, NULL, NULL);
1098 req = v9fs_tlopen(v9p, 1, O_WRONLY, 0);
1099 v9fs_req_wait_for_reply(req, NULL);
1100 v9fs_rlopen(req, NULL, NULL);
1102 /* This will cause the write request to complete right away, before it
1103 * could be actually cancelled.
1105 should_block = 0;
1106 req = v9fs_twrite(v9p, 1, 0, sizeof(should_block), &should_block, 0);
1108 flush_req = v9fs_tflush(v9p, req->tag, 1);
1110 /* The write request is supposed to complete. The server should
1111 * reply to the write request and the flush request.
1113 v9fs_req_wait_for_reply(req, NULL);
1114 v9fs_rwrite(req, &count);
1115 g_assert_cmpint(count, ==, sizeof(should_block));
1116 v9fs_rflush(flush_req);
1118 g_free(wnames[0]);
1121 static void do_mkdir(QVirtio9P *v9p, const char *path, const char *cname)
1123 char *const name = g_strdup(cname);
1124 uint32_t fid;
1125 P9Req *req;
1127 fid = do_walk(v9p, path);
1129 req = v9fs_tmkdir(v9p, fid, name, 0750, 0, 0);
1130 v9fs_req_wait_for_reply(req, NULL);
1131 v9fs_rmkdir(req, NULL);
1133 g_free(name);
1136 /* create a regular file with Tlcreate and return file's fid */
1137 static uint32_t do_lcreate(QVirtio9P *v9p, const char *path,
1138 const char *cname)
1140 char *const name = g_strdup(cname);
1141 uint32_t fid;
1142 P9Req *req;
1144 fid = do_walk(v9p, path);
1146 req = v9fs_tlcreate(v9p, fid, name, 0, 0750, 0, 0);
1147 v9fs_req_wait_for_reply(req, NULL);
1148 v9fs_rlcreate(req, NULL, NULL);
1150 g_free(name);
1151 return fid;
1154 /* create symlink named @a clink in directory @a path pointing to @a to */
1155 static void do_symlink(QVirtio9P *v9p, const char *path, const char *clink,
1156 const char *to)
1158 char *const name = g_strdup(clink);
1159 char *const dst = g_strdup(to);
1160 uint32_t fid;
1161 P9Req *req;
1163 fid = do_walk(v9p, path);
1165 req = v9fs_tsymlink(v9p, fid, name, dst, 0, 0);
1166 v9fs_req_wait_for_reply(req, NULL);
1167 v9fs_rsymlink(req, NULL);
1169 g_free(dst);
1170 g_free(name);
1173 /* create a hard link named @a clink in directory @a path pointing to @a to */
1174 static void do_hardlink(QVirtio9P *v9p, const char *path, const char *clink,
1175 const char *to)
1177 uint32_t dfid, fid;
1178 P9Req *req;
1180 dfid = do_walk(v9p, path);
1181 fid = do_walk(v9p, to);
1183 req = v9fs_tlink(v9p, dfid, fid, clink, 0);
1184 v9fs_req_wait_for_reply(req, NULL);
1185 v9fs_rlink(req);
1188 static void do_unlinkat(QVirtio9P *v9p, const char *atpath, const char *rpath,
1189 uint32_t flags)
1191 char *const name = g_strdup(rpath);
1192 uint32_t fid;
1193 P9Req *req;
1195 fid = do_walk(v9p, atpath);
1197 req = v9fs_tunlinkat(v9p, fid, name, flags, 0);
1198 v9fs_req_wait_for_reply(req, NULL);
1199 v9fs_runlinkat(req);
1201 g_free(name);
1204 static void fs_readdir_split_128(void *obj, void *data,
1205 QGuestAllocator *t_alloc)
1207 alloc = t_alloc;
1208 do_readdir_split(obj, 128);
1211 static void fs_readdir_split_256(void *obj, void *data,
1212 QGuestAllocator *t_alloc)
1214 alloc = t_alloc;
1215 do_readdir_split(obj, 256);
1218 static void fs_readdir_split_512(void *obj, void *data,
1219 QGuestAllocator *t_alloc)
1221 alloc = t_alloc;
1222 do_readdir_split(obj, 512);
1226 /* tests using the 9pfs 'local' fs driver */
1228 static void fs_create_dir(void *obj, void *data, QGuestAllocator *t_alloc)
1230 QVirtio9P *v9p = obj;
1231 alloc = t_alloc;
1232 struct stat st;
1233 char *root_path = virtio_9p_test_path("");
1234 char *new_dir = virtio_9p_test_path("01");
1236 g_assert(root_path != NULL);
1238 do_attach(v9p);
1239 do_mkdir(v9p, "/", "01");
1241 /* check if created directory really exists now ... */
1242 g_assert(stat(new_dir, &st) == 0);
1243 /* ... and is actually a directory */
1244 g_assert((st.st_mode & S_IFMT) == S_IFDIR);
1246 g_free(new_dir);
1247 g_free(root_path);
1250 static void fs_unlinkat_dir(void *obj, void *data, QGuestAllocator *t_alloc)
1252 QVirtio9P *v9p = obj;
1253 alloc = t_alloc;
1254 struct stat st;
1255 char *root_path = virtio_9p_test_path("");
1256 char *new_dir = virtio_9p_test_path("02");
1258 g_assert(root_path != NULL);
1260 do_attach(v9p);
1261 do_mkdir(v9p, "/", "02");
1263 /* check if created directory really exists now ... */
1264 g_assert(stat(new_dir, &st) == 0);
1265 /* ... and is actually a directory */
1266 g_assert((st.st_mode & S_IFMT) == S_IFDIR);
1268 do_unlinkat(v9p, "/", "02", AT_REMOVEDIR);
1269 /* directory should be gone now */
1270 g_assert(stat(new_dir, &st) != 0);
1272 g_free(new_dir);
1273 g_free(root_path);
1276 static void fs_create_file(void *obj, void *data, QGuestAllocator *t_alloc)
1278 QVirtio9P *v9p = obj;
1279 alloc = t_alloc;
1280 struct stat st;
1281 char *new_file = virtio_9p_test_path("03/1st_file");
1283 do_attach(v9p);
1284 do_mkdir(v9p, "/", "03");
1285 do_lcreate(v9p, "03", "1st_file");
1287 /* check if created file exists now ... */
1288 g_assert(stat(new_file, &st) == 0);
1289 /* ... and is a regular file */
1290 g_assert((st.st_mode & S_IFMT) == S_IFREG);
1292 g_free(new_file);
1295 static void fs_unlinkat_file(void *obj, void *data, QGuestAllocator *t_alloc)
1297 QVirtio9P *v9p = obj;
1298 alloc = t_alloc;
1299 struct stat st;
1300 char *new_file = virtio_9p_test_path("04/doa_file");
1302 do_attach(v9p);
1303 do_mkdir(v9p, "/", "04");
1304 do_lcreate(v9p, "04", "doa_file");
1306 /* check if created file exists now ... */
1307 g_assert(stat(new_file, &st) == 0);
1308 /* ... and is a regular file */
1309 g_assert((st.st_mode & S_IFMT) == S_IFREG);
1311 do_unlinkat(v9p, "04", "doa_file", 0);
1312 /* file should be gone now */
1313 g_assert(stat(new_file, &st) != 0);
1315 g_free(new_file);
1318 static void fs_symlink_file(void *obj, void *data, QGuestAllocator *t_alloc)
1320 QVirtio9P *v9p = obj;
1321 alloc = t_alloc;
1322 struct stat st;
1323 char *real_file = virtio_9p_test_path("05/real_file");
1324 char *symlink_file = virtio_9p_test_path("05/symlink_file");
1326 do_attach(v9p);
1327 do_mkdir(v9p, "/", "05");
1328 do_lcreate(v9p, "05", "real_file");
1329 g_assert(stat(real_file, &st) == 0);
1330 g_assert((st.st_mode & S_IFMT) == S_IFREG);
1332 do_symlink(v9p, "05", "symlink_file", "real_file");
1334 /* check if created link exists now */
1335 g_assert(stat(symlink_file, &st) == 0);
1337 g_free(symlink_file);
1338 g_free(real_file);
1341 static void fs_unlinkat_symlink(void *obj, void *data,
1342 QGuestAllocator *t_alloc)
1344 QVirtio9P *v9p = obj;
1345 alloc = t_alloc;
1346 struct stat st;
1347 char *real_file = virtio_9p_test_path("06/real_file");
1348 char *symlink_file = virtio_9p_test_path("06/symlink_file");
1350 do_attach(v9p);
1351 do_mkdir(v9p, "/", "06");
1352 do_lcreate(v9p, "06", "real_file");
1353 g_assert(stat(real_file, &st) == 0);
1354 g_assert((st.st_mode & S_IFMT) == S_IFREG);
1356 do_symlink(v9p, "06", "symlink_file", "real_file");
1357 g_assert(stat(symlink_file, &st) == 0);
1359 do_unlinkat(v9p, "06", "symlink_file", 0);
1360 /* symlink should be gone now */
1361 g_assert(stat(symlink_file, &st) != 0);
1363 g_free(symlink_file);
1364 g_free(real_file);
1367 static void fs_hardlink_file(void *obj, void *data, QGuestAllocator *t_alloc)
1369 QVirtio9P *v9p = obj;
1370 alloc = t_alloc;
1371 struct stat st_real, st_link;
1372 char *real_file = virtio_9p_test_path("07/real_file");
1373 char *hardlink_file = virtio_9p_test_path("07/hardlink_file");
1375 do_attach(v9p);
1376 do_mkdir(v9p, "/", "07");
1377 do_lcreate(v9p, "07", "real_file");
1378 g_assert(stat(real_file, &st_real) == 0);
1379 g_assert((st_real.st_mode & S_IFMT) == S_IFREG);
1381 do_hardlink(v9p, "07", "hardlink_file", "07/real_file");
1383 /* check if link exists now ... */
1384 g_assert(stat(hardlink_file, &st_link) == 0);
1385 /* ... and it's a hard link, right? */
1386 g_assert((st_link.st_mode & S_IFMT) == S_IFREG);
1387 g_assert(st_link.st_dev == st_real.st_dev);
1388 g_assert(st_link.st_ino == st_real.st_ino);
1390 g_free(hardlink_file);
1391 g_free(real_file);
1394 static void fs_unlinkat_hardlink(void *obj, void *data,
1395 QGuestAllocator *t_alloc)
1397 QVirtio9P *v9p = obj;
1398 alloc = t_alloc;
1399 struct stat st_real, st_link;
1400 char *real_file = virtio_9p_test_path("08/real_file");
1401 char *hardlink_file = virtio_9p_test_path("08/hardlink_file");
1403 do_attach(v9p);
1404 do_mkdir(v9p, "/", "08");
1405 do_lcreate(v9p, "08", "real_file");
1406 g_assert(stat(real_file, &st_real) == 0);
1407 g_assert((st_real.st_mode & S_IFMT) == S_IFREG);
1409 do_hardlink(v9p, "08", "hardlink_file", "08/real_file");
1410 g_assert(stat(hardlink_file, &st_link) == 0);
1412 do_unlinkat(v9p, "08", "hardlink_file", 0);
1413 /* symlink should be gone now */
1414 g_assert(stat(hardlink_file, &st_link) != 0);
1415 /* and old file should still exist */
1416 g_assert(stat(real_file, &st_real) == 0);
1418 g_free(hardlink_file);
1419 g_free(real_file);
1422 static void *assign_9p_local_driver(GString *cmd_line, void *arg)
1424 virtio_9p_assign_local_driver(cmd_line, "security_model=mapped-xattr");
1425 return arg;
1428 static void register_virtio_9p_test(void)
1431 QOSGraphTestOptions opts = {
1434 /* 9pfs test cases using the 'synth' filesystem driver */
1435 qos_add_test("synth/config", "virtio-9p", pci_config, &opts);
1436 qos_add_test("synth/version/basic", "virtio-9p", fs_version, &opts);
1437 qos_add_test("synth/attach/basic", "virtio-9p", fs_attach, &opts);
1438 qos_add_test("synth/walk/basic", "virtio-9p", fs_walk, &opts);
1439 qos_add_test("synth/walk/no_slash", "virtio-9p", fs_walk_no_slash,
1440 &opts);
1441 qos_add_test("synth/walk/dotdot_from_root", "virtio-9p",
1442 fs_walk_dotdot, &opts);
1443 qos_add_test("synth/lopen/basic", "virtio-9p", fs_lopen, &opts);
1444 qos_add_test("synth/write/basic", "virtio-9p", fs_write, &opts);
1445 qos_add_test("synth/flush/success", "virtio-9p", fs_flush_success,
1446 &opts);
1447 qos_add_test("synth/flush/ignored", "virtio-9p", fs_flush_ignored,
1448 &opts);
1449 qos_add_test("synth/readdir/basic", "virtio-9p", fs_readdir, &opts);
1450 qos_add_test("synth/readdir/split_512", "virtio-9p",
1451 fs_readdir_split_512, &opts);
1452 qos_add_test("synth/readdir/split_256", "virtio-9p",
1453 fs_readdir_split_256, &opts);
1454 qos_add_test("synth/readdir/split_128", "virtio-9p",
1455 fs_readdir_split_128, &opts);
1458 /* 9pfs test cases using the 'local' filesystem driver */
1461 * XXX: Until we are sure that these tests can run everywhere,
1462 * keep them as "slow" so that they aren't run with "make check".
1464 if (!g_test_slow()) {
1465 return;
1468 opts.before = assign_9p_local_driver;
1469 qos_add_test("local/config", "virtio-9p", pci_config, &opts);
1470 qos_add_test("local/create_dir", "virtio-9p", fs_create_dir, &opts);
1471 qos_add_test("local/unlinkat_dir", "virtio-9p", fs_unlinkat_dir, &opts);
1472 qos_add_test("local/create_file", "virtio-9p", fs_create_file, &opts);
1473 qos_add_test("local/unlinkat_file", "virtio-9p", fs_unlinkat_file, &opts);
1474 qos_add_test("local/symlink_file", "virtio-9p", fs_symlink_file, &opts);
1475 qos_add_test("local/unlinkat_symlink", "virtio-9p", fs_unlinkat_symlink,
1476 &opts);
1477 qos_add_test("local/hardlink_file", "virtio-9p", fs_hardlink_file, &opts);
1478 qos_add_test("local/unlinkat_hardlink", "virtio-9p", fs_unlinkat_hardlink,
1479 &opts);
1482 libqos_init(register_virtio_9p_test);
1484 static void __attribute__((constructor)) construct_9p_test(void)
1486 /* make sure test dir for the 'local' tests exists */
1487 virtio_9p_create_local_test_dir();
1490 static void __attribute__((destructor)) destruct_9p_test(void)
1492 /* remove previously created test dir when test suite completed */
1493 virtio_9p_remove_local_test_dir();