test_blocking_declared.py

tests/test_blocking_declared.py

A repository declares its own blocking primitives, ISR predicates and wait tokens (R5-CORE C1; 2.0.0).

test_a_declared_isr_predicate_guards

None test_blocking_declared.test_a_declared_isr_predicate_guards()

A call of a declared predicate in the enclosing condition is a guard.

tests/test_blocking_declared.py:48

Show on the map →

Called by none

Calls _sites

Checks

  • assert "up_interrupt_context" in site[4]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002inferredtest_a_declared_isr_predicate_guards → _sites → blocking_harvester → manifest_key → hash_file
REQ-DDB-PIPE-003measuredtest_a_declared_isr_predicate_guards → _sites → blocking_harvester → manifest_key
Source · 7 lines
def test_a_declared_isr_predicate_guards() -> None:
    """@brief A call of a declared predicate in the enclosing condition is a guard."""
    src = "void f(void) { if (!up_interrupt_context()) { os_sem_wait(&s, OS_WAIT_FOREVER); } }"
    (site,) = _sites(src, _DECLARED)
    assert "up_interrupt_context" in site[4]

Activity · 3 steps
lines 50–50src = "void f(void) { if (!up_interrupt_context()) { os_sem_wait(&s, OS_WAIT_FOREVER); } }"lines 51–51(site,) = _sites(src, _DECLARED)lines 52–52assert "up_interrupt_context" in site[4]

test_a_declared_primitive_and_its_wait_tokens_are_read

None test_blocking_declared.test_a_declared_primitive_and_its_wait_tokens_are_read()

`os_sem_wait(s, OS_WAIT_FOREVER)` is a forever wait; `OS_MS(5)` a bounded one.

tests/test_blocking_declared.py:40

Show on the map →

Called by none

Calls _sites

Checks

  • assert sorted(waits) == ["bounded", "forever", "none"], waits
  • assert _sites(src) == [], "undeclared, the primitive is not known"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002inferredtest_a_declared_primitive_and_its_wait_tokens_are_read → _sites → blocking_harvester → manifest_key → hash_file
REQ-DDB-PIPE-003measuredtest_a_declared_primitive_and_its_wait_tokens_are_read → _sites → blocking_harvester → manifest_key
Source · 8 lines
def test_a_declared_primitive_and_its_wait_tokens_are_read() -> None:
    """@brief `os_sem_wait(s, OS_WAIT_FOREVER)` is a forever wait; `OS_MS(5)` a bounded one."""
    src = "void f(void) { os_sem_wait(&s, OS_WAIT_FOREVER); os_sem_wait(&s, OS_MS(5)); os_sem_wait(&s, OS_NO_WAIT); }"
    waits = [s[2] for s in sorted(_sites(src, _DECLARED), key=lambda s: s[3])]
    assert sorted(waits) == ["bounded", "forever", "none"], waits
    assert _sites(src) == [], "undeclared, the primitive is not known"

Activity · 4 steps
lines 42–42src = "void f(void) { os_sem_wait(&s, OS_WAIT_FOREVER); os_sem_wait(&s, OS_MS(5)); os_sem_wait(&s, OS_NO_WAIT); }"lines 43–43waits = [s[2] for s in sorted(_sites(src, _DECLARED), key=lambda s: s[3])]lines 44–44assert sorted(waits) == ["bounded", "forever", "none"], waitslines 45–45assert _sites(src) == [], "undeclared, the primitive is not known"

test_a_malformed_declaration_is_refused_by_name

None test_blocking_declared.test_a_malformed_declaration_is_refused_by_name(dict bad)

Unknown keys, a missing name and a wrong shape are refused, never defaulted.

tests/test_blocking_declared.py:71

Show on the map →

Called by none

Calls blocking_harvester

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002inferredtest_a_malformed_declaration_is_refused_by_name → blocking_harvester → manifest_key → hash_file
REQ-DDB-PIPE-003inferredtest_a_malformed_declaration_is_refused_by_name → blocking_harvester → manifest_key
Source · 9 lines
def test_a_malformed_declaration_is_refused_by_name(bad: dict) -> None:
    """@brief Unknown keys, a missing name and a wrong shape are refused, never defaulted."""
    from clew.blocking import blocking_harvester
    from clew.vocabulary import DeclarationError

    with pytest.raises(DeclarationError):
        blocking_harvester(bad)

Activity · 4 steps
lines 73–73from clew.blocking import blocking_harvesterlines 74–74from clew.vocabulary import DeclarationErrorlines 76–76with pytest.raises(DeclarationError)lines 77–77blocking_harvester(bad)

test_the_built_ins_still_apply_beside_a_declaration

None test_blocking_declared.test_the_built_ins_still_apply_beside_a_declaration()

Declaring adds: `k_sem_take(&s, K_FOREVER)` is still found and still forever.

tests/test_blocking_declared.py:55

Show on the map →

Called by none

Calls _sites

Checks

  • assert (site[0], site[2]) == ("k_sem_take", "forever")

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002inferredtest_the_built_ins_still_apply_beside_a_declaration → _sites → blocking_harvester → manifest_key → hash_file
REQ-DDB-PIPE-003measuredtest_the_built_ins_still_apply_beside_a_declaration → _sites → blocking_harvester → manifest_key
Source · 16 lines
def test_the_built_ins_still_apply_beside_a_declaration() -> None:
    """@brief Declaring adds: `k_sem_take(&s, K_FOREVER)` is still found and still forever."""
    (site,) = _sites("void f(void) { k_sem_take(&s, K_FOREVER); }", _DECLARED)
    assert (site[0], site[2]) == ("k_sem_take", "forever")


@pytest.mark.parametrize(
    "bad",
    [
        {"primitive": [{"name": "x"}]},
        {"primitives": [{"name": "x", "timeout_arg": 1}]},
        {"primitives": [{"timeout_arg_index": 1}]},
        {"wait_tokens": {"forevr": ["X"]}},
        {"isr_predicates": "up_interrupt_context"},
    ],
)

test_the_declaration_changes_the_cache_key

None test_blocking_declared.test_the_declaration_changes_the_cache_key()

The declaration is in the harvester's key.

tests/test_blocking_declared.py:80

Show on the map →

Called by none

Calls blocking_harvester

Checks

  • assert blocking_harvester(_DECLARED).extra_key != blocking_harvester(None).extra_key

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002inferredtest_the_declaration_changes_the_cache_key → blocking_harvester → manifest_key → hash_file
REQ-DDB-PIPE-003measuredtest_the_declaration_changes_the_cache_key → blocking_harvester → manifest_key
Source · 10 lines
def test_the_declaration_changes_the_cache_key() -> None:
    """A cached payload from the built-in vocabulary must not be served for a declared one.

    @brief The declaration is in the harvester's key.
    """
    from clew.blocking import blocking_harvester

    assert blocking_harvester(_DECLARED).extra_key != blocking_harvester(None).extra_key

Activity · 2 steps
lines 85–85from clew.blocking import blocking_harvesterlines 87–87assert blocking_harvester(_DECLARED).extra_key != blocking_harvester(None).extra_key