diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f46105596e..8227e3c7eb8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -385,6 +385,49 @@ jobs: if-no-files-found: error retention-days: 14 + common-cells: + name: Upstream SystemVerilog testbench + if: ${{ !cancelled() && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') }} + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@v7 + + - uses: ./.github/actions/setup-rust + + - uses: Swatinem/rust-cache@v2 + with: + save-if: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} + + - uses: actions/setup-node@v7 + with: + node-version: 24 + + - name: Fetch pinned common_cells + run: | + revision="$(cat conformance/common-cells/revision)" + git init -q "$RUNNER_TEMP/common-cells" + git -C "$RUNNER_TEMP/common-cells" fetch -q --depth 1 \ + https://github.com/pulp-platform/common_cells.git "$revision" + git -C "$RUNNER_TEMP/common-cells" checkout -q FETCH_HEAD + + - name: Build the SystemVerilog CLI + run: cargo build --locked -p celox-vpi --features systemverilog --bin celox + + - name: Run upstream TB and assertion negative control + run: >- + node scripts/run-common-cells.mjs "$RUNNER_TEMP/common-cells" + target/debug/celox "$RUNNER_TEMP/common-cells-results" + + - name: Retain testbench logs + if: always() + uses: actions/upload-artifact@v7 + with: + name: common-cells-results + path: ${{ runner.temp }}/common-cells-results + if-no-files-found: ignore + retention-days: 14 + sv-tests: name: sv-tests conformance needs: changes @@ -879,6 +922,7 @@ jobs: rust-tests, sv-tests, external-suites, + common-cells, napi-linux, napi-wasm, rust, diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d8b2cbce565..ab1b238ad16 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -289,6 +289,7 @@ Local validation uses the behavior-based matrix above. | Daily at 01:47 UTC (10:47 JST) | `bench.yml` measures Rust, Verilator, and TypeScript on one host and publishes master history. Manual dispatch supports branch measurements. | | Daily at 02:17 UTC (11:17 JST) | `codspeed.yml` measures compile time on the default branch using CPU simulation. Execution failures and CodSpeed performance-check failures open or update a branch issue; the next healthy run closes it. Manual dispatch supports branch measurements. PRs, merge groups, and pushes do not run CodSpeed. | | Daily at 02:37 UTC (11:37 JST) | `heliodor-bench.yml` runs the complete master Linux suite on x86-64 and AArch64. Explicit manual selections retain focused suite runs and ARM64 profiling. PRs do not run this workflow; its tooling tests run in `Lint & Format` with the other script tests. | +| Every daily/manual full CI run | Run the pinned upstream `common_cells` Gray code SV TB through `celox run --project`, plus an assertion negative control. Logs are retained for 14 days and failures feed the Full CI issue. See [the reproduction instructions](conformance/common-cells/README.md). | | Every full CI run | Run every shared Veryl and SystemVerilog case against both Verilator and Icarus, with locked Nix tools. Run the live adapter tests normally marked ignored because they need external tools. Preserve reports and per-case diagnostics as artifacts for 14 days, including on failure; matrix failures do not cancel the other comparisons. | | Affected pull requests and merge groups; daily at 03:41 UTC (12:41 JST); on demand | `lydite-checks.yml` owns Lydite Rust tests, proof, conformance, editor, and mutation gates. Unrelated changes skip these jobs, and Celox changes skip the bridge. Daily and manual runs enable all lanes and report failures in an issue. | | On demand | Dispatch `ci.yml` on the desired branch to run full CI and external comparisons, regardless of its diff. | diff --git a/conformance/common-cells/README.md b/conformance/common-cells/README.md new file mode 100644 index 00000000000..e4105d2da11 --- /dev/null +++ b/conformance/common-cells/README.md @@ -0,0 +1,38 @@ +# Upstream SystemVerilog testbench smoke test + +Daily full CI runs the unmodified `cc_graycode_tb` from +[PULP common_cells](https://github.com/pulp-platform/common_cells), pinned by +[`revision`](revision). The same job runs on manual `ci.yml` dispatches and on +develop's nightly full CI. It exercises the `celox run --project` CLI with the +SystemVerilog frontend and native timed simulation. + +The default 9-bit TB applies 1,536 inputs using loops, `#1` delays, an untimed +task, and immediate assertions. It checks binary/Gray round trips and changes +in the Gray code population count. This is a small combinational design smoke +test, not coverage of all common_cells modules or clocked testbenches. + +The gate first requires the original RTL/TB to exit successfully. It then forces +the Gray encoder output to zero in a separate RTL copy and requires exit code 1 +with an assertion diagnostic. Compilation errors, crashes and timeouts do not +satisfy this negative control. Upstream files are never edited. Each execution +has a two-minute wall timeout and the CLI's default scheduler step limit. + +To reproduce from the repository root: + +```sh +revision="$(cat conformance/common-cells/revision)" +git init work/common-cells +git -C work/common-cells fetch --depth 1 https://github.com/pulp-platform/common_cells.git "$revision" +git -C work/common-cells checkout FETCH_HEAD +cargo build --locked -p celox-vpi --features systemverilog --bin celox +node scripts/run-common-cells.mjs work/common-cells target/debug/celox work/common-cells-results +``` + +The output directory contains the generated `celox.toml`, negative-control +sources, both logs, and a `result.json` written only after both checks pass. +Use a fresh output directory for each run. CI retains this directory for 14 days, +including on failure; failures feed the existing Full CI issue reporter. + +Update the pin deliberately after reviewing and running the upstream TB. The +negative-control assignment is checked explicitly so an upstream rewrite cannot +silently remove that check. diff --git a/conformance/common-cells/revision b/conformance/common-cells/revision new file mode 100644 index 00000000000..8f27dce2c8c --- /dev/null +++ b/conformance/common-cells/revision @@ -0,0 +1 @@ +e73baaec2ca665cd80c3c384e9258e35242b829c diff --git a/scripts/ci-workflow.test.mjs b/scripts/ci-workflow.test.mjs index 01dcfd5452d..dd96e7a17c5 100644 --- a/scripts/ci-workflow.test.mjs +++ b/scripts/ci-workflow.test.mjs @@ -358,7 +358,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, 8); + assert.equal(cacheSteps.length, 9); for (const [, step] of cacheSteps) { assert.match( step, @@ -461,3 +461,15 @@ test("cocotb retains Celox features without enabling unrelated adapter features" test("full Clippy validation covers every workspace crate", () => { assert.match(job("lint"), /run: cargo clippy --locked --workspace --all-targets --features/); }); + +test("upstream SV TB runs on full CI and feeds failure reporting", () => { + const upstream = job("common-cells"); + assert.match(upstream, /github.event_name == 'schedule' \|\| github.event_name == 'workflow_dispatch'/); + assert.doesNotMatch(upstream, /continue-on-error/); + assert.match(upstream, /conformance\/common-cells\/revision/); + assert.match(upstream, /cargo build --locked -p celox-vpi --features systemverilog --bin celox/); + assert.match(upstream, /node scripts\/run-common-cells.mjs/); + assert.match(upstream, /if: always\(\)/); + assert.match(upstream, /retention-days: 14/); + assert.match(job("report-full-validation"), /common-cells,/); +}); diff --git a/scripts/run-common-cells.mjs b/scripts/run-common-cells.mjs new file mode 100644 index 00000000000..ca6bb5333f8 --- /dev/null +++ b/scripts/run-common-cells.mjs @@ -0,0 +1,70 @@ +import { spawnSync } from "node:child_process"; +import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { resolve, join } from "node:path"; +import { pathToFileURL } from "node:url"; + +export const revision = readFileSync( + new URL("../conformance/common-cells/revision", import.meta.url), "utf8", +).trim(); +const sources = [ + "src/cc_binary_to_gray.sv", + "src/cc_gray_to_binary.sv", + "test/cc_graycode_tb.sv", +]; + +export function run({ source, celox, output }) { + source = resolve(source); + celox = resolve(celox); + output = resolve(output); + mkdirSync(output, { recursive: true }); + rmSync(join(output, "result.json"), { force: true }); + const head = spawnSync("git", ["-C", source, "rev-parse", "HEAD"], { encoding: "utf8" }); + if (head.status !== 0 || head.stdout.trim() !== revision) { + throw new Error(`Expected common_cells revision ${revision}; fetch the pinned checkout first`); + } + const manifest = (files) => `sources = [${files.map((file) => JSON.stringify(file)).join(", ")}]\ntop = "cc_graycode_tb"\n`; + const original = sources.map((file) => join(source, file)); + const project = join(output, "celox.toml"); + writeFileSync(project, manifest(original)); + const execute = (name, projectFile, negative = false) => { + const result = spawnSync(celox, ["run", "--project", projectFile], { + encoding: "utf8", timeout: 120_000, maxBuffer: 8 * 1024 * 1024, + }); + const log = `${result.stdout ?? ""}${result.stderr ?? ""}`; + writeFileSync(join(output, `${name}.log`), log); + if (result.error || result.signal || (negative + ? result.status !== 1 || !log.includes("assert failed") + : result.status !== 0)) { + throw new Error(`${name} failed (exit ${result.status}, signal ${result.signal}): ${result.error ?? log}`); + } + }; + execute("graycode", project); + + // Mutate only a separate RTL copy: prove that the upstream assertions execute. + const text = readFileSync(original[0], "utf8"); + const assignment = "assign z_o = a_i ^ a_ext[Width:1];"; + if (text.split(assignment).length !== 2) throw new Error("Cannot locate the pinned Gray code assignment"); + const broken = join(output, "negative_binary_to_gray.sv"); + writeFileSync(broken, text.replace(assignment, "assign z_o = '0;")); + const negativeProject = join(output, "negative.toml"); + writeFileSync(negativeProject, manifest([broken, ...original.slice(1)])); + execute("graycode-negative", negativeProject, true); + writeFileSync(join(output, "result.json"), `${JSON.stringify({ + revision, top: "cc_graycode_tb", positive: "passed", negative: "assertion failure detected", + }, null, 2)}\n`); + console.log(`common_cells ${revision}: upstream Gray code TB passed; broken RTL rejected`); +} + +if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) { + if (process.argv.length !== 5) { + console.error("Usage: node scripts/run-common-cells.mjs SOURCE CELOX_BIN OUTPUT_DIR"); + process.exitCode = 1; + } else { + try { + run({ source: process.argv[2], celox: process.argv[3], output: process.argv[4] }); + } catch (error) { + console.error(error.message); + process.exitCode = 1; + } + } +} diff --git a/scripts/run-common-cells.test.mjs b/scripts/run-common-cells.test.mjs new file mode 100644 index 00000000000..35948733316 --- /dev/null +++ b/scripts/run-common-cells.test.mjs @@ -0,0 +1,51 @@ +import assert from "node:assert/strict"; +import { spawnSync } from "node:child_process"; +import { chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join, resolve } from "node:path"; +import test from "node:test"; +import { revision } from "./run-common-cells.mjs"; + +test("upstream gate rejects wrong revisions, broken positives, and false negative controls", () => { + const root = mkdtempSync(join(tmpdir(), "common-cells-test-")); + try { + const source = join(root, "source with spaces"); + const bin = join(root, "bin"); + mkdirSync(join(source, "src"), { recursive: true }); + mkdirSync(join(source, "test")); + mkdirSync(bin); + const original = "assign z_o = a_i ^ a_ext[Width:1];"; + writeFileSync(join(source, "src/cc_binary_to_gray.sv"), original); + writeFileSync(join(source, "src/cc_gray_to_binary.sv"), ""); + writeFileSync(join(source, "test/cc_graycode_tb.sv"), ""); + writeFileSync(join(bin, "git"), `#!/usr/bin/env node\nconsole.log(process.env.TEST_REVISION || ${JSON.stringify(revision)});\n`); + const celox = join(bin, "celox"); + writeFileSync(celox, `#!/usr/bin/env node +const negative = process.argv.at(-1).endsWith("negative.toml"); +const mode = process.env.TEST_MODE; +if (!negative) process.exit(mode === "positive-failure" ? 1 : 0); +if (mode === "false-pass") process.exit(0); +if (mode === "compile-error") { console.error("compilation failed"); process.exit(1); } +if (mode === "crash") { process.kill(process.pid, "SIGTERM"); } +console.error("assert failed"); process.exit(1); +`); + chmodSync(join(bin, "git"), 0o755); + chmodSync(celox, 0o755); + for (const mode of ["success", "positive-failure", "false-pass", "compile-error", "crash", "wrong-revision"]) { + const output = join(root, mode); + const result = spawnSync(process.execPath, [resolve("scripts/run-common-cells.mjs"), source, celox, output], { + encoding: "utf8", + env: { ...process.env, PATH: `${bin}:${process.env.PATH}`, TEST_MODE: mode, + TEST_REVISION: mode === "wrong-revision" ? "bad" : revision }, + }); + assert.equal(result.status, mode === "success" ? 0 : 1, `${mode}: ${result.stderr}`); + if (mode === "success") { + assert.equal(JSON.parse(readFileSync(join(output, "result.json"))).positive, "passed"); + assert.match(readFileSync(join(output, "graycode-negative.log"), "utf8"), /assert failed/); + } + } + assert.equal(readFileSync(join(source, "src/cc_binary_to_gray.sv"), "utf8"), original); + } finally { + rmSync(root, { recursive: true, force: true }); + } +});