Files
lucisv/crates/vlog_refactor/tests/qa_warning_scope.rs
T
Guoliang ChenandClaude Mythos 5.2 532a64546c Round 8: semantic and refactor edge cases (#12, #31, #32, L-5/L-6/L-10)
DPI-export names are semantic references. verify_move reconstructs the
result independently and checks equation 3 per edit, with 16 attack tests.
Interface generate-block members are reachable through a port or virtual
interface; bind to a bare instance name is found; nested struct members
get their container key. Escaped identifiers join FileFacts::words
(FACTS_FORMAT 23); generate-scoped bind shorthand resolves. Scope reuses
index_order. Files topo #68-#70.

Co-Authored-By: Claude Mythos 5.2 <[email protected]>
2026-11-26 17:18:59 -08:00

574 lines
25 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Author: Guoliang Chen, a Senior Digital Design Engineer
//! QA attacks on TODO §65.1 rework 3 (`rename/scoped.rs`): a module member's
//! bare spelling in another file's macro argument, `` `define`` body or
//! unstructured assertion is no longer warned about. The danger is a HIDDEN
//! real use — text that expands into the declaring module's scope from
//! another file. `docs/features/generate-label-rename/README.md`, QA log.
use std::path::PathBuf;
use vlog_refactor::rename;
fn workspace(files: &[(&str, &str)]) -> Vec<(PathBuf, String)> {
files.iter().map(|(name, text)| (PathBuf::from("/rtl").join(name), text.to_string())).collect()
}
/// Rename the first `logic <name>` (or `<prefix>` then `name`) in `file`;
/// the rewritten texts and the warnings, or the refusal.
fn run(
files: &[(&str, &str)],
file: &str,
prefix: &str,
name: &str,
new: &str,
) -> Result<(Vec<String>, Vec<String>), String> {
let sources = workspace(files);
let text = files.iter().find(|(n, _)| *n == file).map(|(_, t)| *t).expect("file");
let at = (text.find(prefix).expect("prefix") + prefix.len()) as u32;
let at = at + text[at as usize..].find(name).expect("name") as u32;
let edit = rename(&sources, &PathBuf::from("/rtl").join(file), at, new)?;
let texts = files
.iter()
.map(|(n, t)| {
let mut out = String::new();
let mut cursor = 0usize;
for e in edit.edits_for(&PathBuf::from("/rtl").join(n)) {
out.push_str(&t[cursor..e.range.start as usize]);
out.push_str(&e.new_text);
cursor = e.range.end as usize;
}
out.push_str(&t[cursor..]);
out
})
.collect();
Ok((texts, edit.warnings))
}
/// Whether some warning mentions `file` at `line` (`file:line` or `file at
/// line(s) … line`).
fn said(warnings: &[String], file: &str, line: u32) -> bool {
warnings.iter().any(|w| {
w.contains(&format!("{file}:{line}"))
|| (w.contains(file) && w.contains(&format!(" {line}")))
})
}
const ASSERT_DEFS: &str = "`define ASSERT(n, e) n: assert property (@(posedge clk) e);\n";
/// The opentitan `*_assert.svh` shape: the module includes a fragment whose
/// assertions name the module's own signals bare.
#[test]
fn a_bare_use_in_an_included_fragments_macro_argument_is_said() {
let module = "module m (input logic clk);
logic state_q;
always_ff @(posedge clk) state_q <= ~state_q;
`include \"m_assert.svh\"
endmodule
";
let frag = " `ASSERT(StateKnown_A, !$isunknown(state_q))\n";
let files = [("defs.svh", ASSERT_DEFS), ("m.sv", module), ("m_assert.svh", frag)];
let (_, warnings) = run(&files, "m.sv", "logic ", "state_q", "state_r").expect("renames");
assert!(said(&warnings, "m_assert.svh", 1), "HIDDEN USE: {warnings:#?}");
}
/// The same fragment with the use in plain code, not a macro.
#[test]
fn a_bare_use_in_plain_included_code_is_renamed_or_said() {
let module = "module m (input logic clk, output logic o);
logic state_q;
`include \"m_body.svh\"
endmodule
";
let frag = " assign o = state_q;\n";
let files = [("m.sv", module), ("m_body.svh", frag)];
let (texts, warnings) = run(&files, "m.sv", "logic ", "state_q", "state_r").expect("renames");
// Lead's ruling on H4: said, not renamed (renaming inside included
// fragments is TODO §65.6).
assert_eq!(texts[1], frag, "the fragment is not edited");
assert!(said(&warnings, "m_body.svh", 1), "{warnings:#?}");
}
/// A header's `` `define`` whose body spells the net bare, invoked in the
/// declaring module: the expansion is a real use.
#[test]
fn a_bare_use_in_a_header_macro_body_invoked_in_the_module_is_said() {
let defs = "`define CHK assert property (@(posedge clk) state_q != 0);\n";
let module = "module m (input logic clk);
logic state_q;
always_ff @(posedge clk) state_q <= ~state_q;
`CHK
endmodule
";
let files = [("chk.svh", defs), ("m.sv", module)];
let (_, warnings) = run(&files, "m.sv", "logic ", "state_q", "state_r").expect("renames");
assert!(said(&warnings, "chk.svh", 1), "HIDDEN USE: {warnings:#?}");
}
/// A bind file's connection names the target's net bare inside a macro
/// argument — evaluated in the bound scope.
#[test]
fn a_bare_use_in_a_bind_connection_macro_argument_is_said() {
let defs = "`define Q(x) x\n";
let module = "module m (input logic clk);
logic state_q;
always_ff @(posedge clk) state_q <= ~state_q;
endmodule
";
let chk = "module chk (input logic s);
endmodule
";
let bind = "module m_bind;
bind m chk u_chk (.s(`Q(state_q)));
endmodule
";
let files = [("defs.svh", defs), ("m.sv", module), ("chk.sv", chk), ("m_bind.sv", bind)];
let (texts, warnings) = run(&files, "m.sv", "logic ", "state_q", "state_r").expect("renames");
assert!(texts[3].contains("state_r") || said(&warnings, "m_bind.sv", 2), "{warnings:#?}");
}
/// Same file, several scopes: a function, a generate block and a nested
/// module see the net; an inner declaration of the same name shadows it.
#[test]
fn inside_the_declaring_file_the_lookup_respects_scopes_and_shadowing() {
let module = "module m (input logic clk);
logic state_q;
function automatic logic f();
return `Q(state_q);
endfunction
if (1) begin : g
assign x = `Q(state_q);
end
if (1) begin : h
logic state_q;
assign y = `Q(state_q);
end
endmodule
module other;
logic state_q;
assign z = `Q(state_q);
endmodule
";
let files = [("defs.svh", "`define Q(x) x\n"), ("m.sv", module)];
let (_, warnings) = run(&files, "m.sv", "logic ", "state_q", "state_r").expect("renames");
assert!(said(&warnings, "m.sv", 4), "the function's use: {warnings:#?}");
assert!(said(&warnings, "m.sv", 7), "the generate block's use: {warnings:#?}");
assert!(!said(&warnings, "m.sv", 11), "shadowed by h's own state_q: {warnings:#?}");
assert!(!said(&warnings, "m.sv", 16), "the other module's own: {warnings:#?}");
}
/// Unstructured assertion text and `ifdef`-disabled text in the declaring
/// file.
#[test]
fn unparsed_assertion_and_ifdef_text_in_the_declaring_file_is_said() {
let module = "module m (input logic clk);
logic state_q;
always_ff @(posedge clk) state_q <= ~state_q;
a_weird: assert property (@(posedge clk) state_q |-> ##[1:$] $$$ state_q);
`ifdef NEVER
`Q(state_q)
`endif
endmodule
";
let files = [("defs.svh", "`define Q(x) x\n"), ("m.sv", module)];
let (texts, warnings) = run(&files, "m.sv", "logic ", "state_q", "state_r").expect("renames");
assert!(texts[1].contains("$$$ state_r") || said(&warnings, "m.sv", 4), "{warnings:#?}");
assert!(said(&warnings, "m.sv", 6), "the ifdef'd macro argument: {warnings:#?}");
}
/// Rework 2, R1: three files named `probe.sv` at different depths, each with
/// an unresolved path — each warning must name a findable file. (Since TODO
/// §65.4 a root some file declares resolves, so the set declares no `tb`.)
#[test]
fn recheck_three_same_named_files_are_each_named_by_their_path() {
let dut = "module dut_a;\n for (genvar i = 0; i < 2; i++) begin : g_sw\n logic q;\n end\nendmodule\n";
let probe = "module PROBE (output logic o);\n assign o = tb.dut.g_sw[0].q;\nendmodule\n";
let (p1, p2, p3) =
(probe.replace("PROBE", "p1"), probe.replace("PROBE", "p2"), probe.replace("PROBE", "p3"));
let files = [
("dut_a.sv", dut),
("probe.sv", p1.as_str()),
("x/probe.sv", p2.as_str()),
("x/y/z/probe.sv", p3.as_str()),
];
let (_, warnings) = run(&files, "dut_a.sv", "begin : ", "g_sw", "g_hw").expect("renames");
let paths: Vec<&String> = warnings.iter().filter(|w| w.contains("hierarchical path")).collect();
assert_eq!(paths.len(), 3, "{warnings:#?}");
for w in &paths {
let named = w.split(':').next().unwrap_or("");
assert!(named.ends_with("probe.sv") && named.contains('/'), "unfindable: {w}");
}
let mut named: Vec<&str> = paths.iter().map(|w| w.split(':').next().unwrap_or("")).collect();
named.dedup();
assert_eq!(named.len(), 3, "three distinct names: {warnings:#?}");
}
/// Rework 2, R3: three levels of same-label arms.
#[test]
fn recheck_three_level_same_label_arms_are_all_warned_about() {
let text = "module t (output logic o);
if (1) begin : a
if (1) begin : b
if (1) begin : c
logic x;
end
end
end else begin : a
if (1) begin : b
if (1) begin : c
logic x;
end
end else begin : b
if (1) begin : c
logic x;
end
end
end
assign o = a.b.c.x;
endmodule
";
let (_, warnings) = run(&[("t.sv", text)], "t.sv", "logic ", "x", "y").expect("renames");
for line in [11, 15] {
assert!(
warnings.iter().any(|w| w.contains(&format!("t.sv:{line}"))),
"{line}: {warnings:#?}"
);
}
// …and from the deepest-else arm.
let (_, warnings) = run(
&[("t.sv", text)],
"t.sv",
"end else begin : b\n if (1) begin : c\n logic ",
"x",
"y",
)
.expect("renames");
for line in [5, 11] {
assert!(
warnings.iter().any(|w| w.contains(&format!("t.sv:{line}"))),
"{line}: {warnings:#?}"
);
}
}
/// Rework 2, R2: an escaped net and an escaped label behind an unresolved root
/// — no file declares `tbe` — and, since TODO §65.4, renamed behind one that
/// is declared.
#[test]
fn recheck_escaped_net_and_label_paths_are_named() {
let dut = "module dut_e;\n logic \\n$q ;\n if (1) begin : \\g$sw \n logic q;\n end\nendmodule\n";
let tb = "module tbe;\n dut_e dut ();\nendmodule\n";
let probe = "module pe (output logic o, output logic p);\n assign o = tbe.dut.\\g$sw .q;\n assign p = tbe.dut.\\n$q ;\nendmodule\n";
let files = [("dut_e.sv", dut), ("pe.sv", probe)];
let (_, warnings) = run(&files, "dut_e.sv", "begin : ", "\\g$sw", "g_hw").expect("label");
assert!(warnings.iter().any(|w| w.starts_with("pe.sv:2:")), "{warnings:#?}");
let (_, warnings) = run(&files, "dut_e.sv", "logic ", "\\n$q", "n_q").expect("net");
assert!(warnings.iter().any(|w| w.starts_with("pe.sv:3:")), "{warnings:#?}");
let files = [("dut_e.sv", dut), ("tbe.sv", tb), ("pe.sv", probe)];
let (texts, warnings) = run(&files, "dut_e.sv", "logic ", "\\n$q", "n_q").expect("net");
assert_eq!(texts[2], probe.replace("\\n$q", "n_q"), "{warnings:#?}");
}
// ---------------------------------------------------------------------------
// Rework 4 (home set) attacks, 2026-09-30
// ---------------------------------------------------------------------------
const Q_DEFS: &str = "`define Q(x) x\n";
/// A module and a fragment it includes by `spelled`, the fragment naming
/// `state_q` bare in a macro argument; whether renaming `m.state_q` says so.
fn fragment_said(spelled: &str, frag_path: &str, extra: &[(&str, &str)]) -> (bool, Vec<String>) {
let module = format!(
"module m (input logic clk);\n logic state_q;\n always_ff @(posedge clk) state_q <= ~state_q;\n{spelled}\nendmodule\n"
);
let frag = " initial $display(\"%b\", `Q(state_q));\n";
let mut files: Vec<(&str, &str)> =
vec![("defs.svh", Q_DEFS), ("rtl/m.sv", &module), (frag_path, frag)];
files.extend_from_slice(extra);
let (_, warnings) = run(&files, "rtl/m.sv", "logic ", "state_q", "state_r").expect("renames");
let base = frag_path.rsplit('/').next().unwrap_or(frag_path);
(warnings.iter().any(|w| w.contains(base) && w.contains("macro invocation")), warnings)
}
#[test]
fn rework4_include_spellings_all_reach_the_fragment() {
for (spelled, path) in [
("`include \"../inc/m_assert.svh\"", "inc/m_assert.svh"),
("`include \"m_assert.svh\"", "deep/inc/dir/m_assert.svh"),
("`ifdef FOO\n`include \"m_assert.svh\"\n`endif", "rtl/m_assert.svh"),
("`include \"m_assert.svh\" // the assertions", "rtl/m_assert.svh"),
("`include \"m_assert.svh\"\r", "rtl/m_assert.svh"),
] {
let (ok, warnings) = fragment_said(spelled, path, &[]);
assert!(ok, "HIDDEN USE via {spelled:?} → {path}: {warnings:#?}");
}
}
#[test]
fn rework4_a_base_name_matching_two_files_takes_both() {
let other = ("other/m_assert.svh", " initial $display(\"%b\", `Q(state_q));\n");
let (ok, warnings) = fragment_said("`include \"m_assert.svh\"", "inc/m_assert.svh", &[other]);
assert!(ok, "{warnings:#?}");
let both =
warnings.iter().filter(|w| w.contains("m_assert.svh") && w.contains("macro")).count();
assert_eq!(both, 2, "both candidates are home: {warnings:#?}");
}
#[test]
fn rework4_three_level_includes_and_a_cycle_terminate_and_reach() {
let a = ("inc/a.svh", "`include \"b.svh\"\n");
let b = ("inc/b.svh", "`include \"m_assert.svh\"\n`include \"a.svh\"\n");
let (ok, warnings) = fragment_said("`include \"a.svh\"", "inc/m_assert.svh", &[a, b]);
assert!(ok, "three levels, with a cycle a → b → a: {warnings:#?}");
}
/// `` `include `FRAG `` — an include whose file name a macro builds.
#[test]
fn rework4_an_include_built_by_a_macro_is_followed_or_said() {
let defs = ("inc/paths.svh", "`define FRAG \"m_assert.svh\"\n");
let (ok, warnings) =
fragment_said("`include \"paths.svh\"\n`include `FRAG", "inc/m_assert.svh", &[defs]);
assert!(ok, "HIDDEN USE via `include `FRAG: {warnings:#?}");
}
/// The declaration sits in a fragment included by two modules: both
/// includers are home, and a bare use in either's macro argument is said.
#[test]
fn rework4_a_declaration_in_a_fragment_shared_by_two_modules() {
let decl = " logic shared_q;\n";
let m1 =
"module m1;\n`include \"decl.svh\"\n initial $display(\"%b\", `Q(shared_q));\nendmodule\n";
let m2 = "module m2;\n`include \"decl.svh\"\n assign o = shared_q;\nendmodule\n";
let files = [("defs.svh", Q_DEFS), ("decl.svh", decl), ("m1.sv", m1), ("m2.sv", m2)];
let result = run(&files, "decl.svh", "logic ", "shared_q", "shared_r");
let (_, warnings) = result.expect("renames");
assert!(said(&warnings, "m1.sv", 3), "m1's macro argument: {warnings:#?}");
assert!(said(&warnings, "m2.sv", 3), "m2's plain use: {warnings:#?}");
}
/// H2 closure and noise.
#[test]
fn rework4_define_bodies_reached_through_two_other_bodies() {
let hdr = "`define INNER state_q\n`define MID `INNER\n`define OUTER `MID\n";
let module = "module m (input logic clk, output logic [1:0] o);
logic state_q;
assign o = `OUTER;
endmodule
";
let files = [("hdr.svh", hdr), ("m.sv", module)];
let (_, warnings) = run(&files, "m.sv", "logic ", "state_q", "state_r").expect("renames");
let bodies: Vec<&String> = warnings.iter().filter(|w| w.contains("body of macro")).collect();
assert!(
bodies.iter().any(|w| w.contains("`INNER`")),
"HIDDEN USE through two bodies: {warnings:#?}"
);
}
/// Noise, not a hidden use: a macro whose parameter is named like the net,
/// and a macro "invoked" only inside a string.
#[test]
fn rework4_a_parameter_named_like_the_net_and_a_string_invocation_are_not_news() {
let hdr = "`define PARAM(state_q) (state_q + 1)\n`define UNUSED state_q\n";
let module = "module m (input logic clk, output logic [1:0] o);
logic state_q;
assign o = `PARAM(clk);
initial $display(\"`UNUSED\");
endmodule
";
let files = [("hdr.svh", hdr), ("m.sv", module)];
let (_, warnings) = run(&files, "m.sv", "logic ", "state_q", "state_r").expect("renames");
assert!(
!warnings.iter().any(|w| w.contains("`PARAM`") || w.contains("`UNUSED`")),
"{warnings:#?}"
);
}
/// H2 × H3: a bind file into the declaring module invokes a header macro
/// whose body spells the net bare.
#[test]
fn rework4_a_macro_invoked_inside_a_bind_into_the_unit_is_followed() {
let hdr = "`define SIG state_q\n";
let module = "module m (input logic clk);\n logic state_q;\nendmodule\n";
let chk = "module chk (input logic s);\nendmodule\n";
let bind = "module m_bind;\n bind m chk u_chk (.s(`SIG));\nendmodule\n";
let files = [("hdr.svh", hdr), ("m.sv", module), ("chk.sv", chk), ("m_bind.sv", bind)];
let (_, warnings) = run(&files, "m.sv", "logic ", "state_q", "state_r").expect("renames");
assert!(
warnings.iter().any(|w| w.contains("hdr.svh") || w.contains("m_bind.sv")),
"HIDDEN USE: {warnings:#?}"
);
}
/// H3 shapes: an instance path, an interface target, inside a generate.
#[test]
fn rework4_bind_by_path_to_an_interface_and_inside_a_generate() {
let ifc = "interface bus_if (input logic clk);\n logic state_q;\nendinterface\n";
let chk = "module chk (input logic s);\nendmodule\n";
let binds = "module binds;
bind bus_if chk u_a (.s(`Q(state_q)));
bind tb.u_bus chk u_b (.s(`Q(state_q)));
if (1) begin : g
bind bus_if chk u_c (.s(`Q(state_q)));
end
endmodule
";
let files = [("defs.svh", Q_DEFS), ("bus_if.sv", ifc), ("chk.sv", chk), ("binds.sv", binds)];
let (_, warnings) = run(&files, "bus_if.sv", "logic ", "state_q", "state_r").expect("renames");
for line in [2, 3, 5] {
assert!(said(&warnings, "binds.sv", line), "line {line}: {warnings:#?}");
}
}
/// oct_review L-6: `bind u_m chk …` written inside the parent, the target a
/// bare **instance** name (IEEE 1800 §23.11), binds into `m` as surely as
/// `bind m chk …` does — so a macro argument inside it is news. A bare target
/// naming an instance of another module is not.
#[test]
fn l6_a_bind_onto_a_bare_instance_of_the_unit_is_a_bind_into_it() {
let module = "module m (input logic clk);\n logic state_q;\nendmodule\n";
let other = "module o (input logic clk);\nendmodule\n";
let chk = "module chk (input logic s);\nendmodule\n";
let top = "module top (input logic clk);
m u_m (.clk);
o u_o (.clk);
bind u_m chk u_a (.s(`Q(state_q)));
bind u_o chk u_b (.s(`Q(state_q)));
endmodule
";
let files =
[("defs.svh", Q_DEFS), ("m.sv", module), ("o.sv", other), ("chk.sv", chk), ("top.sv", top)];
let (_, warnings) = run(&files, "m.sv", "logic ", "state_q", "state_r").expect("renames");
assert!(said(&warnings, "top.sv", 4), "HIDDEN USE: {warnings:#?}");
assert!(!said(&warnings, "top.sv", 5), "u_o is an `o`: {warnings:#?}");
}
/// oct_review L-5: renaming a variable inside an interface's generate block
/// edits the paths that reach it through an interface port and through a
/// virtual interface, rather than warning that they could not be resolved.
#[test]
fn l5_a_path_through_an_interface_port_into_its_generate_block_is_renamed() {
let ifc = "interface bus_if (input logic clk);
logic data;
if (1) begin : g_mon
logic seen;
end
endinterface
";
let user = "module u (bus_if bus, output logic o);\n assign o = bus.g_mon.seen;\nendmodule\n";
let tb = "module tb;\n virtual bus_if vif;\n initial $display(vif.g_mon.seen);\nendmodule\n";
let files = [("bus_if.sv", ifc), ("u.sv", user), ("tb.sv", tb)];
let (texts, warnings) = run(&files, "bus_if.sv", "logic ", "seen", "seen_q").expect("renames");
assert!(texts[1].contains("bus.g_mon.seen_q;"), "{}", texts[1]);
assert!(texts[2].contains("vif.g_mon.seen_q)"), "{}", texts[2]);
assert!(!warnings.iter().any(|w| w.contains("could not be resolved")), "{warnings:#?}");
}
/// H4: a fragment that declares its own `mem` is never rewritten; a fragment
/// only an unrelated module includes stays silent.
#[test]
fn rework4_fragment_uses_of_a_different_declaration_are_not_rewritten() {
let module = "module m;\n logic [7:0] mem;\n`include \"own.svh\"\nendmodule\n";
let own =
" function automatic int peek();\n logic [7:0] mem;\n return mem;\n endfunction\n";
let unrelated = "module u;\n logic [7:0] mem;\n`include \"far.svh\"\nendmodule\n";
let far = " initial mem = '0;\n";
let files = [("m.sv", module), ("own.svh", own), ("u.sv", unrelated), ("far.svh", far)];
let (texts, warnings) = run(&files, "m.sv", "logic [7:0] ", "mem", "mem_q").expect("renames");
assert_eq!(texts[1], own, "the fragment's own `mem` is never rewritten");
assert_eq!((texts[2].as_str(), texts[3].as_str()), (unrelated, far));
assert!(!warnings.iter().any(|w| w.contains("far.svh")), "{warnings:#?}");
}
// ---------------------------------------------------------------------------
// Rework 5 closing check, 2026-09-30
// ---------------------------------------------------------------------------
/// N1: renaming `sub.clk_i` edits `top` (its connection). `top` has no
/// `clk_i` of its own and spells one in a macro argument of the connection.
/// The bare spelling cannot name `sub`'s port; whatever is said, the port's
/// own module must still warn its own macro argument.
#[test]
fn rework5_an_edited_instantiator_without_its_own_name() {
let sub =
"module sub (input logic clk_i);\n initial $display(\"%b\", `Q(clk_i));\nendmodule\n";
let top = "module top (input logic c);\n sub u (.clk_i(`Q(clk_i)));\nendmodule\n";
let files = [("defs.svh", Q_DEFS), ("sub.sv", sub), ("top.sv", top)];
let (texts, warnings) = run(&files, "sub.sv", "logic ", "clk_i", "clk").expect("renames");
assert!(said(&warnings, "sub.sv", 2), "{warnings:#?}");
assert!(texts[2].contains(".clk("), "the connection's port name moves: {}", texts[2]);
}
/// N1: an edited file that also includes a fragment the declaring module
/// includes, and a nested module that re-declares the name.
#[test]
fn rework5_an_edited_file_sharing_a_fragment_or_nesting_a_redeclaration() {
let sub = "module sub (input logic clk_i);\n`include \"frag.svh\"\nendmodule\n";
let frag = " initial $display(\"%b\", `Q(clk_i));\n";
let top = "module top (input logic clk_i);\n`include \"frag.svh\"\n sub u (.clk_i);\n module inner;\n logic clk_i;\n initial $display(\"%b\", `Q(clk_i));\n endmodule\nendmodule\n";
let files = [("defs.svh", Q_DEFS), ("sub.sv", sub), ("frag.svh", frag), ("top.sv", top)];
let (_, warnings) = run(&files, "sub.sv", "logic ", "clk_i", "clk").expect("renames");
assert!(said(&warnings, "frag.svh", 1), "the shared fragment pastes into sub: {warnings:#?}");
assert!(!said(&warnings, "top.sv", 6), "inner's own clk_i: {warnings:#?}");
}
/// N2: a parameter named like the net silences only a body that has no
/// other way to the net. A path through the name in the body (`u_m.state_q`)
/// can reach it; 0.59.0 warned, rework 5 did not (QA P1: the parameter check
/// ran before `body_dotted` and the unscoped fallback). Fixed: both now come
/// first in `keeps_define_body`.
#[test]
fn rework5_a_shadowing_parameter_does_not_hide_a_dotted_body_spelling() {
let hdr = "`define PATHY(state_q) (state_q + u_m.state_q)\n";
let module = "module m (input logic clk, output logic [1:0] o);
logic state_q;
assign o = `PATHY(clk);
endmodule
";
let files = [("hdr.svh", hdr), ("m.sv", module)];
let (_, warnings) = run(&files, "m.sv", "logic ", "state_q", "state_r").expect("renames");
assert!(warnings.iter().any(|w| w.contains("`PATHY`")), "the dotted path: {warnings:#?}");
}
/// A default argument spelling the name expands into the module when the
/// macro is invoked without it. Silent in 0.59.0 too (QA P2: default
/// arguments were never scanned); now scanned with the body.
#[test]
fn rework5_a_default_argument_spelling_the_name_is_said() {
let hdr = "`define DFLT(x = state_q) (x)\n";
let module = "module m (input logic clk, output logic [1:0] o);
logic state_q;
assign o = `DFLT();
endmodule
";
let files = [("hdr.svh", hdr), ("m.sv", module)];
let (_, warnings) = run(&files, "m.sv", "logic ", "state_q", "state_r").expect("renames");
assert!(
warnings.iter().any(|w| w.contains("`DFLT`") || w.contains("hdr.svh:1")),
"{warnings:#?}"
);
}
/// K2 through a two-level instance path, and N3 three include levels up.
#[test]
fn rework5_bind_by_two_level_path_and_three_levels_of_includers() {
let hdr = "`define SIG state_q\n";
let m = "module m;\n logic state_q;\nendmodule\n";
let chk = "module chk (input logic s);\nendmodule\n";
let bind = "module b;\n bind tb.u_top.u_m chk u_chk (.s(`SIG));\nendmodule\n";
let files = [("hdr.svh", hdr), ("m.sv", m), ("chk.sv", chk), ("b.sv", bind)];
let (_, warnings) = run(&files, "m.sv", "logic ", "state_q", "state_r").expect("renames");
assert!(warnings.iter().any(|w| w.contains("hdr.svh") || w.contains("b.sv")), "{warnings:#?}");
let body = " logic deep_q;\n initial $display(\"%b\", `Q(deep_q));\n";
let l1 = "`include \"body.svh\"\n";
let l2 = "`include \"l1.svh\"\n";
let l3 = "module top;\n`include \"l2.svh\"\n initial $display(\"%b\", `Q(deep_q));\n assign o = deep_q;\nendmodule\n";
let files =
[("defs.svh", Q_DEFS), ("body.svh", body), ("l1.svh", l1), ("l2.svh", l2), ("top.sv", l3)];
let (_, warnings) = run(&files, "body.svh", "logic ", "deep_q", "deep_r").expect("renames");
assert!(said(&warnings, "top.sv", 3), "three levels up, macro argument: {warnings:#?}");
assert!(said(&warnings, "top.sv", 4), "three levels up, plain use: {warnings:#?}");
}
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com