Skip to content
Merged
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
18 changes: 10 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ jobs:

- name: cargo clippy
if: (needs.changes.result != 'success' || needs.changes.outputs.rust == 'true') && needs.changes.outputs.rust_full != 'false'
run: cargo clippy --locked --workspace --exclude lydite-celox --all-targets --features celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus --no-deps
run: cargo clippy --locked --workspace --exclude lydite-celox --all-targets --features celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus,celox-test-suite/xezim --no-deps

- name: Lint the crates this pull request can affect
if: needs.changes.outputs.rust_full == 'false' && needs.changes.outputs.rust_lint_packages != ''
Expand Down Expand Up @@ -259,7 +259,7 @@ jobs:
if: needs.changes.outputs.rust_full != 'false'
run: >-
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
--features celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus,celox-test-suite/xezim,celox-test-suite/runtime-cases

- name: Run the tests this pull request can affect
id: scoped-tests
Expand Down Expand Up @@ -305,7 +305,7 @@ jobs:
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,celox-test-suite/runtime-cases
--features celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus,celox-test-suite/xezim,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 Down Expand Up @@ -348,9 +348,11 @@ jobs:
fail-fast: false
matrix:
suite: [veryl, sv]
tool: [verilator, icarus]
tool: [verilator, icarus, xezim]
env:
VERIFY_TOOL: ${{ matrix.tool }}
# xezim builds from source, so only its jobs enter the shell with it.
VERIFY_SHELL: ${{ matrix.tool == 'xezim' && '.#xezim' || '.' }}
VERIFY_SUITE: ${{ matrix.suite }}
VERIFY_BIN: ${{ matrix.suite == 'sv' && format('verify-sv-{0}', matrix.tool) || format('verify-{0}', matrix.tool) }}
VERIFY_BASELINE: ${{ matrix.suite == 'sv' && format('crates/celox-test-suite/verification/sv/{0}.json', matrix.tool) || format('crates/celox-test-suite/verification/{0}.json', matrix.tool) }}
Expand All @@ -366,15 +368,15 @@ jobs:
- name: Test live simulator adapters
if: matrix.suite == 'veryl'
run: >-
nix develop --no-update-lock-file --command
nix develop "$VERIFY_SHELL" --no-update-lock-file --command
cargo test --locked -p celox-test-suite --features "$VERIFY_TOOL"
--test oracles -- --ignored

- name: Catalogue every shared case
if: ${{ !cancelled() }}
run: |
mkdir -p "$RUNNER_TEMP/external-suite"
nix develop --no-update-lock-file --command \
nix develop "$VERIFY_SHELL" --no-update-lock-file --command \
cargo run --locked -p celox-test-suite --features "$VERIFY_TOOL" \
--bin "$VERIFY_BIN" -- --list > "$RUNNER_TEMP/external-suite/catalogue.json"

Expand All @@ -385,7 +387,7 @@ jobs:
# The runner returns 1 for retained failures as well as regressions.
# The next step checks the complete fresh report and the exit status.
rm -f "$RUNNER_TEMP/external-suite/logs/results.json"
if nix develop --no-update-lock-file --command \
if nix develop "$VERIFY_SHELL" --no-update-lock-file --command \
cargo run --locked -p celox-test-suite --features "$VERIFY_TOOL" \
--bin "$VERIFY_BIN" -- --fresh --jobs 2 \
--output "$RUNNER_TEMP/external-suite/logs"; then
Expand All @@ -400,7 +402,7 @@ jobs:
env:
VERIFY_EXIT_STATUS: ${{ steps.verify.outputs.exit_status }}
run: >-
nix develop --no-update-lock-file --command
nix develop "$VERIFY_SHELL" --no-update-lock-file --command
node scripts/check-external-suite-report.mjs
"$RUNNER_TEMP/external-suite/logs/results.json" "$VERIFY_BASELINE"
"$RUNNER_TEMP/external-suite/catalogue.json" "$VERIFY_EXIT_STATUS" "$VERIFY_SUITE"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
if: steps.cache.outputs.cache-hit != 'true'
run: >-
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
--features celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus,celox-test-suite/xezim,celox-test-suite/runtime-cases
> /dev/null

