From 015bbb122b6040012f13b47cd5f791642d7116b5 Mon Sep 17 00:00:00 2001 From: tignear Date: Sun, 25 Oct 2026 02:01:42 +0900 Subject: [PATCH 1/2] ci: reuse Rust test builds and warm Windows dependencies Change-Id: Ie43192fc57f87e17226b84ab5779211d3b4245f7 --- .github/workflows/ci.yml | 58 ++++++++++++++---------- .github/workflows/rust-cache.yml | 45 ++++++++++++++++++- CONTRIBUTING.md | 23 +++++++--- Cargo.toml | 2 +- scripts/ci-lydite-changes.test.mjs | 2 +- scripts/ci-rust-reports.mjs | 4 +- scripts/ci-rust-reports.test.mjs | 12 ++++- scripts/ci-workflow.test.mjs | 72 +++++++++++++++++++++++++----- scripts/run-ci-cocotb.mjs | 39 ++++++++++++++++ scripts/run-ci-cocotb.test.mjs | 57 +++++++++++++++++++++++ scripts/run-ci-rust-scope.mjs | 2 +- 11 files changed, 268 insertions(+), 48 deletions(-) create mode 100644 scripts/run-ci-cocotb.mjs create mode 100644 scripts/run-ci-cocotb.test.mjs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a77cd3fe13a..ea6775b6e1b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -223,7 +223,7 @@ jobs: - uses: Swatinem/rust-cache@v2 with: - key: vtest-v1 + key: vtest-v2 save-if: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} - name: Initialize Rust test reports @@ -258,7 +258,7 @@ jobs: id: workspace-tests if: needs.changes.outputs.rust_full != 'false' run: >- - cargo nextest run --locked --workspace --exclude 'lydite*' --profile ci + cargo nextest run --locked --workspace --exclude 'lydite*' --profile ci --cargo-profile vtest --features celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus,celox-test-suite/runtime-cases - name: Run the tests this pull request can affect @@ -274,6 +274,15 @@ jobs: if: success() || failure() run: node scripts/ci-rust-reports.mjs collect + - name: Run cocotb VPI end-to-end test + id: cocotb-tests + if: needs.changes.outputs.rust_vpi_e2e != 'false' + env: + RUST_FULL: ${{ needs.changes.outputs.rust_full }} + BUILDS: ${{ needs.changes.outputs.rust_builds }} + run: | + CELOX_COCOTB_PYTHON="$(command -v python)" node scripts/run-ci-cocotb.mjs + - name: Retain Rust test reports if: (success() || failure()) && hashFiles('work/ci-reports/rust/*.xml') != '' uses: actions/upload-artifact@v7 @@ -289,14 +298,14 @@ jobs: token: ${{ secrets.MERGIFY_TOKEN }} report_path: work/ci-reports/rust/*.xml job_name: rust-tests - test_step_outcome: ${{ steps.workspace-tests.outcome != 'skipped' && steps.workspace-tests.outcome || steps.scoped-tests.outcome }} + test_step_outcome: ${{ steps.cocotb-tests.outcome == 'failure' && 'failure' || steps.workspace-tests.outcome != 'skipped' && steps.workspace-tests.outcome || steps.scoped-tests.outcome }} # nextest does not run documentation tests. - name: Run workspace documentation tests with CI features if: needs.changes.outputs.rust_full != 'false' run: >- - cargo test --locked --workspace --exclude 'lydite*' --doc - --features celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus + cargo test --locked --profile vtest --workspace --exclude 'lydite*' --doc + --features celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus,celox-test-suite/runtime-cases - name: Run the documentation tests of the changed libraries if: needs.changes.outputs.rust_full == 'false' && needs.changes.outputs.rust_libraries != '' @@ -307,29 +316,26 @@ jobs: args=() for package in $LIBRARIES; do args+=(-p "$package"); done if [ -n "$FEATURES" ]; then args+=(--features "$FEATURES"); fi - cargo test --locked --doc "${args[@]}" + cargo test --locked --profile vtest --doc "${args[@]}" + rust-default-tests: + name: Rust default-feature tests + needs: changes + if: ${{ !cancelled() && (needs.changes.result != 'success' || (needs.changes.outputs.rust == 'true' && (needs.changes.outputs.rust_full != 'false' || contains(format(' {0} ', needs.changes.outputs.rust_libraries), ' celox ')))) }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + with: + submodules: recursive + - uses: ./.github/actions/setup-rust + - uses: Swatinem/rust-cache@v2 + with: + save-if: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} - name: Verify default-feature library and documentation tests - if: needs.changes.outputs.rust_full != 'false' || contains(format(' {0} ', needs.changes.outputs.rust_libraries), ' celox ') run: | cargo test --locked -p celox --lib cargo test --locked -p celox --doc - - name: Run cocotb VPI end-to-end test - if: needs.changes.outputs.rust_vpi_e2e != 'false' - env: - FEATURES: ${{ needs.changes.outputs.rust_full != 'false' && 'celox/systemverilog' || needs.changes.outputs.rust_features }} - run: | - args=() - # Match the feature set of VPI's scoped nextest build. Features of - # other selected packages (such as external adapters) are unrelated. - for feature in ${FEATURES//,/ }; do - case "$feature" in celox/*) args+=(--features "$feature");; esac - done - CELOX_COCOTB_PYTHON="$(command -v python)" \ - cargo test --locked -p celox-vpi --features systemverilog "${args[@]}" --test cocotb_e2e \ - cocotb_ -- --ignored - external-suites: name: External suite (${{ matrix.suite }}, ${{ matrix.tool }}) needs: changes @@ -630,13 +636,15 @@ jobs: # into a successful check merely because a downstream job was skipped. rust: name: Rust Test & NAPI Build - needs: [changes, rust-tests, sv-tests, arm64-backend, napi-linux, napi-wasm, external-suites] + needs: [changes, rust-tests, rust-default-tests, sv-tests, arm64-backend, napi-linux, napi-wasm, external-suites] if: ${{ !cancelled() && (needs.changes.result != 'success' || needs.changes.outputs.rust == 'true' || needs.changes.outputs.napi == 'true') }} runs-on: ubuntu-latest env: CHANGES_RESULT: ${{ needs.changes.result }} RUST_REQUIRED: ${{ needs.changes.outputs.rust }} RUST_RESULT: ${{ needs.rust-tests.result }} + DEFAULT_REQUIRED: ${{ needs.changes.result != 'success' || (needs.changes.outputs.rust == 'true' && (needs.changes.outputs.rust_full != 'false' || contains(format(' {0} ', needs.changes.outputs.rust_libraries), ' celox '))) }} + DEFAULT_RESULT: ${{ needs.rust-default-tests.result }} SV_TESTS_REQUIRED: ${{ needs.changes.outputs.rust != 'false' && needs.changes.outputs.rust_sv_tests != 'false' }} SV_TESTS_RESULT: ${{ needs.sv-tests.result }} # Platform coverage is mandatory in queue and full validation runs. @@ -656,6 +664,9 @@ jobs: if [ "$RUST_REQUIRED" != false ] || [ "$RUST_RESULT" != skipped ]; then test "$RUST_RESULT" = success fi + if [ "$DEFAULT_REQUIRED" != false ] || [ "$DEFAULT_RESULT" != skipped ]; then + test "$DEFAULT_RESULT" = success + fi if [ "$SV_TESTS_REQUIRED" != false ] || [ "$SV_TESTS_RESULT" != skipped ]; then test "$SV_TESTS_RESULT" = success fi @@ -959,6 +970,7 @@ jobs: docs, lint, rust-tests, + rust-default-tests, sv-tests, external-suites, common-cells, diff --git a/.github/workflows/rust-cache.yml b/.github/workflows/rust-cache.yml index b7113223635..e7fea04d572 100644 --- a/.github/workflows/rust-cache.yml +++ b/.github/workflows/rust-cache.yml @@ -41,7 +41,7 @@ jobs: - uses: Swatinem/rust-cache@v2 id: cache with: - key: vtest-v1 + key: vtest-v2 - name: Install cargo-nextest if: steps.cache.outputs.cache-hit != 'true' uses: taiki-e/install-action@v2 @@ -53,6 +53,47 @@ jobs: - name: Build test targets to populate dependencies if: steps.cache.outputs.cache-hit != 'true' run: >- - cargo nextest list --locked --workspace --message-format json + cargo nextest list --locked --workspace --exclude 'lydite*' --cargo-profile vtest --message-format json --features celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus,celox-test-suite/runtime-cases > /dev/null + + rust-default-tests: + if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) + name: Populate default-feature dependency cache + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + with: + submodules: recursive + - uses: ./.github/actions/setup-rust + - uses: Swatinem/rust-cache@v2 + id: cache + - name: Build default-feature library test dependencies + if: steps.cache.outputs.cache-hit != 'true' + run: cargo test --locked -p celox --lib --no-run + + napi-windows: + if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) + name: Populate Windows NAPI dependency cache + runs-on: windows-latest + timeout-minutes: 45 + steps: + - uses: actions/checkout@v7 + with: + submodules: recursive + - uses: ./.github/actions/setup-rust + - uses: Swatinem/rust-cache@v2 + id: cache + - uses: pnpm/action-setup@v6 + if: steps.cache.outputs.cache-hit != 'true' + - uses: actions/setup-node@v7 + if: steps.cache.outputs.cache-hit != 'true' + with: + node-version: 24 + cache: pnpm + - name: Install dependencies + if: steps.cache.outputs.cache-hit != 'true' + run: pnpm install --frozen-lockfile --ignore-scripts + - name: Build NAPI with the CI command + if: steps.cache.outputs.cache-hit != 'true' + run: pnpm run build:napi diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b178404a8a2..9c03d665e6f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -58,13 +58,26 @@ ignored registrations deliberately. With `runtime-cases`, `.vtest` bodies are read from disk instead of embedded in Rust binaries, so edits to an existing case do not require recompilation. Adding -a test registration or changing Rust still requires a build. The first run builds -both the optimized executor and ordinary test binaries; the executor profile has -its own Cargo cache. Ordinary Cargo test commands retain the embedded, in-process -path. CI's Rust Tests job prepares the executor once and uses it for both full -workspace runs and scoped runs that include Celox. Scopes without Celox skip that +a test registration or changing Rust still requires a build. The local command +builds both the optimized executor and ordinary test binaries; the executor +profile has its own Cargo cache. CI instead builds both with the `vtest` Cargo profile so +shared dependencies and Celox libraries can be reused. Ordinary Cargo test +commands retain the embedded, in-process path. CI's Rust Tests job prepares the +executor once and uses it for both full workspace runs and scoped runs that +include Celox. Scopes without Celox skip that build. The default-branch cache warmer builds both executor and test dependencies under the same cache key; vtest preparation failures fail the test job. +CI documentation tests also use this Cargo profile. Cocotb runs through nextest +with the exact packages, features and targets of its original build, selecting +only the ignored `cocotb_` cases; an empty selection fails. Its reports are kept +separately and uploaded with the regular test results. + +Default-feature library and documentation tests run in a separate parallel job +with no extra features. The required Rust gate still requires this job whenever +Celox libraries or the full workspace are selected, and on detection failure. +The cache warmer also primes this job and Windows NAPI dependencies on master +using their CI job IDs, environments and build commands. Windows builds still +need a first cache fill after a toolchain or dependency change. The CI nextest profile also emits JUnit results. The Rust Tests job preserves each scoped invocation separately under `work/ci-reports/rust/`, retains the XML diff --git a/Cargo.toml b/Cargo.toml index 8c770d54d64..a0bf1785a54 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -166,7 +166,7 @@ incremental = true [profile.bench] debug = true -# Optimize the shared vtest executor while keeping development checks enabled. +# Optimize the shared vtest executor and CI tests, keeping development checks enabled. # External dependencies retain the dev profile's package-specific optimization. [profile.vtest] inherits = "dev" diff --git a/scripts/ci-lydite-changes.test.mjs b/scripts/ci-lydite-changes.test.mjs index b745af57b4a..b63228be0f4 100644 --- a/scripts/ci-lydite-changes.test.mjs +++ b/scripts/ci-lydite-changes.test.mjs @@ -234,7 +234,7 @@ test("workflows transfer Rust tests and gate each Lydite lane", () => { ); assert.match( ci, - /cargo test --locked --workspace --exclude 'lydite\*' --doc/, + /cargo test --locked --profile vtest --workspace --exclude 'lydite\*' --doc/, ); const workflow = readFileSync(`${root}.github/workflows/lydite-checks.yml`, "utf8"); assert.match( diff --git a/scripts/ci-rust-reports.mjs b/scripts/ci-rust-reports.mjs index ddfb851c8ee..3eb072ba73a 100644 --- a/scripts/ci-rust-reports.mjs +++ b/scripts/ci-rust-reports.mjs @@ -15,12 +15,12 @@ export function resetReports(directory, source = currentReport(process.cwd())) { clearCurrentReport(source); if (!existsSync(directory)) return; for (const name of readdirSync(directory)) { - if (/^nextest-(?:full|\d+)\.xml$/.test(name)) rmSync(resolve(directory, name)); + if (/^nextest-(?:full|cocotb-\d+|\d+)\.xml$/.test(name)) rmSync(resolve(directory, name)); } } export function saveCurrentReport(directory, name, source = currentReport(process.cwd())) { - if (!/^(?:full|\d+)$/.test(name)) throw new Error("Invalid Rust report name"); + if (!/^(?:full|cocotb-\d+|\d+)$/.test(name)) throw new Error("Invalid Rust report name"); // A build failure or an empty selection may produce no report. Keep the // Cargo exit status and any earlier reports; never reuse a previous result. if (!existsSync(source)) return; diff --git a/scripts/ci-rust-reports.test.mjs b/scripts/ci-rust-reports.test.mjs index e0ef8709eef..63cc287a2d5 100644 --- a/scripts/ci-rust-reports.test.mjs +++ b/scripts/ci-rust-reports.test.mjs @@ -34,7 +34,7 @@ test("initialization removes only this job's stale reports and creates no target resetReports(directory, source); assert.ok(!existsSync(directory)); mkdirSync(directory); - for (const name of ["nextest-full.xml", "nextest-0.xml", "unrelated.xml"]) + for (const name of ["nextest-full.xml", "nextest-0.xml", "nextest-cocotb-0.xml", "unrelated.xml"]) writeFileSync(join(directory, name), "old"); writeFileSync(source, "old"); resetReports(directory, source); @@ -49,3 +49,13 @@ test("full runs use a stable report name and reject invalid paths", (t) => { assert.ok(existsSync(source)); assert.equal(saveCurrentReport(directory, "full", source), join(directory, "nextest-full.xml")); }); + +test("cocotb reports do not overwrite normal test reports", (t) => { + const { source, directory } = fixture(t); + writeFileSync(source, "normal"); + saveCurrentReport(directory, "full", source); + writeFileSync(source, "cocotb failure"); + saveCurrentReport(directory, "cocotb-0", source); + assert.equal(readFileSync(join(directory, "nextest-full.xml"), "utf8"), "normal"); + assert.equal(readFileSync(join(directory, "nextest-cocotb-0.xml"), "utf8"), "cocotb failure"); +}); diff --git a/scripts/ci-workflow.test.mjs b/scripts/ci-workflow.test.mjs index ed9ff3e9e7c..4ecd44add32 100644 --- a/scripts/ci-workflow.test.mjs +++ b/scripts/ci-workflow.test.mjs @@ -23,7 +23,7 @@ test("the required gate rejects failures and only accepts explicitly optional sk assert.match(gate, /if: \$\{\{ !cancelled\(\)/); assert.match( gate, - /needs: \[changes, rust-tests, sv-tests, arm64-backend, napi-linux, napi-wasm, external-suites\]/, + /needs: \[changes, rust-tests, rust-default-tests, sv-tests, arm64-backend, napi-linux, napi-wasm, external-suites\]/, ); assert.match( gate, @@ -39,6 +39,8 @@ test("the required gate rejects failures and only accepts explicitly optional sk CHANGES_RESULT: "success", RUST_REQUIRED: "true", RUST_RESULT: "success", + DEFAULT_REQUIRED: "true", + DEFAULT_RESULT: "success", SV_TESTS_REQUIRED: "true", SV_TESTS_RESULT: "success", ARM64_REQUIRED: "true", @@ -50,6 +52,9 @@ test("the required gate rejects failures and only accepts explicitly optional sk EXTERNAL_RESULT: "skipped", }; const cases = [ + { env: { ...success, DEFAULT_REQUIRED: "false", DEFAULT_RESULT: "skipped" }, passes: true }, + { env: { ...success, DEFAULT_REQUIRED: "", DEFAULT_RESULT: "skipped" }, passes: false }, + { env: { ...success, DEFAULT_REQUIRED: "false", DEFAULT_RESULT: "failure" }, passes: false }, { env: { ...success, RUST_REQUIRED: "", RUST_RESULT: "skipped" }, passes: false, @@ -69,6 +74,7 @@ test("the required gate rejects failures and only accepts explicitly optional sk for (const producer of [ "CHANGES_RESULT", "RUST_RESULT", + "DEFAULT_RESULT", "SV_TESTS_RESULT", "ARM64_RESULT", "NATIVE_RESULT", @@ -358,7 +364,7 @@ test("PR caches cannot evict the shared default-branch Rust caches", () => { / - uses: Swatinem\/rust-cache@v2\n([\s\S]*?)(?=\n -|\n [a-z]|$)/g, ), ]; - assert.equal(cacheSteps.length, 9); + assert.equal(cacheSteps.length, 10); for (const [, step] of cacheSteps) { assert.match( step, @@ -378,18 +384,18 @@ test("cache warming shares the Rust Tests key and builds without running tests", assert.match(warm, /cancel-in-progress: false/); assert.doesNotMatch( warm, - /pull_request:|cargo nextest run|cargo test|shared-key:/, + /pull_request:|cargo nextest run|shared-key:/, ); assert.match(warm, /steps.cache.outputs.cache-hit != 'true'/); for (const text of [warm, job("rust-tests")]) { - assert.match(text, /key: vtest-v1/); + assert.match(text, /key: vtest-v2/); assert.match(text, /run: node scripts\/run-vtest.mjs --prepare-ci/); } assert.match(warm, /name: Build the optimized vtest executor to populate dependencies\n if: steps.cache.outputs.cache-hit != 'true'/); assert.match(warm, /"scripts\/run-vtest.mjs"/); assert.match( warm, - /cargo nextest list --locked --workspace --message-format json/, + /cargo nextest list --locked --workspace --exclude 'lydite\*' --cargo-profile vtest --message-format json/, ); const features = job("rust-tests").match(/--features (\S+)/)[1]; assert.ok(warm.includes(`--features ${features}`)); @@ -430,7 +436,7 @@ test("scoped Cargo commands build only the selected integration targets", () => TARGETS: "flip_flop systemverilog", FILTER: "binary_id(celox::flip_flop) | binary_id(celox::systemverilog)", }; assert.deepEqual(cargoArguments("rust-tests", "Run the tests this pull request can affect", env), [ - "nextest", "run", "--locked", "--profile", "ci", "--no-tests=pass", + "nextest", "run", "--locked", "--profile", "ci", "--cargo-profile", "vtest", "--no-tests=pass", "-p", "celox", "--features", "celox/systemverilog,celox-test-suite/runtime-cases", "--test", "flip_flop", "--test", "systemverilog", "-E", env.FILTER, ]); @@ -457,7 +463,7 @@ test("CI prepares one executor for full runs and scopes containing Celox", () => assert.deepEqual(cargoArguments("rust-tests", "Run the tests this pull request can affect", { PACKAGES: "celox-heap", FEATURES: "", TARGETS: "", FILTER: "package(celox-heap)", CELOX_VTEST_RUNNER: "", - }), ["nextest", "run", "--locked", "--profile", "ci", "--no-tests=pass", + }), ["nextest", "run", "--locked", "--profile", "ci", "--cargo-profile", "vtest", "--no-tests=pass", "-p", "celox-heap", "-E", "package(celox-heap)"]); }); @@ -492,13 +498,55 @@ test("scoped checks preserve full-run fallbacks and use their own package scopes assert.match(lint, /name: Build the API documentation this pull request can affect\n if: .*outputs\.rust_doc_libraries != ''/); }); -test("cocotb retains Celox features without enabling unrelated adapter features", () => { +test("cocotb reuses the original scoped Cargo build", () => { + const builds = [{ packages: ["celox", "celox-vpi", "celox-test-suite"], targets: [], + features: ["celox/systemverilog", "celox-test-suite/icarus"] }]; const args = cargoArguments("rust-tests", "Run cocotb VPI end-to-end test", { - FEATURES: "celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus", + RUST_FULL: "false", BUILDS: JSON.stringify(builds), }); - assert.deepEqual(args, ["test", "--locked", "-p", "celox-vpi", "--features", "systemverilog", "--features", "celox/systemverilog", "--test", "cocotb_e2e", - "cocotb_", "--", "--ignored"]); - assert.match(job("rust-tests"), /name: Run cocotb VPI end-to-end test\n if: needs.changes.outputs.rust_vpi_e2e != 'false'/); + assert.deepEqual(args, ["nextest", "run", "--locked", "--profile", "ci", "--cargo-profile", "vtest", + "-p", "celox", "-p", "celox-vpi", "-p", "celox-test-suite", "--features", + "celox/systemverilog,celox-test-suite/icarus,celox-test-suite/runtime-cases", + "-E", 'binary_id(celox-vpi::cocotb_e2e) & test(/^cocotb_/)', "--run-ignored", "only"]); +}); + +test("full cocotb runs reuse the workspace build and report failures before upload", () => { + const rust = job("rust-tests"); + const full = rust.match(/run: >-\n\s+(cargo nextest run[^\n]*)\n\s+(--features [^\n]*)/); + assert.ok(full); + const original = `${full[1]} ${full[2]}`.replaceAll("'", "").split(/\s+/).slice(1); + const args = cargoArguments("rust-tests", "Run cocotb VPI end-to-end test", { RUST_FULL: "true" }); + assert.deepEqual(args.slice(0, -4), original); + assert.ok(rust.indexOf("Collect Rust test reports") < rust.indexOf("Run cocotb VPI end-to-end test")); + assert.ok(rust.indexOf("Run cocotb VPI end-to-end test") < rust.indexOf("Retain Rust test reports")); + assert.match(rust, /test_step_outcome: .*steps.cocotb-tests.outcome == 'failure' && 'failure'/); +}); + +test("default-feature validation is parallel and mandatory when selected", () => { + const defaults = job("rust-default-tests"); + assert.match(defaults, /needs: changes/); + assert.match(defaults, /needs.changes.result != 'success'/); + assert.match(defaults, /outputs.rust_full != 'false'/); + assert.match(defaults, /outputs.rust_libraries/); + assert.match(defaults, /cargo test --locked -p celox --lib/); + assert.match(defaults, /cargo test --locked -p celox --doc/); + assert.doesNotMatch(defaults, /--features|--no-default-features/); + assert.doesNotMatch(job("rust-tests"), /cargo test --locked -p celox --lib/); + assert.match(job("rust"), /DEFAULT_RESULT: .*needs.rust-default-tests.result/); + assert.match(job("report-full-validation"), /rust-default-tests,/); +}); + +test("CI shares the executor profile and warms each platform's cache", () => { + const rust = job("rust-tests"); + assert.match(rust, /cargo nextest run .*--cargo-profile vtest/); + assert.match(rust, /cargo test --locked --profile vtest --workspace/); + const warm = readFileSync(new URL("../.github/workflows/rust-cache.yml", import.meta.url), "utf8"); + const windows = warm.split(" napi-windows:")[1]; + assert.match(windows, /runs-on: windows-latest/); + assert.match(windows, /run: pnpm run build:napi/); + assert.match(windows, /steps.cache.outputs.cache-hit != 'true'/); + assert.match(windows, /if: github.ref == format/); + assert.match(warm, /rust-default-tests:[\s\S]*cargo test --locked -p celox --lib --no-run/); }); test("full Clippy validation covers every workspace crate", () => { diff --git a/scripts/run-ci-cocotb.mjs b/scripts/run-ci-cocotb.mjs new file mode 100644 index 00000000000..ce08571dded --- /dev/null +++ b/scripts/run-ci-cocotb.mjs @@ -0,0 +1,39 @@ +import { spawnSync } from "node:child_process"; +import { pathToFileURL } from "node:url"; +import { clearCurrentReport, saveCurrentReport } from "./ci-rust-reports.mjs"; +import { cargoCommands } from "./run-ci-rust-scope.mjs"; + +export const cocotbFilter = 'binary_id(celox-vpi::cocotb_e2e) & test(/^cocotb_/)'; + +// Keep exactly the original packages, features, targets and Cargo profile. +// Narrowing -p to celox-vpi would resolve a different dependency feature graph. +export function cocotbCommands(full, builds) { + if (full !== "false") return [[ + "nextest", "run", "--locked", "--workspace", "--exclude", "lydite*", + "--profile", "ci", "--cargo-profile", "vtest", + "--features", "celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus,celox-test-suite/runtime-cases", + "--run-ignored", "only", "-E", cocotbFilter, + ]]; + // Validate all plans first, including ones we do not need to execute. + const commands = cargoCommands("test", builds, cocotbFilter); + const selected = commands.filter((_, i) => builds[i].packages.includes("celox-vpi") + && (!builds[i].targets.length || builds[i].targets.includes("cocotb_e2e"))); + if (!selected.length) throw new Error("Cocotb CI requires a VPI test build"); + return selected.map(args => [ + ...args.filter(arg => arg !== "--no-tests=pass"), "--run-ignored", "only", + ]); +} + +if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { + if (!process.env.CELOX_COCOTB_PYTHON) throw new Error("Cocotb Python interpreter is required"); + let reportIndex = 0; + for (const args of cocotbCommands(process.env.RUST_FULL, + process.env.RUST_FULL === "false" ? JSON.parse(process.env.BUILDS) : null)) { + if (process.env.CELOX_CI_REPORT_DIR) clearCurrentReport(); + const result = spawnSync("cargo", args, { stdio: "inherit" }); + if (process.env.CELOX_CI_REPORT_DIR) + saveCurrentReport(process.env.CELOX_CI_REPORT_DIR, `cocotb-${reportIndex++}`); + if (result.error) throw result.error; + if (result.status !== 0) process.exit(result.status ?? 1); + } +} diff --git a/scripts/run-ci-cocotb.test.mjs b/scripts/run-ci-cocotb.test.mjs new file mode 100644 index 00000000000..cd84a86127e --- /dev/null +++ b/scripts/run-ci-cocotb.test.mjs @@ -0,0 +1,57 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { spawnSync } from "node:child_process"; +import { chmodSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { cocotbCommands, cocotbFilter } from "./run-ci-cocotb.mjs"; +import { cargoCommands } from "./run-ci-rust-scope.mjs"; + +test("cocotb preserves build resolution and selects only its ignored tests", () => { + const builds = [ + { packages: ["celox-heap"], targets: [], features: [] }, + { packages: ["celox", "celox-vpi"], targets: [], features: ["celox/systemverilog"] }, + ]; + const original = structuredClone(builds); + const expected = cargoCommands("test", builds, cocotbFilter)[1] + .filter(arg => arg !== "--no-tests=pass"); + assert.deepEqual(cocotbCommands("false", builds), [[...expected, "--run-ignored", "only"]]); + assert.deepEqual(builds, original); + for (const full of ["true", "", undefined]) { + const [args] = cocotbCommands(full, null); + assert.ok(args.includes("--workspace")); + assert.ok(args.includes("vtest")); + assert.ok(!args.includes("--no-tests=pass")); + assert.deepEqual(args.slice(-4), ["--run-ignored", "only", "-E", cocotbFilter]); + } +}); + +test("missing or wrong VPI targets fail closed", () => { + for (const builds of [[], [{ packages: ["celox"], targets: [], features: [] }], + [{ packages: ["celox-vpi"], targets: ["other_test"], features: [] }]]) + assert.throws(() => cocotbCommands("false", builds)); + const [args] = cocotbCommands("false", [{ packages: ["celox-vpi"], targets: ["cocotb_e2e"], features: [] }]); + assert.equal(args[args.indexOf("--test") + 1], "cocotb_e2e"); +}); + +test("cocotb requires Python and propagates Cargo failures without running later plans", () => { + const directory = mkdtempSync(join(tmpdir(), "celox-cocotb-command-")); + try { + const executable = join(directory, "cargo"); + const log = join(directory, "calls"); + writeFileSync(executable, '#!/bin/sh\necho called >> "$COCOTB_CALL_LOG"\nexit 17\n'); + chmodSync(executable, 0o755); + const build = { packages: ["celox-vpi"], targets: [], features: [] }; + const env = { ...process.env, RUST_FULL: "false", BUILDS: JSON.stringify([build, build]), + PATH: `${directory}:${process.env.PATH}`, COCOTB_CALL_LOG: log, + CELOX_CI_REPORT_DIR: "", CELOX_COCOTB_PYTHON: "" }; + const missing = spawnSync(process.execPath, ["scripts/run-ci-cocotb.mjs"], { env, encoding: "utf8" }); + assert.notEqual(missing.status, 0); + assert.match(missing.stderr, /Python interpreter is required/); + const failed = spawnSync(process.execPath, ["scripts/run-ci-cocotb.mjs"], { + env: { ...env, CELOX_COCOTB_PYTHON: "/test/python" }, encoding: "utf8", + }); + assert.equal(failed.status, 17); + assert.equal(readFileSync(log, "utf8"), "called\n"); + } finally { rmSync(directory, { recursive: true, force: true }); } +}); diff --git a/scripts/run-ci-rust-scope.mjs b/scripts/run-ci-rust-scope.mjs index 80850239528..965efe6632f 100644 --- a/scripts/run-ci-rust-scope.mjs +++ b/scripts/run-ci-rust-scope.mjs @@ -16,7 +16,7 @@ export function cargoCommands(mode, builds, filter) { if (!packages.length || (mode === "test" && !filter)) throw new Error("Empty package or test selection"); const args = mode === "test" - ? ["nextest", "run", "--locked", "--profile", "ci", "--no-tests=pass"] + ? ["nextest", "run", "--locked", "--profile", "ci", "--cargo-profile", "vtest", "--no-tests=pass"] : ["clippy", "--locked"]; for (const name of packages) args.push("-p", name); const enabled = mode === "test" && packages.includes("celox") From e97945b759124c201a913366e3bacb4f16b93e19 Mon Sep 17 00:00:00 2001 From: tignear Date: Sun, 25 Oct 2026 02:50:21 +0900 Subject: [PATCH 2/2] ci: retain cached normal-profile test builds Change-Id: I4b6427df26ee17c68a606e4b9c68d3424f866390 --- .github/workflows/ci.yml | 8 ++++---- .github/workflows/rust-cache.yml | 4 ++-- CONTRIBUTING.md | 22 +++++++++++----------- Cargo.toml | 2 +- scripts/ci-lydite-changes.test.mjs | 2 +- scripts/ci-workflow.test.mjs | 16 ++++++++-------- scripts/run-ci-cocotb.mjs | 2 +- scripts/run-ci-cocotb.test.mjs | 2 +- scripts/run-ci-rust-scope.mjs | 2 +- 9 files changed, 30 insertions(+), 30 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea6775b6e1b..e1731134b78 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -223,7 +223,7 @@ jobs: - uses: Swatinem/rust-cache@v2 with: - key: vtest-v2 + key: vtest-v1 save-if: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} - name: Initialize Rust test reports @@ -258,7 +258,7 @@ jobs: id: workspace-tests if: needs.changes.outputs.rust_full != 'false' run: >- - cargo nextest run --locked --workspace --exclude 'lydite*' --profile ci --cargo-profile vtest + cargo nextest run --locked --workspace --exclude 'lydite*' --profile ci --features celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus,celox-test-suite/runtime-cases - name: Run the tests this pull request can affect @@ -304,7 +304,7 @@ jobs: - name: Run workspace documentation tests with CI features if: needs.changes.outputs.rust_full != 'false' run: >- - cargo test --locked --profile vtest --workspace --exclude 'lydite*' --doc + cargo test --locked --workspace --exclude 'lydite*' --doc --features celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus,celox-test-suite/runtime-cases - name: Run the documentation tests of the changed libraries @@ -316,7 +316,7 @@ jobs: args=() for package in $LIBRARIES; do args+=(-p "$package"); done if [ -n "$FEATURES" ]; then args+=(--features "$FEATURES"); fi - cargo test --locked --profile vtest --doc "${args[@]}" + cargo test --locked --doc "${args[@]}" rust-default-tests: name: Rust default-feature tests diff --git a/.github/workflows/rust-cache.yml b/.github/workflows/rust-cache.yml index e7fea04d572..33fdcdb80c7 100644 --- a/.github/workflows/rust-cache.yml +++ b/.github/workflows/rust-cache.yml @@ -41,7 +41,7 @@ jobs: - uses: Swatinem/rust-cache@v2 id: cache with: - key: vtest-v2 + key: vtest-v1 - name: Install cargo-nextest if: steps.cache.outputs.cache-hit != 'true' uses: taiki-e/install-action@v2 @@ -53,7 +53,7 @@ jobs: - name: Build test targets to populate dependencies if: steps.cache.outputs.cache-hit != 'true' run: >- - cargo nextest list --locked --workspace --exclude 'lydite*' --cargo-profile vtest --message-format json + cargo nextest list --locked --workspace --exclude 'lydite*' --message-format json --features celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus,celox-test-suite/runtime-cases > /dev/null diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9c03d665e6f..095a0dad575 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -58,17 +58,17 @@ ignored registrations deliberately. With `runtime-cases`, `.vtest` bodies are read from disk instead of embedded in Rust binaries, so edits to an existing case do not require recompilation. Adding -a test registration or changing Rust still requires a build. The local command -builds both the optimized executor and ordinary test binaries; the executor -profile has its own Cargo cache. CI instead builds both with the `vtest` Cargo profile so -shared dependencies and Celox libraries can be reused. Ordinary Cargo test -commands retain the embedded, in-process path. CI's Rust Tests job prepares the -executor once and uses it for both full workspace runs and scoped runs that -include Celox. Scopes without Celox skip that -build. The default-branch cache warmer builds both executor and test dependencies -under the same cache key; vtest preparation failures fail the test job. -CI documentation tests also use this Cargo profile. Cocotb runs through nextest -with the exact packages, features and targets of its original build, selecting +a test registration or changing Rust still requires a build. Both local commands +and CI build the optimized executor separately from ordinary test binaries. +CI keeps the normal test profile and existing dependency cache: sharing a Cargo +profile alone does not share artifacts when the executor and workspace resolve +different dependency features. Ordinary Cargo test commands retain the embedded, +in-process path. CI's Rust Tests job prepares the executor once and uses it for +full workspace runs and scoped runs that include Celox. Scopes without Celox +skip that build. The default-branch cache warmer builds both executor and test +dependencies under the same cache key; preparation failures fail the test job. +Cocotb runs through nextest with the exact packages, features and targets of its +original build, selecting only the ignored `cocotb_` cases; an empty selection fails. Its reports are kept separately and uploaded with the regular test results. diff --git a/Cargo.toml b/Cargo.toml index a0bf1785a54..8c770d54d64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -166,7 +166,7 @@ incremental = true [profile.bench] debug = true -# Optimize the shared vtest executor and CI tests, keeping development checks enabled. +# Optimize the shared vtest executor while keeping development checks enabled. # External dependencies retain the dev profile's package-specific optimization. [profile.vtest] inherits = "dev" diff --git a/scripts/ci-lydite-changes.test.mjs b/scripts/ci-lydite-changes.test.mjs index b63228be0f4..b745af57b4a 100644 --- a/scripts/ci-lydite-changes.test.mjs +++ b/scripts/ci-lydite-changes.test.mjs @@ -234,7 +234,7 @@ test("workflows transfer Rust tests and gate each Lydite lane", () => { ); assert.match( ci, - /cargo test --locked --profile vtest --workspace --exclude 'lydite\*' --doc/, + /cargo test --locked --workspace --exclude 'lydite\*' --doc/, ); const workflow = readFileSync(`${root}.github/workflows/lydite-checks.yml`, "utf8"); assert.match( diff --git a/scripts/ci-workflow.test.mjs b/scripts/ci-workflow.test.mjs index 4ecd44add32..f9122c8d15c 100644 --- a/scripts/ci-workflow.test.mjs +++ b/scripts/ci-workflow.test.mjs @@ -388,14 +388,14 @@ test("cache warming shares the Rust Tests key and builds without running tests", ); assert.match(warm, /steps.cache.outputs.cache-hit != 'true'/); for (const text of [warm, job("rust-tests")]) { - assert.match(text, /key: vtest-v2/); + assert.match(text, /key: vtest-v1/); assert.match(text, /run: node scripts\/run-vtest.mjs --prepare-ci/); } assert.match(warm, /name: Build the optimized vtest executor to populate dependencies\n if: steps.cache.outputs.cache-hit != 'true'/); assert.match(warm, /"scripts\/run-vtest.mjs"/); assert.match( warm, - /cargo nextest list --locked --workspace --exclude 'lydite\*' --cargo-profile vtest --message-format json/, + /cargo nextest list --locked --workspace --exclude 'lydite\*' --message-format json/, ); const features = job("rust-tests").match(/--features (\S+)/)[1]; assert.ok(warm.includes(`--features ${features}`)); @@ -436,7 +436,7 @@ test("scoped Cargo commands build only the selected integration targets", () => TARGETS: "flip_flop systemverilog", FILTER: "binary_id(celox::flip_flop) | binary_id(celox::systemverilog)", }; assert.deepEqual(cargoArguments("rust-tests", "Run the tests this pull request can affect", env), [ - "nextest", "run", "--locked", "--profile", "ci", "--cargo-profile", "vtest", "--no-tests=pass", + "nextest", "run", "--locked", "--profile", "ci", "--no-tests=pass", "-p", "celox", "--features", "celox/systemverilog,celox-test-suite/runtime-cases", "--test", "flip_flop", "--test", "systemverilog", "-E", env.FILTER, ]); @@ -463,7 +463,7 @@ test("CI prepares one executor for full runs and scopes containing Celox", () => assert.deepEqual(cargoArguments("rust-tests", "Run the tests this pull request can affect", { PACKAGES: "celox-heap", FEATURES: "", TARGETS: "", FILTER: "package(celox-heap)", CELOX_VTEST_RUNNER: "", - }), ["nextest", "run", "--locked", "--profile", "ci", "--cargo-profile", "vtest", "--no-tests=pass", + }), ["nextest", "run", "--locked", "--profile", "ci", "--no-tests=pass", "-p", "celox-heap", "-E", "package(celox-heap)"]); }); @@ -504,7 +504,7 @@ test("cocotb reuses the original scoped Cargo build", () => { const args = cargoArguments("rust-tests", "Run cocotb VPI end-to-end test", { RUST_FULL: "false", BUILDS: JSON.stringify(builds), }); - assert.deepEqual(args, ["nextest", "run", "--locked", "--profile", "ci", "--cargo-profile", "vtest", + assert.deepEqual(args, ["nextest", "run", "--locked", "--profile", "ci", "-p", "celox", "-p", "celox-vpi", "-p", "celox-test-suite", "--features", "celox/systemverilog,celox-test-suite/icarus,celox-test-suite/runtime-cases", "-E", 'binary_id(celox-vpi::cocotb_e2e) & test(/^cocotb_/)', "--run-ignored", "only"]); @@ -536,10 +536,10 @@ test("default-feature validation is parallel and mandatory when selected", () => assert.match(job("report-full-validation"), /rust-default-tests,/); }); -test("CI shares the executor profile and warms each platform's cache", () => { +test("CI retains the normal test profile and warms each platform's cache", () => { const rust = job("rust-tests"); - assert.match(rust, /cargo nextest run .*--cargo-profile vtest/); - assert.match(rust, /cargo test --locked --profile vtest --workspace/); + assert.doesNotMatch(rust, /--cargo-profile/); + assert.match(rust, /cargo test --locked --workspace/); const warm = readFileSync(new URL("../.github/workflows/rust-cache.yml", import.meta.url), "utf8"); const windows = warm.split(" napi-windows:")[1]; assert.match(windows, /runs-on: windows-latest/); diff --git a/scripts/run-ci-cocotb.mjs b/scripts/run-ci-cocotb.mjs index ce08571dded..30765f798c0 100644 --- a/scripts/run-ci-cocotb.mjs +++ b/scripts/run-ci-cocotb.mjs @@ -10,7 +10,7 @@ export const cocotbFilter = 'binary_id(celox-vpi::cocotb_e2e) & test(/^cocotb_/) export function cocotbCommands(full, builds) { if (full !== "false") return [[ "nextest", "run", "--locked", "--workspace", "--exclude", "lydite*", - "--profile", "ci", "--cargo-profile", "vtest", + "--profile", "ci", "--features", "celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus,celox-test-suite/runtime-cases", "--run-ignored", "only", "-E", cocotbFilter, ]]; diff --git a/scripts/run-ci-cocotb.test.mjs b/scripts/run-ci-cocotb.test.mjs index cd84a86127e..a53a46060d6 100644 --- a/scripts/run-ci-cocotb.test.mjs +++ b/scripts/run-ci-cocotb.test.mjs @@ -20,7 +20,7 @@ test("cocotb preserves build resolution and selects only its ignored tests", () for (const full of ["true", "", undefined]) { const [args] = cocotbCommands(full, null); assert.ok(args.includes("--workspace")); - assert.ok(args.includes("vtest")); + assert.ok(!args.includes("--cargo-profile")); assert.ok(!args.includes("--no-tests=pass")); assert.deepEqual(args.slice(-4), ["--run-ignored", "only", "-E", cocotbFilter]); } diff --git a/scripts/run-ci-rust-scope.mjs b/scripts/run-ci-rust-scope.mjs index 965efe6632f..80850239528 100644 --- a/scripts/run-ci-rust-scope.mjs +++ b/scripts/run-ci-rust-scope.mjs @@ -16,7 +16,7 @@ export function cargoCommands(mode, builds, filter) { if (!packages.length || (mode === "test" && !filter)) throw new Error("Empty package or test selection"); const args = mode === "test" - ? ["nextest", "run", "--locked", "--profile", "ci", "--cargo-profile", "vtest", "--no-tests=pass"] + ? ["nextest", "run", "--locked", "--profile", "ci", "--no-tests=pass"] : ["clippy", "--locked"]; for (const name of packages) args.push("-p", name); const enabled = mode === "test" && packages.includes("celox")