From d868983b9c6e0ffb1ac7ea8cf737fc3e5ed0a528 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Mon, 3 Oct 2022 23:27:55 +0200 Subject: [PATCH] Add regression tests for package export Check that package exports are supported. Also check for various scenarios where package exports should fail. Signed-off-by: Lars-Peter Clausen --- ivtest/ivltests/sv_export1.v | 25 +++++++++++++++++++++++++ ivtest/ivltests/sv_export2.v | 25 +++++++++++++++++++++++++ ivtest/ivltests/sv_export3.v | 25 +++++++++++++++++++++++++ ivtest/ivltests/sv_export4.v | 25 +++++++++++++++++++++++++ ivtest/ivltests/sv_export5.v | 26 ++++++++++++++++++++++++++ ivtest/ivltests/sv_export6.v | 28 ++++++++++++++++++++++++++++ ivtest/ivltests/sv_export_fail1.v | 22 ++++++++++++++++++++++ ivtest/ivltests/sv_export_fail2.v | 17 +++++++++++++++++ ivtest/ivltests/sv_export_fail3.v | 23 +++++++++++++++++++++++ ivtest/ivltests/sv_export_fail4.v | 23 +++++++++++++++++++++++ ivtest/ivltests/sv_export_fail5.v | 25 +++++++++++++++++++++++++ ivtest/ivltests/sv_export_fail6.v | 22 ++++++++++++++++++++++ ivtest/regress-sv.list | 12 ++++++++++++ 13 files changed, 298 insertions(+) create mode 100644 ivtest/ivltests/sv_export1.v create mode 100644 ivtest/ivltests/sv_export2.v create mode 100644 ivtest/ivltests/sv_export3.v create mode 100644 ivtest/ivltests/sv_export4.v create mode 100644 ivtest/ivltests/sv_export5.v create mode 100644 ivtest/ivltests/sv_export6.v create mode 100644 ivtest/ivltests/sv_export_fail1.v create mode 100644 ivtest/ivltests/sv_export_fail2.v create mode 100644 ivtest/ivltests/sv_export_fail3.v create mode 100644 ivtest/ivltests/sv_export_fail4.v create mode 100644 ivtest/ivltests/sv_export_fail5.v create mode 100644 ivtest/ivltests/sv_export_fail6.v diff --git a/ivtest/ivltests/sv_export1.v b/ivtest/ivltests/sv_export1.v new file mode 100644 index 000000000..5413c355e --- /dev/null +++ b/ivtest/ivltests/sv_export1.v @@ -0,0 +1,25 @@ +// Check that it is possible to explicitly export an identifier and import it +// from another scope. + +package P1; + integer x = 123; +endpackage + +package P2; + import P1::x; + export P1::x; +endpackage + +module test; + + import P2::x; + + initial begin + if (x == 123) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_export2.v b/ivtest/ivltests/sv_export2.v new file mode 100644 index 000000000..3d1bebe68 --- /dev/null +++ b/ivtest/ivltests/sv_export2.v @@ -0,0 +1,25 @@ +// Check that it is possible use package wildcard export an identifier and +// import it from another scope. + +package P1; + integer x = 123; +endpackage + +package P2; + import P1::x; + export P1::*; +endpackage + +module test; + + import P2::x; + + initial begin + if (x == 123) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_export3.v b/ivtest/ivltests/sv_export3.v new file mode 100644 index 000000000..acfb1e294 --- /dev/null +++ b/ivtest/ivltests/sv_export3.v @@ -0,0 +1,25 @@ +// Check that it is possible use full wildcard export an identifier and import +// it from another scope. + +package P1; + integer x = 123; +endpackage + +package P2; + import P1::x; + export *::*; +endpackage + +module test; + + import P2::x; + + initial begin + if (x == 123) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_export4.v b/ivtest/ivltests/sv_export4.v new file mode 100644 index 000000000..af51f1fda --- /dev/null +++ b/ivtest/ivltests/sv_export4.v @@ -0,0 +1,25 @@ +// Check that it is possible to export an implicitly imported identifier and +// import it again from another scope. + +package P1; + integer x = 123; +endpackage + +package P2; + import P1::*; + export P1::x; +endpackage + +module test; + + import P2::x; + + initial begin + if (x == 123) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_export5.v b/ivtest/ivltests/sv_export5.v new file mode 100644 index 000000000..6591c88db --- /dev/null +++ b/ivtest/ivltests/sv_export5.v @@ -0,0 +1,26 @@ +// Check that implicitly imported identifiers can be exported through a package +// wildcard export. + +package P1; + integer x = 123; +endpackage + +package P2; + import P1::*; + export P1::*; + integer y = x; // Creates an import for P1::x +endpackage + +module test; + + import P2::x; + + initial begin + if (x == 123) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_export6.v b/ivtest/ivltests/sv_export6.v new file mode 100644 index 000000000..e5a676f17 --- /dev/null +++ b/ivtest/ivltests/sv_export6.v @@ -0,0 +1,28 @@ +// Check that it is possible to implicitly import the same identifier through +// multiple paths without causing a conflict. + +package P1; + integer x = 123; +endpackage + +package P2; + import P1::x; + export P1::x; +endpackage + +module test; + + // P1::x is visible through either of the imports below. This should not + // create a conflict since it is the same identifier. + import P1::*; + import P2::*; + + initial begin + if (x == 123) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_export_fail1.v b/ivtest/ivltests/sv_export_fail1.v new file mode 100644 index 000000000..0ccc9b891 --- /dev/null +++ b/ivtest/ivltests/sv_export_fail1.v @@ -0,0 +1,22 @@ +// Check that it is an error to export an identifier from a package from which +// it has not been imported from. + +package P1; + integer x; +endpackage + +package P2; + import P1::x; + export P1::x; +endpackage + +package P3; + import P1::x; + export P2::x; // This should fail, even though P2::x is the same as P1::x +endpackage + +module test; + initial begin + $display("FAILED"); + end +endmodule diff --git a/ivtest/ivltests/sv_export_fail2.v b/ivtest/ivltests/sv_export_fail2.v new file mode 100644 index 000000000..653ea70c9 --- /dev/null +++ b/ivtest/ivltests/sv_export_fail2.v @@ -0,0 +1,17 @@ +// Check that it is an error to export an identifier that has not been imported. + +package P1; + integer x; + integer y; +endpackage + +package P2; + import P1::x; + export P1::y; // Should fail, P1::y has not been imported. +endpackage + +module test; + initial begin + $display("FAILED"); + end +endmodule diff --git a/ivtest/ivltests/sv_export_fail3.v b/ivtest/ivltests/sv_export_fail3.v new file mode 100644 index 000000000..ae10455e6 --- /dev/null +++ b/ivtest/ivltests/sv_export_fail3.v @@ -0,0 +1,23 @@ +// Check that an identifier importable through a wildcard import is not exported +// through a wildcard export if the identifier has not been referenced in +// package. + +package P1; + integer x = 123; +endpackage + +package P2; + import P1::*; + export *::*; +endpackage + +module test; + + import P2::x; // This should fail, P1::x is not referenced in P2 and hence not + // exportable through P2 + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_export_fail4.v b/ivtest/ivltests/sv_export_fail4.v new file mode 100644 index 000000000..2b2996778 --- /dev/null +++ b/ivtest/ivltests/sv_export_fail4.v @@ -0,0 +1,23 @@ +// Check that it is an error to export an identifier that is importable through +// a wildcard import if it creates a conflict with a local identifier. + +package P1; + integer x = 123; +endpackage + +package P2; + import P1::*; + integer x = 456; + export P1::x; // This should fail, P1::x can not be imported into this scope + // since the name already exists. +endpackage + +module test; + + import P2::x; + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_export_fail5.v b/ivtest/ivltests/sv_export_fail5.v new file mode 100644 index 000000000..d1398b81b --- /dev/null +++ b/ivtest/ivltests/sv_export_fail5.v @@ -0,0 +1,25 @@ +// Check that it is an error to export an identifier that is importable through +// a wildcard import if it creates a conflict with a local identifier, even if +// the local identifier is declared after the export. + +package P1; + integer x = 123; +endpackage + +package P2; + import P1::*; + export P1::x; // This should fail, P1::x can not be imported into this scope + // since the there is a local symbol with the same name. Even if + // it is declared after the export. + integer x = 456; +endpackage + +module test; + + import P2::x; + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_export_fail6.v b/ivtest/ivltests/sv_export_fail6.v new file mode 100644 index 000000000..c403f51d4 --- /dev/null +++ b/ivtest/ivltests/sv_export_fail6.v @@ -0,0 +1,22 @@ +// Check that an error is reported if trying to export an identifier that is +// declared outside of a package + +integer x = 123; + +package P1; +endpackage + +package P2; + import P1::*; + export P1::x; // This should fail. x is visible in P1, but not declared in P1 +endpackage + +module test; + + import P2::x; + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/regress-sv.list b/ivtest/regress-sv.list index c59386de7..a888672ba 100644 --- a/ivtest/regress-sv.list +++ b/ivtest/regress-sv.list @@ -668,6 +668,18 @@ sv_end_labels normal,-g2009 ivltests sv_end_labels_bad CE,-g2009 ivltests gold=sv_end_labels_bad.gold sv_end_labels_unnamed CE,-g2009 ivltests gold=sv_end_labels_unnamed.gold sv_enum1 normal,-g2009 ivltests +sv_export1 normal,-g2009 ivltests +sv_export2 normal,-g2009 ivltests +sv_export3 normal,-g2009 ivltests +sv_export4 normal,-g2009 ivltests +sv_export5 normal,-g2009 ivltests +sv_export6 normal,-g2009 ivltests +sv_export_fail1 CE,-g2009 ivltests +sv_export_fail2 CE,-g2009 ivltests +sv_export_fail3 CE,-g2009 ivltests +sv_export_fail4 CE,-g2009 ivltests +sv_export_fail5 CE,-g2009 ivltests +sv_export_fail6 CE,-g2009 ivltests sv_for_variable normal,-g2009 ivltests sv_foreach1 normal,-g2009 ivltests sv_foreach2 normal,-g2009 ivltests