Skip to content
Merged
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
17 changes: 17 additions & 0 deletions scripts/pr_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
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
SMOKE_FIELDS = ("title", "seconds", "frames shown")
SMOKE_NUMBERS = ("seconds", "frames shown")


def smoke_blocks(body):
Expand All @@ -52,6 +56,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."""
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
if block.get(k) and number(block[k]) is None]
return out


def runtime(path):
return path.startswith("crates/xcl/src/") and "/tests" not in path and not path.endswith("tests.rs")

Expand Down Expand Up @@ -125,13 +139,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")
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"):
problems.append("the PR's regression run did not end by itself (killed)")
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:
problems += field_problems(b, "the main")
if m is None:
problems.append("the main and PR regression runs are not of the same title for the same time")
else:
Expand Down
23 changes: 21 additions & 2 deletions scripts/test_pr_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ def test_test_paths_do_not_need_approval(self):

class SmokeBlockTests(unittest.TestCase):
def test_two_blocks_in_one_fence_are_two_blocks(self):
body = ("```\nxcl-smoke v1\ncommit: 1111111aaaa\ntitle: G\nseconds: 60\n\n"
"xcl-smoke v1\ncommit: 1234567890\ntitle: G\nseconds: 60\n```\n")
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")
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 @@ -63,6 +64,24 @@ def test_blocks_in_separate_fences_stay_separate(self):
"```\nxcl-smoke v1\ncommit: 1234567890\ntitle: G\n```\n")
self.assertEqual(["1111111aaaa", "1234567890"], [b["commit"] for b in smoke_blocks(body)])

def smoke_problems(self, main_run, pr_run):
body = ("```\nxcl-smoke v1\ncommit: 1111111aaaa\n" + main_run + "```\n"
"```\nxcl-smoke v1\ncommit: 1234567890\n" + pr_run + "```\n")
files = [changed("crates/xcl/src/hle/d3d12x/vram.rs")]
return check(BODY + body, HEAD, files, lambda sha: sha == "1111111aaaa")

def test_blocks_with_only_commit_lines_fail(self):
problems = self.smoke_problems("", "")
for field in ("title", "seconds", "frames shown"):
for run in ("the PR's", "the main"):
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"
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)


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