Testing
Test Targets
The Braid C tests are registered in braid-lang/CMakeLists.txt via add_cpu_test(). Each target is a standalone executable:
| Target | Source | Purpose |
|---|---|---|
test-ternary | test_ternary_matmul.c | Ternary packing, unpacking, and ternary matrix multiplication |
test-hierarchical-head | test_hierarchical_head.c | Hierarchical tree-based classification head construction and loss |
test-local-learning | test_local_learning.c | Local learning rules, ridge regression, LoRA-style updates |
test-cpu-convergence | test_cpu_convergence.c | End-to-end weight convergence over multiple training steps |
test-diameter-step | test_diameter_step.c | Diameter training step with target tensor generation |
test-tensor-transpose | test_tensor_transpose.c | N-dimensional tensor transpose operations (views) |
test-mempool-c | test_mempool_c.c | Memory pool alloc/free, arena allocator for tensors |
test-llm-api | test_llm_api.c | LLM config defaults, model creation, forward pass, training step |
test-cpu-streaming-edge | test_cpu_streaming_edge.c | Edge cases: null engine, null model, null input handling |
test-cpu-train-driver | test_train_cpu_driver.c | Null and invalid config validation for training pipeline |
Additional Braid-language test files (.bd or .br) exist in braid-lang/tests/ covering tensors, autograd, transformer, tokenizer, optimizer, quantization, diameters, Bond/Blend UI, and Junction apps.
Running Tests
Use ctest to run all registered C tests from the build directory:
cd braid-lang/build cmake --build . ctest --output-on-failure
Run a specific test target:
ctest -R test-ternary -V
Or run individual test executables directly:
./tests/test-ternary ./tests/test-cpu-convergence
For Braid-language tests (.bd files), use:
braidc run tests/test_tensor_ops.bd
Writing New Tests
C tests follow a pattern: each test function returns 0 on pass, nonzero on failure. The run_test() helper catches SIGABRT for structured testing. Register new tests in CMakeLists.txt:
add_cpu_test(test-my-feature tests/test_my_feature.c)
Braid-language tests are plain .bd files that can be run directly with braidc run.