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
50 changes: 31 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
--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 != ''
Expand All @@ -309,27 +318,24 @@ jobs:
if [ -n "$FEATURES" ]; then args+=(--features "$FEATURES"); fi
cargo test --locked --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
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -959,6 +970,7 @@ jobs:
docs,
lint,
rust-tests,
rust-default-tests,
sv-tests,
external-suites,
common-cells,
Expand Down
43 changes: 42 additions & 1 deletion .github/workflows/rust-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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*' --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
27 changes: 20 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
build. The default-branch cache warmer builds both executor and test dependencies
under the same cache key; vtest preparation failures fail the test job.
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.

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
Expand Down
4 changes: 2 additions & 2 deletions scripts/ci-rust-reports.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 11 additions & 1 deletion scripts/ci-rust-reports.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");
});
66 changes: 57 additions & 9 deletions scripts/ci-workflow.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand All @@ -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,
Expand All @@ -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",
Expand Down Expand Up @@ -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,
Expand All @@ -378,7 +384,7 @@ 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")]) {
Expand All @@ -389,7 +395,7 @@ test("cache warming shares the Rust Tests key and builds without running tests",
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\*' --message-format json/,
);
const features = job("rust-tests").match(/--features (\S+)/)[1];
assert.ok(warm.includes(`--features ${features}`));
Expand Down Expand Up @@ -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",
"-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 retains the normal test profile and warms each platform's cache", () => {
const rust = job("rust-tests");
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/);
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", () => {
Expand Down
Loading
Loading