From 37392383b528c62d47b2fe94f243f3352a55eee4 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 1 May 2022 12:16:38 +0200 Subject: [PATCH] Add regression test for scalar and 1-bit parameters Check that scalar typed parameters are handled correctly. Make sure the width of the parameter only depends on the type and not on the value assigned to the parameter. Same for parameters with a 1-bit range specification. Signed-off-by: Lars-Peter Clausen --- ivtest/ivltests/parameter_1bit.v | 26 ++++++++++++++++++++++++++ ivtest/ivltests/parameter_scalar.v | 26 ++++++++++++++++++++++++++ ivtest/regress-sv.list | 1 + ivtest/regress-vlg.list | 1 + 4 files changed, 54 insertions(+) create mode 100644 ivtest/ivltests/parameter_1bit.v create mode 100644 ivtest/ivltests/parameter_scalar.v diff --git a/ivtest/ivltests/parameter_1bit.v b/ivtest/ivltests/parameter_1bit.v new file mode 100644 index 000000000..bf59e5b5c --- /dev/null +++ b/ivtest/ivltests/parameter_1bit.v @@ -0,0 +1,26 @@ +// Check that parameters with a implicit and 1-bit range type are handled correctly + +module test #( + // This should get truncated to 1'b1 + parameter [0:0] P = 2'b11 +); + + reg failed = 1'b0; + + `define check(expr, val) \ + if (expr !== val) begin \ + $display("FAILED: `%s`, expected %0d, got %0d", `"expr`", val, expr); \ + failed = 1'b1; \ + end + + initial begin + `check($bits(P), 1); + `check(P + 1'b1, 1'b0); + `check(P, 1'b1); + + if (!failed) begin + $display("PASSED"); + end + end + +endmodule diff --git a/ivtest/ivltests/parameter_scalar.v b/ivtest/ivltests/parameter_scalar.v new file mode 100644 index 000000000..069193e60 --- /dev/null +++ b/ivtest/ivltests/parameter_scalar.v @@ -0,0 +1,26 @@ +// Check that parameters with a scalar type are handled correctly + +module test #( + // This should get truncated to 1'b1 + parameter bit P = 2'b11 +); + + bit failed = 1'b0; + + `define check(expr, val) \ + if (expr !== val) begin \ + $display("FAILED: `%s`, expected %0d, got %0d", `"expr`", val, expr); \ + failed = 1'b1; \ + end + + initial begin + `check($bits(P), 1); + `check(P + 1'b1, 1'b0); + `check(P, 1'b1); + + if (!failed) begin + $display("PASSED"); + end + end + +endmodule diff --git a/ivtest/regress-sv.list b/ivtest/regress-sv.list index 65140e653..2aa6adcbe 100644 --- a/ivtest/regress-sv.list +++ b/ivtest/regress-sv.list @@ -374,6 +374,7 @@ parameter_no_default_fail2 CE ivltests parameter_no_default_toplvl normal,-g2005-sv ivltests parameter_override_invalid7 CE,-g2005-sv ivltests parameter_override_invalid8 CE,-g2005-sv ivltests +parameter_scalar normal,-g2005-sv ivltests parameter_type2 normal,-g2009 ivltests parpkg_test normal,-g2009 ivltests parpkg_test2 normal,-g2009 ivltests diff --git a/ivtest/regress-vlg.list b/ivtest/regress-vlg.list index 5f32b39d2..3bd41a707 100644 --- a/ivtest/regress-vlg.list +++ b/ivtest/regress-vlg.list @@ -712,6 +712,7 @@ param_test2 normal ivltests gold=param_test2.gold param_test3 normal ivltests gold=param_test3.gold # PR#293 param_test4 normal ivltests param_times normal ivltests # param has multiplication. +parameter_1bit normal ivltests parameter_type normal ivltests gold=parameter_type.gold parameter_in_generate1 CE ivltests parameter_no_default CE ivltests