Qué hace
- Tests simples, con fixture, parametrizados y tipados
- Los fallos muestran la expresión, ambos valores, el archivo y la línea
- Filtros, etiquetas, repetición, orden aleatorio, procesos en paralelo
- Salida JUnit y JSON
- <code>ETL_EXPECT_NO_ALLOC</code> y <code>ETL_EXPECT_NO_LOCK</code>
- Tests de propiedades con shrinking, targets de fuzzing (libFuzzer/AFL), snapshots
- Tests de fallo de compilación a través de CMake
Medido
- 500 aserciones, mediana de 5 builds. Sin optimización: 0.84 s en GCC 15.2 y 0.90 s en MSVC 19.51
- Con <code>-O2</code>/<code>/O2</code>: 1.78 s y 1.92 s
Límites conocidos
- <code>NO_LOCK</code> solo intercepta en glibc. En Windows solo cuenta lo que se anuncia
- La salida JUnit se comprobó contra el esquema, todavía no en una CI real
Ethereal::Testing · Tier 0, prerequisite
Header-only assertions and registration (C++17), plus a small linked runner (Ethereal::Testing) and the main object (Ethereal::TestingMain). No exceptions, no RTTI, no allocation on the assertion path, no external dependency at all.
---
Usage
#include <ethereal/cpp/testing/testing.hpp>
ETL_TEST( TimeSuite, MonotonicNeverGoesBackwards ) { ETL_EXPECT_LE( a, b ); }
ETL_TEST_F( CMyFixture, DoesTheThing ) { ... } // protected SetUp/TearDown
ETL_TEST_P( ParamSuite, HandlesAllLevels, ELogLevel ) { ETL_EXPECT( Valid( Param ) ); }
ETL_TEST_VALUES( ParamSuite, HandlesAllLevels, ELogLevel::Trace, ELogLevel::Info );
ETL_TEST_T( TypedSuite, WorksForAllIntegers, int8_t, int32_t, int64_t ) { T x{}; ... }
ETL_TEST_WITH( Net, Slow, ( Ethereal::Testing::STestOptions{ "slow,network", 5000, false } ) )
{ ... } // tags, timeout in ms, expected failureadd_executable( ethereal-time-tests time_tests.cpp )
target_link_libraries( ethereal-time-tests PRIVATE Ethereal::Testing Ethereal::TestingMain )ETL_EXPECT* records and continues. ETL_ASSERT_* records and exits the test (TearDown runs all the same). Forms: ETL_EXPECT, _EQ/_NE/_LT/_LE/_GT/_GE, _NEAR, _STREQ (it counts the length: an embedded NUL takes part in the comparison), _SPAN_EQ (first differing offset and a hexadecimal window), _STATUS, _DEATH (out of process), ETL_ASSERT_T/_EQ/_NE/_LT/_GE, ETL_SKIP( "reason" ).
The failure output is the feature. Each form prints the text of the expression, both values, file and line. A struct described with ETL_META_DESCRIBE prints field by field ({ x = 1, y = 2 }), a described enum prints the name, a Meta::Sensitive field prints <sensitive>, and a type that cannot be printed shows its bytes instead of failing to compile. Each operand is evaluated once (ETL_EXPECT_EQ( i++, 0 ) increments once and shows the compared value). Integers of different signedness are compared by mathematical value (-1 != 0xFFFFFFFFu).
The runner
./ethereal-time-tests # everything
--filter 'TimeSuite.*:-*.Slow' # globs separated by ':', a leading '-' excludes
--tag '!slow' # ',' = OR, '+' = AND, '!' = NOT
--repeat 100 --fail-fast
--shuffle --seed 12345 # --no-shuffle to turn it off
--jobs 8 # processes in shards
--isolate # one process per test
--output junit --out results.xml # or --output json
--list --timeout 2000
--property-seed N --property-runs N
--snapshot-dir D --update-snapshots --fuzz-corpus D- **Shuffling turns on by itself when the
CIvariable exists**, with the seed printed on the first line and reproducible with--seed. - **
--jobsis one process per shard (no thread per test). Before each test the child writes the test name to a file. A crash or an exceeded timeout is attributed to the right test, and the shard restarts right after** the one that broke. - Exit codes: 0 everything passed. 1 some failure. 2 invalid usage. 124 timeout expired.
- The output is in English, with the labels
[ RUN ],[ OK ],[ FAILED ],[ SKIPPED ],[ XFAIL ](failed as expected),[ XPASS ](passed when it should not have) and[ TIMEOUT ], and the summaryN passed, N failed, N skipped, N failed as expected (seed S). Until 2026-10-05 these labels and messages were in Portuguese ([ CORRE ],[ FALHOU ]...): a script that searched for them has to change along with them.
---
Instrumentation
| What it is | How it sees | |
|---|---|---|
ETL_EXPECT_NO_ALLOC { ... } | fails on any operator new inside the scope, on the thread | TestingMain replaces all forms of operator new. Without TestingMain the scope fails, with a sentence: it never passes because it is not measuring |
ETL_EXPECT_NO_LOCK { ... } | fails on any lock acquisition inside the scope, on the thread | on glibc, TestingMain intercepts pthread_mutex_*, pthread_rwlock_* and pthread_spin_*: every std::mutex, shared_mutex, timed_mutex in the executable. On other platforms it only counts callers of NoteLockAcquired(), and a note says so |
CTestAllocator / CFailingAllocator / TStdAllocator | count, bytes, peak, leaks. Fail the Nth allocation. Adapter for containers | explicit |
CManualClock, CMemoryTransport, CFailingTransport, CRecordingSink, CNullSerializer | the test doubles everyone needs | explicit |
ETL_PROPERTY( S, N, const T & x ) | generators (integers, floats, bool, vectors, strings with hostile Unicode, pairs, described structs) and shrinking | seed printed, --property-seed repeats |
ETL_DIFFERENTIAL( S, N, Input ) | an oracle against the other implementations | |
ETL_FUZZ_TARGET( Name, p, n ) | corpus replay test + 256 random inputs. With -DETL_FUZZ_LIBFUZZER or -DETL_FUZZ_STDIN and ETL_FUZZ_ENTRY( Name ) it is a libFuzzer or AFL target | see below |
ETL_EXPECT_SNAPSHOT( "name", text ) | compares with a committed golden file | --update-snapshots writes |
CBarrier, SpinUntil, RunInterleaved | barrier, wait with a timeout, N repetitions with shuffled start order | |
etl_add_compile_fail_test() (CMake) | a file that must fail to compile, with the required sentence in the compiler output | include( EtherealTesting ) |
Fuzzing turns a finding into a regression with one copy. The failing input is always named: the corpus one by its file, the random one saved to a temporary file with the instruction to copy it to <corpus>/<Name>/. In external engine mode (libFuzzer/AFL) a failing assertion aborts the process, because the engine only keeps what breaks. That executable links Ethereal::Testing but not TestingMain (the main is the one from ETL_FUZZ_ENTRY).
The lock hook needs the dynamic linker. A -static executable must define ETL_TESTING_NO_LOCK_HOOK when compiling TestingMain. With ASan and TSan, the interception forwards to the sanitizer's interceptor, and TSan keeps seeing the locks (measured: no false positives with the lock, and the real race conditions are still reported).
---
Measurements
Reproducible with tools/testing_check/measure_500.sh (GCC, on WSL) and measure_500_msvc.ps1 (MSVC, with vcvars64). The file comes from gen_500.py: 500 assertions of every form, in 50 tests with real content (std::string, two std::vector, a described struct and enum). All 500 pass when the file runs. Five builds per mode, median:
| Build | GCC 15.2 | MSVC 19.51 | Clang |
|---|---|---|---|
500-assertion file, -O0 / /Od | ✅ 0.84 s | ✅ 0.90 s | not measured |
500-assertion file, -O2 / /O2 | ✅ 1.78 s | ✅ 1.92 s (one of the five at 2.30) | not measured |
Only the #include and one test, -O0/-O2 | 0.30 / 0.36 s | 0.56 / 0.61 s | not measured |
**The margin at -O2 is short, and that needs to be said.** The breakdown on MSVC /O2: the same file without the 500 assertions (only the test content) compiles in ~1.45 s, so the 500 assertions cost ~0.45 s, less than 1 ms each. The rest is the content the generator put in the tests. Before the failure path was moved out of line (noinline/cold), GCC -O2 took 2.2 to 2.3 s, 76% in code generation: the message formatting was copied into each assertion.
---
Implementation status
| Criterion (spec §9) | Status |
|---|---|
| External dependencies | ✅ none |
| Build: 500 assertions < 2 s on the three compilers | ✅ GCC and MSVC, -O0 and -O2 (see the margin above) · Clang not measured: there is no Clang on this machine |
| Failure output: expression, both values, file and line | ✅ in all forms. Checked line by line by testing.fails |
| Span output: first offset + hex window | ✅ first differing offset: 37 (0x25) and the byte between [ ] |
-fno-exceptions / -fno-rtti | ✅ testing.selftest.noexc: the entire runner recompiled with -fno-exceptions -fno-rtti (GCC) and /EHs-c- /GR- _HAS_EXCEPTIONS=0 (MSVC) |
| Shuffle by default in CI, repeatable seed | ✅ turns on with CI. testing.order proves that the same seed gives the same order and that the order changes with another one |
| Parallel in processes, results equal to serial | ✅ testing.parallel compares serial with --jobs 4 |
| Crash attribution | ✅ testing.shards.assign: the abort and the timeout belong to the right test, and the next one in the same shard runs |
| JUnit validates against the schema, consumed by a real CI | ⚠️ **meets Jenkins' junit-10.xsd**, the strictest one (checked by check_junit.py, with the rules taken from the XSD and a negative control that catches 7 planted defects), and the numbers match the cases. A deliberate failure carries U+FFFF in the message (well-formed UTF-8, forbidden in XML 1.0) and the file stays readable. Three testing.junit.* tests, only where Python is present (on this machine: GCC. Windows has no Python, and the writer is the same code). Consumed by a real CI: not done, there is no CI here |
| No allocation: catches an allocation three calls down | ✅ Fail.AllocationThreeLevelsDown (the pointer escapes through a volatile global: GCC -O2 eliminates a local new+delete, and the test would prove nothing) |
No locks (NO_LOCK, §5.2) | ✅ on glibc: Fail.LockThreeLevelsDown requires exactly 2 (a std::mutex and a std::shared_mutex, three calls down) · ⚠️ Windows and macOS: no interception, it only counts those who report themselves, and the output says so (the test is skipped, with the reason) |
| Property shrinking on a planted defect | ✅ vector without byte 42 → [1] { 42 }. Integer < 1000 → 1000 |
| Compile-fail tests with the right message | ✅ cf.meta.* (4) and cf.testing.no_generator require the static_assert sentence. cf.control.compiles proves that the mechanism fails a file that compiles. It is a CMake function (etl_add_compile_fail_test), in place of the spec's C++ macro ETL_EXPECT_COMPILE_FAIL: a file that does not compile cannot be tested from inside C++ |
| The framework tests itself, including failures verified as failures | ✅ testing.selftest (must pass) and testing.fails (17 deliberate failures, each message required by testing_check.cmake, and NAO_DEVIA_CHEGAR forbidden) |
| Fuzz: committed corpus, reproducer replay | ✅ testing.fuzz.corpus (two committed files run) · the failing input is named/saved (testing.fails) · ✅ AFL mode: testing.fuzz.stdin (the good one exits 0, the defective one aborts) · libFuzzer did not run (it needs Clang) |
| Sanitizers ASan, UBSan, TSan | ✅ GCC 15.2: all testing.* under ASan+UBSan and under TSan, zero reports, including the binary that fails on purpose, in process and in shards · **MSVC /fsanitize=address did not run** |
Counts on this machine: GCC 15.2 (WSL, build/linux-release) 102 of 102 with ctest -j8, twice in a row. MSVC 19.51 (build/vs-dev) 108 of 108 in Release with ctest -j8, three times in a row, and the testing.* tests also in Debug (the debug CRT does not open windows). No warnings in the Testing targets on either.
**ctest -j8 exposed five tests from other modules that assert timings in nanoseconds** (event.signal, guard, platform.modules, plugin.manifest, time.civil): they passed alone and failed with the CPU contended. They are marked RUN_SERIAL, and ctest runs them separately. The targets themselves did not change.
macOS: the runner's __APPLE__ branch (_NSGetExecutablePath) has only gone through the syntax probe (macos.syntax), which does not prove that it compiles on Darwin.
---
C layer
There is none, on purpose, and there is no ethereal/c/testing/ folder. The framework is made of C++ macros that register functions through static objects, compare by template and print the expression, and the test doubles (IClock, ITransport) are C++ interfaces. None of that has an equivalent worth having in C. The library's C layers are tested in their own pattern: tests/<m>_c_abi.c, compiled as C11 and C17 without extensions, with Check( bOk, "text" ), counters and a return of 1 on failure, registered by etl_add_cabi_test as <m>.cabi.c11|c17.
---
Non-goals
Coverage collection (use the compiler's), mutation testing, BDD syntax, a graphical runner, a results dashboard, mock generation. The SDK seams (IClock, ITransport, ...) are tested by writing the small test double, and the ones everyone needs already come here.