Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ on:
- "tools/cf_diff.py"
- "tools/cf_ref.py"
- "tools/cfg_structure.py"
- "tools/conformance/**"
- "tools/cpu_ref.py"
- "tools/f32_fuzz.py"
- "tools/file_mode.py"
Expand Down Expand Up @@ -78,6 +79,7 @@ on:
- "tools/cf_diff.py"
- "tools/cf_ref.py"
- "tools/cfg_structure.py"
- "tools/conformance/**"
- "tools/cpu_ref.py"
- "tools/f32_fuzz.py"
- "tools/file_mode.py"
Expand Down
50 changes: 30 additions & 20 deletions tests/test_runner_calls_all_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
only unrouted assert (PR #3051). This is the runner counterpart of tests/test_ci_registration.py: it reuses
that file's classification straight from the workflow (so it cannot drift from ci.yml) and fails for every
stdlib-mode file whose __main__ block neither names each top-level test function nor dispatches the whole set
through the ``globals()`` loop some runners use. Intentional non-calls live in RUNNER_SKIPS with their reason,
through a ``globals()`` loop or comprehension, as some runners do. Intentional non-calls live in RUNNER_SKIPS with their reason,
so a new dead test cannot hide behind a documented one.

Only the tracked test files and the workflow are read; no game files, no build tools, no pytest.
Expand All @@ -35,22 +35,6 @@
# drop this entry once that merges and the runner calls test_depth() first.
"test_depth",
},
"tests/test_feature_scan.py": {
# Its __main__ runner calls every test_* through run_tests([... for ... in globals().items() ...]), a
# comprehension dispatches_tests() does not follow, so each top-level test is listed here.
"test_feature_scan",
"test_short_signature",
"test_part_payload_outside_container_is_unreadable",
"test_bad_shaders_folder_is_one_line",
"test_out_inside_corpus_is_a_usage_error",
"test_duplicate_shader_names_keep_file_stages",
"test_v_perm_b32_selectors",
"test_typed_buffers_and_psv0",
"test_a_test_that_raises_fails_the_run_and_the_rest_still_run",
"test_a_failed_check_fails_only_its_own_test",
"test_out_via_directory_alias_into_corpus_is_a_usage_error",
"test_out_hard_link_to_carved_index_is_a_usage_error",
},
}


Expand All @@ -62,14 +46,30 @@ def runner_block(tree):
return None


def _reads_namespace(node):
"""True when ``node`` calls globals(), locals() or vars() somewhere inside it."""
return any(isinstance(n, ast.Call) and isinstance(n.func, ast.Name)
and n.func.id in ("globals", "locals", "vars") for n in ast.walk(node))


def dispatches_tests(block):
"""True when the runner runs its tests through a loop over module globals and calls the loop variable."""
"""True when the runner runs its tests through a loop over module globals and calls the loop variable, or
hands a comprehension over module globals that yields the loop variable straight to a call, as in
``run_tests([fn for name, fn in globals().items() if name.startswith("test_")])``."""
for node in ast.walk(block):
if isinstance(node, ast.Call):
for arg in list(node.args) + [k.value for k in node.keywords]:
if not isinstance(arg, (ast.ListComp, ast.GeneratorExp, ast.SetComp)):
continue
if not any(_reads_namespace(g.iter) for g in arg.generators):
continue
targets = {t.id for g in arg.generators for t in ast.walk(g.target) if isinstance(t, ast.Name)}
if isinstance(arg.elt, ast.Name) and arg.elt.id in targets:
return True
if not isinstance(node, ast.For):
continue
targets = {t.id for t in ast.walk(node.target) if isinstance(t, ast.Name)}
if not any(isinstance(n, ast.Call) and isinstance(n.func, ast.Name)
and n.func.id in ("globals", "locals", "vars") for n in ast.walk(node)):
if not _reads_namespace(node):
continue
if any(isinstance(n, ast.Call) and isinstance(n.func, ast.Name) and n.func.id in targets
for n in ast.walk(node)):
Expand Down Expand Up @@ -124,6 +124,16 @@ def test_a_dropped_call_is_flagged(self):
sabotaged = source.replace(" test_straight_line()", " # dropped for the bite check", 1)
self.assertEqual(uncalled_tests(sabotaged), ["test_straight_line"])

def test_a_globals_comprehension_dispatches_every_test(self):
# tests/test_feature_scan.py hands run_tests() a comprehension over globals(): a test added there is run,
# so it must not need a RUNNER_SKIPS entry, while the same comprehension over a fixed table runs only what
# the table lists and leaves every test it misses reported.
source = registration.read(registration.ROOT, "tests/test_feature_scan.py")
self.assertEqual(uncalled_tests(source), [])
fixed_table = source.replace("list(globals().items())", "list(TESTS.items())", 1)
self.assertNotEqual(fixed_table, source, "the runner's comprehension moved; update this bite check")
self.assertIn("test_feature_scan", uncalled_tests(fixed_table))


if __name__ == "__main__":
unittest.main()
4 changes: 4 additions & 0 deletions tools/compute_heap_layout_census.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ def census(disasm, captured, per_program=False):


if __name__ == "__main__":
try: # a redirected stdout is strict ANSI code page under -I; write '?' for what it cannot encode
sys.stdout.reconfigure(errors="replace")
except (AttributeError, ValueError, OSError):
pass
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("disasm", type=Path)
parser.add_argument("--dispatch-log", action="append", default=[], type=Path)
Expand Down