A green test suite proves less than it seems. It shows the current code passes the current tests. It does not show the tests would notice if the code broke. A suite that never actually checks the consumed count will stay green when the consumed count is wrong. The way to measure that is mutation testing: make a small, deliberate bug, called a mutant, run the suite, and expect it to fail. A failing suite has killed the mutant. A mutant that survives points at a contract nobody is checking.
The project keeps its mutants in manifest.json, each as an exact before and after string in telemetry.c. The checker applies them one at a time and requires every one to be killed:
ignore checksum: the checksum comparison becomes if (0).
accept unsupported version and accept unsupported type: one header condition is replaced by 0.
reverse field byte order:read_u16 combines its octets little-endian.
Each one maps to a clause of the header contract, and each is killed by a specific assertion. Mutants are kept in a file, rather than tried once by hand, so the evidence can be rerun after every future change.
Predict and run
Read the program before pressing Run. Predict the output, then explain why consumed <= supplied alone would not catch a decoder that always returns zero.
The upper bound is satisfied by 10, and also by 0. A decoder that never makes progress passes it and leaves its caller looping forever. Killing that mutant needs a second assertion: when a healthy decoder is given at least one byte, it consumes at least one. The project's chunk loop asserts result.consumed > 0, and its partition test asserts the exact count, which kills both "too few" and "too many".
What you will use
A function under test and several mutants of it. Each mutant differs from the original in one small change.
Function pointers. One suite function takes the implementation as a parameter, so the same tests run against every version.
Targeted cases. At least one case per rule, chosen so the rule's mutant gives a different answer from the original.
A survivor report. Print which mutants survived, because each one names a missing test.
Plan before you type
Read the original valid_header and each mutant, and write down which input would tell them apart.
Write int suite(int (*valid)(const unsigned char *)) that returns 1 only if every case gives the expected answer.
Start with a single case, the valid fixture header, and run it against all versions. Note which mutants survive.
Add one rejection case per rule until every mutant is killed.
Confirm the original still passes after every addition.
Prove it can fail
Before you add the rejection cases, run the suite with only the valid header. You should see original: passes and only the byte-swap mutant killed, because it is the only mutant that rejects a valid header. Every other mutant accepts more than it should, and a test that only feeds good input cannot see that. Then add your cases one at a time and watch each mutant flip from SURVIVED to killed.
Mistakes worth checking for
The original fails your suite. One expected answer is wrong, often a typo in a test header. Fix the test before judging any mutant.
A mutant survives every test you add. It may be equivalent to the original, such as length <= 16 && length == 4 with the first clause removed, which accepts exactly the same headers. Equivalent mutants cannot be killed and should be dropped from the manifest, with a note saying why.
A rejection test kills the wrong mutant. The test header differs from the valid one in two places, so it is rejected for a different reason. Change exactly one byte per case.
A mutant crashes instead of failing. It caused undefined behavior, such as an out-of-bounds write. A crash counts as killed, but it is not reliable evidence; run such mutants under AddressSanitizer so the failure is deterministic.
The suite passes only in a debug build. It relied on assert, and the release build defined NDEBUG. Keep test assertions enabled.
Practice
Exercise
Your turn
The starter has an original valid_header and four mutants. Write suite so that it passes the original and kills all four. Print:
Each mutant is killed by an input where it answers differently from the original. Three of the mutants are too permissive, so they need inputs the original rejects; one is too strict, so the valid header already catches it.
Hint 2: a first step
Store cases as {header bytes, expected} pairs in an array. Start with {0x54, 1, 1, 0, 4} expected 1, then add {0x55, 1, 1, 0, 4} expected 0 for the magic rule.
Every case changes one byte of the valid header, so each rejection can only be caused by the rule it names. The type and "too long" cases kill no mutant here, and that is fine: they protect against mutants you have not written yet. Below, the real suite runs against the real decoder. Try one of the manifest's mutations by hand in telemetry.c, predict which assertion will fire, run, and restore the original before the next one. Day 7 assembles the whole project.
Find the assertions for consumed counts and output sentinels in test_telemetry.c. Then replace the checksum comparison in telemetry.c with if (0), predict which loop fails first, and run. Header flips are still rejected by the header checks, but the single-byte corruption loop's first payload flip, byte 5, turns sensor 1 into sensor 257. That is a valid sensor, so with the checksum gone the frame decodes and the assertion on DECODE_ERROR fires. Restore the line before trying the next mutation. Do not rely on the exact wording of assertion messages, which varies between C libraries.
Completion is saved in this browser only. It does not measure mastery.