Building & Testing triepack

Prerequisites

Requirement Minimum Version
CMake 3.16+
C compiler C99-compatible
C++ compiler C++11 (for C++ wrapper only)
Doxygen any (optional, for docs)

Basic Build

cmake -B build
cmake --build build
ctest --test-dir build

Build Options

Option Default Description
BUILD_TESTS ON Build the test suite
BUILD_EXAMPLES ON Build example programs
BUILD_JSON ON Build the triepack_json library
BUILD_DOCS OFF Generate Doxygen HTML documentation
ENABLE_COVERAGE OFF Instrument for code coverage reporting

Pass options with -D:

cmake -B build -DBUILD_DOCS=ON -DENABLE_COVERAGE=ON

Build Types

cmake -B build -DCMAKE_BUILD_TYPE=Release   # optimized, no debug info
cmake -B build -DCMAKE_BUILD_TYPE=Debug      # -g, assertions enabled
cmake -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo  # optimized + debug info

Cross-Compilation Notes

32-bit build on a 64-bit host

triepack supports both 32-bit and 64-bit targets. To build for 32-bit:

cmake -B build32 -DCMAKE_C_FLAGS=-m32 -DCMAKE_CXX_FLAGS=-m32
cmake --build build32

On Debian/Ubuntu you may need the multilib packages:

sudo apt-get install gcc-multilib g++-multilib

Embedded / bare-metal

triepack’s core library avoids heap allocation in the read path, making it suitable for ROM-based embedded use. Provide a CMake toolchain file:

cmake -B build-arm -DCMAKE_TOOLCHAIN_FILE=arm-none-eabi.cmake

Installing

cmake --install build --prefix /usr/local

This installs headers to <prefix>/include/triepack/ and libraries to <prefix>/lib/.


Testing

TriePack has comprehensive test suites across C, C++, Python, and JavaScript, with cross-language fixture validation ensuring binary compatibility.

Running C/C++ Tests

Build with tests enabled (on by default), then run via CTest:

cmake -B build -DBUILD_TESTS=ON -DBUILD_JSON=ON
cmake --build build
ctest --test-dir build --output-on-failure

To run a specific test by name:

ctest --test-dir build -R test_bitstream

Running Python Tests

cd bindings/python
pip install -e ".[test]"
pytest -v

Running JavaScript / TypeScript Tests

cd bindings/javascript && npm test
cd bindings/typescript && npm test

Test Summary

Suite Test Programs / Files Total Tests
C Bitstream 6 ~100
C Core 6 ~80
C JSON 4 ~100
C Cross-Language 1 14
C++ Wrappers 3 ~30
Examples (smoke) 7 7
C/C++ Total 27 ~330
Python 5 70
JavaScript 4 70
TypeScript 2 38
Grand Total 38 ~508

Test Organization

Tests live in tests/ and use the Unity test framework (v2.6.0), organized by component:

Cross-Language Fixture Tests

The tests/fixtures/ directory contains .trp files generated by the C library. Python, JavaScript, and TypeScript bindings each verify:

Adding a New Test

  1. Create a new source file in tests/, e.g. tests/test_feature.c.
  2. Register it in tests/CMakeLists.txt:
    triepack_add_c_test(test_feature test_feature.c triepack_core)
    
  3. Run ctest to verify it passes.

Code Coverage

Enable coverage instrumentation and generate an HTML report:

cmake -B build -DENABLE_COVERAGE=ON -DCMAKE_BUILD_TYPE=Debug
cmake --build build
ctest --test-dir build
cmake --build build --target coverage

The HTML report is written to build/coverage/index.html. Current coverage: 93.7% line coverage (remaining lines are malloc failure paths).