diff --git a/conformance/common-cells/README.md b/conformance/common-cells/README.md index e4105d2da11..eec535ddb97 100644 --- a/conformance/common-cells/README.md +++ b/conformance/common-cells/README.md @@ -1,6 +1,6 @@ # Upstream SystemVerilog testbench smoke test -Daily full CI runs the unmodified `cc_graycode_tb` from +Daily full CI runs the unmodified `cc_graycode_tb` and `cc_popcount_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 @@ -11,9 +11,15 @@ 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 popcount TB covers widths 1, 5, 16, 32, 64, and 981 with unconstrained +scope randomization, explicit-unit `#5ns` delays, and immediate assertions +comparing the RTL with `$countones`. The randomizer supports arbitrary packed +widths; 981 is this upstream test's largest vector, not an implementation limit. + 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 +the Gray encoder output to zero and disables popcount accumulation in separate +RTL copies, requiring exit code 1 with the corresponding assertion diagnostic +for each. 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. @@ -29,7 +35,8 @@ node scripts/run-common-cells.mjs work/common-cells target/debug/celox work/comm ``` The output directory contains the generated `celox.toml`, negative-control -sources, both logs, and a `result.json` written only after both checks pass. +sources, the popcount manifests, four logs, and a `result.json` written only after all +four executions pass their positive or negative expectations. 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. diff --git a/scripts/run-common-cells.mjs b/scripts/run-common-cells.mjs index ca6bb5333f8..c6e4d3ca0cb 100644 --- a/scripts/run-common-cells.mjs +++ b/scripts/run-common-cells.mjs @@ -22,18 +22,19 @@ export function run({ source, celox, output }) { 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 manifest = (files, top = "cc_graycode_tb") => `sources = [${files.map((file) => JSON.stringify(file)).join(", ")}]\ntop = ${JSON.stringify(top)}\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 execute = (name, projectFile, negative = false, diagnostic = "assert failed") => { 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 !== 1 || !log.includes(diagnostic) + || !log.includes("SystemVerilog testbench reported an assertion failure or $error") : result.status !== 0)) { throw new Error(`${name} failed (exit ${result.status}, signal ${result.signal}): ${result.error ?? log}`); } @@ -49,10 +50,25 @@ export function run({ source, celox, output }) { const negativeProject = join(output, "negative.toml"); writeFileSync(negativeProject, manifest([broken, ...original.slice(1)])); execute("graycode-negative", negativeProject, true); + const popcount = join(source, "src/cc_popcount.sv"); + const popcountTb = join(source, "test/cc_popcount_tb.sv"); + const popcountProject = join(output, "popcount.toml"); + writeFileSync(popcountProject, manifest([popcount, popcountTb], "cc_popcount_tb")); + execute("popcount", popcountProject); + + const popcountText = readFileSync(popcount, "utf8"); + const increment = "popcount_o += data_i[i];"; + if (popcountText.split(increment).length !== 2) throw new Error("Cannot locate the pinned popcount accumulation"); + const brokenPopcount = join(output, "negative_popcount.sv"); + writeFileSync(brokenPopcount, popcountText.replace(increment, "popcount_o += 0;")); + const negativePopcountProject = join(output, "popcount-negative.toml"); + writeFileSync(negativePopcountProject, manifest([brokenPopcount, popcountTb], "cc_popcount_tb")); + execute("popcount-negative", negativePopcountProject, true, "Popcount of"); writeFileSync(join(output, "result.json"), `${JSON.stringify({ revision, top: "cc_graycode_tb", positive: "passed", negative: "assertion failure detected", + testbenches: ["cc_graycode_tb", "cc_popcount_tb"], }, null, 2)}\n`); - console.log(`common_cells ${revision}: upstream Gray code TB passed; broken RTL rejected`); + console.log(`common_cells ${revision}: upstream Gray code and popcount TBs passed; both broken RTL copies rejected`); } if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) { diff --git a/scripts/run-common-cells.test.mjs b/scripts/run-common-cells.test.mjs index 35948733316..6614de22602 100644 --- a/scripts/run-common-cells.test.mjs +++ b/scripts/run-common-cells.test.mjs @@ -18,20 +18,28 @@ test("upstream gate rejects wrong revisions, broken positives, and false negativ 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"), ""); + const popcountOriginal = "popcount_o += data_i[i];"; + writeFileSync(join(source, "src/cc_popcount.sv"), popcountOriginal); + writeFileSync(join(source, "test/cc_popcount_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; +const popcount = process.argv.at(-1).endsWith("popcount.toml") || process.argv.at(-1).endsWith("popcount-negative.toml"); +if (popcount && mode === "popcount-positive-failure" && !negative) process.exit(1); +if (popcount && mode === "popcount-false-pass" && negative) process.exit(0); 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 === "quoted-compile-error") { console.error("compilation failed: source contains assert failed / Popcount of"); process.exit(1); } if (mode === "crash") { process.kill(process.pid, "SIGTERM"); } -console.error("assert failed"); process.exit(1); +console.error(popcount ? "Popcount of 1 was 0 but should be 1" : "assert failed"); +console.error("SystemVerilog testbench reported an assertion failure or $error"); 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"]) { + for (const mode of ["success", "positive-failure", "false-pass", "compile-error", "quoted-compile-error", "crash", "wrong-revision", "popcount-positive-failure", "popcount-false-pass"]) { const output = join(root, mode); const result = spawnSync(process.execPath, [resolve("scripts/run-common-cells.mjs"), source, celox, output], { encoding: "utf8", @@ -40,11 +48,15 @@ console.error("assert failed"); process.exit(1); }); 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"); + const report = JSON.parse(readFileSync(join(output, "result.json"))); + assert.equal(report.positive, "passed"); + assert.deepEqual(report.testbenches, ["cc_graycode_tb", "cc_popcount_tb"]); + assert.match(readFileSync(join(output, "popcount-negative.log"), "utf8"), /Popcount of/); assert.match(readFileSync(join(output, "graycode-negative.log"), "utf8"), /assert failed/); } } assert.equal(readFileSync(join(source, "src/cc_binary_to_gray.sv"), "utf8"), original); + assert.equal(readFileSync(join(source, "src/cc_popcount.sv"), "utf8"), popcountOriginal); } finally { rmSync(root, { recursive: true, force: true }); }