test_isr.py

tests/test_isr.py

gh#47 part 1: an interrupt handler is an execution context, not an unreferenced function.

test_a_handler_declared_at_its_definition_is_an_isr_entry

None test_isr.test_a_handler_declared_at_its_definition_is_an_isr_entry()

Attribute, macro-wrapper and naming definitions are harvested.

tests/test_isr.py:180

Show on the map →

Called by none

Calls _sites

Checks

  • assert entry in found, f"{entry} is an interrupt handler; found {sorted(found)}"
  • assert found[entry][KIND] == "isr", f"{entry} got kind {found[entry][KIND]!r}"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-003measuredtest_a_handler_declared_at_its_definition_is_an_isr_entry → _sites → _walk_spawn_sites → is_python_tree
REQ-DDB-SCHEMA-001measuredtest_a_handler_declared_at_its_definition_is_an_isr_entry → _sites → load_thread_patterns
REQ-DDB-SCHEMA-012inferredtest_a_handler_declared_at_its_definition_is_an_isr_entry → _sites → load_thread_patterns → declaration_origin
Source · 26 lines
def test_a_handler_declared_at_its_definition_is_an_isr_entry() -> None:
    """RIOT and FreeRTOS mostly do NOT register their handlers by call — the vector table is in
    assembly or generated at build time, and the C side is a definition the linker resolves by
    NAME. Read at their pins: 127 `isr_*` definitions in RIOT, 882 `*_IRQHandler` in the
    FreeRTOS demos, plus the CMSIS core exception names and FreeRTOS's documented hooks.

    A call-site matcher sees none of them, which is why the FreeRTOS demo scope reports ZERO
    interrupt handlers from registrations alone.

    @brief Attribute, macro-wrapper and naming definitions are harvested.
    @version 1
    """
    found = {site[ENTRY]: site for site in _sites(_DEFINITIONS)}

    for entry in (
        "tim0_handler",
        "TIM1_IRQHandler",
        "isr_uart0",
        "SysTick_Handler",
        "vApplicationTickHook",
        "uarte_isr",
    ):
        assert entry in found, f"{entry} is an interrupt handler; found {sorted(found)}"
        assert found[entry][KIND] == "isr", f"{entry} got kind {found[entry][KIND]!r}"

