Skip to content
Open
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
28 changes: 19 additions & 9 deletions scripts/pr_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@
MAX_BINARY = 1 << 20
FRAMES_KEPT = 0.8 # the PR's frames at least this share of main's
COMMIT_GROWTH = 1.25 # the PR's peak commit at most this times main's
# the lines a smoke block needs to be compared with the other (the crash and device-removal
# counts are checked where they are used), and those of them that are numbers
# the lines a smoke block needs to be compared with the other, and those of them that are numbers
SMOKE_FIELDS = ("title", "seconds", "frames shown")
SMOKE_NUMBERS = ("seconds", "frames shown")
# the lines the PR's own block also needs, to show it ended cleanly (smoke.ps1 always prints
# them; main's run may have crashed, #1506), and the exact form smoke.ps1 prints their values in
PR_SMOKE_FIELDS = ("device removals", "crashes", "exit", "peak commit")
PR_SMOKE_FORMS = {"device removals": r"\d+", "crashes": r"\d+", "peak commit": r"\d+ MB"}


def smoke_blocks(body):
Expand All @@ -58,13 +61,16 @@ def number(s):
return int(m.group(1)) if m else None


def field_problems(block, run):
"""What `block` (the smoke block of `run`) lacks for the comparison: a missing line or a
number that is not one."""
def field_problems(block, run, fields=SMOKE_FIELDS, numbers=SMOKE_NUMBERS, forms=None, positive=("seconds",)):
"""What is wrong with `block` (the smoke block of `run`): a missing line, a number that is not
one, a value not in the form smoke.ps1 prints it in, or a 0 where a real run has more."""
name = f"{run} regression run (`xcl-smoke` block of commit {(block.get('commit') or '?').split()[0]})"
out = [f"{name} has no `{k}` line" for k in SMOKE_FIELDS if not block.get(k)]
out += [f"{name} has a non-numeric `{k}`: {block[k]}" for k in SMOKE_NUMBERS
out = [f"{name} has no `{k}` line" for k in fields if not block.get(k)]
out += [f"{name} has a non-numeric `{k}`: {block[k]}" for k in numbers
if block.get(k) and number(block[k]) is None]
out += [f"{name} has a malformed `{k}`: {block[k]}" for k, form in (forms or {}).items()
if block.get(k) and not re.fullmatch(form, block[k])]
out += [f"{name} shows `{k}: 0`" for k in positive if number(block.get(k)) == 0]
return out


Expand Down Expand Up @@ -141,12 +147,16 @@ def check(body, head, files, is_main_ancestor, *, test_only=False):
"with the same title and time as the PR's")
if clean:
pr = clean[-1]
problems += field_problems(pr, "the PR's")
problems += field_problems(pr, "the PR's", SMOKE_FIELDS + PR_SMOKE_FIELDS, forms=PR_SMOKE_FORMS,
positive=("seconds", "frames shown", "peak commit"))
for key in ("device removals", "crashes"):
if (number(pr.get(key)) or 0) > 0:
problems.append(f"the PR's regression run shows {key}: {pr.get(key)}")
if pr.get("exit", "").startswith("killed"):
code = pr.get("exit", "")
if code.startswith("killed"):
problems.append("the PR's regression run did not end by itself (killed)")
elif code and code != "0x0":
problems.append(f"the PR's regression run ended with exit {code}")
if main:
m = next((b for b in main if b.get("title") == pr.get("title") and b.get("seconds") == pr.get("seconds")), None)
for b in [m] if m else main:
Expand Down
44 changes: 43 additions & 1 deletion scripts/test_pr_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

HEAD = "1234567890abcdef"
BODY = "**Tested**\nSynthetic fixtures\n**Not tested**\nRetail titles\n**AI use**\nNone\n"
# the lines scripts/smoke.ps1 prints for a run that ended cleanly
CLEAN_RUN = ("title: G\nseconds: 60\nexit: 0x0\nframes shown: 100 (PresentX 100)\n"
"device removals: 0\ncrashes: 0\npeak commit: 3000 MB\n")


