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 <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-10-03 23:27:55 +02:00
parent 78382e72d0
commit d868983b9c
13 changed files with 298 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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