aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-06-10 13:14:08 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-06-14 08:27:03 +0200
commitc7a7a30219dbb61d7c378d2c123ebaf58a5541b9 (patch)
tree82d92b6c2a001456ecd6198953b19c6a57e9d33f
parent4db7a34e62afbfbf05d38d66ffcc5fc0f4de06c3 (diff)
downloadffwd-c7a7a30219dbb61d7c378d2c123ebaf58a5541b9.tar.gz
ffwd-c7a7a30219dbb61d7c378d2c123ebaf58a5541b9.zip
tests: make test_workspace hermetic, add it to make test
-rw-r--r--.gitignore1
-rw-r--r--Makefile12
-rw-r--r--tests/test_workspace.c29
3 files changed, 35 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
index ce8bceb..a65605d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,7 @@ tests/test_safetensors
tests/test_bf16_model
tests/test_server
tests/test_tokenizer
+tests/test_workspace
bench/bench_tokenizer
coverage/
book/
diff --git a/Makefile b/Makefile
index a3a510b..420c3c2 100644
--- a/Makefile
+++ b/Makefile
@@ -165,6 +165,8 @@ TEST_TOKENIZER_SRCS = tests/test_tokenizer.c qwen_tokenizer.c $(KERNEL_SRCS)
TEST_SAFETENSORS_SRCS = tests/test_safetensors.c qwen_safetensors.c
TEST_BF16_SRCS = tests/test_bf16_model.c embed.c qwen_safetensors.c \
$(KERNEL_SRCS)
+TEST_WORKSPACE_SRCS = tests/test_workspace.c embed.c qwen_tokenizer.c \
+ qwen_safetensors.c $(KERNEL_SRCS)
TEST_SERVER_SRCS = tests/test_server.c embed.c embed_distributed.c \
qwen_tokenizer.c qwen_safetensors.c $(KERNEL_SRCS) \
deps/ae/ae.c deps/ae/anet.c deps/ae/monotonic.c
@@ -184,6 +186,9 @@ test:
$(CC) $(TEST_CC_FLAGS) -o tests/test_bf16_model \
$(TEST_BF16_SRCS) -lm -lpthread
./tests/test_bf16_model
+ $(CC) $(TEST_CC_FLAGS) -o tests/test_workspace \
+ $(TEST_WORKSPACE_SRCS) -lm -lpthread
+ ./tests/test_workspace
$(CC) $(TEST_CC_FLAGS) $(TEST_BLAS_CFLAGS) $(CJSON_CFLAGS) -Ideps/ae \
-o tests/test_server $(TEST_SERVER_SRCS) \
-lm -lpthread $(TEST_BLAS_LDFLAGS) $(CJSON_LDFLAGS)
@@ -199,7 +204,7 @@ COV_DIR = coverage
COV_FLAGS = -fprofile-instr-generate -fcoverage-mapping -O0
COV_BINS = tests/test_kernels_generic tests/test_kernels_blas \
tests/test_tokenizer tests/test_safetensors \
- tests/test_bf16_model tests/test_server
+ tests/test_bf16_model tests/test_workspace tests/test_server
# Report on project sources only, not the harnesses or vendored deps.
COV_IGNORE = -ignore-filename-regex='deps/|tests/'
@@ -227,6 +232,9 @@ coverage:
$(CC) $(TEST_CC_FLAGS) $(COV_FLAGS) -o tests/test_bf16_model \
$(TEST_BF16_SRCS) -lm -lpthread
LLVM_PROFILE_FILE=$(COV_DIR)/bf16_model.profraw ./tests/test_bf16_model
+ $(CC) $(TEST_CC_FLAGS) $(COV_FLAGS) -o tests/test_workspace \
+ $(TEST_WORKSPACE_SRCS) -lm -lpthread
+ LLVM_PROFILE_FILE=$(COV_DIR)/workspace.profraw ./tests/test_workspace
$(CC) $(TEST_CC_FLAGS) $(COV_FLAGS) $(TEST_BLAS_CFLAGS) $(CJSON_CFLAGS) -Ideps/ae \
-o tests/test_server $(TEST_SERVER_SRCS) \
-lm -lpthread $(TEST_BLAS_LDFLAGS) $(CJSON_LDFLAGS)
@@ -312,6 +320,6 @@ clean:
$(TARGET) $(SERVER_TARGET) $(LIB) libpplxembed.dylib libpplxembed.so \
tests/test_kernels_generic tests/test_kernels_blas \
tests/test_safetensors tests/test_bf16_model tests/test_server \
- tests/test_tokenizer \
+ tests/test_tokenizer tests/test_workspace \
bench/bench_tokenizer
rm -rf $(COV_DIR)
diff --git a/tests/test_workspace.c b/tests/test_workspace.c
index a87e9f8..7a6ed03 100644
--- a/tests/test_workspace.c
+++ b/tests/test_workspace.c
@@ -1,13 +1,18 @@
/* tests/test_workspace.c - model/workspace API lifecycle tests.
- * Runs via `make test`. Uses a tiny synthetic model. */
+ * Hermetic by default (synthesizes a tiny model + tokenizer fixture);
+ * pass a MODEL_DIR to run the same checks against real weights, which is
+ * what scripts/check_workspace_api.py does. Runs via `make test`. */
#include "embed.h"
#include "qwen_tokenizer.h"
+#include "tiny_model.h"
+#include "tok_fixture.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
static float max_abs_diff(const float *a, const float *b, int n)
{
@@ -21,12 +26,26 @@ static float max_abs_diff(const float *a, const float *b, int n)
int main(int argc, char **argv)
{
- if (argc != 2) {
- fprintf(stderr, "usage: %s MODEL_DIR\n", argv[0]);
+ char fixture_dir[1024];
+ const char *model_dir;
+ if (argc == 2) {
+ model_dir = argv[1];
+ } else if (argc == 1) {
+ /* Tiny hidden size keeps it fast; the vocab must cover every id the
+ * byte-complete tokenizer fixture can emit. */
+ tm_dims_t dims = {4, 2, 1, 2, 8, TF_VOCAB_SIZE};
+ snprintf(fixture_dir, sizeof(fixture_dir), "%s/pplx-ws-test-XXXXXX",
+ getenv("TMPDIR") ? getenv("TMPDIR") : "/tmp");
+ if (!mkdtemp(fixture_dir) || tf_write_vocab(fixture_dir) != 0 ||
+ tm_write_model_dims(fixture_dir, "F32", &dims) != 0) {
+ fprintf(stderr, "fixture creation failed\n");
+ return 2;
+ }
+ model_dir = fixture_dir;
+ } else {
+ fprintf(stderr, "usage: %s [MODEL_DIR]\n", argv[0]);
return 2;
}
-
- const char *model_dir = argv[1];
char vocab_path[4096];
snprintf(vocab_path, sizeof(vocab_path), "%s/vocab.json", model_dir);