From ef7f0a8f38782dfc0872b1e352ccf32343c10bb8 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sat, 6 Apr 2024 10:19:00 +0100 Subject: [PATCH] Add regression tests for early signal elaboration. --- .../gold/early_sig_elab3-iverilog-stderr.gold | 2 ++ ivtest/ivltests/br_gh1097.v | 18 +++++++++++++ ivtest/ivltests/br_gh483a.v | 21 +++++++++++++++ ivtest/ivltests/br_gh483b.v | 18 +++++++++++++ ivtest/ivltests/early_sig_elab1.v | 25 +++++++++++++++++ ivtest/ivltests/early_sig_elab2.v | 27 +++++++++++++++++++ ivtest/ivltests/early_sig_elab3.v | 16 +++++++++++ ivtest/regress-vvp.list | 6 +++++ ivtest/vvp_tests/br_gh1097.json | 5 ++++ ivtest/vvp_tests/br_gh483a.json | 4 +++ ivtest/vvp_tests/br_gh483b.json | 4 +++ ivtest/vvp_tests/early_sig_elab1.json | 4 +++ ivtest/vvp_tests/early_sig_elab2.json | 4 +++ ivtest/vvp_tests/early_sig_elab3.json | 5 ++++ 14 files changed, 159 insertions(+) create mode 100644 ivtest/gold/early_sig_elab3-iverilog-stderr.gold create mode 100644 ivtest/ivltests/br_gh1097.v create mode 100644 ivtest/ivltests/br_gh483a.v create mode 100644 ivtest/ivltests/br_gh483b.v create mode 100644 ivtest/ivltests/early_sig_elab1.v create mode 100644 ivtest/ivltests/early_sig_elab2.v create mode 100644 ivtest/ivltests/early_sig_elab3.v create mode 100644 ivtest/vvp_tests/br_gh1097.json create mode 100644 ivtest/vvp_tests/br_gh483a.json create mode 100644 ivtest/vvp_tests/br_gh483b.json create mode 100644 ivtest/vvp_tests/early_sig_elab1.json create mode 100644 ivtest/vvp_tests/early_sig_elab2.json create mode 100644 ivtest/vvp_tests/early_sig_elab3.json diff --git a/ivtest/gold/early_sig_elab3-iverilog-stderr.gold b/ivtest/gold/early_sig_elab3-iverilog-stderr.gold new file mode 100644 index 000000000..3122434b0 --- /dev/null +++ b/ivtest/gold/early_sig_elab3-iverilog-stderr.gold @@ -0,0 +1,2 @@ +ivltests/early_sig_elab3.v:8: error: Circular dependency detected in declaration of 'a'. +1 error(s) during elaboration. diff --git a/ivtest/ivltests/br_gh1097.v b/ivtest/ivltests/br_gh1097.v new file mode 100644 index 000000000..373346228 --- /dev/null +++ b/ivtest/ivltests/br_gh1097.v @@ -0,0 +1,18 @@ +module test_mod (); + + typedef enum logic [4:0] {ENUM_ELEM1, ENUM_ELEM2} test_enum_t; + + test_enum_t test_mem_addr_e; + logic [1:0] test_mem [test_mem_addr_e.num()]; + + initial begin + test_mem[ENUM_ELEM1] = 1; + test_mem[ENUM_ELEM2] = 2; + $display("ENUM_ELEM1 = %d test_mem[ENUM_ELEM1] = %d", ENUM_ELEM1, test_mem[ENUM_ELEM1]); + $display("ENUM_ELEM2 = %d test_mem[ENUM_ELEM2] = %d", ENUM_ELEM2, test_mem[ENUM_ELEM2]); + if (test_mem[ENUM_ELEM1] === 1 && test_mem[ENUM_ELEM2] === 2) + $display("PASSED"); + else + $display("FAILED"); + end +endmodule diff --git a/ivtest/ivltests/br_gh483a.v b/ivtest/ivltests/br_gh483a.v new file mode 100644 index 000000000..b700d1693 --- /dev/null +++ b/ivtest/ivltests/br_gh483a.v @@ -0,0 +1,21 @@ +// Strictly speaking this is illegal as it uses a hierarchical name in a +// constant expression. +module top; + parameter ENABLE = 1; + if (ENABLE) begin : blk + wire [7:0] w; + end + wire [7:0] x; + wire [$bits(blk.w)-1:0] y = 8'h55; + wire [$bits(x)-1:0] z = 8'haa; + initial begin + $display("blk.w: %b (%0d bits)", blk.w, $bits(blk.w)); + $display("x: %b (%0d bits)", x, $bits(x)); + $display("y: %b (%0d bits)", y, $bits(y)); + $display("z: %b (%0d bits)", z, $bits(z)); + if (y === 8'h55 && z === 8'haa) + $display("PASSED"); + else + $display("FAILED"); + end +endmodule diff --git a/ivtest/ivltests/br_gh483b.v b/ivtest/ivltests/br_gh483b.v new file mode 100644 index 000000000..ac4910d44 --- /dev/null +++ b/ivtest/ivltests/br_gh483b.v @@ -0,0 +1,18 @@ +module Module; + parameter T = 10; + wire [T-1:0] x = 8'h55; + initial $display("Module %b %0d", x, T); +endmodule + +module top; + wire [7:0] x; + Module #($bits(x)) mA(); + Module #(8) mB(); + + initial begin + if (mA.x === 8'h55 && mB.x === 8'h55) + $display("PASSED"); + else + $display("FAILED"); + end +endmodule diff --git a/ivtest/ivltests/early_sig_elab1.v b/ivtest/ivltests/early_sig_elab1.v new file mode 100644 index 000000000..6993f7e40 --- /dev/null +++ b/ivtest/ivltests/early_sig_elab1.v @@ -0,0 +1,25 @@ +// Icarus elaborates signals in alphabetical order, so force early +// elaboration that way. + +module test; + +localparam LSB = 0; +localparam MSB = 7; + +reg [MSB:LSB] c; +reg [$bits(c):1] a; + +localparam WIDTH = $bits(c); + +reg [WIDTH:1] b; + +initial begin + $display("a = %b", a); + $display("b = %b", b); + if ($bits(a) === 8 && $bits(b) == 8) + $display("PASSED"); + else + $display("FAILED"); +end + +endmodule diff --git a/ivtest/ivltests/early_sig_elab2.v b/ivtest/ivltests/early_sig_elab2.v new file mode 100644 index 000000000..36ab17ec7 --- /dev/null +++ b/ivtest/ivltests/early_sig_elab2.v @@ -0,0 +1,27 @@ +// Strictly speaking this is not legal as it uses a hierarchical name in a +// constant expression, + +module test1; + +reg [$bits(test2.v):1] v; + +endmodule + +module test2; + +reg [7:0] v; + +initial begin + if ($bits(test1.v) === 8 && $bits(test3.v) === 8) + $display("PASSED"); + else + $display("FAILED"); +end + +endmodule + +module test3; + +reg [$bits(test2.v):1] v; + +endmodule diff --git a/ivtest/ivltests/early_sig_elab3.v b/ivtest/ivltests/early_sig_elab3.v new file mode 100644 index 000000000..12eb1f783 --- /dev/null +++ b/ivtest/ivltests/early_sig_elab3.v @@ -0,0 +1,16 @@ +// Test we detect and report circular dependencies. + +// Strictly speaking this is not legal as it uses a hierarchical name in a +// constant expression, + +module test; + +reg [$bits(test.b):1] a; +reg [$bits(test.a):1] b; + +initial begin + // This test is expected to fail at compile time. + $display("FAILED"); +end + +endmodule diff --git a/ivtest/regress-vvp.list b/ivtest/regress-vvp.list index 468ca7d14..1e67e16b9 100644 --- a/ivtest/regress-vvp.list +++ b/ivtest/regress-vvp.list @@ -25,6 +25,8 @@ br_gh383b vvp_tests/br_gh383b.json br_gh383c vvp_tests/br_gh383c.json br_gh383d vvp_tests/br_gh383d.json br_gh440 vvp_tests/br_gh440.json +br_gh483a vvp_tests/br_gh483a.json +br_gh483b vvp_tests/br_gh483b.json br_gh552 vvp_tests/br_gh552.json br_gh687 vvp_tests/br_gh687.json br_gh703 vvp_tests/br_gh703.json @@ -42,6 +44,7 @@ br_gh1087a2 vvp_tests/br_gh1087a2.json br_gh1087a3 vvp_tests/br_gh1087a3.json br_gh1087b vvp_tests/br_gh1087b.json br_gh1087c vvp_tests/br_gh1087c.json +br_gh1097 vvp_tests/br_gh1097.json br_gh1099a vvp_tests/br_gh1099a.json br_gh1099b vvp_tests/br_gh1099b.json br_gh1099c vvp_tests/br_gh1099c.json @@ -84,6 +87,9 @@ dffsynth9 vvp_tests/dffsynth9.json dffsynth10 vvp_tests/dffsynth10.json dffsynth11 vvp_tests/dffsynth11.json dumpfile vvp_tests/dumpfile.json +early_sig_elab1 vvp_tests/early_sig_elab1.json +early_sig_elab2 vvp_tests/early_sig_elab2.json +early_sig_elab3 vvp_tests/early_sig_elab3.json eofmt_percent vvp_tests/eofmt_percent.json eofmt_percent-vlog95 vvp_tests/eofmt_percent-vlog95.json fdisplay3 vvp_tests/fdisplay3.json diff --git a/ivtest/vvp_tests/br_gh1097.json b/ivtest/vvp_tests/br_gh1097.json new file mode 100644 index 000000000..1e1441acc --- /dev/null +++ b/ivtest/vvp_tests/br_gh1097.json @@ -0,0 +1,5 @@ +{ + "type" : "normal", + "source" : "br_gh1097.v", + "iverilog-args" : [ "-g2009" ] +} diff --git a/ivtest/vvp_tests/br_gh483a.json b/ivtest/vvp_tests/br_gh483a.json new file mode 100644 index 000000000..84edbe6a5 --- /dev/null +++ b/ivtest/vvp_tests/br_gh483a.json @@ -0,0 +1,4 @@ +{ + "type" : "normal", + "source" : "br_gh483a.v" +} diff --git a/ivtest/vvp_tests/br_gh483b.json b/ivtest/vvp_tests/br_gh483b.json new file mode 100644 index 000000000..528efd88b --- /dev/null +++ b/ivtest/vvp_tests/br_gh483b.json @@ -0,0 +1,4 @@ +{ + "type" : "normal", + "source" : "br_gh483b.v" +} diff --git a/ivtest/vvp_tests/early_sig_elab1.json b/ivtest/vvp_tests/early_sig_elab1.json new file mode 100644 index 000000000..3e1e3f505 --- /dev/null +++ b/ivtest/vvp_tests/early_sig_elab1.json @@ -0,0 +1,4 @@ +{ + "type" : "normal", + "source" : "early_sig_elab1.v" +} diff --git a/ivtest/vvp_tests/early_sig_elab2.json b/ivtest/vvp_tests/early_sig_elab2.json new file mode 100644 index 000000000..805aa0b54 --- /dev/null +++ b/ivtest/vvp_tests/early_sig_elab2.json @@ -0,0 +1,4 @@ +{ + "type" : "normal", + "source" : "early_sig_elab2.v" +} diff --git a/ivtest/vvp_tests/early_sig_elab3.json b/ivtest/vvp_tests/early_sig_elab3.json new file mode 100644 index 000000000..35f8e98ce --- /dev/null +++ b/ivtest/vvp_tests/early_sig_elab3.json @@ -0,0 +1,5 @@ +{ + "type" : "CE", + "source" : "early_sig_elab3.v", + "gold" : "early_sig_elab3" +}