|
Safe Data API Test Specification
Annotated ztest sources of the Safe Data API
|
|
v0.0-dev+gbb519af | |
Functions | |
| void | test_init_and_verify (void) |
| Init seals and verification passes. | |
| void | test_read_roundtrip (void) |
| Read returns the sealed value. | |
| void | test_write_reseals (void) |
| Write replaces the payload and reseals. | |
| void | test_update_commits (void) |
| Update commits a mutator transaction. | |
| void | test_update_abort_keeps_integrity (void) |
| Aborted update leaves a consistent container. | |
| void | test_section_scope (void) |
| SAFE_SECTION reseals at scope exit. | |
| void | test_detects_corruption (void) |
| Payload corruption detected; verification is pure. | |
| void | test_verify_repair_fixes_in_place (void) |
| verify_repair restores the payload in place | |
| void | test_commit_reseals_external_write (void) |
| Unchecked commit reseals an external modification. | |
| void | test_stale_tag_recovers (void) |
| Stale tag with consistent data recovers. | |
| void | test_double_fault_unrecoverable (void) |
| Double fault is unrecoverable. | |
| void | test_null_args (void) |
| NULL and zero-size arguments are rejected. | |
| void | test_reduced_api_surface (void) |
| Optional API surface matches the configuration. | |
| void | test_concurrent_access_is_serialised (void) |
| Concurrent access never yields torn snapshots. | |
| void | test_selftest (void) |
| Self-test reports a healthy mechanism. | |
| void | test_stats_count_events (void) |
| Statistics count every integrity event. | |
| void | test_fault_handler_events (void) |
| Registered handler receives all event kinds. | |
| void | test_update_clamps_positive_mutator_return (void) |
| Positive mutator return is clamped and aborted. | |
| void | test_write_observes_overwritten_corruption (void) |
| Write observes corruption before overwriting. | |
| void | test_lock_timeout_is_bounded_and_reported (void) |
| Blocked access fails within the lock bound. | |
|
active |
Init seals and verification passes.
SAFE_INIT seals the freshly written payload; SAFE_VERIFY on the untouched container returns 0.
Definition at line 44 of file main.c.
Verifies requirements SD-REQ-001 (Sealing on initialisation), and SD-REQ-003 (Pure verification).
|
active |
Read returns the sealed value.
A value written through SAFE_WRITE is returned bit-exact by a validated SAFE_READ.
Definition at line 61 of file main.c.
Verifies requirements SD-REQ-005 (Validated read), and SD-REQ-006 (Atomic sealed write).
|
obsolete |
Write replaces the payload and reseals.
After SAFE_WRITE the container verifies clean and a subsequent read returns the new value: the tag can never go stale across a write.
Status obsolete (demonstration of status handling): superseded by TC_SAFE_DATA_READ_ROUNDTRIP, which checks the resealed write through a validated read. The test still runs.
Definition at line 86 of file main.c.
Verifies requirement SD-REQ-006 (Atomic sealed write).
|
active |
Update commits a mutator transaction.
SAFE_UPDATE runs the mutator under the lock and reseals on a zero return; the committed value is visible to the next read.
Definition at line 125 of file main.c.
Verifies requirement SD-REQ-007 (Transactional read-modify-write).
|
active |
Aborted update leaves a consistent container.
A mutator returning a negative errno aborts the transaction. With the redundant shadow the payload is rolled back to the pre-update value; without it the partial write is detectable via the (not resealed) tag.
Definition at line 147 of file main.c.
Verifies requirement SD-REQ-007 (Transactional read-modify-write).
|
active |
SAFE_SECTION reseals at scope exit.
Modifications made through the typed pointer inside a SAFE_SECTION block are sealed automatically on normal scope exit and visible to the next read.
Definition at line 181 of file main.c.
Verifies requirement SD-REQ-021 (Scoped access block).
|
active |
Payload corruption detected; verification is pure.
Out-of-band payload corruption is detected by SAFE_VERIFY without modifying the payload (pure check). With the shadow copy the subsequent locked read repairs and reseals; without it the fault is unrecoverable.
Definition at line 212 of file main.c.
Verifies requirements SD-REQ-003 (Pure verification), and SD-REQ-009 (Single-copy fault recovery).
|
active |
verify_repair restores the payload in place
safe_data_verify_repair() (lock-held contract) restores a corrupted payload from the shadow copy in place; the container verifies clean afterwards.
Definition at line 250 of file main.c.
Verifies requirements SD-REQ-004 (In-place repair under mutual exclusion), and SD-REQ-009 (Single-copy fault recovery).
|
active |
Unchecked commit reseals an external modification.
SAFE_COMMIT re-tags the current contents after an audited direct modification of the storage (only available with CONFIG_SAFE_DATA_ALLOW_UNCHECKED_COMMIT).
Definition at line 282 of file main.c.
Verifies requirement SD-REQ-022 (Unchecked commit).
|
draft |
Stale tag with consistent data recovers.
When only the stored tag is corrupted (payload and shadow agree), the fault is recoverable; a locked read makes the reseal durable.
Status draft (demonstration of status handling): SD-REQ-009 is also verified by TC_SAFE_DATA_DETECTS_CORRUPTION and TC_SAFE_DATA_VERIFY_REPAIR_FIXES_IN_PLACE. The test still runs.
Definition at line 319 of file main.c.
Verifies requirement SD-REQ-009 (Single-copy fault recovery).
|
active |
Double fault is unrecoverable.
Inconsistent corruption of payload AND shadow leaves no copy to vouch for the data: verification reports -EILSEQ.
Definition at line 353 of file main.c.
Verifies requirement SD-REQ-010 (Double-fault detection).
|
active |
NULL and zero-size arguments are rejected.
Every API entry point rejects missing required pointers and zero-length payloads with -EINVAL (a NULL lock is legal: locking is optional). Each entry point is called once per required pointer and once with a zero length; the locked entry points are also called with a NULL lock and valid arguments, which must succeed.
Definition at line 394 of file main.c.
Verifies requirement SD-REQ-002 (Argument validation).
|
active |
Optional API surface matches the configuration.
SAFE_COMMIT and safe_data_commit() exist only with CONFIG_SAFE_DATA_ALLOW_UNCHECKED_COMMIT, and SAFE_SECTION only with CONFIG_SAFE_DATA_GNU_EXTENSIONS. Where an option is disabled, the macro is not defined and the image links no safe_data_commit(), so a use fails at build time. At the Strict level both are absent.
Definition at line 482 of file main.c.
Verifies requirement SD-REQ-020 (Reduced API surface at the Strict level).
|
active |
Concurrent access never yields torn snapshots.
A producer mutating dependent fields under SAFE_UPDATE and a consumer using SAFE_READ run concurrently for many iterations; the consumer never observes a snapshot violating the payload invariant.
Definition at line 593 of file main.c.
Verifies requirement SD-REQ-016 (Serialised access — no torn snapshots).
|
active |
Self-test reports a healthy mechanism.
safe_data_selftest() passes on a healthy system: CRC known-answer test plus a seal/corrupt/detect(/recover) round trip on a scratch container.
Definition at line 633 of file main.c.
Verifies requirement SD-REQ-017 (Integrity-mechanism self-test).
|
active |
Statistics count every integrity event.
Recovered-payload, recovered-tag and unrecoverable detections each increment their dedicated counter exactly once per detection.
Definition at line 653 of file main.c.
Verifies requirement SD-REQ-012 (Integrity-event statistics).
|
active |
Registered handler receives all event kinds.
safe_data_fault_handler_register() accepts one callback (second registration is rejected with -EALREADY, re-registration is idempotent) and the callback receives recovery events as well as unrecoverable faults with a populated event descriptor.
Definition at line 721 of file main.c.
Verifies requirements SD-REQ-011 (Configurable unrecoverable-fault reaction), and SD-REQ-013 (Fault-handler registration and event reporting).
|
active |
Positive mutator return is clamped and aborted.
A mutator returning a positive value violates the contract: SAFE_UPDATE returns -EINVAL, the transaction aborts (rollback with shadow), and the violation is counted.
Definition at line 777 of file main.c.
Verifies requirement SD-REQ-008 (Mutator contract enforcement).
|
active |
Write observes corruption before overwriting.
With CONFIG_SAFE_DATA_WRITE_CHECKS_OLD a write over corrupted contents still succeeds, but the destroyed evidence is counted in the statistics first.
CONFIG_SAFE_DATA_WRITE_CHECKS_OLD
CONFIG_SAFE_DATA_STATS
Definition at line 815 of file main.c.
Verifies requirement SD-REQ-018 (Write may not silently mask corruption).
|
active |
Blocked access fails within the lock bound.
While another thread holds the container lock, every locked operation (read, write, update, and commit and SAFE_SECTION where configured) fails with -ETIMEDOUT within CONFIG_SAFE_DATA_LOCK_TIMEOUT_MS and each timeout is counted; the container is usable again after the holder releases.
CONFIG_SAFE_DATA_LOCK_TIMEOUT_MS > 0
CONFIG_SAFE_DATA_LOCKING
Definition at line 871 of file main.c.
Verifies requirement SD-REQ-014 (Bounded lock acquisition).