test_an_undeclared_acquire_release_pair_is_suggested

Tests › tests/test_locks.py

passed Passed in the packaged run.

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

  1. db = tmp_path / "clew.db"
  2. conn = sqlite3.connect(str(db))
5 more
  1. conn.execute("CREATE TABLE memberdef (name TEXT, kind TEXT)")
  2. 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"), ], )
  3. conn.commit()
  4. conn.close()
  5. conn = sqlite3.connect(f"file:{db}?mode=ro", uri=True)
→

When

  1. try: found = dict(detect_undeclared_lock_primitives(conn, list(DEFAULT_LOCK_PATTERNS))) finally: conn.close()
  2. declared = load_lock_patterns({"locks": [{"name": "proj_mutex_lock", "form": "call"}]})
  3. conn = sqlite3.connect(f"file:{db}?mode=ro", uri=True)
  4. try: after = dict(detect_undeclared_lock_primitives(conn, declared)) finally: conn.close()
→

Then

  1. ✓ found equals { "proj_mutex_lock": "proj_mutex_unlock", "bsp_sem_take": "bsp_sem_give", }
  2. ✓ after does not contain "proj_mutex_lock"
  3. ✓ after contains "bsp_sem_take"

tests/test_locks.py:374 · its file's page

What it checks (3)

  1. assert found == { "proj_mutex_lock": "proj_mutex_unlock", "bsp_sem_take": "bsp_sem_give", }, found observes detect_undeclared_lock_primitives via found
  2. assert "proj_mutex_lock" not in after observes detect_undeclared_lock_primitives via after
  3. assert "bsp_sem_take" in after, "declaring one primitive must not silence the others" observes detect_undeclared_lock_primitives via after

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_patterns

What 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.

test_an_undeclared_acquire_release_pair_is_suggested · 3 checksdetect_undeclared_lock_primitivesREQ-DDB-CONFIG-007 · measuredload_lock_patternsREQ-DDB-SCHEMA-011 · measuredload_lock_patternsdeclaration_originREQ-DDB-SCHEMA-012 · measured
Also reaches 3 requirements

Its run touches their code; that is reach, not proof.