diff --git a/conformance/sv-tests/README.md b/conformance/sv-tests/README.md index f63ce204b07..4f0509b2d9c 100644 --- a/conformance/sv-tests/README.md +++ b/conformance/sv-tests/README.md @@ -10,10 +10,14 @@ Each test has separate `2state` and `4state` rows (`test`, `state_mode`, `result The official runner owns metadata parsing, compatible-runner filtering, mode priority, library injection, timeouts, expected failures and simulation `:assert:` evaluation. The adapter declares only the driver’s supported -`elaboration` and `simulation` modes. It forwards source files, include +`parsing`, `elaboration` and `simulation` modes. It forwards source files, include directories, defines, an optional explicit top and the selected state mode to -the Rust driver. Sources without a module still undergo preprocessing and -parsing; root detection then reports the actual no-root diagnostic. The current +the Rust driver. Parsing mode stops after preprocessing and syntax parsing; it +does not build semantic module metadata, select a root, elaborate or simulate. +The official mode priority still chooses elaboration for default cases and for +cases that permit both parsing and elaboration. In elaboration and simulation +modes, sources without a module still undergo preprocessing and parsing; root +detection then reports the actual no-root diagnostic. The current compiler and simulator require a module root, so the driver reports a failure for rootless unit, package and interface inputs. The official runner still decides the case verdict, including expected failures. There is no `no_top` classification diff --git a/conformance/sv-tests/expected.tsv b/conformance/sv-tests/expected.tsv index cdd5641e8be..36d591b5987 100644 --- a/conformance/sv-tests/expected.tsv +++ b/conformance/sv-tests/expected.tsv @@ -671,14 +671,14 @@ chapter-18/18.9--controlling-constraints-with-constraint_mode_1.sv 2state pass chapter-18/18.9--controlling-constraints-with-constraint_mode_1.sv 4state pass chapter-18/18.9--controlling-constraints-with-constraint_mode_2.sv 2state pass chapter-18/18.9--controlling-constraints-with-constraint_mode_2.sv 4state pass -chapter-20/20.10--error.sv 2state skip -chapter-20/20.10--error.sv 4state skip -chapter-20/20.10--fatal.sv 2state skip -chapter-20/20.10--fatal.sv 4state skip +chapter-20/20.10--error.sv 2state pass +chapter-20/20.10--error.sv 4state pass +chapter-20/20.10--fatal.sv 2state pass +chapter-20/20.10--fatal.sv 4state pass chapter-20/20.10--info.sv 2state pass chapter-20/20.10--info.sv 4state pass -chapter-20/20.10--warning.sv 2state skip -chapter-20/20.10--warning.sv 4state skip +chapter-20/20.10--warning.sv 2state pass +chapter-20/20.10--warning.sv 4state pass chapter-20/20.14--coverage.sv 2state fail chapter-20/20.14--coverage.sv 4state fail chapter-20/20.15--dist_chi_square.sv 2state fail @@ -811,10 +811,10 @@ chapter-21/21.3--sscanf.sv 2state fail chapter-21/21.3--sscanf.sv 4state fail chapter-21/21.3--ungetc.sv 2state fail chapter-21/21.3--ungetc.sv 4state fail -chapter-21/21.4--readmemb.sv 2state skip -chapter-21/21.4--readmemb.sv 4state skip -chapter-21/21.4--readmemh.sv 2state skip -chapter-21/21.4--readmemh.sv 4state skip +chapter-21/21.4--readmemb.sv 2state pass +chapter-21/21.4--readmemb.sv 4state pass +chapter-21/21.4--readmemh.sv 2state pass +chapter-21/21.4--readmemh.sv 4state pass chapter-21/21.6--test.sv 2state fail chapter-21/21.6--test.sv 4state fail chapter-21/21.6--value.sv 2state fail @@ -853,24 +853,24 @@ chapter-22/22.12--line-illegal-4.sv 2state skip chapter-22/22.12--line-illegal-4.sv 4state skip chapter-22/22.12--line-illegal-5.sv 2state skip chapter-22/22.12--line-illegal-5.sv 4state skip -chapter-22/22.3--resetall_basic.sv 2state skip -chapter-22/22.3--resetall_basic.sv 4state skip -chapter-22/22.3--resetall_illegal.sv 2state skip -chapter-22/22.3--resetall_illegal.sv 4state skip -chapter-22/22.3--resetall_multiple.sv 2state skip -chapter-22/22.3--resetall_multiple.sv 4state skip -chapter-22/22.4--check_included_definitions.sv 2state skip -chapter-22/22.4--check_included_definitions.sv 4state skip -chapter-22/22.4--include_basic.sv 2state skip -chapter-22/22.4--include_basic.sv 4state skip -chapter-22/22.4--include_basic_rpath.sv 2state skip -chapter-22/22.4--include_basic_rpath.sv 4state skip -chapter-22/22.4--include_from_other_directory.sv 2state skip -chapter-22/22.4--include_from_other_directory.sv 4state skip -chapter-22/22.4--include_via_define.sv 2state skip -chapter-22/22.4--include_via_define.sv 4state skip -chapter-22/22.4--include_with_comment.sv 2state skip -chapter-22/22.4--include_with_comment.sv 4state skip +chapter-22/22.3--resetall_basic.sv 2state pass +chapter-22/22.3--resetall_basic.sv 4state pass +chapter-22/22.3--resetall_illegal.sv 2state pass +chapter-22/22.3--resetall_illegal.sv 4state pass +chapter-22/22.3--resetall_multiple.sv 2state pass +chapter-22/22.3--resetall_multiple.sv 4state pass +chapter-22/22.4--check_included_definitions.sv 2state pass +chapter-22/22.4--check_included_definitions.sv 4state pass +chapter-22/22.4--include_basic.sv 2state pass +chapter-22/22.4--include_basic.sv 4state pass +chapter-22/22.4--include_basic_rpath.sv 2state pass +chapter-22/22.4--include_basic_rpath.sv 4state pass +chapter-22/22.4--include_from_other_directory.sv 2state pass +chapter-22/22.4--include_from_other_directory.sv 4state pass +chapter-22/22.4--include_via_define.sv 2state pass +chapter-22/22.4--include_via_define.sv 4state pass +chapter-22/22.4--include_with_comment.sv 2state pass +chapter-22/22.4--include_with_comment.sv 4state pass chapter-22/22.5.1--define-expansion_1.sv 2state skip chapter-22/22.5.1--define-expansion_1.sv 4state skip chapter-22/22.5.1--define-expansion_10.sv 2state skip diff --git a/conformance/sv-tests/runners/celox.py b/conformance/sv-tests/runners/celox.py index 2e174a7b59d..8eff962dc17 100644 --- a/conformance/sv-tests/runners/celox.py +++ b/conformance/sv-tests/runners/celox.py @@ -14,7 +14,7 @@ def __init__(self): super().__init__( name="celox", executable=os.environ["CELOX_SV_TESTS_DRIVER"], - supported_features={"elaboration", "simulation"}, + supported_features={"parsing", "elaboration", "simulation"}, ) self.url = "https://github.com/celox-sim/celox" diff --git a/conformance/sv-tests/test_runner.py b/conformance/sv-tests/test_runner.py index 570a4d615a0..9a36b97b2b1 100644 --- a/conformance/sv-tests/test_runner.py +++ b/conformance/sv-tests/test_runner.py @@ -77,6 +77,7 @@ def case(self, metadata="", body="", mode="2state"): def test_official_metadata_defaults_priority_negative_and_assertions(self): self.assertEqual(self.case()["mode"], "elaboration") + self.assertEqual(self.case(":type: parsing elaboration\n")["mode"], "elaboration") self.assertEqual(self.case(":type: elaboration simulation\n", "// OUTPUT: :assert: 1 == 1")["result"], "pass") self.assertEqual(self.case(":type: simulation\n", "// OUTPUT: :assert: 1 == 2")["result"], "fail") row = self.case(":type: simulation\n:should_fail_because: invalid\n", "// EXIT: 1") @@ -85,7 +86,10 @@ def test_official_metadata_defaults_priority_negative_and_assertions(self): self.assertEqual(self.case(":should_fail_because: invalid\n", "// EXIT: 126")["result"], "fail") def test_official_skips_and_no_module_is_not_preemptively_skipped(self): - self.assertEqual(self.case(":type: parsing\n")["result"], "skip") + row = self.case(":type: parsing\n") + self.assertEqual((row["mode"], row["result"]), ("parsing", "pass")) + self.assertEqual(self.case(":type: parsing\n:should_fail_because: syntax\n", "// EXIT: 1")["result"], "pass") + self.assertEqual(self.case(":type: preprocessing\n")["result"], "skip") self.assertEqual(self.case(":compatible-runners: other\n")["result"], "skip") # The source has no module. Its diagnostic still reaches official judgement. row = self.case(body="// OUTPUT: no module diagnostic\n// EXIT: 1") diff --git a/crates/celox/examples/sv_tests.rs b/crates/celox/examples/sv_tests.rs index 8ef174de581..fe465e1cfa6 100644 --- a/crates/celox/examples/sv_tests.rs +++ b/crates/celox/examples/sv_tests.rs @@ -4,7 +4,7 @@ //! sv-tests. This process reports only compiler/simulator success or failure. //! //! ```text -//! sv_tests --mode elaboration|simulation --state-mode 2state|4state \ +//! sv_tests --mode parsing|elaboration|simulation --state-mode 2state|4state \ //! [--top NAME] [--define NAME[=VALUE]] [--include DIR] -- FILE... //! ``` @@ -15,6 +15,7 @@ use std::{collections::BTreeSet, env, path::PathBuf, process::ExitCode}; #[derive(Clone, Copy, Debug, PartialEq, Eq)] enum Mode { + Parsing, Elaboration, Simulation, } @@ -52,6 +53,7 @@ fn parse_options(args: &[String]) -> Result { match arg.as_str() { "--mode" if mode.is_none() => { mode = Some(match value.as_str() { + "parsing" => Mode::Parsing, "elaboration" => Mode::Elaboration, "simulation" => Mode::Simulation, _ => return Err(format!("unsupported mode: {value}")), @@ -147,6 +149,15 @@ fn run(options: &Options) -> Result<(), String> { .zip(&options.files) .map(|(text, path)| (text.as_str(), path.as_path())) .collect(); + // ParsedSource also builds semantic module metadata. Parsing-only cases + // must stop at the syntax tree, before that analysis or root selection. + if options.mode == Mode::Parsing { + for (text, path) in &sources { + celox_sv_analyzer::syntax::parse_source(text, path) + .map_err(|error| error.to_string())?; + } + return Ok(()); + } let parsed = sources .iter() .map(|(text, path)| celox_sv_analyzer::ParsedSource::parse(text, path)) @@ -154,6 +165,7 @@ fn run(options: &Options) -> Result<(), String> { .map_err(|error| error.to_string())?; let top = select_top(&parsed, options.top.as_deref())?; match options.mode { + Mode::Parsing => unreachable!("parsing returned before root selection"), Mode::Elaboration => celox::Simulator::from_sv_sources(sources, &top) .four_state(options.four_state) .build() @@ -225,7 +237,7 @@ fn main() -> ExitCode { Ok(options) => options, Err(error) => { eprintln!( - "{error}\nusage: sv_tests --mode elaboration|simulation --state-mode 2state|4state [--top NAME] [--define NAME[=VALUE]] [--include DIR] -- FILE..." + "{error}\nusage: sv_tests --mode parsing|elaboration|simulation --state-mode 2state|4state [--top NAME] [--define NAME[=VALUE]] [--include DIR] -- FILE..." ); return ExitCode::from(2); } @@ -278,7 +290,7 @@ mod tests { assert_eq!(o.includes, [PathBuf::from("headers")]); assert_eq!(o.files, [PathBuf::from("a.sv"), PathBuf::from("b.sv")]); for args in [ - vec!["--mode", "parsing", "--state-mode", "2state", "a.sv"], + vec!["--mode", "preprocessing", "--state-mode", "2state", "a.sv"], vec!["--mode", "elaboration", "--state-mode", "both", "a.sv"], vec![ "--mode", @@ -339,6 +351,45 @@ mod tests { } } + #[test] + fn parsing_stops_before_metadata_roots_elaboration_and_simulation() { + let dir = tempfile::tempdir().unwrap(); + for (name, code) in [ + ("unit.sv", "typedef logic [7:0] Byte;"), + ("package.sv", "package P; typedef logic Byte; endpackage"), + ("roots.sv", "module A; endmodule module B; endmodule"), + ("unresolved.sv", "module Top; Missing child(); endmodule"), + ("semantic.sv", "module Top(input MissingType x); endmodule"), + ("runtime.sv", "module Top; initial $fatal(1); endmodule"), + ] { + let path = fixture(dir.path(), name, code); + let mut options = fixture_options(vec![path], Mode::Parsing); + // Even an explicit nonexistent top is irrelevant to syntax parsing. + options.top = Some("Missing".into()); + run(&options).unwrap_or_else(|error| panic!("{name}: {error}")); + } + for code in [ + "module Top;", + "typedef logic [7:0]", + "`include \"missing.svh\"\n", + ] { + let path = fixture(dir.path(), "invalid.sv", code); + let options = fixture_options(vec![path], Mode::Parsing); + assert!( + run(&options) + .unwrap_err() + .to_lowercase() + .contains("parse error") + ); + } + assert_eq!( + options(&["--mode", "parsing", "--state-mode", "2state", "a.sv"]) + .unwrap() + .mode, + Mode::Parsing + ); + } + #[test] fn rejects_sources_without_a_module_root() { let dir = tempfile::tempdir().unwrap();