summaryrefslogtreecommitdiff
path: root/lib9p/tests
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-02-09 22:20:00 -0700
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-02-09 22:22:19 -0700
commitfa10ceb13e66309ba24605dd5df91c4d626f0614 (patch)
treebf92b1e44918d0d04584b473490d67c12363ecf1 /lib9p/tests
parent026afb5113fbeed097308a0fe43da105b549c807 (diff)
lib9p: test_server: Simplify construction of the file tree
Diffstat (limited to 'lib9p/tests')
-rwxr-xr-xlib9p/tests/runtest2
-rw-r--r--lib9p/tests/test_server/main.c91
2 files changed, 42 insertions, 51 deletions
diff --git a/lib9p/tests/runtest b/lib9p/tests/runtest
index 02cd791..0966000 100755
--- a/lib9p/tests/runtest
+++ b/lib9p/tests/runtest
@@ -43,7 +43,7 @@ expect_lines \
out=$("${client[@]}" stat 'Documentation/x')
expect_lines \
- "'x' 'root' 'root' 'root' q (0000000000000003 1 ) m 0444 at 1728337905 mt 1728337904 l 4 t 0 d 0"
+ "'x' 'root' 'root' 'root' q (0000000000000001 1 ) m 0444 at 1728337905 mt 1728337904 l 4 t 0 d 0"
out=$("${client[@]}" write 'shutdown' <<<1)
expect_lines ''
diff --git a/lib9p/tests/test_server/main.c b/lib9p/tests/test_server/main.c
index 7211322..f4b21db 100644
--- a/lib9p/tests/test_server/main.c
+++ b/lib9p/tests/test_server/main.c
@@ -111,59 +111,50 @@ static struct lib9p_srv_file_vtable api_file_vtable = {
enum { PATH_BASE = __COUNTER__ };
#define PATH_COUNTER __COUNTER__ - PATH_BASE
-#define FILE_COMMON(NAME) { \
- .vtable = &util9p_static_file_vtable, \
- \
- .u_name = "root", .u_num = 0, /* owner user */ \
- .g_name = "root", .g_num = 0, /* owner group */ \
- .m_name = "root", .m_num = 0, /* last-modified-by user */ \
- \
- .pathnum = PATH_COUNTER, \
- .name = NAME, \
- .perm = 0444, \
- .atime = 1728337905, \
- .mtime = 1728337904, \
- }
-
-#define DIR_COMMON(NAME) { \
- .vtable = &util9p_static_dir_vtable, \
- \
- .u_name = "root", .u_num = 0, /* owner user */ \
- .g_name = "root", .g_num = 0, /* owner group */ \
- .m_name = "root", .m_num = 0, /* last-modified-by user */ \
- \
- .pathnum = PATH_COUNTER, \
- .name = NAME, \
- .perm = 0555, \
- .atime = 1728337905, \
- .mtime = 1728337904, \
- }
+#define STATIC_FILE(STRNAME, SYMNAME) \
+ ((struct util9p_static_file){ \
+ ._util9p_static_common = { \
+ .vtable = &util9p_static_file_vtable, \
+ \
+ .u_name = "root", .u_num = 0, /* owner user */ \
+ .g_name = "root", .g_num = 0, /* owner group */ \
+ .m_name = "root", .m_num = 0, /* last-modified-by user */ \
+ \
+ .pathnum = PATH_COUNTER, \
+ .name = STRNAME, \
+ .perm = 0444, \
+ .atime = 1728337905, \
+ .mtime = 1728337904, \
+ }, \
+ .data_start = _binary_static_##SYMNAME##_start, \
+ .data_end = _binary_static_##SYMNAME##_end, \
+ })
-#define STATIC_FILE(STRNAME, SYMNAME) \
- &((static struct util9p_static_file){ \
- ._util9p_static_common = FILE_COMMON(STRNAME), \
- .data_start = _binary_static_##SYMNAME##_start, \
- .data_end = _binary_static_##SYMNAME##_end, \
+#define STATIC_DIR(STRNAME, ...) \
+ ((struct util9p_static_dir){ \
+ ._util9p_static_common = { \
+ .vtable = &util9p_static_dir_vtable, \
+ \
+ .u_name = "root", .u_num = 0, /* owner user */ \
+ .g_name = "root", .g_num = 0, /* owner group */ \
+ .m_name = "root", .m_num = 0, /* last-modified-by user */ \
+ \
+ .pathnum = PATH_COUNTER, \
+ .name = STRNAME, \
+ .perm = 0555, \
+ .atime = 1728337905, \
+ .mtime = 1728337904, \
+ }, \
+ .members = { __VA_ARGS__ __VA_OPT__(,) NULL }, \
})
-static struct util9p_static_dir root = {
- ._util9p_static_common = DIR_COMMON(""),
- .members = {
- &((static struct util9p_static_dir){
- ._util9p_static_common = DIR_COMMON("Documentation"),
- .members = {
- STATIC_FILE("x", Documentation_x),
- NULL
- },
- }),
- STATIC_FILE("README.md", README_md),
- &((struct api_file){
- .vtable = &api_file_vtable,
- .pathnum = PATH_COUNTER,
- }),
- NULL,
- },
-};
+/* NB: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118814 */
+static struct util9p_static_dir root =
+ STATIC_DIR("",
+ &STATIC_DIR("Documentation",
+ &STATIC_FILE("x", Documentation_x)),
+ &STATIC_FILE("README.md", README_md),
+ &((struct api_file){.vtable = &api_file_vtable, .pathnum = PATH_COUNTER}));
static implements_lib9p_srv_file *get_root(struct lib9p_srv_ctx *LM_UNUSED(ctx), struct lib9p_s LM_UNUSED(treename)) {
return &root;