diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index dfdd78a9ec..a5f4eee794 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -23,8 +23,10 @@ checked before anything else; a PR that does not meet them waits (or is closed a time. The PR's block must name its head commit with no uncommitted changes (rerun it after every push); the other must be made on a commit of `main`. The PR's run must show no device removal and no crash (the `main` run may: a PR that fixes a crash shows it there), at least 80 % of `main`'s - frames and at most 125 % of its peak commit. A run on a title that does not reach the code the PR - changes still counts as a regression check; say what it does not cover under **Not tested**. + frames and at most 125 % of its peak commit. One run's peak commit varies by up to ~1.8x on the + same build (#2225), so the 125 % holds for the medians when each side has 3 or more blocks; with + fewer, the check prints the ratio and fails only above 200 %. A run on a title that does not + reach the code the PR changes still counts as a regression check; say what it does not cover under **Not tested**. `scripts/pr_check.py` checks all of this (and the rest of this list it can see) on every PR. If a test-only diff touches a runtime file, a maintainer can apply the `test-only` label after reviewing the diff. The label event waives only the smoke check for that revision. Adding or diff --git a/scripts/pr_check.py b/scripts/pr_check.py index cb0ef3ef9e..571be5af41 100644 --- a/scripts/pr_check.py +++ b/scripts/pr_check.py @@ -8,7 +8,7 @@ asks git instead of the GitHub API (whether a commit is on main, a blob's size). --test-only skips only the smoke check. GitHub Actions passes it after a test-only label approval. """ -import argparse, os, re, subprocess, sys +import argparse, os, re, statistics, subprocess, sys SECTIONS = ("Tested", "Not tested", "AI use") HEADINGS = ("What is in it", "Tested", "Regression run", "Not tested", "AI use") @@ -32,7 +32,12 @@ TEST_DATA = ("tests/data/",) 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 +COMMIT_GROWTH = 1.25 # the PR's peak commit at most this times main's, as medians of COMMIT_RUNS runs +# One run's peak commit is bimodal: the same build of main gave 11,374 to 20,977 MB in a row (#2225), +# so one pair cannot carry the 125 % limit. It is enforced on the medians when each side has at least +# COMMIT_RUNS runs; with fewer, the ratio is printed and only more than COMMIT_NOISE times main's fails. +COMMIT_RUNS = 3 +COMMIT_NOISE = 2.0 # 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") @@ -100,10 +105,10 @@ def section_has_content(body, section): return False -def check(body, head, files, is_main_ancestor, *, test_only=False): +def check(body, head, files, is_main_ancestor, *, test_only=False, notes=None): """The problems (empty: mergeable as far as this check goes). `files`: (path, status, binary, size) with `size` a function giving the file's bytes; `is_main_ancestor(sha)`: whether the - commit is on main.""" + commit is on main. Advice that does not block the merge is appended to the list `notes`.""" body = body.replace("\r\n", "\n") problems = [] for section in SECTIONS: @@ -157,9 +162,20 @@ def check(body, head, files, is_main_ancestor, *, test_only=False): pf, mf = number(pr.get("frames shown")), number(m.get("frames shown")) if mf and (pf is None or pf < FRAMES_KEPT * mf): problems.append(f"the PR's run shows fewer frames than main's ({pf} against {mf})") - pc, mc = number(pr.get("peak commit")), number(m.get("peak commit")) - if pc and mc and pc > COMMIT_GROWTH * mc: - problems.append(f"the PR's run commits much more memory than main's ({pc} MB against {mc} MB)") + same = lambda b: b.get("title") == pr.get("title") and b.get("seconds") == pr.get("seconds") + pcs = [c for c in (number(b.get("peak commit")) for b in clean if same(b)) if c] + mcs = [c for c in (number(b.get("peak commit")) for b in main if same(b)) if c] + if pcs and mcs: + pc, mc = statistics.median(pcs), statistics.median(mcs) + runs = min(len(pcs), len(mcs)) + of = f", medians of {len(pcs)} and {len(mcs)} runs" if max(len(pcs), len(mcs)) > 1 else "" + if pc > (COMMIT_GROWTH if runs >= COMMIT_RUNS else COMMIT_NOISE) * mc: + problems.append(f"the PR's run commits much more memory than main's ({pc} MB against {mc} MB{of})") + elif pc > COMMIT_GROWTH * mc and notes is not None: + notes.append(f"the PR's run commits {int(pc * 100 // mc)} % of main's peak commit ({pc} MB against " + f"{mc} MB{of}): over 125 %, but with fewer than {COMMIT_RUNS} runs on each side " + f"that is inside the run-to-run spread (#2225), so it does not fail; paste " + f"{COMMIT_RUNS} `xcl-smoke` blocks of each to have the medians compared") return problems @@ -193,7 +209,10 @@ def is_main_ancestor(sha): r = subprocess.run(["gh", "api", f"repos/{o.repo}/compare/{sha}...main", "--jq", ".status"], capture_output=True, text=True) return r.returncode == 0 and r.stdout.strip() in ("ahead", "identical") - problems = check(body, o.head, files, is_main_ancestor, test_only=o.test_only) + notes = [] + problems = check(body, o.head, files, is_main_ancestor, test_only=o.test_only, notes=notes) + for n in notes: + print("note:", n) if problems: print("This PR cannot be merged yet (see CONTRIBUTING.md, 'What a PR needs to be merged'):") for p in problems: diff --git a/scripts/test_pr_check.py b/scripts/test_pr_check.py index 8cc45d5d06..5c21e1d1a3 100644 --- a/scripts/test_pr_check.py +++ b/scripts/test_pr_check.py @@ -103,6 +103,76 @@ def test_non_numeric_frames_shown_fails(self): "has a non-numeric `frames shown`: many", problems) +class PeakCommitTests(unittest.TestCase): + """The 125 % peak-commit limit on the medians of 3+ runs a side; one run is too noisy (#2225).""" + + RUN = "title: G\nseconds: 60\nframes shown: 100\ndevice removals: 0\ncrashes: 0\n" + + def problems_and_notes(self, main_peaks, pr_peaks): + body = "".join(f"```\nxcl-smoke v1\ncommit: {commit}\n{self.RUN}peak commit: {peak} MB\n```\n" + for commit, peaks in (("1111111aaaa", main_peaks), ("1234567890", pr_peaks)) + for peak in peaks) + notes = [] + problems = check(BODY + body, HEAD, [changed("crates/xcl/src/hle/d3d12x/vram.rs")], + lambda sha: sha == "1111111aaaa", notes=notes) + return problems, notes + + def test_one_pair_inside_the_spread_passes_with_a_note(self): + # #2223's first pair: a help-text change; the same two commits came out the other way round later + problems, notes = self.problems_and_notes([11952], [19558]) + self.assertEqual([], problems) + self.assertEqual(1, len(notes), notes) + self.assertIn("163 % of main's peak commit (19558 MB against 11952 MB)", notes[0]) + + def test_one_pair_under_the_limit_passes_without_a_note(self): + self.assertEqual(([], []), self.problems_and_notes([18160], [22700])) + self.assertEqual(([], []), self.problems_and_notes([20977], [11435])) + + def test_one_pair_beyond_the_spread_still_fails(self): + problems, notes = self.problems_and_notes([10000], [20001]) + self.assertEqual(["the PR's run commits much more memory than main's (20001 MB against 10000 MB)"], problems) + self.assertEqual([], notes) + + def test_medians_over_the_limit_fail(self): + problems, notes = self.problems_and_notes([18160, 18964, 17393], [24000, 11374, 25000]) + self.assertEqual(["the PR's run commits much more memory than main's " + "(24000 MB against 18160 MB, medians of 3 and 3 runs)"], problems) + self.assertEqual([], notes) + + def test_even_run_counts_keep_half_mb_at_the_limits(self): + for main_peaks, pr_peaks, pr_median in [ + ([10000] * 4, [12500, 12500, 12501, 12501], '12500.5'), + ([10000] * 2, [20000, 20001], '20000.5'), + ]: + with self.subTest(pr_median=pr_median): + problems, notes = self.problems_and_notes(main_peaks, pr_peaks) + self.assertEqual(1, len(problems), problems) + self.assertIn(f'{pr_median} MB', problems[0]) + self.assertEqual([], notes) + + def test_a_low_draw_among_three_runs_does_not_decide(self): + # Creaa's runs of one build of main (#2225): one low run among high ones + self.assertEqual(([], []), self.problems_and_notes([19705, 11374, 17690], [17408, 19806, 17499])) + problems, notes = self.problems_and_notes([11374], [19705]) + self.assertEqual([], problems) + self.assertEqual(1, len(notes), notes) + + def test_fewer_than_three_runs_on_one_side_is_judged_as_one_pair(self): + problems, notes = self.problems_and_notes([12000, 12500, 11800], [19000]) + self.assertEqual([], problems) + self.assertIn("medians of 1 and 3 runs", notes[0]) + problems, _ = self.problems_and_notes([12000, 12500, 11800], [25000]) + self.assertEqual(1, len(problems), problems) + + def test_without_peak_commit_nothing_is_compared(self): + body = ("```\nxcl-smoke v1\ncommit: 1111111aaaa\n" + self.RUN + "peak commit: 1000 MB\n```\n" + "```\nxcl-smoke v1\ncommit: 1234567890\n" + self.RUN + "```\n") + notes = [] + files = [changed("crates/xcl/src/hle/d3d12x/vram.rs")] + self.assertEqual([], check(BODY + body, HEAD, files, lambda sha: sha == "1111111aaaa", notes=notes)) + self.assertEqual([], notes) + + class TemplatePlaceholderTests(unittest.TestCase): def test_untouched_pr_template_fails_all_required_sections(self): template = Path(__file__).resolve().parent.parent / ".github" / "pull_request_template.md"