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
4 changes: 4 additions & 0 deletions .config/nextest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ fail-fast = false
slow-timeout = { period = "60s", terminate-after = 10 }
failure-output = "immediate-final"

[profile.ci.junit]
path = "junit.xml"
store-success-output = false

[[profile.ci.overrides]]
# Deep per-bit graphs consume substantial compiler memory and CPU. Reserve the
# pool so these regressions retain the same timeout without competing builds.
Expand Down
36 changes: 35 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ jobs:
needs: changes
if: ${{ !cancelled() && (needs.changes.result != 'success' || needs.changes.outputs.rust == 'true') }}
runs-on: ubuntu-latest
env:
CELOX_CI_REPORT_DIR: work/ci-reports/rust
HAS_MERGIFY_TOKEN: ${{ secrets.MERGIFY_TOKEN != '' }}
steps:
- uses: actions/checkout@v7
with:
Expand All @@ -220,8 +223,12 @@ jobs:

- uses: Swatinem/rust-cache@v2
with:
key: vtest-v1
save-if: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}

- name: Initialize Rust test reports
run: node scripts/ci-rust-reports.mjs reset

- uses: actions/setup-python@v7
if: needs.changes.outputs.rust_vpi_e2e != 'false'
with:
Expand All @@ -236,6 +243,10 @@ jobs:
with:
tool: cargo-nextest@0.9.144

- name: Build the optimized vtest executor
if: needs.changes.outputs.rust_full != 'false' || contains(format(' {0} ', needs.changes.outputs.rust_packages), ' celox ')
run: node scripts/run-vtest.mjs --prepare-ci

# Enable the frontend and suite features together so common integration
# tests run once, rather than once per Cargo feature combination.
# nextest schedules tests from all binaries on one pool; `cargo test`
Expand All @@ -244,19 +255,42 @@ jobs:
# (scripts/ci-rust-scope.mjs); merge groups and the daily run keep the
# Celox workspace. lydite-checks.yml owns Lydite tests at its own cadence.
- name: Run workspace tests with CI features
id: workspace-tests
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
--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
id: scoped-tests
if: needs.changes.outputs.rust_full == 'false' && needs.changes.outputs.rust_packages != ''
env:
BUILDS: ${{ needs.changes.outputs.rust_builds }}
FILTER: ${{ needs.changes.outputs.rust_filter }}
run: |
node scripts/run-ci-rust-scope.mjs test

- name: Collect Rust test reports
if: success() || failure()
run: node scripts/ci-rust-reports.mjs collect