rust-default-tests:
Expand Down
11 changes: 11 additions & 0 deletions crates/celox-test-suite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ emit = ["dep:veryl-analyzer", "dep:veryl-emitter", "dep:veryl-parser", "dep:very
external = ["emit", "dep:clap", "dep:serde_json", "dep:sha2", "dep:celox-sv-analyzer"]
verilator = ["external"]
icarus = ["external"]
xezim = ["external"]

[[bin]]
name = "verify-verilator"
Expand All @@ -42,6 +43,16 @@ name = "verify-sv-icarus"
path = "src/bin/verify-sv-icarus.rs"
required-features = ["icarus"]

[[bin]]
name = "verify-xezim"
path = "src/bin/verify-xezim.rs"
required-features = ["xezim"]

[[bin]]
name = "verify-sv-xezim"
path = "src/bin/verify-sv-xezim.rs"
required-features = ["xezim"]

[[example]]
name = "inspect-mismatch-ir"
required-features = ["emit"]
Expand Down
23 changes: 23 additions & 0 deletions crates/celox-test-suite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,29 @@ which only reads declarations (after expanding interfaces) for this purpose. Its
in [`verification/sv/limitations.json`](verification/sv/limitations.json). Compiler diagnostics are not suppressed and emitted SV is not
rewritten to fit a simulator.

The optional `xezim` feature adds [xezim](https://github.com/aionhw/xezim), a
four-state event-driven simulator, through its command line only
(`verify-xezim`, `verify-sv-xezim`). It has no signal access: it runs the
generated testbenches and native testbenches, which report through their stdout
markers and their completion. Each design is first checked with
`xezim --compile`, which tells source rejections apart from a run that ends in
`$fatal`, and then simulated by a second xezim process, which parses it again;
a run passes only when xezim reports that `$finish` ended it. The xezim branch of a timed testbench
(``CELOX_SUITE_XEZIM``) settles through a `program`: program code runs in the
reactive region set, which the scheduler reaches only once the active region
set is empty, NBA updates and the events they cause included (IEEE 1800-2023
4.5, 24.3.1). The testbench increments a request count, which is a design event,
and waits for the program's acknowledgement; a bare `#0` would resume before the
design reacts. Two-state cases start xezim's flip-flops and memories at zero
(`XEZIM_INIT_REG=0`, `XEZIM_INIT_MEM=0`) and the generated testbench inputs at
zero. Other variables start at X, whereas the Icarus harness zeroes all
storage, so a two-state testbench fails when it reads unknown bits from the
design. `nix develop .#xezim` adds a pinned xezim (`nix/xezim`) to the
development shell.
xezim's retained failures stay executed evidence rather than exclusions:
[`verification/xezim-review.json`](verification/xezim-review.json) classifies
each one against IEEE 1800-2023 and names the xezim bug it reproduces.

Local verification reuses unchanged successful results by default. Select the
cases affected by executable source, stimulus or assertion changes:

Expand Down
3 changes: 3 additions & 0 deletions crates/celox-test-suite/src/bin/verify-sv-xezim.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() -> celox_test_suite::Result<()> {
celox_test_suite::sv::verification::run(celox_test_suite::verification::Tool::Xezim)
}
3 changes: 3 additions & 0 deletions crates/celox-test-suite/src/bin/verify-xezim.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() -> celox_test_suite::Result<()> {
celox_test_suite::veryl::verification::run(celox_test_suite::verification::Tool::Xezim)
}
2 changes: 2 additions & 0 deletions crates/celox-test-suite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ mod process;
pub mod verification;
#[cfg(feature = "external")]
pub mod verilator;
#[cfg(feature = "external")]
pub mod xezim;

pub use backend::{
Backend, Design, Event, Factory, Instance, Signal, SignalPath, Simulator, Source,
Expand Down
126 changes: 106 additions & 20 deletions crates/celox-test-suite/src/script/sv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
//! each, and restores a level that was neither.
//!
//! A timed case settles without advancing time: Icarus resumes from a
//! read/write synchronization callback and Verilator from a clocking event in
//! the observed region. Its script begins with `run_until` or
//! read/write synchronization callback, Verilator from a clocking event in
//! the observed region, and xezim once a program has run in the reactive
//! region. Its script begins with `run_until` or
//! `run_to_finish`, so the design's time-zero processes have run before the
//! testbench touches it. `run_until` drains its target timestamp before the
//! next script operation. The checks after `run_to_finish` run in a `final`
Expand Down Expand Up @@ -522,20 +523,28 @@ impl Generator<'_> {
match expr {
Expr::Literal(value) => self.literal(value),
Expr::Var(name) => format!("v_{name}"),
Expr::Get(path) => match self.design.arrays.get(&path.name) {
// Element 0 in the least significant bits.
Some((_, bounds)) if path.instances.is_empty() => {
let base = path_text(path);
let elements: Vec<String> = bounds
.indices()
.into_iter()
.rev()
.map(|i| format!("{base}[{i}]"))
.collect();
format!("$signed({n}'({{{}}}))", elements.join(", "))
Expr::Get(path) => {
let value = match self.design.arrays.get(&path.name) {
// Element 0 in the least significant bits.
Some((_, bounds)) if path.instances.is_empty() => {
let base = path_text(path);
let elements: Vec<String> = bounds
.indices()
.into_iter()
.rev()
.map(|i| format!("{base}[{i}]"))
.collect();
format!("$signed({n}'({{{}}}))", elements.join(", "))
}
_ => format!("$signed({n}'({{{}}}))", path_text(path)),
};
if self.case.four_state {
value
} else {
let what = format!("{} reads {}", self.case.name, path_label(path));
format!("suite_read({value}, {})", sv_string(&what))
}
_ => format!("$signed({n}'({{{}}}))", path_text(path)),
},
}
Expr::Op(op, operands) => {
let args: Vec<String> = operands.iter().map(|e| self.expr(e)).collect();
let fold = |symbol: &str| format!("({})", args.join(&format!(" {symbol} ")));
Expand Down Expand Up @@ -1019,6 +1028,24 @@ impl Generator<'_> {
}
}

/// The program that settles a timed testbench under xezim. Program code runs
/// in the reactive region set, which the scheduler reaches only once the
/// active region set is empty, NBA updates and the events they cause included
/// (IEEE 1800-2023 4.5, 24.3.1). The testbench's request is a design event,
/// so the acknowledgement follows the design's whole reaction to the stimulus
/// before it; a bare `#0` would resume in the reactive set before the design
/// reacts. The program starts in the reactive region too, possibly after the
/// first request, so it compares the counts instead of waiting first.
const XEZIM_SETTLER: &str = r#"`ifdef CELOX_SUITE_XEZIM
program celox_suite_settler (input int request, output int ack);
initial forever begin
if (ack == request) @(request);
ack = request;
end
endprogram
`endif
"#;

/// Generate the testbench for `case`. Every event the script ticks must be an
/// input port listed in `design.edges`.
pub fn testbench(case: &ScriptCase, design: &DesignInfo) -> Result<String, Unsupported> {
Expand Down Expand Up @@ -1079,19 +1106,29 @@ pub fn testbench(case: &ScriptCase, design: &DesignInfo) -> Result<String, Unsup
let _ = writeln!(out, "// Generated from {} by celox-test-suite.", case.name);
// Script values are deliberately wider than the signals they meet.
let _ = writeln!(out, "/* verilator lint_off WIDTH */");
if timed {
out.push_str(XEZIM_SETTLER);
}
let _ = writeln!(out, "module {TESTBENCH_TOP};");
if timed {
let _ = writeln!(out, " timeunit 1ps;");
let _ = writeln!(out, " timeprecision 1ps;");
}
// A two-state run starts every input at zero. The Icarus harness zeroes
// storage and Verilator starts it at zero; xezim does neither for these.
for port in &design.inputs {
let range = port
.array
.map(|bounds| format!(" [{}:{}]", bounds.left, bounds.right))
.unwrap_or_default();
let zero = match (case.four_state, port.array) {
(true, _) => "",
(false, None) => "\n`ifdef CELOX_SUITE_XEZIM\n = '0\n`endif\n ",
(false, Some(_)) => "\n`ifdef CELOX_SUITE_XEZIM\n = '{default: '0}\n`endif\n ",
};
let _ = writeln!(
out,
" logic [{}:0] i_{}{range};",
" logic [{}:0] i_{}{range}{zero};",
port.width.max(1) - 1,
port.name
);
Expand Down Expand Up @@ -1156,6 +1193,19 @@ pub fn testbench(case: &ScriptCase, design: &DesignInfo) -> Result<String, Unsup
for (int i = 0; i < {width}; i++) xmask[i] = (v[i] === 1'bx) || (v[i] === 1'bz);
endfunction

// A two-state read. Icarus and Verilator hold no unknown bits in a
// two-state run, but xezim starts some variables at X: reading one fails
// the run rather than letting comparisons and conditions decide on X.
function automatic logic signed [{w}:0] suite_read(input logic signed [{w}:0] v, input string what);
`ifdef CELOX_SUITE_XEZIM
if ($isunknown(v)) begin
$display("@suite assert %s with unknown bits in a two-state run", what);
$fatal(1, "%s with unknown bits", what);
end
`endif
return v;
endfunction

function automatic logic signed [{w}:0] bitlen(input logic signed [{w}:0] v);
bitlen = 0;
for (int i = 0; i < {width}; i++) if (v[i]) bitlen = i + 1;
Expand Down Expand Up @@ -1191,17 +1241,27 @@ pub fn testbench(case: &ScriptCase, design: &DesignInfo) -> Result<String, Unsup
// Settling waits until the scheduler has run everything due at the
// current time, without advancing it: Icarus resumes from a
// read/write synchronization callback, Verilator from a clocking
// event sampled in the observed region.
// event sampled in the observed region, and xezim from the
// acknowledgement of `XEZIM_SETTLER`.
out = out.replace(
" task automatic settle_now;\n #1;\n settled = 1;\n endtask",
r#" bit suite_progress = 0;
r#"`ifdef CELOX_SUITE_XEZIM
int suite_request = 0;
int suite_ack;
celox_suite_settler suite_settler (suite_request, suite_ack);
`else
bit suite_progress = 0;
`ifndef CELOX_SUITE_ICARUS
clocking suite_settled @(suite_progress);
input #0 progress = suite_progress;
endclocking
`endif
`endif
task automatic settle_now;
`ifdef CELOX_SUITE_ICARUS
`ifdef CELOX_SUITE_XEZIM
suite_request++;
while (suite_ack != suite_request) @(suite_ack);
`elsif CELOX_SUITE_ICARUS
suite_progress = 0;
$celox_suite_settle(suite_progress);
wait (suite_progress);
Expand Down Expand Up @@ -1325,7 +1385,7 @@ mod tests {
assert!(text.contains("Top dut (.clk(i_clk), .a(i_a), .o());"));
assert!(text.contains("i_a = t1;"));
assert!(text.contains("repeat (128'sh2) begin"));
assert!(text.contains("actual = $signed(128'({dut.o}));"));
assert!(text.contains("actual = suite_read($signed(128'({dut.o})), \"g::t reads o\");"));
assert!(text.contains("@suite assert g::t at"));
assert!(text.contains("$finish;"));
}
Expand Down Expand Up @@ -1380,6 +1440,32 @@ mod tests {
assert!(text.contains("@suite output 80ff00"));
}

#[test]
fn xezim_starts_two_state_inputs_at_zero_and_settles_timed_cases_in_a_program() {
let untimed = testbench(&case("(tick clk)"), &design()).unwrap();
assert!(
untimed
.contains(" logic [7:0] i_a\n`ifdef CELOX_SUITE_XEZIM\n = '0\n`endif\n ;\n")
);
assert!(!untimed.contains("program celox_suite_settler"));
let four_state = testbench(&case("(four_state) (tick clk)"), &design()).unwrap();
assert!(four_state.contains(" logic [7:0] i_a;\n"));
// Only a two-state read rejects unknown bits, and only under xezim.
let read = testbench(&case("(assert_eq o 1)"), &design()).unwrap();
assert!(read.contains("suite_read($signed(128'({dut.o})), \"g::t reads o\")"));
assert!(read.contains(
"`ifdef CELOX_SUITE_XEZIM\n if ($isunknown(v)) begin\n $display(\"@suite assert %s with unknown bits in a two-state run\", what);"
));
let read = testbench(&case("(four_state) (assert_eq o 1)"), &design()).unwrap();
assert!(read.contains("actual = $signed(128'({dut.o}));"));
let timed = testbench(&case("(run_until 0) (assert_eq o 1)"), &design()).unwrap();
assert!(timed.contains("program celox_suite_settler (input int request, output int ack);"));
assert!(timed.contains("celox_suite_settler suite_settler (suite_request, suite_ack);"));
assert!(timed.contains(
" while (suite_ack != suite_request) @(suite_ack);\n`elsif CELOX_SUITE_ICARUS"
));
}

#[test]
fn rejects_unknown_events() {
assert!(testbench(&case("(tick rst)"), &design()).is_err());
Expand Down
Loading
Loading