Validate mutation baselines and cover blended gesture reset

This commit is contained in:
firestar5683
2026-11-19 15:47:27 -06:00
parent dc1eef9f6a
commit c4c7918066
4 changed files with 48 additions and 33 deletions
+12 -28
View File
@@ -429,33 +429,8 @@ def verify_equivalence_artifact(path):
def _build_core_tests(catalog):
"""Build test ordering for core (non-mode) files.
Tests are ordered by how widely each method is shared. Methods inherited by
many classes exercise the most fundamental safety logic and run first.
Keep every implementation of each method.
"""
method_freq = {}
method_by_module = {}
for name in sorted(catalog.keys()):
for test_id in catalog[name]:
method = test_id.rsplit(".", 1)[-1]
method_freq[method] = method_freq.get(method, 0) + 1
if method not in method_by_module:
method_by_module[method] = {}
method_by_module[method].setdefault(name, []).append(test_id)
# Round-robin: first instance of each method (by freq), then second, etc.
# This ensures diverse early coverage with failfast.
sorted_methods = sorted(method_freq, key=lambda m: -method_freq[m])
ordered = []
max_implementations = max(sum(len(ids) for ids in module_map.values()) for module_map in method_by_module.values())
for round_idx in range(max_implementations):
for m in sorted_methods:
ids = [test_id for module in sorted(method_by_module[m]) for test_id in method_by_module[m][module]]
if round_idx < len(ids):
ordered.append(ids[round_idx])
return ordered
"""Keep the complete ordering that passed the unmutated baseline."""
return [test_id for name in sorted(catalog) for test_id in catalog[name]]
def build_priority_tests(site, catalog, core_tests):
@@ -851,7 +826,7 @@ def require_full_baseline(catalog, sites, lib_path, verbose):
if not catalog or any(not ids for ids in catalog.values()):
raise RuntimeError("empty safety test catalog or module")
baseline_ids = [test_id for module in sorted(catalog) for test_id in catalog[module]]
baseline = run_unittest(baseline_ids, lib_path, mutant_id=-1, verbose=verbose)
baseline = _run_isolated_unittest(-1, baseline_ids, lib_path, 300.0)
if (baseline.failures or baseline.errors or baseline.ran + baseline.suppressed != len(baseline_ids) or
baseline.ran == baseline.skipped):
raise RuntimeError(f"unmutated full safety baseline failed: {baseline}")
@@ -861,6 +836,15 @@ def require_full_baseline(catalog, sites, lib_path, verbose):
missing = [site_id for site_id, ids in targets.items() if not ids]
if missing:
raise RuntimeError(f"mutants lack test targets: {missing[:20]} ({len(missing)} total)")
checked = {tuple(baseline_ids)}
for selected in targets.values():
identity = tuple(selected)
if identity in checked:
continue
run = _run_isolated_unittest(-1, selected, lib_path, 300.0)
if (run.failures or run.errors or run.ran + run.suppressed != len(selected) or run.ran == run.skipped):
raise RuntimeError(f"unmutated selected safety baseline failed: {run}")
checked.add(identity)
return targets
@@ -549,6 +549,19 @@ class TestHyundaiBlendedAlphaAol(unittest.TestCase):
self.assertEqual(self.safety.safety_fwd_hook(2, address), -1)
self.assertEqual(self.safety.safety_fwd_hook(0, address), 2)
def test_heartbeat_loss_requires_a_new_neutral_gesture_sample(self):
for word in (0x2004, 0x2014):
with self.subTest(word=word):
self.counter, self.now = 0, 1_000_000
self.reset(word)
self.warm()
self.assertEqual(self.request(1), 0)
self.safety.set_aol_test_heartbeat(False)
self.assertEqual(self.request(0), 0)
self.safety.set_aol_test_heartbeat(True)
self.feed(lda=True)
self.assertEqual(self.request(1), 0)
class TestHyundaiBlendedHda2Integrity(unittest.TestCase):
def setUp(self):
@@ -206,6 +206,24 @@ def test_native_variant(native_variant):
actual = mutation.build_priority_tests(site, catalog, all_targets)
self.assertEqual(Counter(actual), Counter(target for name in names for target in catalog[name]))
def test_core_order_matches_the_validated_full_baseline(self):
catalog = {"test_z.py": ["fixture.Z.test_first", "fixture.Z.test_second"],
"test_a.py": ["fixture.A.test_first"]}
expected = ["fixture.A.test_first", "fixture.Z.test_first", "fixture.Z.test_second"]
self.assertEqual(mutation._build_core_tests(catalog), expected)
def test_each_distinct_selected_order_must_pass_unmutated(self):
catalog = {"test_fixture.py": ["fixture.one", "fixture.two"]}
selected = ["fixture.two", "fixture.one"]
healthy = mutation.TestRun(2, 0, 0, (), ())
broken = mutation.TestRun(2, 0, 0, ("fixture.one",), ())
for bad in (broken, mutation.TestRun(1, 0, 0, (), ()), mutation.TestRun(2, 2, 0, (), ())):
with self.subTest(run=bad), patch.object(mutation, "_run_isolated_unittest", side_effect=[healthy, bad]) as run, \
patch.object(mutation, "build_priority_tests", return_value=selected):
with self.assertRaisesRegex(RuntimeError, "unmutated selected safety baseline failed"):
mutation.require_full_baseline(catalog, [self.site()], Path("libsafety.so"), False)
self.assertEqual(run.call_count, 2)
def test_worker_crash_is_infrastructure_error(self):
site = self.site()
future = Future()
@@ -222,16 +240,16 @@ def test_native_variant(native_variant):
def test_full_baseline_failure_aborts_before_mutant_targets(self):
catalog = {"test_defaults.py": ["test_defaults.TestNoOutput.test_tx_hook"]}
with patch.object(mutation, "run_unittest", return_value=mutation.TestRun(1, 0, 0, (catalog["test_defaults.py"][0],), ())) as baseline, \
with patch.object(mutation, "_run_isolated_unittest", return_value=mutation.TestRun(1, 0, 0, (catalog["test_defaults.py"][0],), ())) as baseline, \
patch.object(mutation, "build_priority_tests") as targets:
with self.assertRaisesRegex(RuntimeError, "unmutated full safety baseline failed"):
mutation.require_full_baseline(catalog, [self.site()], Path("libsafety.so"), False)
baseline.assert_called_once_with(catalog["test_defaults.py"], Path("libsafety.so"), mutant_id=-1, verbose=False)
baseline.assert_called_once_with(-1, catalog["test_defaults.py"], Path("libsafety.so"), 300.0)
targets.assert_not_called()
def test_empty_target_is_not_treated_as_surviving_mutant(self):
catalog = {"test_defaults.py": ["test_defaults.TestNoOutput.test_tx_hook"]}
with patch.object(mutation, "run_unittest", return_value=mutation.TestRun(1, 0, 0, (), ())), \
with patch.object(mutation, "_run_isolated_unittest", return_value=mutation.TestRun(1, 0, 0, (), ())), \
patch.object(mutation, "build_priority_tests", return_value=[]):
with self.assertRaisesRegex(RuntimeError, "mutants lack test targets"):
mutation.require_full_baseline(catalog, [self.site()], Path("libsafety.so"), False)
@@ -250,7 +268,7 @@ def test_native_variant(native_variant):
def test_partial_or_all_skipped_baseline_aborts(self):
catalog = {"test_defaults.py": ["test.one", "test.two"]}
for run in (mutation.TestRun(1, 0, 0, (), ()), mutation.TestRun(2, 2, 0, (), ())):
with self.subTest(run=run), patch.object(mutation, "run_unittest", return_value=run):
with self.subTest(run=run), patch.object(mutation, "_run_isolated_unittest", return_value=run):
with self.assertRaisesRegex(RuntimeError, "unmutated full safety baseline failed"):
mutation.require_full_baseline(catalog, [self.site()], Path("libsafety.so"), False)
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "00dc2f3d6b66df7a9f3a2011350ccd8d7fbaff98dbb78d616d317b3604d3e4ca", "schema_version": 1}
{"protected_inventory_sha256": "972ca48df861316d293c41cc3ddb3601e9e4057a542f4648aff477752d68f5d8", "schema_version": 1}