BRAIDGROUP
RESEARCH & DEV
32. Documentation

Testing

Test Targets

The Braid C tests are registered in braid-lang/CMakeLists.txt via add_cpu_test(). Each target is a standalone executable:

TargetSourcePurpose
test-ternarytest_ternary_matmul.cTernary packing, unpacking, and ternary matrix multiplication
test-hierarchical-headtest_hierarchical_head.cHierarchical tree-based classification head construction and loss
test-local-learningtest_local_learning.cLocal learning rules, ridge regression, LoRA-style updates
test-cpu-convergencetest_cpu_convergence.cEnd-to-end weight convergence over multiple training steps
test-diameter-steptest_diameter_step.cDiameter training step with target tensor generation
test-tensor-transposetest_tensor_transpose.cN-dimensional tensor transpose operations (views)
test-mempool-ctest_mempool_c.cMemory pool alloc/free, arena allocator for tensors
test-llm-apitest_llm_api.cLLM config defaults, model creation, forward pass, training step
test-cpu-streaming-edgetest_cpu_streaming_edge.cEdge cases: null engine, null model, null input handling
test-cpu-train-drivertest_train_cpu_driver.cNull 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.