Activity · 4 steps
lines 192–192found = {site[ENTRY]: site for site in _sites(_DEFINITIONS)}lines 194–194◇ for entry in (lines 202–202assert entry in found, f"{entry} is an interrupt handler; found {sorted(found)}"lines 203–203assert found[entry][KIND] == "isr", f"{entry} got kind {found[entry][KIND]!r}"

test_a_handler_named_by_a_board_macro_is_still_a_handler

None test_isr.test_a_handler_named_by_a_board_macro_is_still_a_handler()

The ISR_*/*_ISR naming shapes are recognised.

tests/test_isr.py:383

Show on the map →

Called by none

Calls _sites

Checks

  • assert entry in found, f"{entry} is a vector handler; found {sorted(found)}"
  • assert found[entry][SOURCE] == "ast_isr_name", (f"a macro name is an inference, not a declaration; got {found[entry][SOURCE]!r}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-003measuredtest_a_handler_named_by_a_board_macro_is_still_a_handler → _sites → _walk_spawn_sites → is_python_tree
REQ-DDB-SCHEMA-001measuredtest_a_handler_named_by_a_board_macro_is_still_a_handler → _sites → load_thread_patterns
REQ-DDB-SCHEMA-012inferredtest_a_handler_named_by_a_board_macro_is_still_a_handler → _sites → load_thread_patterns → declaration_origin
Source · 20 lines
def test_a_handler_named_by_a_board_macro_is_still_a_handler() -> None:
    """MEASURED ON RIOT AT ITS PIN: 12 vector handlers in the indexed scope were missed because
    the function's NAME is a board macro — `void ISR_GPIOTE(void)` (cpu/nrf5x_common/periph/gpio.c:231),
    `void TIMER_0_ISR(void)` (periph/timer.c:301), `ISR_SPIM0`, `SERIAL0_ISR`. The macro expands
    to `isr_gpiote` and the mapping lives in `boards/*/periph_conf.h`, outside any cpu-scoped
    index, so the expansion is not available — but the SHAPE is unambiguous: a zero-argument
    void definition whose name is ISR-prefixed or ISR-suffixed.

    @brief The ISR_*/*_ISR naming shapes are recognised.
    @version 1
    """
    found = {site[ENTRY]: site for site in _sites(_MACRO_NAMED)}

    for entry in ("ISR_GPIOTE", "TIMER_0_ISR"):
        assert entry in found, f"{entry} is a vector handler; found {sorted(found)}"
        assert found[entry][SOURCE] == "ast_isr_name", (
            f"a macro name is an inference, not a declaration; got {found[entry][SOURCE]!r}"
        )

Activity · 4 steps
lines 394–394found = {site[ENTRY]: site for site in _sites(_MACRO_NAMED)}lines 396–396◇ for entry in ("ISR_GPIOTE", "TIMER_0_ISR")lines 397–397assert entry in found, f"{entry} is a vector handler; found {sorted(found)}"lines 398–400assert found[entry][SOURCE] == "ast_isr_name", ( f"a macro name is an inference, not a declaration; got {found[entry][SOURCE]!r}" )

test_a_naming_guess_is_labelled_differently_from_a_declared_interrupt

None test_isr.test_a_naming_guess_is_labelled_differently_from_a_declared_interrupt()

Evidence strength rides on the source column, not on the kind.

tests/test_isr.py:225

Show on the map →

Called by none

Calls _sites

Checks

  • assert found["tim0_handler"][SOURCE] == "ast_isr_decl", (f"an interrupt attribute is declared, not guessed; got {found['tim0_handler'][SOURCE]!r}" )
  • assert found["uarte_isr"][SOURCE] == "ast_isr_decl", (f"a handler-declaring macro is declared; got {found['uarte_isr'][SOURCE]!r}" )
  • assert found["TIM1_IRQHandler"][SOURCE] == "ast_isr_name", (f"a naming convention is an inference; got {found['TIM1_IRQHandler'][SOURCE]!r}" )
  • assert registered["timer_isr"][SOURCE] == "ast_spawn", (f"a registration call is the existing source; got {registered['timer_isr'][SOURCE]!r}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-003measuredtest_a_naming_guess_is_labelled_differently_from_a_declared_interrupt → _sites → _walk_spawn_sites → is_python_tree
REQ-DDB-SCHEMA-001measuredtest_a_naming_guess_is_labelled_differently_from_a_declared_interrupt → _sites → load_thread_patterns
REQ-DDB-SCHEMA-012inferredtest_a_naming_guess_is_labelled_differently_from_a_declared_interrupt → _sites → load_thread_patterns → declaration_origin
Source · 25 lines
def test_a_naming_guess_is_labelled_differently_from_a_declared_interrupt() -> None:
    """`__attribute__((interrupt))` and `ISR_DIRECT_DECLARE(x)` are what the SOURCE SAYS; a name
    ending in _IRQHandler is what the index INFERRED. Both are worth recording and they are not
    the same evidence, so they are not written under the same `threads.source`.

    @brief Evidence strength rides on the source column, not on the kind.
    @version 1
    """
    found = {site[ENTRY]: site for site in _sites(_DEFINITIONS)}

    assert found["tim0_handler"][SOURCE] == "ast_isr_decl", (
        f"an interrupt attribute is declared, not guessed; got {found['tim0_handler'][SOURCE]!r}"
    )
    assert found["uarte_isr"][SOURCE] == "ast_isr_decl", (
        f"a handler-declaring macro is declared; got {found['uarte_isr'][SOURCE]!r}"
    )
    assert found["TIM1_IRQHandler"][SOURCE] == "ast_isr_name", (
        f"a naming convention is an inference; got {found['TIM1_IRQHandler'][SOURCE]!r}"
    )
    registered = {site[ENTRY]: site for site in _sites(_REGISTRATIONS)}
    assert registered["timer_isr"][SOURCE] == "ast_spawn", (
        f"a registration call is the existing source; got {registered['timer_isr'][SOURCE]!r}"
    )

Activity · 6 steps
lines 233–233found = {site[ENTRY]: site for site in _sites(_DEFINITIONS)}lines 235–237assert found["tim0_handler"][SOURCE] == "ast_isr_decl", ( f"an interrupt attribute is declared, not guessed; got {found['tim0_handler'][SOURCE]!r}" )lines 238–240assert found["uarte_isr"][SOURCE] == "ast_isr_decl", ( f"a handler-declaring macro is declared; got {found['uarte_isr'][SOURCE]!r}" )lines 241–243assert found["TIM1_IRQHandler"][SOURCE] == "ast_isr_name", ( f"a naming convention is an inference; got {found['TIM1_IRQHandler'][SOURCE]!r}" )lines 244–244registered = {site[ENTRY]: site for site in _sites(_REGISTRATIONS)}lines 245–247assert registered["timer_isr"][SOURCE] == "ast_spawn", ( f"a registration call is the existing source; got {registered['timer_isr'][SOURCE]!r}" )

test_a_registration_inside_a_macro_body_is_counted_not_ignored

None test_isr.test_a_registration_inside_a_macro_body_is_counted_not_ignored()

Registrations hidden in macro bodies are counted.

tests/test_isr.py:250

Checks

  • assert hidden == 1, f"the registration inside the #define body must be counted, got {hidden}"
  • assert [site[ENTRY] for site in visible] == ["other_isr"], (f"only the call outside the macro body is harvested, got {visible}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-003measuredtest_a_registration_inside_a_macro_body_is_counted_not_ignored → _sites → _walk_spawn_sites → is_python_tree
REQ-DDB-SCHEMA-001measuredtest_a_registration_inside_a_macro_body_is_counted_not_ignored → count_macro_body_registrations
REQ-DDB-SCHEMA-012inferredtest_a_registration_inside_a_macro_body_is_counted_not_ignored → load_thread_patterns → declaration_origin
Source · 44 lines
def test_a_registration_inside_a_macro_body_is_counted_not_ignored() -> None:
    """THE NUMBER THAT KEEPS A ZERO HONEST. A Zephyr driver instantiates itself once per
    devicetree node, so its IRQ_CONNECT is written inside a `#define` body and expanded by
    `DT_INST_FOREACH_STATUS_OKAY`. tree-sitter exposes a macro body as opaque text — there is no
    call node to match — and at v4.4.2 that is 718 of 1110 sites (64.7%).

    Reporting "0 interrupt handlers" on such a driver would be a measured-looking claim about a
    file the layer could not read. The count says what was not read; it does NOT invent a
    handler, because 46 of those sites name a macro parameter or a token-pasted identifier that
    only exists after preprocessing.

    @brief Registrations hidden in macro bodies are counted.
    @version 1
    """
    from clew.tsnode import Parser

    from clew.isr import count_macro_body_registrations

    src = b"""\
#define UART_INIT(n)                                                   \\
    static void uart_irq_config_##n(const struct device *dev)          \\
    {                                                                  \\
        IRQ_CONNECT(DT_INST_IRQN(n), DT_INST_IRQ(n, priority),         \\
                    uart_isr, DEVICE_DT_INST_GET(n), 0);               \\
    }

void visible_setup(void)
{
    IRQ_CONNECT(3, 1, other_isr, NULL, 0);
}
"""
    parser = Parser("c")
    tree = parser.parse(src)
    spellings = frozenset(load_thread_patterns(None) and {p.name for p in DEFAULT_SPAWN_PATTERNS})

    hidden = count_macro_body_registrations(tree, src, spellings)
    visible = _sites(src)

    assert hidden == 1, f"the registration inside the #define body must be counted, got {hidden}"
    assert [site[ENTRY] for site in visible] == ["other_isr"], (
        f"only the call outside the macro body is harvested, got {visible}"
    )

Activity · 10 steps
lines 264–264from clew.tsnode import Parserlines 266–266from clew.isr import count_macro_body_registrationslines 268–280src = b"""\ #define UART_INIT(n) \\ static void uart_irq_config_##n(const struct device *dev) \\ { \\ IRQ_CONNECT(DT_INST_IRQN(n), DT_INST_IRQ(n, priority), \\ uart_isr, DEVICE_DT_INST_GET(n), 0); \\ } void visible_setup(void) { IRQ_CONNECT(3, 1, other_isr, NULL, 0); } """lines 281–281parser = Parser("c")lines 282–282tree = parser.parse(src)lines 283–283spellings = frozenset(load_thread_patterns(None) and {p.name for p in DEFAULT_SPAWN_PATTERNS})lines 285–285hidden = count_macro_body_registrations(tree, src, spellings)lines 286–286visible = _sites(src)lines 288–288assert hidden == 1, f"the registration inside the #define body must be counted, got {hidden}"lines 289–291assert [site[ENTRY] for site in visible] == ["other_isr"], ( f"only the call outside the macro body is harvested, got {visible}" )

test_a_sentinel_handler_is_not_a_function

None test_isr.test_a_sentinel_handler_is_not_a_function()

A sentinel or null handler argument records nothing.

tests/test_isr.py:123

Show on the map →

Called by none

Calls _sites

Checks

  • assert "SIG_IGN" not in entries, f"SIG_IGN names no function; got {sorted(entries)}"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-003measuredtest_a_sentinel_handler_is_not_a_function → _sites → _walk_spawn_sites → is_python_tree
REQ-DDB-SCHEMA-001measuredtest_a_sentinel_handler_is_not_a_function → _sites → load_thread_patterns
REQ-DDB-SCHEMA-012inferredtest_a_sentinel_handler_is_not_a_function → _sites → load_thread_patterns → declaration_origin
Source · 15 lines
def test_a_sentinel_handler_is_not_a_function() -> None:
    """`signal(SIGTERM, SIG_IGN)` names no function. Recorded as written it mints a thread
    called SIG_IGN whose entry never resolves, and a NULL entry does not deduplicate — SQLite
    treats NULLs as distinct in a UNIQUE constraint — so every such site adds another row.

    The same shape appears with a deregistering registration: RIOT's
    `install_irq(RTC_INT, NULL, 1)` (cpu/lpc23xx/periph/rtc.c:191) passes NULL for the handler.

    @brief A sentinel or null handler argument records nothing.
    @version 1
    """
    entries = {site[ENTRY] for site in _sites(_REGISTRATIONS)}
    assert "SIG_IGN" not in entries, f"SIG_IGN names no function; got {sorted(entries)}"

Activity · 2 steps
lines 134–134entries = {site[ENTRY] for site in _sites(_REGISTRATIONS)}lines 135–135assert "SIG_IGN" not in entries, f"SIG_IGN names no function; got {sorted(entries)}"

test_a_thread_payload_cached_before_the_widened_patterns_is_not_served

None test_isr.test_a_thread_payload_cached_before_the_widened_patterns_is_not_served(tmp_path)

A stale-version thread payload must not be reused.

tests/test_isr.py:498

Checks

  • assert sha is not None
  • assert entries == ["ISR_GPIOTE", "isr_port1"], (f"a payload cached under the pre-widening version was served; got {entries}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measuredtest_a_thread_payload_cached_before_the_widened_patterns_is_not_served → spawn_harvester → manifest_key → hash_file
REQ-DDB-PIPE-003measuredtest_a_thread_payload_cached_before_the_widened_patterns_is_not_served → run_harvest
REQ-DDB-PIPE-011measuredtest_a_thread_payload_cached_before_the_widened_patterns_is_not_served → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_thread_payload_cached_before_the_widened_patterns_is_not_served → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-001measuredtest_a_thread_payload_cached_before_the_widened_patterns_is_not_served → spawn_harvester
REQ-DDB-SCHEMA-012inferredtest_a_thread_payload_cached_before_the_widened_patterns_is_not_served → spawn_harvester → load_thread_patterns → declaration_origin
Source · 45 lines
def test_a_thread_payload_cached_before_the_widened_patterns_is_not_served(tmp_path) -> None:
    """THE SAME LOCKSTEP THE LOCK STAGE ALREADY OWED ONCE. gh#47's follow-up widened
    `ISR_NAME_GLOBS`, added the msp430 `ISR` spawn pattern and added the avr-libc attribute
    sentinels — three inputs read AT HARVEST TIME — and bumped nothing. The stage key is
    `(content_sha, stage, stage_version, extra_key)` and `extra_key` hashes only the DECLARED
    document, so a repository that built under the previous release keys the same payload
    afterwards: a hit, serving the handler set from before the widening.

    MEASURED ON RIOT AT ITS PIN: 104 interrupt rows cold against 79 from a warm pre-widening
    payload — 25 handlers, a quarter of the roster, vanishing with no miss and no warning, and
    the conflict layer runs over whatever survives.

    @brief A stale-version thread payload must not be reused.
    @version 1
    """
    import sqlite3

    from clew.harvest import run_harvest
    from clew.indexcache import IndexCache
    from clew.threads import spawn_harvester

    root = tmp_path / "repo"
    (root / "src").mkdir(parents=True)
    rel = "src/vectors.c"
    (root / rel).write_bytes(
        b"void drain(void);\nvoid ISR_GPIOTE(void) { drain(); }\n"
        b"ISR(PORT1_VECTOR, isr_port1)\n{\n    drain();\n}\n"
    )
    harvester = spawn_harvester(None)
    cache = IndexCache(tmp_path / "index.idxcache", root)
    sha = cache.sha_for(rel, root / rel)
    assert sha is not None
    ## What the previous release's extraction produced for this file: nothing at all.
    cache.extract_put(sha, harvester.stage, 6, harvester.extra_key, {"sites": []})

    conn = sqlite3.connect(":memory:")
    conn.execute("CREATE TABLE path (name TEXT)")
    conn.execute("INSERT INTO path (name) VALUES (?)", (rel,))

    payload = run_harvest(conn, root, harvester, cache)[0][1]
    entries = sorted(site[ENTRY] for site in payload["sites"])

    assert entries == ["ISR_GPIOTE", "isr_port1"], (
        f"a payload cached under the pre-widening version was served; got {entries}"
    )

1 more lines, not shown

Activity · 19 steps
lines 513–513import sqlite3lines 515–515from clew.harvest import run_harvestlines 516–516from clew.indexcache import IndexCachelines 517–517from clew.threads import spawn_harvesterlines 519–519root = tmp_path / "repo"lines 520–520(root / "src").mkdir(parents=True)lines 521–521rel = "src/vectors.c"lines 522–525(root / rel).write_bytes( b"void drain(void);\nvoid ISR_GPIOTE(void) { drain(); }\n" b"ISR(PORT1_VECTOR, isr_port1)\n{\n drain();\n}\n" )lines 526–526harvester = spawn_harvester(None)lines 527–527cache = IndexCache(tmp_path / "index.idxcache", root)lines 528–528sha = cache.sha_for(rel, root / rel)lines 529–529assert sha is not Nonelines 531–531cache.extract_put(sha, harvester.stage, 6, harvester.extra_key, {"sites": []})lines 533–533conn = sqlite3.connect(":memory:")lines 534–534conn.execute("CREATE TABLE path (name TEXT)")lines 535–535conn.execute("INSERT INTO path (name) VALUES (?)", (rel,))lines 537–537payload = run_harvest(conn, root, harvester, cache)[0][1]lines 538–538entries = sorted(site[ENTRY] for site in payload["sites"])lines 540–542assert entries == ["ISR_GPIOTE", "isr_port1"], ( f"a payload cached under the pre-widening version was served; got {entries}" )

test_a_threaded_irq_files_its_bottom_half_as_a_thread_not_an_isr

None test_isr.test_a_threaded_irq_files_its_bottom_half_as_a_thread_not_an_isr()

Both handlers of a threaded IRQ are recorded, with different kinds.

tests/test_isr.py:102

Show on the map →

Called by none

Calls _sites

Checks

  • assert found.get("hard_isr") == "isr", f"the hard handler is interrupt context; got {found}"
  • assert found.get("work_thread") == "task", (f"the threaded bottom half is a THREAD, and may block; got {found}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-003measuredtest_a_threaded_irq_files_its_bottom_half_as_a_thread_not_an_isr → _sites → _walk_spawn_sites → is_python_tree
REQ-DDB-SCHEMA-001measuredtest_a_threaded_irq_files_its_bottom_half_as_a_thread_not_an_isr → _sites → load_thread_patterns
REQ-DDB-SCHEMA-012inferredtest_a_threaded_irq_files_its_bottom_half_as_a_thread_not_an_isr → _sites → load_thread_patterns → declaration_origin
Source · 21 lines
def test_a_threaded_irq_files_its_bottom_half_as_a_thread_not_an_isr() -> None:
    """`request_threaded_irq(irq, handler, thread_fn, ...)` registers TWO functions with two
    execution contexts: `handler` runs in hard interrupt context, `thread_fn` on a kernel
    thread created for it — where blocking is the entire point.

    ONE PATTERN PER CALLEE NAME cannot express that, which is why the pattern map is keyed to a
    LIST. Filing `thread_fn` as 'isr' would report every mutex the bottom half takes as an
    interrupt-context conflict; omitting it loses a real thread.

    @brief Both handlers of a threaded IRQ are recorded, with different kinds.
    @version 1
    """
    sites = _sites(_REGISTRATIONS)
    found = {site[ENTRY]: site[KIND] for site in sites}

    assert found.get("hard_isr") == "isr", f"the hard handler is interrupt context; got {found}"
    assert found.get("work_thread") == "task", (
        f"the threaded bottom half is a THREAD, and may block; got {found}"
    )

Activity · 4 steps
lines 114–114sites = _sites(_REGISTRATIONS)lines 115–115found = {site[ENTRY]: site[KIND] for site in sites}lines 117–117assert found.get("hard_isr") == "isr", f"the hard handler is interrupt context; got {found}"lines 118–120assert found.get("work_thread") == "task", ( f"the threaded bottom half is a THREAD, and may block; got {found}" )

test_registration_calls_are_isr_entries

None test_isr.test_registration_calls_are_isr_entries()

Interrupt registrations are harvested as kind 'isr'.

tests/test_isr.py:70

Show on the map →

Called by none

Calls _sites

Checks

  • assert entry in found, f"{entry} must be harvested as an interrupt entry; got {found}"
  • assert found[entry] == "isr", (f"{entry} runs in interrupt context, got kind {found[entry]!r}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-003measuredtest_registration_calls_are_isr_entries → _sites → _walk_spawn_sites → is_python_tree
REQ-DDB-SCHEMA-001measuredtest_registration_calls_are_isr_entries → _sites → load_thread_patterns
REQ-DDB-SCHEMA-012inferredtest_registration_calls_are_isr_entries → _sites → load_thread_patterns → declaration_origin
Source · 32 lines
def test_registration_calls_are_isr_entries() -> None:
    """THE SHIPPED SET, not a declaration. The acceptance targets for this feature build with
    `declare: {}` on purpose — a rubric that declares the patterns grades the declaration, not
    the index — so an ISR spelling that is declarable-only contributes nothing where it counts.

    `k_timer_init` and `gpio_init_callback` are in the same list for the same reason as
    `IRQ_CONNECT`: Zephyr documents both callbacks as running in interrupt context
    (include/zephyr/kernel.h:1861-1864 for the timer expiry function;
    include/zephyr/drivers/gpio/gpio_utils.h:139 dispatches the GPIO handler from the
    controller's ISR). The context is what the layer models, not the vector.

    @brief Interrupt registrations are harvested as kind 'isr'.
    @version 1
    """
    sites = _sites(_REGISTRATIONS)
    found = {site[ENTRY]: site[KIND] for site in sites}

    for entry in (
        "timer_isr",
        "dma_isr",
        "gpio_isr",
        "hard_isr",
        "on_int",
        "expiry",
        "button_pressed",
    ):
        assert entry in found, f"{entry} must be harvested as an interrupt entry; got {found}"
        assert found[entry] == "isr", (
            f"{entry} runs in interrupt context, got kind {found[entry]!r}"
        )

Activity · 5 steps
lines 84–84sites = _sites(_REGISTRATIONS)lines 85–85found = {site[ENTRY]: site[KIND] for site in sites}lines 87–87◇ for entry in (lines 96–96assert entry in found, f"{entry} must be harvested as an interrupt entry; got {found}"lines 97–99assert found[entry] == "isr", ( f"{entry} runs in interrupt context, got kind {found[entry]!r}" )

test_the_msp430_two_argument_isr_macro_names_its_handler

None test_isr.test_the_msp430_two_argument_isr_macro_names_its_handler()

The msp430 ISR macro is a registration; the AVR attribute form is refused.

tests/test_isr.py:403

Show on the map →

Called by none

Calls _sites

Checks

  • assert "isr_timer0_cc0" in found, f"the msp430 handler must be named; found {sorted(found)}"
  • assert found["isr_timer0_cc0"][KIND] == "isr"
  • assert "ISR_NAKED" not in found, "an avr-libc ISR attribute is not a handler"
  • assert "ISR_BLOCK" not in found, "an avr-libc ISR attribute is not a handler"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-003measuredtest_the_msp430_two_argument_isr_macro_names_its_handler → _sites → _walk_spawn_sites → is_python_tree
REQ-DDB-SCHEMA-001measuredtest_the_msp430_two_argument_isr_macro_names_its_handler → _sites → load_thread_patterns
REQ-DDB-SCHEMA-012inferredtest_the_msp430_two_argument_isr_macro_names_its_handler → _sites → load_thread_patterns → declaration_origin
Source · 24 lines
def test_the_msp430_two_argument_isr_macro_names_its_handler() -> None:
    """`ISR(VECTOR, name) { ... }` (cpu/msp430/include/cpu.h:42) expands to
    `void __attribute__((naked, interrupt(VECTOR))) name(void)`, and tree-sitter parses the site
    as a CALL followed by a detached compound statement — so there is no function_definition to
    classify and the definition walk sees nothing. 9 handlers missed in the RIOT scope.

    As a call it is an ordinary registration whose second argument names the handler, which the
    existing spawn machinery already expresses.

    THE AVR FORM SHARES THE SPELLING AND MUST NOT MATCH. avr-libc's `ISR(vect, ISR_NAKED)` takes
    an ATTRIBUTE in that position (cpu/atmega_common/atmega_cpu.c:87), and recording it would
    mint a handler called ISR_NAKED whose entry never resolves.

    @brief The msp430 ISR macro is a registration; the AVR attribute form is refused.
    @version 1
    """
    found = {site[ENTRY]: site for site in _sites(_MACRO_NAMED)}

    assert "isr_timer0_cc0" in found, f"the msp430 handler must be named; found {sorted(found)}"
    assert found["isr_timer0_cc0"][KIND] == "isr"
    assert "ISR_NAKED" not in found, "an avr-libc ISR attribute is not a handler"
    assert "ISR_BLOCK" not in found, "an avr-libc ISR attribute is not a handler"

Activity · 5 steps
lines 419–419found = {site[ENTRY]: site for site in _sites(_MACRO_NAMED)}lines 421–421assert "isr_timer0_cc0" in found, f"the msp430 handler must be named; found {sorted(found)}"lines 422–422assert found["isr_timer0_cc0"][KIND] == "isr"lines 423–423assert "ISR_NAKED" not in found, "an avr-libc ISR attribute is not a handler"lines 424–424assert "ISR_BLOCK" not in found, "an avr-libc ISR attribute is not a handler"

test_two_definitions_of_one_handler_in_one_file_each_resolve

None test_isr.test_two_definitions_of_one_handler_in_one_file_each_resolve(tmp_path)

A definition-form handler resolves by its own line, not by its name.

tests/test_isr.py:427

Checks

  • assert entries == [1, 2], f"each arm resolves to its own definition, got {entries}"
  • assert members == 4, f"both closures are populated (entry + drain, twice), got {members}"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002inferredtest_two_definitions_of_one_handler_in_one_file_each_resolve → extract_threads → spawn_harvester → manifest_key → hash_file
REQ-DDB-PIPE-003measuredtest_two_definitions_of_one_handler_in_one_file_each_resolve → extract_threads → spawn_harvester → manifest_key
REQ-DDB-PIPE-004measuredtest_two_definitions_of_one_handler_in_one_file_each_resolve → extract_threads → _populate_membership → _bfs_live_set
REQ-DDB-PIPE-011measuredtest_two_definitions_of_one_handler_in_one_file_each_resolve → extract_threads → _harvest_all_spawn_sites → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_two_definitions_of_one_handler_in_one_file_each_resolve → extract_threads → _harvest_all_spawn_sites → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-003measuredtest_two_definitions_of_one_handler_in_one_file_each_resolve → extract_threads → _definition_preferring_name_index
REQ-DDB-QUERY-011measuredtest_two_definitions_of_one_handler_in_one_file_each_resolve → extract_threads → _ensure_threads_tables
REQ-DDB-SCHEMA-001measuredtest_two_definitions_of_one_handler_in_one_file_each_resolve → extract_threads
REQ-DDB-SCHEMA-007measuredtest_two_definitions_of_one_handler_in_one_file_each_resolve → extract_threads → _ensure_threads_tables
REQ-DDB-SCHEMA-012measuredtest_two_definitions_of_one_handler_in_one_file_each_resolve → extract_threads → spawn_harvester → load_thread_patterns → declaration_origin
Source · 71 lines
def test_two_definitions_of_one_handler_in_one_file_each_resolve(tmp_path) -> None:
    """MEASURED ON RIOT: five rows carried NO entry and therefore no closure — `isr_svc` twice
    and `isr_pendsv` twice, each pair being the two `#if` arms of ONE file
    (cpu/cortexm_common/thread_arch.c:311/378 and :460/540), plus `RTC_IRQHandler`. The name is
    ambiguous and the FILE does not disambiguate either, so name resolution failed both ways and
    the layer said "a handler is here" while being unable to say what it reaches.

    A handler found at its DEFINITION does not need a name lookup at all: the site IS the
    definition, and its line pins the exact memberdef — the same resolution the lock layer uses
    for a holder. Only a REGISTRATION, which names its handler from somewhere else, has to look
    a name up.

    @brief A definition-form handler resolves by its own line, not by its name.
    @version 1
    """
    import sqlite3

    from clew.threads import extract_threads

    db = tmp_path / "clew.db"
    (tmp_path / "src").mkdir()
    (tmp_path / "src" / "a.c").write_text(
        "void drain(void);\n"
        "#ifdef CPU_A\n"
        "void isr_svc(void)\n"
        "{\n"
        "    drain();\n"
        "}\n"
        "#else\n"
        "void isr_svc(void)\n"
        "{\n"
        "    drain();\n"
        "}\n"
        "#endif\n"
    )
    conn = sqlite3.connect(str(db))
    conn.executescript(
        """
        CREATE TABLE path (name TEXT);
        CREATE TABLE memberdef (
            rowid INTEGER PRIMARY KEY, kind TEXT, name TEXT,
            file_id INTEGER, bodyfile_id INTEGER, bodystart INTEGER, bodyend INTEGER);
        CREATE TABLE call_edges (
            caller_rowid INTEGER, callee_rowid INTEGER, source TEXT, confidence TEXT);
        INSERT INTO path (rowid, name) VALUES (1, 'src/a.c');
        INSERT INTO memberdef (rowid, kind, name, file_id, bodyfile_id, bodystart, bodyend)
          VALUES (1, 'function', 'isr_svc', 1, 1, 3, 6),
                 (2, 'function', 'isr_svc', 1, 1, 8, 11),
                 (3, 'function', 'drain', 1, 1, 1, 1);
        INSERT INTO call_edges VALUES (1, 3, 'ast', 'resolved'), (2, 3, 'ast', 'resolved');
        """
    )
    conn.commit()
    conn.close()

    extract_threads(db, tmp_path)

    conn = sqlite3.connect(str(db))
    entries = [
        r[0]
        for r in conn.execute(
            "SELECT entry_memberdef_rowid FROM threads WHERE kind='isr' ORDER BY spawn_line"
        )
    ]
    members = conn.execute("SELECT COUNT(*) FROM thread_membership").fetchone()[0]
    conn.close()

    assert entries == [1, 2], f"each arm resolves to its own definition, got {entries}"
    assert members == 4, f"both closures are populated (entry + drain, twice), got {members}"

Activity · 16 steps
lines 442–442import sqlite3lines 444–444from clew.threads import extract_threadslines 446–446db = tmp_path / "clew.db"lines 447–447(tmp_path / "src").mkdir()lines 448–461(tmp_path / "src" / "a.c").write_text( "void drain(void);\n" "#ifdef CPU_A\n" "void isr_svc(void)\n" "{\n" " drain();\n" "}\n" "#else\n" "void isr_svc(void)\n" "{\n" " drain();\n" "}\n" "#endif\n" )lines 462–462conn = sqlite3.connect(str(db))lines 463–478conn.executescript( """ CREATE TABLE path (name TEXT); CREATE TABLE memberdef ( rowid INTEGER PRIMARY KEY, kind TEXT, name TEXT, file_id INTEGER, bodyfile_id INTEGER, bodystart INTEGER, bodyend INTEGER); CREATE TABLE call_edges ( caller_rowid INTEGER, callee_rowid INTEGER, source TEXT, confidence TEXT); INSERT INTO path (rowid, name) VALUES (1, 'src/a.c'); INSERT INTO memberdef (rowid, kind, name, file_id, bodyfile_id, bodystart, bodyend) VALUES (1, 'function', 'isr_svc', 1, 1, 3, 6), (2, 'function', 'isr_svc', 1, 1, 8, 11), (3, 'function', 'drain', 1, 1, 1, 1); INSERT INTO call_edges VALUES (1, 3, 'ast', 'resolved'), (2, 3, 'ast', 'resolved'); """ )lines 479–479conn.commit()lines 480–480conn.close()lines 482–482extract_threads(db, tmp_path)lines 484–484conn = sqlite3.connect(str(db))lines 485–490entries = [ r[0] for r in conn.execute( "SELECT entry_memberdef_rowid FROM threads WHERE kind='isr' ORDER BY spawn_line" ) ]lines 491–491members = conn.execute("SELECT COUNT(*) FROM thread_membership").fetchone()[0]lines 492–492conn.close()lines 494–494assert entries == [1, 2], f"each arm resolves to its own definition, got {entries}"lines 495–495assert members == 4, f"both closures are populated (entry + drain, twice), got {members}"

test_two_handlers_of_the_same_name_resolve_to_their_own_file

None test_isr.test_two_handlers_of_the_same_name_resolve_to_their_own_file(tmp_path)

An ambiguous handler name resolves within its own file.

tests/test_isr.py:294

Checks

  • assert [(r[1], r[2]) for r in rows] == [(1, "src/a.c"), (3, "src/b.c")], (f"each registration must resolve to the handler defined beside it, got {rows}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002inferredtest_two_handlers_of_the_same_name_resolve_to_their_own_file → extract_threads → spawn_harvester → manifest_key → hash_file
REQ-DDB-PIPE-003measuredtest_two_handlers_of_the_same_name_resolve_to_their_own_file → extract_threads → spawn_harvester → manifest_key
REQ-DDB-PIPE-004measuredtest_two_handlers_of_the_same_name_resolve_to_their_own_file → extract_threads → _populate_membership → _bfs_live_set
REQ-DDB-PIPE-011measuredtest_two_handlers_of_the_same_name_resolve_to_their_own_file → extract_threads → _harvest_all_spawn_sites → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_two_handlers_of_the_same_name_resolve_to_their_own_file → extract_threads → _harvest_all_spawn_sites → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-003measuredtest_two_handlers_of_the_same_name_resolve_to_their_own_file → extract_threads → _definition_preferring_name_index
REQ-DDB-QUERY-011measuredtest_two_handlers_of_the_same_name_resolve_to_their_own_file → extract_threads → _ensure_threads_tables
REQ-DDB-SCHEMA-001measuredtest_two_handlers_of_the_same_name_resolve_to_their_own_file → extract_threads
REQ-DDB-SCHEMA-007measuredtest_two_handlers_of_the_same_name_resolve_to_their_own_file → extract_threads → _ensure_threads_tables
REQ-DDB-SCHEMA-012measuredtest_two_handlers_of_the_same_name_resolve_to_their_own_file → extract_threads → spawn_harvester → load_thread_patterns → declaration_origin
Source · 69 lines
def test_two_handlers_of_the_same_name_resolve_to_their_own_file(tmp_path) -> None:
    """MEASURED ON ZEPHYR, AND IT COST THE FEATURE ITS BEST FINDING. `button_pressed` is defined
    in samples/bluetooth/encrypted_advertising/central AND .../peripheral, each registered in its
    own file, each calling k_sleep — a textbook violation. The bare name resolved to two
    candidates, so both threads got a NULL entry, no closure, and no conflict: the layer found
    the handlers and could say nothing about either.

    A handler is normally `static` and registered in the file that defines it, so the file is
    the disambiguator that is always available. Falling back to it is not a guess — it is the
    same identity rule the rest of the pipeline uses when a name is ambiguous, and never merges
    two same-named statics into one.

    @brief An ambiguous handler name resolves within its own file.
    @version 1
    """
    import sqlite3

    from clew.threads import extract_threads

    db = tmp_path / "clew.db"
    (tmp_path / "src").mkdir()
    for index, folder in enumerate(("a", "b"), start=1):
        path = tmp_path / "src" / f"{folder}.c"
        path.write_text(
            "void k_sleep(int t);\n"
            "static void button_pressed(void)\n"
            "{\n"
            "    k_sleep(1);\n"
            "}\n"
            "void setup(void)\n"
            "{\n"
            "    gpio_init_callback(&cb, button_pressed, 1);\n"
            "}\n"
        )
    conn = sqlite3.connect(str(db))
    conn.executescript(
        """
        CREATE TABLE path (name TEXT);
        CREATE TABLE memberdef (
            rowid INTEGER PRIMARY KEY, kind TEXT, name TEXT,
            file_id INTEGER, bodyfile_id INTEGER, bodystart INTEGER, bodyend INTEGER);
        CREATE TABLE call_edges (
            caller_rowid INTEGER, callee_rowid INTEGER, source TEXT, confidence TEXT);
        INSERT INTO path (rowid, name) VALUES (1, 'src/a.c'), (2, 'src/b.c');
        INSERT INTO memberdef (rowid, kind, name, file_id, bodyfile_id, bodystart, bodyend)
          VALUES (1, 'function', 'button_pressed', 1, 1, 2, 5),
                 (2, 'function', 'setup', 1, 1, 6, 9),
                 (3, 'function', 'button_pressed', 2, 2, 2, 5),
                 (4, 'function', 'setup', 2, 2, 6, 9);
        """
    )
    conn.commit()
    conn.close()

    extract_threads(db, tmp_path)

    conn = sqlite3.connect(str(db))
    rows = conn.execute(
        "SELECT t.name, t.entry_memberdef_rowid, p.name FROM threads t "
        "LEFT JOIN path p ON p.rowid = t.spawn_path_rowid WHERE t.kind = 'isr' "
        "ORDER BY p.name"
    ).fetchall()
    conn.close()

    assert [(r[1], r[2]) for r in rows] == [(1, "src/a.c"), (3, "src/b.c")], (
        f"each registration must resolve to the handler defined beside it, got {rows}"
    )

Activity · 16 steps
lines 309–309import sqlite3lines 311–311from clew.threads import extract_threadslines 313–313db = tmp_path / "clew.db"lines 314–314(tmp_path / "src").mkdir()lines 315–315◇ for index, folder in enumerate(("a", "b"), start=1)lines 316–316path = tmp_path / "src" / f"{folder}.c"lines 317–327path.write_text( "void k_sleep(int t);\n" "static void button_pressed(void)\n" "{\n" " k_sleep(1);\n" "}\n" "void setup(void)\n" "{\n" " gpio_init_callback(&cb, button_pressed, 1);\n" "}\n" )lines 328–328conn = sqlite3.connect(str(db))lines 329–344conn.executescript( """ CREATE TABLE path (name TEXT); CREATE TABLE memberdef ( rowid INTEGER PRIMARY KEY, kind TEXT, name TEXT, file_id INTEGER, bodyfile_id INTEGER, bodystart INTEGER, bodyend INTEGER); CREATE TABLE call_edges ( caller_rowid INTEGER, callee_rowid INTEGER, source TEXT, confidence TEXT); INSERT INTO path (rowid, name) VALUES (1, 'src/a.c'), (2, 'src/b.c'); INSERT INTO memberdef (rowid, kind, name, file_id, bodyfile_id, bodystart, bodyend) VALUES (1, 'function', 'button_pressed', 1, 1, 2, 5), (2, 'function', 'setup', 1, 1, 6, 9), (3, 'function', 'button_pressed', 2, 2, 2, 5), (4, 'function', 'setup', 2, 2, 6, 9); """ )lines 345–345conn.commit()lines 346–346conn.close()lines 348–348extract_threads(db, tmp_path)lines 350–350conn = sqlite3.connect(str(db))lines 351–355rows = conn.execute( "SELECT t.name, t.entry_memberdef_rowid, p.name FROM threads t " "LEFT JOIN path p ON p.rowid = t.spawn_path_rowid WHERE t.kind = 'isr' " "ORDER BY p.name" ).fetchall()lines 356–356conn.close()lines 358–360assert [(r[1], r[2]) for r in rows] == [(1, "src/a.c"), (3, "src/b.c")], ( f"each registration must resolve to the handler defined beside it, got {rows}" )

test_what_the_definition_forms_refuse

None test_isr.test_what_the_definition_forms_refuse()

A reset entry, an argument-taking lookalike and a declaration are refused.

tests/test_isr.py:206

Show on the map →

Called by none

Calls _sites

Checks

  • assert "Reset_Handler" not in entries, "the reset entry reaches main(); it is not an ISR"
  • assert "isr_helper" not in entries, "a handler-shaped name taking an argument is a helper"
  • assert "TIM2_IRQHandler" not in entries, "a declaration defines no handler"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-003measuredtest_what_the_definition_forms_refuse → _sites → _walk_spawn_sites → is_python_tree
REQ-DDB-SCHEMA-001measuredtest_what_the_definition_forms_refuse → _sites → load_thread_patterns
REQ-DDB-SCHEMA-012inferredtest_what_the_definition_forms_refuse → _sites → load_thread_patterns → declaration_origin
Source · 19 lines
def test_what_the_definition_forms_refuse() -> None:
    """THE THREE REFUSALS, each measured rather than assumed.

    `Reset_Handler` satisfies the CMSIS naming convention and is the one entry that must never
    be an ISR: it calls main(), so every blocking call in the program becomes interrupt-
    reachable through it. `isr_helper(int)` is named like a handler and takes an argument — in
    RIOT that shape is a helper the real handler calls (cpu/msp430/periph/gpio.c:213), not a
    vector. A bare declaration is not a definition and names no body to walk.

    @brief A reset entry, an argument-taking lookalike and a declaration are refused.
    @version 1
    """
    entries = {site[ENTRY] for site in _sites(_DEFINITIONS)}

    assert "Reset_Handler" not in entries, "the reset entry reaches main(); it is not an ISR"
    assert "isr_helper" not in entries, "a handler-shaped name taking an argument is a helper"
    assert "TIM2_IRQHandler" not in entries, "a declaration defines no handler"

Activity · 4 steps
lines 218–218entries = {site[ENTRY] for site in _sites(_DEFINITIONS)}lines 220–220assert "Reset_Handler" not in entries, "the reset entry reaches main(); it is not an ISR"lines 221–221assert "isr_helper" not in entries, "a handler-shaped name taking an argument is a helper"lines 222–222assert "TIM2_IRQHandler" not in entries, "a declaration defines no handler"