def changed(path, binary=False):
Expand Down Expand Up @@ -71,7 +74,7 @@ def test_frontier_models_and_ordinary_words_pass(self):

class SmokeBlockTests(unittest.TestCase):
def test_two_blocks_in_one_fence_are_two_blocks(self):
run = "title: G\nseconds: 60\nframes shown: 100\ndevice removals: 0\ncrashes: 0\n"
run = CLEAN_RUN
body = ("```\nxcl-smoke v1\ncommit: 1111111aaaa\n" + run + "\n"
"xcl-smoke v1\ncommit: 1234567890\n" + run + "```\n")
blocks = smoke_blocks(body)
Expand Down Expand Up @@ -102,6 +105,45 @@ def test_non_numeric_frames_shown_fails(self):
self.assertIn("the PR's regression run (`xcl-smoke` block of commit 1234567890) "
"has a non-numeric `frames shown`: many", problems)

def test_clean_pr_run_passes(self):
self.assertEqual([], self.smoke_problems(CLEAN_RUN, CLEAN_RUN))

def test_pr_run_without_a_safety_line_fails(self):
for field in ("device removals", "crashes", "exit", "peak commit"):
with self.subTest(field=field):
pr_run = "".join(l + "\n" for l in CLEAN_RUN.splitlines() if not l.startswith(field + ":"))
self.assertEqual([f"the PR's regression run (`xcl-smoke` block of commit 1234567890) has no `{field}` line"],
self.smoke_problems(CLEAN_RUN, pr_run))

def test_pr_run_with_malformed_counters_fails(self):
for field, value in (("crashes", "none"), ("crashes", "0x0"), ("device removals", "n/a"), ("device removals", "0.0"),
("peak commit", "n/a MB"), ("peak commit", "1.5 GB"), ("peak commit", "3,000 MB")):
with self.subTest(field=field, value=value):
pr_run = CLEAN_RUN.replace(f"{field}: {'0' if field != 'peak commit' else '3000 MB'}", f"{field}: {value}")
self.assertEqual([f"the PR's regression run (`xcl-smoke` block of commit 1234567890) "
f"has a malformed `{field}`: {value}"], self.smoke_problems(CLEAN_RUN, pr_run))

def test_zero_seconds_frames_or_commit_fail(self):
pr = "the PR's regression run (`xcl-smoke` block of commit 1234567890)"
no_memory = self.smoke_problems(CLEAN_RUN, CLEAN_RUN.replace("peak commit: 3000 MB", "peak commit: 0 MB"))
self.assertEqual([f"{pr} shows `peak commit: 0`"], no_memory)
no_frames = self.smoke_problems(CLEAN_RUN, CLEAN_RUN.replace("frames shown: 100 (PresentX 100)", "frames shown: 0"))
self.assertIn(f"{pr} shows `frames shown: 0`", no_frames)
zeros = CLEAN_RUN.replace("seconds: 60", "seconds: 0")
problems = self.smoke_problems(zeros, zeros)
self.assertIn(f"{pr} shows `seconds: 0`", problems)
self.assertIn("the main regression run (`xcl-smoke` block of commit 1111111aaaa) shows `seconds: 0`", problems)

def test_pr_run_that_did_not_exit_cleanly_fails(self):
crashed = self.smoke_problems(CLEAN_RUN, CLEAN_RUN.replace("exit: 0x0", "exit: 0xc0000005"))
self.assertEqual(["the PR's regression run ended with exit 0xc0000005"], crashed)
killed = self.smoke_problems(CLEAN_RUN, CLEAN_RUN.replace("exit: 0x0", "exit: killed (no exit)"))
self.assertEqual(["the PR's regression run did not end by itself (killed)"], killed)

def test_main_run_may_lack_the_safety_lines(self):
main_run = "title: G\nseconds: 60\nframes shown: 100\n"
self.assertEqual([], self.smoke_problems(main_run, CLEAN_RUN))


class TemplatePlaceholderTests(unittest.TestCase):
def test_untouched_pr_template_fails_all_required_sections(self):
Expand Down
Loading