- name: Retain Rust test reports
if: (success() || failure()) && hashFiles('work/ci-reports/rust/*.xml') != ''
uses: actions/upload-artifact@v7
with:
name: rust-test-results
path: work/ci-reports/rust/*.xml
retention-days: 14

- name: Upload Rust test results to Mergify
if: (success() || failure()) && env.HAS_MERGIFY_TOKEN == 'true' && hashFiles('work/ci-reports/rust/*.xml') != ''
uses: mergifyio/gha-mergify-ci@392d123d84a27960993927aec1f2cbb059fb95c1 # v27
with:
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 }}

# nextest does not run documentation tests.
- name: Run workspace documentation tests with CI features
if: needs.changes.outputs.rust_full != 'false'
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/rust-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
- ".github/actions/setup-rust/**"
- ".github/workflows/rust-cache.yml"
- ".github/workflows/ci.yml"
- "scripts/run-vtest.mjs"
workflow_dispatch:

permissions:
Expand All @@ -39,14 +40,19 @@ jobs:
- uses: ./.github/actions/setup-rust
- uses: Swatinem/rust-cache@v2
id: cache
with:
key: vtest-v1
- name: Install cargo-nextest
if: steps.cache.outputs.cache-hit != 'true'
uses: taiki-e/install-action@v2
with:
tool: cargo-nextest@0.9.144
- name: Build the optimized vtest executor to populate dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: node scripts/run-vtest.mjs --prepare-ci
- name: Build test targets to populate dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: >-
cargo nextest list --locked --workspace --message-format json
--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
> /dev/null
47 changes: 47 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,53 @@ Use the actual affected case or group as the filter. For SystemVerilog cases,
use the `verify-sv-verilator` and `verify-sv-icarus` binaries. Missing tools,
empty selections, compilation failures, and simulator errors are not passes.

For repeated local vtest runs, use the optimized shared executor:

```sh
node scripts/run-vtest.mjs --test counter
node scripts/run-vtest.mjs --test systemverilog -E 'test(operators::)'
```

This builds `vtest-exec` with the `vtest` Cargo profile (`opt-level = 1`,
development assertions and overflow checks enabled), then runs the existing
Celox test registrations with nextest. Both builds enable `systemverilog` and
`celox-test-suite/runtime-cases`. Cases execute in the shared binary, while
Rust API tests execute normally. Existing test names, filters, backend omissions,
ignored cases and nextest's parallel scheduling/timeouts are preserved. Additional
arguments are passed to `cargo nextest run`; use `--run-ignored all` to include
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.

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
as the `rust-test-results` artifact for 14 days, and uploads it to Mergify CI
Insights when the repository's `MERGIFY_TOKEN` secret is available. The secret
must be a Mergify application key with `ci` scope, and CI Insights must be enabled
for the repository. Tests keep their normal failure status; reporting does not
enable retries or quarantine. Forks without the secret still run tests and retain
the artifact. `cargo test`/doctest invocations are not part of this nextest report.

For debugging a single case after building, the executor also accepts
`<veryl|sv> <group::case> <backend>` directly, for example:

```sh
target/vtest/examples/vtest-exec veryl counter::test_counter_n4_basic native
```

Direct invocations do not apply registration-level ignores. `CELOX_VTEST_ROOT`
can point to an alternative corpus root containing `veryl/cases` and `sv/cases`;
otherwise the executor uses the suite's source directory from its build checkout.
The script sets that root and `CELOX_VTEST_RUNNER` for its test invocation only.

External results are reused locally by default, including between worktrees,
when the case, verifier and tool fingerprints match. New/changed cases and
prior failures run again; `--fresh` forces execution. A Celox implementation
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ incremental = true
[profile.bench]
debug = true

# Optimize the shared vtest executor while keeping development checks enabled.
# External dependencies retain the dev profile's package-specific optimization.
[profile.vtest]
inherits = "dev"
opt-level = 1

# Profile for wasm-pack builds. LTO is disabled to avoid a known issue
# where proc-macro dependencies (syn) get incorrectly compiled for the
# wasm32 target under full LTO.
Expand Down
5 changes: 5 additions & 0 deletions crates/celox-test-suite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ readme = "README.md"

[features]
default = []
# Load the corpus from disk so editing a case does not rebuild Rust runners.
runtime-cases = []
# Emit the Veryl cases to SystemVerilog.
emit = ["dep:veryl-analyzer", "dep:veryl-emitter", "dep:veryl-parser", "dep:veryl-metadata"]
# The external-simulator runners shared by both suites. Port shapes of the
Expand Down Expand Up @@ -62,5 +64,8 @@ veryl-std.workspace = true
serde_json = { workspace = true, optional = true }
sha2 = { version = "0.11", optional = true }

[dev-dependencies]
tempfile.workspace = true

[lints]
workspace = true
5 changes: 4 additions & 1 deletion crates/celox-test-suite/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Fingerprint the compiled verifier independently of the embedded case corpus.
// Hashing the executable itself would invalidate every case after adding one.
#[cfg(not(feature = "external"))]
fn main() {}
fn main() {
// Do not let Cargo's default package-wide scan track runtime-only cases.
println!("cargo:rerun-if-changed=build.rs");
}

#[cfg(feature = "external")]
fn main() {
Expand Down
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 @@ -2,6 +2,8 @@
#![forbid(unsafe_code)]

mod backend;
#[cfg(feature = "runtime-cases")]
mod runtime_cases;
mod scalar;
pub mod script;
pub mod sv;
Expand Down
101 changes: 101 additions & 0 deletions crates/celox-test-suite/src/runtime_cases.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
//! Runtime corpus loading for the development executor.

use crate::{StdResolver, TestCase};
use std::path::Path;

#[allow(
clippy::disallowed_methods,
reason = "test corpus configuration boundary"
)]
pub(crate) fn load(language: &str, resolver: StdResolver) -> Vec<&'static TestCase> {
let root = std::env::var_os("CELOX_VTEST_ROOT")
.map(std::path::PathBuf::from)
.unwrap_or_else(|| Path::new(env!("CARGO_MANIFEST_DIR")).join("src"));
load_directory(&root.join(language).join("cases"), resolver)
}

fn load_directory(directory: &Path, resolver: StdResolver) -> Vec<&'static TestCase> {
let mut paths = std::fs::read_dir(directory)
.unwrap_or_else(|error| panic!("read {}: {error}", directory.display()))
.map(|entry| entry.expect("read corpus entry").path())
.filter(|path| {
path.extension()
.is_some_and(|extension| extension == "vtest")
})
.collect::<Vec<_>>();
paths.sort();
assert!(
!paths.is_empty(),
"no .vtest files in {}",
directory.display()
);
let mut names = std::collections::BTreeSet::new();
paths
.into_iter()
.flat_map(|path| {
let text = std::fs::read_to_string(&path)
.unwrap_or_else(|error| panic!("read {}: {error}", path.display()));
crate::load_group(&path.to_string_lossy(), &text, resolver)
})
.inspect(|case| {
assert!(
names.insert(case.name),
"duplicate vtest case: {}",
case.name
);
})
.collect()
}

#[cfg(test)]
mod tests {
use super::*;

fn case(group: &str, source: &str) -> String {
format!(
"(group {group} (category operators)) (case t (source \"top.sv\" \"{source}\") (top Top))"
)
}

#[test]
fn discovers_files_in_order_and_reads_edited_sources() {
let directory = tempfile::tempdir().unwrap();
std::fs::write(directory.path().join("b.vtest"), case("b", "before")).unwrap();
std::fs::write(directory.path().join("a.vtest"), case("a", "a")).unwrap();
std::fs::write(directory.path().join("ignored.txt"), "not a vtest").unwrap();
let cases = load_directory(directory.path(), crate::no_std_library);
assert_eq!(
cases.iter().map(|case| case.name).collect::<Vec<_>>(),
["a::t", "b::t"]
);
assert_eq!(cases[1].design().sources[0].text, "before");
std::fs::write(directory.path().join("b.vtest"), case("b", "after")).unwrap();
let cases = load_directory(directory.path(), crate::no_std_library);
assert_eq!(cases[1].design().sources[0].text, "after");
}

#[test]
#[should_panic(expected = "duplicate vtest case: a::t")]
fn duplicate_names_are_errors() {
let directory = tempfile::tempdir().unwrap();
for file in ["a.vtest", "b.vtest"] {
std::fs::write(directory.path().join(file), case("a", "")).unwrap();
}
load_directory(directory.path(), crate::no_std_library);
}

#[test]
#[should_panic(expected = "no .vtest files")]
fn empty_corpus_is_an_error() {
let directory = tempfile::tempdir().unwrap();
load_directory(directory.path(), crate::no_std_library);
}

#[test]
#[should_panic(expected = "broken.vtest:")]
fn malformed_cases_report_the_file() {
let directory = tempfile::tempdir().unwrap();
std::fs::write(directory.path().join("broken.vtest"), "(case").unwrap();
load_directory(directory.path(), crate::no_std_library);
}
}
11 changes: 9 additions & 2 deletions crates/celox-test-suite/src/sv/mod.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
//! The SystemVerilog suite: cases whose designs are SystemVerilog source.

#[cfg(not(feature = "runtime-cases"))]
mod cases;

#[cfg(feature = "external")]
pub mod verification;

use crate::TestCase;

/// All cases in deterministic declaration order. A case's design is
/// SystemVerilog source; build it with your SystemVerilog frontend.
/// All cases in deterministic order (file-name order with `runtime-cases`,
/// otherwise catalogue declaration order). A case's design is SystemVerilog
/// source; build it with your SystemVerilog frontend.
pub fn cases() -> impl Iterator<Item = &'static TestCase> {
static CASES: std::sync::OnceLock<Vec<&'static TestCase>> = std::sync::OnceLock::new();
CASES
.get_or_init(|| {
#[cfg(feature = "runtime-cases")]
{
crate::runtime_cases::load("sv", crate::no_std_library)
}
#[cfg(not(feature = "runtime-cases"))]
cases::GROUPS
.iter()
.flat_map(|group| crate::load_group(group.file, group.text, crate::no_std_library))
Expand Down
9 changes: 8 additions & 1 deletion crates/celox-test-suite/src/veryl/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! The Veryl suite: cases whose designs are Veryl source.

#[cfg(not(feature = "runtime-cases"))]
mod cases;

#[cfg(feature = "emit")]
Expand Down Expand Up @@ -69,12 +70,18 @@ fn std_source(path: &str) -> String {
.unwrap_or_else(|err| panic!("failed to read {}: {err}", src.src.display()))
}

/// All cases in deterministic declaration order. Filter by category or name in the
/// All cases in deterministic order (file-name order with `runtime-cases`,
/// otherwise catalogue declaration order). Filter by category or name in the
/// host test runner; nothing is silently skipped by the suite itself.
pub fn cases() -> impl Iterator<Item = &'static TestCase> {
static CASES: std::sync::OnceLock<Vec<&'static TestCase>> = std::sync::OnceLock::new();
CASES
.get_or_init(|| {
#[cfg(feature = "runtime-cases")]
{
crate::runtime_cases::load("veryl", std_source)
}
#[cfg(not(feature = "runtime-cases"))]
cases::GROUPS
.iter()
.flat_map(|group| crate::load_group(group.file, group.text, std_source))
Expand Down
4 changes: 4 additions & 0 deletions crates/celox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,9 @@ name = "frontend_binary"
path = "examples/frontend_binary.rs"
required-features = ["host-runtime"]

[[example]]
name = "vtest-exec"
required-features = ["host-runtime"]

[lints]
workspace = true
Loading
Loading