asoma.dev · the C reference for libose
libose
the C library every o.se host is built on
Loading...
Searching...
No Matches
ose_test Directory Reference
Directory dependency graph for ose_test:

Files

 
ose_test_bundle_literal.h
 
ose_test_common.h
 provides utility functions and global variables for testing
 
ose_test_ctosc.h
 provides a compile-time OSC implementation.
 
ose_test_unit.h
 provides unit testing functions for OSE/OSC bundles.
 
ose_test_vm_literal.h

Detailed Description

ose_test

The test harness for libose and the modules that build on it.

The one rule

Test code never uses the library under test to build its expected values. They are constructed by preprocessor macros in ose_test_ctosc.h:

B(BE_M(A(0, ""), T(1, "i"), Di(32)))
#define BE_M(...)
Instantiate a bundle element message.
Definition ose_test_ctosc.h:272
#define T(n, s)
Instantiate a message type string.
Definition ose_test_ctosc.h:113
#define B(...)
Instantiate a top-level OSC bundle.
Definition ose_test_ctosc.h:339
#define Di(i)
Instantiate a 32-bit integer message item.
Definition ose_test_ctosc.h:122
#define A(n, a)
Instantiate a message address.
Definition ose_test_ctosc.h:102

That is a bundle containing one message with an empty address, typetag i, and the integer 32 — assembled by the C preprocessor into bytes, without calling libose at all. So a bug in the library cannot make a test agree with it, which is the failure mode that makes a green suite worthless.

What is here

file
ose_test_ctosc.h the macros above: expected OSC, built by the preprocessor
ose_test_unit.h the test macros — UNIT_TEST_BUNDLE_TRANSFORM, UNIT_TEST_WITH_VM, and friends
ose_test_common.h reporting, comparison, the signal handling that lets a test expect an assert
ose_test_bundle_literal.h, ose_test_vm_literal.h generated fixtures — a known-good bundle and a known-good VM, byte by byte
tools/emit_bundle_literal.c, tools/emit_vm_literal.c what generates them

The fixtures are generated rather than hand-written because they are several thousand bytes of layout-sensitive hex. They went stale once when the context layout changed underneath them and nobody noticed, which is what the generators exist to prevent. Regenerate after any change to the context layout; the header of each generator says how.

Running

From libose:

make -C test/ose_test check

Twelve suites. Each binary exits nonzero if any of its tests fail, so check is usable as a CI gate.

A note on configuration

Every suite is built with OSE_CONF_DEBUG and OSE_QUIET_ASSERT — asserts live — because an assert firing is a legitimate way to show that a precondition is enforced.

ut_ose_preconditions is the exception, built deliberately without them. It asks what the library does when a precondition is violated and there is no assert to catch it, which is the configuration that ships. That cannot be asked with asserts on, because a quiet assert still calls abort().