test_gate_polarity.py¶
tests/test_gate_polarity.py
A single-symbol `#if defined(X)` has a polarity, and so does its `#else` (UPERF T5; 2.0.0).
test_a_compound_or_elif_condition_stays_unevaluated
None test_gate_polarity.test_a_compound_or_elif_condition_stays_unevaluated()
`&&` and `#elif` keep `if_expr`: their presence depends on more than one symbol.
tests/test_gate_polarity.py:46
Checks
assert {form for _m, form, _l, _e in rows} == {"if_expr"}, rows
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-007 | measured | test_a_compound_or_elif_condition_stays_unevaluated → _gates → gate_harvester |
Source · 6 lines
def test_a_compound_or_elif_condition_stays_unevaluated() -> None:
"""@brief `&&` and `#elif` keep `if_expr`: their presence depends on more than one symbol."""
rows = _gates("#if defined(A) && defined(B)\nint a;\n#elif defined(C)\nint c;\n#endif\n")
assert {form for _m, form, _l, _e in rows} == {"if_expr"}, rows
Activity · 2 steps
test_a_declared_config_header_outvotes_heuristic_ones
None test_gate_polarity.test_a_declared_config_header_outvotes_heuristic_ones(tmp_path)
Declared rows, where a macro has any, are the only votes.
tests/test_gate_polarity.py:166
Checks
assert macro_definitions(conn)["mem_calloc"] == [11], "declared off wins over a heuristic on"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-QUERY-013 | measured |
Source · 19 lines
def test_a_declared_config_header_outvotes_heuristic_ones(tmp_path) -> None:
"""THE OPERATOR CAN SAY WHICH HEADER IS THE BUILD'S. `config_defaults` already tiers each row:
`declared` for a header the repository states, `heuristic` for one that merely looks like a
config header. mbedtls's motivating case, MBEDTLS_PLATFORM_MEMORY, is off in mbedtls_config.h
and on in an alternative profile, so it is undecided by unanimity alone; with the shipped
header declared, the declared rows decide and the other profiles do not vote.
@brief Declared rows, where a macro has any, are the only votes.
"""
from clew.macro_refs import macro_definitions
conn = _macro_db(tmp_path)
conn.execute("UPDATE config_defaults SET origin = 'declared'")
conn.execute(
"INSERT INTO config_defaults VALUES ('MEM', 'on', '', 'profile.h', 1, '', 'heuristic')"
)
assert macro_definitions(conn)["mem_calloc"] == [11], "declared off wins over a heuristic on"
Activity · 5 steps
test_a_same_name_macro_resolves_to_the_definition_the_default_build_compiles
None test_gate_polarity.test_a_same_name_macro_resolves_to_the_definition_the_default_build_compiles(tmp_path)
The default build picks the definition.
tests/test_gate_polarity.py:82
Checks
assert macro_definitions(conn)["mem_calloc"] == [11]assert macro_definitions(conn)["mem_calloc"] == [10]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-QUERY-013 | measured |
Source · 14 lines
def test_a_same_name_macro_resolves_to_the_definition_the_default_build_compiles(tmp_path) -> None:
"""mbedtls F3: `{name: rowid}` kept whichever definition was read last. With MEM off as
shipped, the `#else` definition is the one compiled.
@brief The default build picks the definition.
"""
from clew.macro_refs import macro_definitions
conn = _macro_db(tmp_path)
assert macro_definitions(conn)["mem_calloc"] == [11]
conn.execute("UPDATE config_defaults SET state = 'on'")
assert macro_definitions(conn)["mem_calloc"] == [10]
Activity · 5 steps
test_a_single_defined_test_is_an_ifdef_or_ifndef
None test_gate_polarity.test_a_single_defined_test_is_an_ifdef_or_ifndef(str condition, str form)
`#if [!]defined(X)` carries X's polarity, and the `#else` the inverse.
tests/test_gate_polarity.py:39
Checks
assert rows == [("A", form, 1, 3), ("A", inverse, 3, 4)], rows
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-007 | measured | test_a_single_defined_test_is_an_ifdef_or_ifndef → _gates → gate_harvester |
Source · 7 lines
def test_a_single_defined_test_is_an_ifdef_or_ifndef(condition: str, form: str) -> None:
"""@brief `#if [!]defined(X)` carries X's polarity, and the `#else` the inverse."""
inverse = {"ifdef": "ifndef", "ifndef": "ifdef"}[form]
rows = _gates(f"#if {condition}\nint a;\n#else\nint b;\n#endif\n")
assert rows == [("A", form, 1, 3), ("A", inverse, 3, 4)], rows
Activity · 3 steps
test_a_spelled_out_include_guard_is_still_not_a_gate
None test_gate_polarity.test_a_spelled_out_include_guard_is_still_not_a_gate()
`#if !defined(FOO_H)` + `#define FOO_H` is an include guard, like `#ifndef FOO_H`.
tests/test_gate_polarity.py:52
Checks
assert _gates("#if !defined(FOO_H)\n#define FOO_H\nint a;\n#endif\n") == []
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-007 | measured | test_a_spelled_out_include_guard_is_still_not_a_gate → _gates → gate_harvester |
Source · 5 lines
def test_a_spelled_out_include_guard_is_still_not_a_gate() -> None:
"""@brief `#if !defined(FOO_H)` + `#define FOO_H` is an include guard, like `#ifndef FOO_H`."""
assert _gates("#if !defined(FOO_H)\n#define FOO_H\nint a;\n#endif\n") == []
Activity · 1 steps
test_an_undecided_symbol_keeps_every_definition
None test_gate_polarity.test_an_undecided_symbol_keeps_every_definition(tmp_path)
Unknown activity keeps both.
tests/test_gate_polarity.py:96
Checks
assert sorted(macro_definitions(conn)["mem_calloc"]) == [10, 11]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured |
Source · 12 lines
def test_an_undecided_symbol_keeps_every_definition(tmp_path) -> None:
"""No config row: the build's choice is unknown here, so neither definition is dropped.
@brief Unknown activity keeps both.
"""
from clew.macro_refs import macro_definitions
conn = _macro_db(tmp_path)
conn.execute("DELETE FROM config_defaults")
assert sorted(macro_definitions(conn)["mem_calloc"]) == [10, 11]
Activity · 4 steps
test_conflicting_or_test_only_states_decide_nothing
None test_gate_polarity.test_conflicting_or_test_only_states_decide_nothing(tmp_path)
Disagreeing or test-only states are unknown, so both definitions are kept.
tests/test_gate_polarity.py:124
Checks
assert sorted(macro_definitions(conn)["mem_calloc"]) == [10, 11], "off vs on: undecided"assert sorted(macro_definitions(conn)["mem_calloc"]) == [10, 11], ("a test config decides nothing" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-QUERY-013 | measured |
Source · 27 lines
def test_conflicting_or_test_only_states_decide_nothing(tmp_path) -> None:
"""MEASURED ON MBEDTLS: `config_defaults` holds rows from alternative profiles, the
`config_adjust_*` headers and test configs — 92 macros with conflicting states, and
`MBEDTLS_PSA_ACCEL_ALG_RSA_OAEP` "on" from a test-driver config alone. Taking the last row
dropped definitions the default build compiles. A symbol is decided only when every row
outside the test files agrees.
@brief Disagreeing or test-only states are unknown, so both definitions are kept.
"""
from clew.macro_refs import macro_definitions
conn = _macro_db(tmp_path)
conn.execute(
"INSERT INTO config_defaults VALUES ('MEM', 'on', '', 'profile.h', 1, '', 'source')"
)
assert sorted(macro_definitions(conn)["mem_calloc"]) == [10, 11], "off vs on: undecided"
conn.execute("DELETE FROM config_defaults")
conn.executescript(
"INSERT INTO path VALUES (9, 'tests/cfg.h');"
"CREATE TABLE test_scope (path_rowid INTEGER PRIMARY KEY); INSERT INTO test_scope VALUES (9);"
"INSERT INTO config_defaults VALUES ('MEM', 'on', '', 'tests/cfg.h', 1, '', 'source');"
)
assert sorted(macro_definitions(conn)["mem_calloc"]) == [10, 11], (
"a test config decides nothing"
)
Activity · 7 steps
test_the_build_s_test_patterns_apply_before_test_scope_exists
None test_gate_polarity.test_the_build_s_test_patterns_apply_before_test_scope_exists(tmp_path)
Patterns, not the table, at build time.
tests/test_gate_polarity.py:151
Checks
assert sorted(macro_definitions(conn, ["tests/*"])["mem_calloc"]) == [10, 11]assert macro_definitions(conn)["mem_calloc"] == [11], "no patterns, no table: the row decides"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-QUERY-013 | measured |
Source · 15 lines
def test_the_build_s_test_patterns_apply_before_test_scope_exists(tmp_path) -> None:
"""The macro stage runs before `test_scope` is marked, so the build passes its patterns.
Measured on mbedtls: with only the table consulted, a test-driver config still decided
`MBEDTLS_PSA_ACCEL_ALG_RSA_OAEP` at build time and dropped definitions of MBEDTLS_RSA_C.
@brief Patterns, not the table, at build time.
"""
from clew.macro_refs import macro_definitions
conn = _macro_db(tmp_path)
conn.execute("UPDATE config_defaults SET file_path = 'tests/cfg.h'")
assert sorted(macro_definitions(conn, ["tests/*"])["mem_calloc"]) == [10, 11]
assert macro_definitions(conn)["mem_calloc"] == [11], "no patterns, no table: the row decides"
Activity · 5 steps
test_the_shipped_header_decides_over_an_alternative_profile
None test_gate_polarity.test_the_shipped_header_decides_over_an_alternative_profile(tmp_path)
A configs/ profile does not outvote the shipped header.
tests/test_gate_polarity.py:185
Checks
assert macro_definitions(conn)["mem_calloc"] == [11], "shipped off wins over a configs/ on"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-QUERY-013 | measured |
Source · 17 lines
def test_the_shipped_header_decides_over_an_alternative_profile(tmp_path) -> None:
"""THE QUERY LAYER'S RULE, AT BUILD TIME TOO (2.0.0, T5 served). `query.kconfig._with_defaults`
lets the shipped header settle a disagreement with an alternative profile, so a dossier said
MBEDTLS_PLATFORM_MEMORY is off while `macro_refs`, deciding by unanimity alone, kept both
`mbedtls_calloc` definitions. One rule now serves both (`query._common.decided_default`).
@brief A configs/ profile does not outvote the shipped header.
"""
from clew.macro_refs import macro_definitions
conn = _macro_db(tmp_path)
conn.execute(
"INSERT INTO config_defaults VALUES ('MEM', 'on', '', 'configs/profile.h', 1, '', 'heuristic')"
)
assert macro_definitions(conn)["mem_calloc"] == [11], "shipped off wins over a configs/ on"
Activity · 4 steps
test_two_shipped_headers_that_disagree_decide_nothing_on_either_side
None test_gate_polarity.test_two_shipped_headers_that_disagree_decide_nothing_on_either_side(tmp_path)
Disagreement within a tier is undecided, at build time and at query time.
tests/test_gate_polarity.py:202
Checks
assert sorted(macro_definitions(conn)["mem_calloc"]) == [10, 11]assert served.default_state == "" and served.in_default_build is None
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-003 | measured | |
| REQ-DDB-QUERY-003 | measured | test_two_shipped_headers_that_disagree_decide_nothing_on_either_side → _with_defaults → table_exists |
| REQ-DDB-QUERY-004 | inferred | test_two_shipped_headers_that_disagree_decide_nothing_on_either_side → _with_defaults → _in_default_build |
| REQ-DDB-QUERY-013 | measured | test_two_shipped_headers_that_disagree_decide_nothing_on_either_side → _with_defaults → decided_default |
Source · 20 lines
def test_two_shipped_headers_that_disagree_decide_nothing_on_either_side(tmp_path) -> None:
"""NO LAST-ROW-WINS ANYWHERE. Both sides used to differ here: the query layer kept whichever
shipped row it met last, the build kept both definitions. Now both say undecided.
@brief Disagreement within a tier is undecided, at build time and at query time.
"""
from clew.macro_refs import macro_definitions
from clew.query.kconfig import _with_defaults
from clew.query.models import KconfigGate
conn = _macro_db(tmp_path)
conn.execute(
"INSERT INTO config_defaults VALUES ('MEM', 'on', '', 'include/adjust.h', 1, '', 'heuristic')"
)
assert sorted(macro_definitions(conn)["mem_calloc"]) == [10, 11]
gate = KconfigGate(symbol="MEM", macro="MEM", form="ifdef", file_path="platform.h", line=1)
(served,) = _with_defaults(conn, (gate,))
assert served.default_state == "" and served.in_default_build is None