From 315bc1908acdaaea989f0dbe32ef09202b1591ad Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sat, 19 Mar 2022 19:11:00 +0100 Subject: [PATCH] Add regression tests for enum base type Check that the behavior for all sorts of base types for enums is correctly implemented. Both for valid as well as invalid base types. Signed-off-by: Lars-Peter Clausen --- ivtest/ivltests/enum_base_atom2.v | 31 ++++++++++++++++++++++++ ivtest/ivltests/enum_base_fail_array.v | 16 ++++++++++++ ivtest/ivltests/enum_base_fail_class.v | 17 +++++++++++++ ivtest/ivltests/enum_base_fail_darray.v | 16 ++++++++++++ ivtest/ivltests/enum_base_fail_enum.v | 18 ++++++++++++++ ivtest/ivltests/enum_base_fail_queue.v | 16 ++++++++++++ ivtest/ivltests/enum_base_fail_range1.v | 17 +++++++++++++ ivtest/ivltests/enum_base_fail_range2.v | 16 ++++++++++++ ivtest/ivltests/enum_base_fail_range3.v | 14 +++++++++++ ivtest/ivltests/enum_base_fail_real1.v | 14 +++++++++++ ivtest/ivltests/enum_base_fail_real2.v | 16 ++++++++++++ ivtest/ivltests/enum_base_fail_string1.v | 14 +++++++++++ ivtest/ivltests/enum_base_fail_string2.v | 16 ++++++++++++ ivtest/ivltests/enum_base_fail_struct.v | 18 ++++++++++++++ ivtest/ivltests/enum_base_integer.v | 18 ++++++++++++++ ivtest/ivltests/enum_base_none.v | 18 ++++++++++++++ ivtest/ivltests/enum_base_scalar.v | 26 ++++++++++++++++++++ ivtest/ivltests/enum_base_time.v | 18 ++++++++++++++ ivtest/ivltests/enum_base_typename1.v | 20 +++++++++++++++ ivtest/ivltests/enum_base_typename2.v | 20 +++++++++++++++ ivtest/regress-sv.list | 20 +++++++++++++++ ivtest/regress-vlog95.list | 2 ++ 22 files changed, 381 insertions(+) create mode 100644 ivtest/ivltests/enum_base_atom2.v create mode 100644 ivtest/ivltests/enum_base_fail_array.v create mode 100644 ivtest/ivltests/enum_base_fail_class.v create mode 100644 ivtest/ivltests/enum_base_fail_darray.v create mode 100644 ivtest/ivltests/enum_base_fail_enum.v create mode 100644 ivtest/ivltests/enum_base_fail_queue.v create mode 100644 ivtest/ivltests/enum_base_fail_range1.v create mode 100644 ivtest/ivltests/enum_base_fail_range2.v create mode 100644 ivtest/ivltests/enum_base_fail_range3.v create mode 100644 ivtest/ivltests/enum_base_fail_real1.v create mode 100644 ivtest/ivltests/enum_base_fail_real2.v create mode 100644 ivtest/ivltests/enum_base_fail_string1.v create mode 100644 ivtest/ivltests/enum_base_fail_string2.v create mode 100644 ivtest/ivltests/enum_base_fail_struct.v create mode 100644 ivtest/ivltests/enum_base_integer.v create mode 100644 ivtest/ivltests/enum_base_none.v create mode 100644 ivtest/ivltests/enum_base_scalar.v create mode 100644 ivtest/ivltests/enum_base_time.v create mode 100644 ivtest/ivltests/enum_base_typename1.v create mode 100644 ivtest/ivltests/enum_base_typename2.v diff --git a/ivtest/ivltests/enum_base_atom2.v b/ivtest/ivltests/enum_base_atom2.v new file mode 100644 index 000000000..467ed0d00 --- /dev/null +++ b/ivtest/ivltests/enum_base_atom2.v @@ -0,0 +1,31 @@ +// Check that it is possible to declare an enum type with an atom2 type as the +// base type. + +module test; + + enum byte { + A + } e1; + + enum shortint { + B + } e2; + + enum int { + C + } e3; + + enum longint { + D + } e4; + + initial begin + if ($bits(e1) == 8 && $bits(e2) == 16 && + $bits(e3) == 32 && $bits(e4) == 64) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule diff --git a/ivtest/ivltests/enum_base_fail_array.v b/ivtest/ivltests/enum_base_fail_array.v new file mode 100644 index 000000000..6e11d34d9 --- /dev/null +++ b/ivtest/ivltests/enum_base_fail_array.v @@ -0,0 +1,16 @@ +// Check that using an array type as the base type for an enum results in an +// error. + +module test; + + typedef logic T[1:0]; + + enum T { + A + } e; + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/enum_base_fail_class.v b/ivtest/ivltests/enum_base_fail_class.v new file mode 100644 index 000000000..cd36d254a --- /dev/null +++ b/ivtest/ivltests/enum_base_fail_class.v @@ -0,0 +1,17 @@ +// Check that using a class type as the base type for an enum results in an +// error. + +class C; +endclass + +module test; + + enum C { + A + } e; + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/enum_base_fail_darray.v b/ivtest/ivltests/enum_base_fail_darray.v new file mode 100644 index 000000000..7eeb8718d --- /dev/null +++ b/ivtest/ivltests/enum_base_fail_darray.v @@ -0,0 +1,16 @@ +// Check that using a dynamic array type as the base type for an enum results in +// an error. + +module test; + + typedef logic T[]; + + enum T { + A + } e; + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/enum_base_fail_enum.v b/ivtest/ivltests/enum_base_fail_enum.v new file mode 100644 index 000000000..32b84efd5 --- /dev/null +++ b/ivtest/ivltests/enum_base_fail_enum.v @@ -0,0 +1,18 @@ +// Check that using an enum type as the base type for an enum results in an +// error. + +module test; + + typedef enum { + X + } T; + + enum T { + A + } e; + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/enum_base_fail_queue.v b/ivtest/ivltests/enum_base_fail_queue.v new file mode 100644 index 000000000..38a0921aa --- /dev/null +++ b/ivtest/ivltests/enum_base_fail_queue.v @@ -0,0 +1,16 @@ +// Check that using a queue type as the base type for an enum results in an +// error + +module test; + + typedef logic T[$]; + + enum T { + A + } e; + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/enum_base_fail_range1.v b/ivtest/ivltests/enum_base_fail_range1.v new file mode 100644 index 000000000..a5bbf74a4 --- /dev/null +++ b/ivtest/ivltests/enum_base_fail_range1.v @@ -0,0 +1,17 @@ +// Check that using a type identifier that resolves to a type with a packed +// dimensions together with another packed dimensions as the base type for an +// enum results in an error. + +module test; + + typedef int T; + + enum T [1:0] { + A + } e; + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/enum_base_fail_range2.v b/ivtest/ivltests/enum_base_fail_range2.v new file mode 100644 index 000000000..e82e640bd --- /dev/null +++ b/ivtest/ivltests/enum_base_fail_range2.v @@ -0,0 +1,16 @@ +// Check that using a type identifier that resolves to a type with multiple +// packed dimensions as the base type for an enum results in an error. + +module test; + + typedef bit [1:0][1:0] T; + + enum T { + A + } e; + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/enum_base_fail_range3.v b/ivtest/ivltests/enum_base_fail_range3.v new file mode 100644 index 000000000..a7ccf5928 --- /dev/null +++ b/ivtest/ivltests/enum_base_fail_range3.v @@ -0,0 +1,14 @@ +// Check that specifying a vector type with multiple packed dimensions as the +// base type for an enum results in an error. + +module test; + + enum logic [1:0][1:0] { + A + } e; + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/enum_base_fail_real1.v b/ivtest/ivltests/enum_base_fail_real1.v new file mode 100644 index 000000000..cfd5df8bf --- /dev/null +++ b/ivtest/ivltests/enum_base_fail_real1.v @@ -0,0 +1,14 @@ +// Check that using a real type as the base type for an enum results in an +// error. + +module test; + + enum real { + A + } e; + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/enum_base_fail_real2.v b/ivtest/ivltests/enum_base_fail_real2.v new file mode 100644 index 000000000..c51748e21 --- /dev/null +++ b/ivtest/ivltests/enum_base_fail_real2.v @@ -0,0 +1,16 @@ +// Check that using a real type as the base type for an enum results in an +// error. + +module test; + + typedef real T; + + enum T { + A + } e; + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/enum_base_fail_string1.v b/ivtest/ivltests/enum_base_fail_string1.v new file mode 100644 index 000000000..58b789a46 --- /dev/null +++ b/ivtest/ivltests/enum_base_fail_string1.v @@ -0,0 +1,14 @@ +// Check that using a string type as the base type for an enum results in an +// error. + +module test; + + enum string { + A + } e; + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/enum_base_fail_string2.v b/ivtest/ivltests/enum_base_fail_string2.v new file mode 100644 index 000000000..638282f09 --- /dev/null +++ b/ivtest/ivltests/enum_base_fail_string2.v @@ -0,0 +1,16 @@ +// Check that using a string type as the base type for an enum results in an +// error. + +module test; + + typedef string T; + + enum T { + A + } e; + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/enum_base_fail_struct.v b/ivtest/ivltests/enum_base_fail_struct.v new file mode 100644 index 000000000..556fb092c --- /dev/null +++ b/ivtest/ivltests/enum_base_fail_struct.v @@ -0,0 +1,18 @@ +// Check that using a struct type as the base type for an enum results in an +// error. + +module test; + + typedef struct packed { + int x; + } T; + + enum T { + A + } e; + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/enum_base_integer.v b/ivtest/ivltests/enum_base_integer.v new file mode 100644 index 000000000..a419dddcc --- /dev/null +++ b/ivtest/ivltests/enum_base_integer.v @@ -0,0 +1,18 @@ +// Check that it is possible to declare an enum type with the integer type as +// the base type. + +module test; + + enum integer { + A + } E; + + initial begin + if ($bits(E) == $bits(integer)) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule diff --git a/ivtest/ivltests/enum_base_none.v b/ivtest/ivltests/enum_base_none.v new file mode 100644 index 000000000..ab5d06ac0 --- /dev/null +++ b/ivtest/ivltests/enum_base_none.v @@ -0,0 +1,18 @@ +// Check that it is possible to declare an enum type without an explicit base +// type. In this case the base type should default to `int`. + +module test; + + enum { + A + } E; + + initial begin + if ($bits(E) == 32) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule diff --git a/ivtest/ivltests/enum_base_scalar.v b/ivtest/ivltests/enum_base_scalar.v new file mode 100644 index 000000000..baf859934 --- /dev/null +++ b/ivtest/ivltests/enum_base_scalar.v @@ -0,0 +1,26 @@ +// Check that it is possible to declare an enum type with a scalar vector type +// as the base type. + +module test; + + enum reg { + A + } e1; + + enum logic { + B + } e2; + + enum bit { + C + } e3; + + initial begin + if ($bits(e1) == 1 && $bits(e2) == 1 && $bits(e3) == 1) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule diff --git a/ivtest/ivltests/enum_base_time.v b/ivtest/ivltests/enum_base_time.v new file mode 100644 index 000000000..b8923ef23 --- /dev/null +++ b/ivtest/ivltests/enum_base_time.v @@ -0,0 +1,18 @@ +// Check that it is possible to declare an enum type with the time type as the +// base type. + +module test; + + enum time { + A + } E; + + initial begin + if ($bits(E) == 64) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule diff --git a/ivtest/ivltests/enum_base_typename1.v b/ivtest/ivltests/enum_base_typename1.v new file mode 100644 index 000000000..98dbaca1b --- /dev/null +++ b/ivtest/ivltests/enum_base_typename1.v @@ -0,0 +1,20 @@ +// Check that it is possible to declare an enum type with a type identifier that +// resolves to an integer type as the base type. + +module test; + + typedef integer T; + + enum T { + A + } E; + + initial begin + if ($bits(E) == $bits(integer)) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule diff --git a/ivtest/ivltests/enum_base_typename2.v b/ivtest/ivltests/enum_base_typename2.v new file mode 100644 index 000000000..efd1a2302 --- /dev/null +++ b/ivtest/ivltests/enum_base_typename2.v @@ -0,0 +1,20 @@ +// Check that it is possible to declare an enum type with a type identifier plus +// packed dimensions as the the base type. + +module test; + + typedef bit T; + + enum T [31:0] { + A + } E; + + initial begin + if ($bits(E) == 32) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule diff --git a/ivtest/regress-sv.list b/ivtest/regress-sv.list index 70e7b90c5..291377749 100644 --- a/ivtest/regress-sv.list +++ b/ivtest/regress-sv.list @@ -231,7 +231,27 @@ clkgen_reg normal,-g2009 ivltests disable_fork_cmd normal,-g2009 ivltests display_bug normal,-g2009 ivltests gold=display_bug.gold edge normal,-g2009 ivltests +enum_base_atom2 normal,-g2005-sv ivltests +enum_base_fail_array CE,-g2005-sv ivltests +enum_base_fail_darray CE,-g2005-sv ivltests +enum_base_fail_darray CE,-g2005-sv ivltests +enum_base_fail_enum CE,-g2005-sv ivltests +enum_base_fail_queue CE,-g2005-sv ivltests +enum_base_fail_range1 CE,-g2005-sv ivltests +enum_base_fail_range2 CE,-g2005-sv ivltests +enum_base_fail_range3 CE,-g2005-sv ivltests +enum_base_fail_real1 CE,-g2005-sv ivltests +enum_base_fail_real2 CE,-g2005-sv ivltests +enum_base_fail_string1 CE,-g2005-sv ivltests +enum_base_fail_string2 CE,-g2005-sv ivltests +enum_base_fail_struct CE,-g2005-sv ivltests +enum_base_integer normal,-g2005-sv ivltests +enum_base_none normal,-g2005-sv ivltests enum_base_range normal,-g2005-sv ivltests +enum_base_scalar normal,-g2005-sv ivltests +enum_base_time normal,-g2005-sv ivltests +enum_base_typename1 normal,-g2005-sv ivltests +enum_base_typename2 normal,-g2005-sv ivltests enum_compatibility1 normal,-g2005-sv ivltests enum_compatibility2 normal,-g2005-sv ivltests enum_compatibility3 normal,-g2005-sv ivltests diff --git a/ivtest/regress-vlog95.list b/ivtest/regress-vlog95.list index cb68c4df5..8357e0afc 100644 --- a/ivtest/regress-vlog95.list +++ b/ivtest/regress-vlog95.list @@ -776,6 +776,8 @@ constfunc6_ams normal,-pallowsigned=1 ivltests constfunc7 normal,-pallowsigned=1 ivltests constfunc13 normal,-pallowsigned=1 ivltests constfunc14 normal,-pallowsigned=1 ivltests +enum_base_atom2 normal,-g2005-sv,-pallowsigned=1 ivltests +enum_base_none normal,-g2005-sv,-pallowsigned=1 ivltests enum_elem_ranges normal,-g2009,-pallowsigned=1 ivltests enum_value_expr normal,-g2009,-pallowsigned=1 ivltests enum_values normal,-g2009,-pallowsigned=1 ivltests