test_an_undeclared_acquire_release_pair_is_suggested¶
Tests › tests/test_locks.py
What this test is for
Why it exists
gh#385. The lock layer held ONE identity on mbedtls — `mutex->mutex`, scope unknown, confidence low — for a repository with five named global mutexes and 38 lock sites, and a graded agent copied that into its answer as "one first-party mutex identity resolved with 1 acquisition". Every acquisition goes through the function POINTER `mbedtls_mutex_lock`, so the detector only ever saw `pthread_mutex_lock(&mutex->mutex)` inside the one wrapper.
Given
db = tmp_path / "clew.db"conn = sqlite3.connect(str(db))
5 more
conn.execute("CREATE TABLE memberdef (name TEXT, kind TEXT)")conn.executemany( "INSERT INTO memberdef(name, kind) VALUES(?, ?)", [ ## The mbedtls shape: a function-POINTER pair, so neither half is ever a callee. ("proj_mutex_lock", "variable"), ("proj_mutex_unlock", "variable"), ## A FreeRTOS-style pair, to prove the suffix table is not just `_lock`. ("bsp_sem_take", "function"), ("bsp_sem_give", "function"), ## THE NEGATIVES, each a name a sniffer would fire on: ("spinlock_t", "typedef"), ("unlock_reason", "variable"), ("lock_free_queue", "function"), ## An acquire with NO partner is not a pair. ("orphan_lock", "function"), ], )conn.commit()conn.close()conn = sqlite3.connect(f"file:{db}?mode=ro", uri=True)
When
try: found = dict(detect_undeclared_lock_primitives(conn, list(DEFAULT_LOCK_PATTERNS))) finally: conn.close()declared = load_lock_patterns({"locks": [{"name": "proj_mutex_lock", "form": "call"}]})conn = sqlite3.connect(f"file:{db}?mode=ro", uri=True)try: after = dict(detect_undeclared_lock_primitives(conn, declared)) finally: conn.close()
Then
- ✓ found equals { "proj_mutex_lock": "proj_mutex_unlock", "bsp_sem_take": "bsp_sem_give", }
- ✓ after does not contain "proj_mutex_lock"
- ✓ after contains "bsp_sem_take"
tests/test_locks.py:374 · its file's page
What it checks (3)
assert found == { "proj_mutex_lock": "proj_mutex_unlock", "bsp_sem_take": "bsp_sem_give", }, foundobservesdetect_undeclared_lock_primitivesviafoundassert "proj_mutex_lock" not in afterobservesdetect_undeclared_lock_primitivesviaafterassert "bsp_sem_take" in after, "declaring one primitive must not silence the others"observesdetect_undeclared_lock_primitivesviaafter
Where the product reaches it
dossier→subject_payload→_flatten_subject→list(flow)
Call flow
test_an_undeclared_acquire_release_pair_is_suggested→detect_undeclared_lock_primitives→list→load_lock_patternsWhat it reaches
Each row runs from this test, through the calls it makes, to the code a requirement names. If that code breaks, the test's checks are what should catch it. Reaching is not proving: a check only proves what it observes. No mutation records were given, so these rows say what the test REACHES.
Also reaches 3 requirements
Its run touches their code; that is reach, not proof.
- REQ-DDB-CONFIG-007 measured
- REQ-DDB-SCHEMA-011 measured
- REQ-DDB-SCHEMA-012 measured