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
27 changes: 19 additions & 8 deletions scripts/pr_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
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 both smoke blocks need for comparison, the additional safety lines the PR's run needs,
# and the comparison fields whose values begin with numbers
SMOKE_FIELDS = ("title", "seconds", "frames shown")
SMOKE_NUMBERS = ("seconds", "frames shown")
PR_SMOKE_FIELDS = SMOKE_FIELDS + ("device removals", "crashes", "exit", "peak commit")


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


def field_problems(block, run):
def field_problems(block, run, fields=SMOKE_FIELDS):
"""What `block` (the smoke block of `run`) lacks for the comparison: a missing line or a
number that is not one."""
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 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 SMOKE_NUMBERS
if block.get(k) and number(block[k]) is None]
return out
Expand Down Expand Up @@ -141,12 +142,22 @@ 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", PR_SMOKE_FIELDS)
for key in ("device removals", "crashes"):
if (number(pr.get(key)) or 0) > 0:
value = pr.get(key)
if value and not re.fullmatch(r"\d+", value):
problems.append(f"the PR's regression run has a non-numeric `{key}`: {value}")
elif value and int(value) > 0:
problems.append(f"the PR's regression run shows {key}: {pr.get(key)}")
if pr.get("exit", "").startswith("killed"):
problems.append("the PR's regression run did not end by itself (killed)")
exit_code = pr.get("exit")
if exit_code and exit_code != "0x0":
if exit_code.startswith("killed"):
problems.append("the PR's regression run did not end by itself (killed)")
else:
problems.append(f"the PR's regression run exited with {exit_code}, not 0x0")
peak_commit = pr.get("peak commit")
if peak_commit and not re.fullmatch(r"\d+\s+MB", peak_commit):
problems.append(f"the PR's regression run has a non-numeric `peak commit`: {peak_commit}")
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
34 changes: 30 additions & 4 deletions scripts/test_pr_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ def test_frontier_models_and_ordinary_words_pass(self):


class SmokeBlockTests(unittest.TestCase):
RUN = ("title: G\nseconds: 60\nexit: 0x0\nframes shown: 100\n"
"device removals: 0\ncrashes: 0\npeak commit: 1000 MB\n")

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"
body = ("```\nxcl-smoke v1\ncommit: 1111111aaaa\n" + run + "\n"
"xcl-smoke v1\ncommit: 1234567890\n" + run + "```\n")
body = ("```\nxcl-smoke v1\ncommit: 1111111aaaa\n" + self.RUN + "\n"
"xcl-smoke v1\ncommit: 1234567890\n" + self.RUN + "```\n")
blocks = smoke_blocks(body)
self.assertEqual(["1111111aaaa", "1234567890"], [b["commit"] for b in blocks])
files = [changed("crates/xcl/src/hle/d3d12x/vram.rs")]
Expand All @@ -97,11 +99,35 @@ def test_blocks_with_only_commit_lines_fail(self):
self.assertTrue(any(p.startswith(run) and f"no `{field}` line" in p for p in problems), problems)

def test_non_numeric_frames_shown_fails(self):
run = "title: G\nseconds: 60\ndevice removals: 0\ncrashes: 0\n"
run = self.RUN.replace("frames shown: 100\n", "")
problems = self.smoke_problems(run + "frames shown: 100\n", run + "frames shown: many\n")
self.assertIn("the PR's regression run (`xcl-smoke` block of commit 1234567890) "
"has a non-numeric `frames shown`: many", problems)

def test_pr_block_requires_safety_fields(self):
for field in ("device removals", "crashes", "exit", "peak commit"):
with self.subTest(field=field):
pr_run = "\n".join(line for line in self.RUN.splitlines()
if not line.startswith(field + ":")) + "\n"
problems = self.smoke_problems(self.RUN, pr_run)
self.assertTrue(any(p.startswith("the PR's") and f"no `{field}` line" in p
for p in problems), problems)

def test_pr_block_rejects_invalid_safety_values(self):
cases = {
"device removals: none": "non-numeric `device removals`",
"crashes: none": "non-numeric `crashes`",
"exit: 0xc0000005": "exited with 0xc0000005, not 0x0",
"peak commit: n/a MB": "non-numeric `peak commit`",
}
for replacement, expected in cases.items():
with self.subTest(replacement=replacement):
field = replacement.split(":", 1)[0]
pr_run = "\n".join(replacement if line.startswith(field + ":") else line
for line in self.RUN.splitlines()) + "\n"
problems = self.smoke_problems(self.RUN, pr_run)
self.assertTrue(any(expected in p for p in problems), problems)


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