From 15351aea5f3fb56bb44df643d83070ef391257db Mon Sep 17 00:00:00 2001 From: tignear Date: Wed, 21 Oct 2026 08:29:54 +0900 Subject: [PATCH] fix(cli): reject empty cocotb test selections Parse cocotb JUnit results with Python's standard library and require at least one executed test. Report failures and errors with a nonzero process status, including statuses that previously wrapped to zero on Unix. Accept successful runs that also contain skipped tests. Validation: checked the embedded result parser against seven XML fixtures, including empty/all-skipped, mixed, failure/error, 256 failures and malformed results; opt-in cocotb end-to-end regression tests include an unmatched filter and verify that the generated executable rejects it; formatting and affected-crate Clippy. Change-Id: I93316d15fc83f37bc786288376446d3ae825c1ed --- crates/celox-vpi/src/bin/celox.rs | 14 +++++++++++++- crates/celox-vpi/tests/cocotb_e2e.rs | 25 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/crates/celox-vpi/src/bin/celox.rs b/crates/celox-vpi/src/bin/celox.rs index 99295fba55a..46d2a3882eb 100644 --- a/crates/celox-vpi/src/bin/celox.rs +++ b/crates/celox-vpi/src/bin/celox.rs @@ -571,7 +571,19 @@ fn discover_vpi(python: &Path) -> Result { fn check_results(python: &Path, results_file: &Path) -> Result<(), String> { let output = Command::new(python) - .args([OsStr::new("-m"), OsStr::new("cocotb_tools.check_results")]) + .args(["-c", r#" +import sys +from xml.etree import ElementTree + +cases = list(ElementTree.parse(sys.argv[1]).getroot().iter("testcase")) +executed = [case for case in cases if case.find("skipped") is None] +failed = [case for case in executed if case.find("failure") is not None or case.find("error") is not None] +if not executed: + sys.exit("no cocotb tests were executed (check the test filter and skip settings)") +if failed: + names = ", ".join(case.get("name", "") for case in failed[:8]) + sys.exit(f"{len(failed)} cocotb test(s) failed: {names}") +"#]) .arg(results_file) .output() .map_err(|error| format!("failed to check cocotb results: {error}"))?; diff --git a/crates/celox-vpi/tests/cocotb_e2e.rs b/crates/celox-vpi/tests/cocotb_e2e.rs index ba7ef9a8ff6..d2049d78e88 100644 --- a/crates/celox-vpi/tests/cocotb_e2e.rs +++ b/crates/celox-vpi/tests/cocotb_e2e.rs @@ -155,6 +155,31 @@ fn check_cocotb_native_design(source: &[&str], module: &str, filter: &str) { assert!(results.is_file()); + let unmatched = Command::new(&executable) + .args([ + "--test-module", + module, + "--test-filter", + "^no_such_cocotb_test$", + "--python", + &python, + ]) + .arg("--results-file") + .arg(&results) + .current_dir(&fixture) + .env("PYTHONPATH", &python_path) + .output() + .unwrap(); + assert!( + !unmatched.status.success(), + "an empty test selection was reported as successful" + ); + assert!( + String::from_utf8_lossy(&unmatched.stderr).contains("no cocotb tests were executed"), + "{}", + String::from_utf8_lossy(&unmatched.stderr) + ); + let failed_runtime = Command::new(&executable) .args(["--test-module", "missing_test_module", "--python", &python]) .arg("--results-file")