summaryrefslogtreecommitdiff
path: root/lib9p/tests
diff options
context:
space:
mode:
Diffstat (limited to 'lib9p/tests')
-rwxr-xr-xlib9p/tests/runtest24
-rw-r--r--lib9p/tests/test_server/main.c46
-rw-r--r--lib9p/tests/test_server/static/Documentation/x6
-rw-r--r--lib9p/tests/test_server/static/README.md6
4 files changed, 40 insertions, 42 deletions
diff --git a/lib9p/tests/runtest b/lib9p/tests/runtest
index 0966000..c2f6c41 100755
--- a/lib9p/tests/runtest
+++ b/lib9p/tests/runtest
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
-# lib9p/tests/runtest - TODO
+# lib9p/tests/runtest - Simple tests for the 9P `test_server`
#
# Copyright (C) 2025 Luke T. Shumaker <lukeshu@lukeshu.com>
# SPDX-License-Identifier: AGPL-3.0-or-later
@@ -25,25 +25,37 @@ while [[ -d /proc/$server_pid && "$(readlink /proc/$server_pid/fd/4 2>/dev/null)
out=$("${client[@]}" ls -l '')
expect_lines \
- 'd-r-xr-xr-x M 0 root root 0 Oct 7 15:51 Documentation' \
- '--r--r--r-- M 0 root root 14 Oct 7 15:51 README.md' \
- '---w--w--w- M 0 root root 0 Oct 7 15:51 shutdown'
+ 'd-r-xr-xr-x M 0 root root 0 Oct 7 15:51 Documentation' \
+ '--r--r--r-- M 0 root root 166 Oct 7 15:51 README.md' \
+ '---w--w--w- M 0 root root 0 Oct 7 15:51 shutdown'
out=$("${client[@]}" ls -l 'Documentation/')
expect_lines \
- '--r--r--r-- M 0 root root 4 Oct 7 15:51 x'
+ '--r--r--r-- M 0 root root 162 Oct 7 15:51 x'
out=$("${client[@]}" read 'README.md')
expect_lines \
+ '<!--' \
+ ' README.md - test static file' \
+ '' \
+ ' Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com>' \
+ ' SPDX-License-Identifier: AGPL-3.0-or-later' \
+ '-->' \
'Hello, world!'
out=$("${client[@]}" read 'Documentation/x')
expect_lines \
+ '<!--' \
+ ' Documentation/x - test static file' \
+ '' \
+ ' Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com>' \
+ ' SPDX-License-Identifier: AGPL-3.0-or-later' \
+ '-->' \
'foo'
out=$("${client[@]}" stat 'Documentation/x')
expect_lines \
- "'x' 'root' 'root' 'root' q (0000000000000001 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 162 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 2c64cd4..c60dd71 100644
--- a/lib9p/tests/test_server/main.c
+++ b/lib9p/tests/test_server/main.c
@@ -73,8 +73,8 @@ static struct lib9p_stat api_stat(struct api_file *self, struct lib9p_srv_ctx *c
.kern_dev = 0,
.file_qid = api_qid(self),
.file_mode = 0222,
- .file_atime = 1728337905,
- .file_mtime = 1728337904,
+ .file_atime = UTIL9P_ATIME,
+ .file_mtime = UTIL9P_MTIME,
.file_size = 0,
.file_name = lib9p_str("shutdown"),
.file_owner_uid = lib9p_str("root"),
@@ -113,45 +113,19 @@ static uint32_t api_pread(struct api_file *, struct lib9p_srv_ctx *, void *, uin
assert_notreached("not readable");
}
-/* file tree ******************************************************************/
+#define lo_box_api_as_lib9p_srv_file(obj) util9p_box(api, obj)
-#define _box(nam, obj) \
- ((struct lib9p_srv_file){ \
- .self = obj, \
- .vtable = (void*)&_lo_##nam##_lib9p_srv_file_vtable, \
- })
-#define lo_box_util9p_static_file_as_lib9p_srv_file(obj) _box(util9p_static_file, obj)
-#define lo_box_util9p_static_dir_as_lib9p_srv_file(obj) _box(util9p_static_dir, obj)
-#define lo_box_api_as_lib9p_srv_file(obj) _box(api, obj)
+/* file tree ******************************************************************/
enum { PATH_BASE = __COUNTER__ };
#define PATH_COUNTER __COUNTER__ - PATH_BASE
-#define STATIC_COMMON(STRNAME, MODE) \
- { \
- .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 = MODE, \
- .atime = 1728337905, \
- .mtime = 1728337904, \
- }
-
-#define STATIC_FILE(STRNAME, SYMNAME) \
- lo_box_util9p_static_file_as_lib9p_srv_file(&((struct util9p_static_file){ \
- ._util9p_static_common = STATIC_COMMON(STRNAME, 0444), \
- .data_start = _binary_static_##SYMNAME##_start, \
- .data_end = _binary_static_##SYMNAME##_end, \
- }))
-
-#define STATIC_DIR(STRNAME, ...) \
- lo_box_util9p_static_dir_as_lib9p_srv_file(&((struct util9p_static_dir){ \
- ._util9p_static_common = STATIC_COMMON(STRNAME, 0555), \
- .members = { __VA_ARGS__ LO_NULL(lib9p_srv_file) }, \
- }))
+#define STATIC_FILE(STRNAME, SYMNAME) \
+ UTIL9P_STATIC_FILE(PATH_COUNTER, STRNAME, \
+ .data_start = _binary_static_##SYMNAME##_start, \
+ .data_end = _binary_static_##SYMNAME##_end)
+#define STATIC_DIR(STRNAME, ...) \
+ UTIL9P_STATIC_DIR(PATH_COUNTER, STRNAME, __VA_ARGS__)
struct lib9p_srv_file root =
STATIC_DIR("",
diff --git a/lib9p/tests/test_server/static/Documentation/x b/lib9p/tests/test_server/static/Documentation/x
index 257cc56..b9b08d4 100644
--- a/lib9p/tests/test_server/static/Documentation/x
+++ b/lib9p/tests/test_server/static/Documentation/x
@@ -1 +1,7 @@
+<!--
+ Documentation/x - test static file
+
+ Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com>
+ SPDX-License-Identifier: AGPL-3.0-or-later
+-->
foo
diff --git a/lib9p/tests/test_server/static/README.md b/lib9p/tests/test_server/static/README.md
index af5626b..c2d88ed 100644
--- a/lib9p/tests/test_server/static/README.md
+++ b/lib9p/tests/test_server/static/README.md
@@ -1 +1,7 @@
+<!--
+ README.md - test static file
+
+ Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com>
+ SPDX-License-Identifier: AGPL-3.0-or-later
+-->
Hello, world!