Skip to content

Commit 7aab609

Browse files
authored
Keep a green pull request green on master and at release (#14)
1 parent b9e229e commit 7aab609

6 files changed

Lines changed: 51 additions & 23 deletions

File tree

‎.github/workflows/jtreg.yml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,14 @@ jobs:
7272
read -ra filters <<< "$FILTERS"
7373
node scripts/jtreg/run.ts build/ref/jdk25u --only-passing --jobs 4 --timeout 600 \
7474
--shard ${{ matrix.shard }}/${{ strategy.job-total }} "${filters[@]}"
75+
76+
# one check for branch protection, whatever the number of shards
77+
result:
78+
needs: [plan, run]
79+
if: always()
80+
runs-on: ubuntu-latest
81+
steps:
82+
- env:
83+
PLAN: ${{ needs.plan.result }}
84+
RUN: ${{ needs.run.result }}
85+
run: test "$PLAN" = success && { test "$RUN" = success || test "$RUN" = skipped; }

‎.github/workflows/test.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
- name: Node entry on the built dist/
3838
run: node --expose-gc --test test/image.test.ts
3939

40+
# master only takes up-to-date pull requests, so this already ran on the merged code
4041
jtreg:
42+
if: github.event_name == 'pull_request'
4143
uses: ./.github/workflows/jtreg.yml
42-
with:
43-
full: ${{ github.event_name == 'push' }}

‎AGENTS.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ Node, which is how the tests run.
6464
needs inputs first (see docs/development.md)
6565
- `JW_JIT_STATS=1` prints what the JIT compiled, fell back on and entered
6666
through the run loop; `JW_JIT_DUMP=<method>` prints a method's generated JS
67+
- Pull requests run the OpenJDK tests in `test/jtreg/passing.txt` that their
68+
changes need (`scripts/jtreg/select.ts`); releases run all of them. A test
69+
that fails without a code change is fixed or taken out of `passing.txt`, so
70+
a green pull request stays green on `master` and at release
6771
- `project516-review-bot` reviews every PR. Merge only once its review of the
6872
head commit has every finding fixed or answered on its thread. When it
6973
cannot read the whole diff, a subagent reviews the files it skipped

‎scripts/jtreg/run.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,8 @@ console.log(`${selected.length} tests, ${queue.length} to run, ${jobs} at a time
446446

447447
const counts: Record<string, number> = {};
448448
const regressions: string[] = [];
449+
// java-web's time per test, to spot tests that run close to the timeout
450+
const times: [string, number][] = [];
449451
let finished = 0;
450452
async function coolDown() {
451453
const zone = "/sys/class/thermal/thermal_zone0/temp";
@@ -464,7 +466,10 @@ async function worker() {
464466
const r: Record<string, any> = { id: tc.id, ...(await runCase(tc)) };
465467
counts[r.status as string] = (counts[r.status as string] ?? 0) + 1;
466468
finished++;
467-
if (onlyPassing) { if (r.status !== "pass") regressions.push(`${tc.id}: ${r.status} ${r.why ?? ""}`); }
469+
if (onlyPassing) {
470+
if (r.status !== "pass") regressions.push(`${tc.id}: ${r.status} ${r.why ?? ""}`);
471+
if (typeof r.ms === "number") times.push([tc.id, r.ms]);
472+
}
468473
else appendFileSync(resultsFile, JSON.stringify(r) + "\n");
469474
if (r.status !== "skip") console.log(`[${finished}] ${r.status.toString().padEnd(7)} ${tc.id}${r.why ? " " + r.why : ""}`);
470475
}
@@ -474,6 +479,9 @@ await Promise.all(Array.from({ length: jobs }, worker));
474479
console.log(counts);
475480

476481
if (onlyPassing) {
482+
times.sort((a, b) => b[1] - a[1]);
483+
writeFileSync(join(out, "times.tsv"), times.map(([id, ms]) => `${ms}\t${id}`).join("\n") + "\n");
484+
console.log("slowest:\n" + times.slice(0, 15).map(([id, ms]) => `${Math.round(ms / 1000)}s ${id}`).join("\n"));
477485
if (regressions.length) {
478486
console.log("regressions:\n" + regressions.join("\n"));
479487
process.exit(1);

‎scripts/jtreg/select.ts‎

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,35 @@
22
//
33
// node scripts/jtreg/select.ts [<base> | --full]
44
//
5-
// Prints GitHub Actions outputs: `filters`, the test areas to pass to run.ts
6-
// (empty for all of them), and `shards`, a JSON list of shard numbers ([] when
7-
// no test is needed). A changed file this does not know runs every test.
5+
// Prints GitHub Actions outputs: `filters`, the tests to pass to run.ts (empty
6+
// for all of them), and `shards`, a JSON list of shard numbers ([] when no test
7+
// is needed). Tests added to passing.txt run alone; a change to anything the
8+
// tests load runs them all.
89

910
import { execFileSync } from "node:child_process";
1011
import { readFileSync } from "node:fs";
11-
import { join } from "node:path";
12+
import { dirname, join } from "node:path";
1213

1314
const root = join(import.meta.dirname, "..", "..");
1415
const passingFile = "test/jtreg/passing.txt";
1516

16-
// first match wins; null runs no test
17-
const areas: [RegExp, string[] | null][] = [
18-
[/\.md$|^docs\/|^LICENSE|^renovate\.json$|^\.coderabbit/, null],
19-
[/^src\/browser\/|^src\/(bridge|library|image|http-proxy)\.ts$|^types\/|^scripts\/(build-web|serve)\.ts$/, null],
20-
[/^test\/(?!jtreg\/)/, null],
21-
[/^src\/natives\/zip\.ts$|^src\/inflate\.ts$/, ["java/util/zip", "java/util/jar"]],
22-
[/^src\/natives\/(io|nio)\.ts$|^src\/fs\.ts$/, ["java/io", "java/nio", "java/util/zip", "java/util/jar"]],
23-
[/^src\/natives\/(net|sockets)\.ts$|^src\/(sockets|net-node)\.ts$|^scripts\/tls\//, ["java/net", "java/nio/channels"]],
24-
[/^src\/natives\/(font|java2d)[\w-]*\.ts$/, ["java/awt", "java/beans"]],
25-
[/^src\/natives\/management\.ts$/, ["java/lang/management"]],
26-
];
17+
// TypeScript the tests load: everything src/node.ts (the VM each test runs on),
18+
// the runner and this selection import, followed through their imports. Other .ts files under
19+
// src/ and scripts/ (the page API, the web build) cannot change a test's result.
20+
function loaded(): Set<string> {
21+
const seen = new Set<string>();
22+
const visit = (file: string) => {
23+
if (seen.has(file)) return;
24+
seen.add(file);
25+
const text = readFileSync(join(root, file), "utf8");
26+
for (const m of text.matchAll(/(?:from|import)\s*\(?\s*["'](\.{1,2}\/[^"']+\.ts)["']/g)) visit(join(dirname(file), m[1]));
27+
};
28+
visit("src/node.ts");
29+
visit("scripts/jtreg/run.ts");
30+
visit("scripts/jtreg/select.ts");
31+
return seen;
32+
}
33+
const notLoaded = /\.md$|^docs\/|^LICENSE|^renovate\.json$|^\.coderabbit|^types\/|^test\/(?!jtreg\/)/;
2734

2835
const shardsFor = (n: number) => Array.from({ length: Math.min(4, Math.ceil(n / 400)) }, (_, i) => i + 1);
2936
const listed = readFileSync(join(root, passingFile), "utf8").split("\n").map((l) => l.trim()).filter((l) => l && !l.startsWith("#"));
@@ -33,6 +40,7 @@ function select(base: string | undefined): string[] | "all" {
3340
if (!base) return "all";
3441
const git = (...args: string[]) => execFileSync("git", args, { cwd: root, encoding: "utf8" });
3542
const filters = new Set<string>();
43+
let graph: Set<string> | undefined;
3644
for (const file of git("diff", "--name-only", "--no-renames", `${base}...HEAD`).split("\n").filter(Boolean)) {
3745
if (file === passingFile) {
3846
// the tests it adds
@@ -41,9 +49,8 @@ function select(base: string | undefined): string[] | "all" {
4149
}
4250
continue;
4351
}
44-
const hit = areas.find(([re]) => re.test(file));
45-
if (!hit) return "all";
46-
for (const f of hit[1] ?? []) filters.add(f);
52+
const ts = /^(src|scripts)\/.*\.ts$/.test(file);
53+
if (ts ? (graph ??= loaded()).has(file) : !notLoaded.test(file)) return "all";
4754
}
4855
return [...filters];
4956
}

‎test/jtreg/passing.txt‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,7 +1658,6 @@ java/security/KeyAgreement/NegativeTest.java
16581658
java/security/KeyFactory/Failover.java
16591659
java/security/KeyFactory/GenerateRSAPrivateCrtKey.java
16601660
java/security/KeyFactory/KeyFactoryGetKeySpecForInvalidSpec.java
1661-
java/security/KeyPairGenerator/Failover.java
16621661
java/security/KeyPairGenerator/GenerateKeypair.java
16631662
java/security/KeyPairGenerator/GenerateRSAKeyPair.java
16641663
java/security/KeyRep/Serial.java
@@ -1711,7 +1710,6 @@ java/security/SecureRandom/GetAlgorithm.java
17111710
java/security/SecureRandom/GetInstanceTest.java
17121711
java/security/SecureRandom/MultiThreadTest.java
17131712
java/security/SecureRandom/NextBytesNull.java
1714-
java/security/SecureRandom/NoSync.java
17151713
java/security/SecureRandom/Serialize.java
17161714
java/security/SecureRandom/SerializedSeedTest.java
17171715
java/security/SecureRandom/TestStrong.java

0 commit comments

Comments
 (0)