summaryrefslogtreecommitdiff
path: root/lib9p/tests
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-01-09 23:29:30 -0700
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-01-11 23:33:26 -0700
commitd29cb3f3deda2ae55fbccfdaae3b2481410a0894 (patch)
tree0f00fdf307cfa78337c50a43e2ff842942922af5 /lib9p/tests
parentf6b4897e86ee68836794caa641cf0d4a93131c0f (diff)
Add basic smoke tests for the 9p server
Diffstat (limited to 'lib9p/tests')
-rwxr-xr-xlib9p/tests/runtest45
-rw-r--r--lib9p/tests/test_server/main.c4
2 files changed, 47 insertions, 2 deletions
diff --git a/lib9p/tests/runtest b/lib9p/tests/runtest
new file mode 100755
index 0000000..29d2089
--- /dev/null
+++ b/lib9p/tests/runtest
@@ -0,0 +1,45 @@
+#!/usr/bin/env bash
+# lib9p/tests/runtest - TODO
+#
+# Copyright (C) 2025 Luke T. Shumaker <lukeshu@lukeshu.com>
+# SPDX-License-Identifier: AGPL-3.0-or-later
+
+set -euE -o pipefail
+set -x
+
+valgrind --error-exitcode=2 ./tests/test_server/test_server &
+server_pid=$!
+# shellcheck disable=SC2064
+trap "kill $server_pid || true; wait $server_pid || true" EXIT
+server_addr='localhost:9000'
+
+client=(9p -a "$server_addr")
+
+expect_lines() (
+ { set +x; } &>/dev/null
+ printf >&2 '+ diff -u expected.txt actual.txt\n'
+ diff -u <(printf '%s\n' "$@") <(printf '%s\n' "$out")
+)
+
+while [[ -d /proc/$server_pid && "$(readlink /proc/$server_pid/fd/4 2>/dev/null)" != socket:* ]]; do sleep 0.1; done
+
+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'
+
+out=$("${client[@]}" ls -l 'Documentation/')
+expect_lines \
+ '--r--r--r-- M 0 root root 4 Oct 7 15:51 x'
+
+out=$("${client[@]}" read 'README.md')
+expect_lines \
+ 'Hello, world!'
+
+out=$("${client[@]}" read 'Documentation/x')
+expect_lines \
+ 'foo'
+
+out=$("${client[@]}" stat 'Documentation/x')
+expect_lines \
+ "'x' 'root' 'root' 'root' q (0000000000000009 1 ) m 0444 at 1728337905 mt 1728337904 l 4 t 0 d 0"
diff --git a/lib9p/tests/test_server/main.c b/lib9p/tests/test_server/main.c
index adeba38..a6e4eeb 100644
--- a/lib9p/tests/test_server/main.c
+++ b/lib9p/tests/test_server/main.c
@@ -107,17 +107,17 @@ struct lib9p_srv srv = {
static COROUTINE init_cr(void *) {
cr_begin();
+ sleep_for_ms(1);
+
for (int i = 0; i < CONFIG_SRV9P_NUM_CONNS; i++) {
char name[] = {'r', 'e', 'a', 'd', '-', hexdig[i], '\0'};
if (!coroutine_add(name, read_cr, &srv))
error(1, 0, "coroutine_add(read_cr, &srv)");
- sleep_for_s(1);
}
for (int i = 0; i < 2*CONFIG_SRV9P_NUM_CONNS; i++) {
char name[] = {'w', 'r', 'i', 't', 'e', '-', hexdig[i], '\0'};
if (!coroutine_add(name, lib9p_srv_write_cr, &srv))
error(1, 0, "coroutine_add(lib9p_srv_write_cr, &srv)");
- sleep_for_s(1);
}
cr_exit();