Skip to content

Commit

Permalink
Add regression tests for binding task/function arguments by name
Browse files Browse the repository at this point in the history
Check that binding task and function arguments by name works as expected.
Also check that is works for the various variations of invoking a class
constructor.

Signed-off-by: Lars-Peter Clausen <[email protected]>
  • Loading branch information
larsclausen committed Aug 20, 2023
1 parent f6a51bc commit 250c456
Show file tree
Hide file tree
Showing 80 changed files with 1,009 additions and 0 deletions.
25 changes: 25 additions & 0 deletions ivtest/ivltests/sv_named_arg_base1.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Check that binding task arguments by name is supported.

module test;

class B;
integer val;

function new(integer a, integer b);
val = a + b * 10;
endfunction
endclass

class C extends B(.b(2), .a(1));
endclass

initial begin
C c;
c = new;
if (c.val == 21) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule
26 changes: 26 additions & 0 deletions ivtest/ivltests/sv_named_arg_base2.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Check that binding task arguments by name is supported and that a mix of
// positional and named arguments is supported.

module test;

class B;
integer val;

function new(integer a, integer b, integer c);
val = a + b * 10 + c * 100;
endfunction
endclass

class C extends B(1, .c(3), .b(2));
endclass

initial begin
C c;
c = new;
if (c.val == 321) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule
27 changes: 27 additions & 0 deletions ivtest/ivltests/sv_named_arg_base3.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Check that binding task arguments by name is supported and that an empty
// value can be bound to the name, in which case the default argument value
// should be used.

module test;

class B;
integer val;

function new(integer a, integer b = 2);
val = a + b * 10;
endfunction
endclass

class C extends B(.a(1), .b());
endclass

initial begin
C c;
c = new;
if (c.val == 21) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule
21 changes: 21 additions & 0 deletions ivtest/ivltests/sv_named_arg_base_fail1.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Check that an error is reported when trying to bind an argument by nae that
// does not exist

module test;

class B;
function new(integer a, integer b);
$display("FAILED");
endfunction
endclass

class C extends B(.b(2), .c(1)); // This should fail. `c` is not an arugment
// of the base constructor.
endclass

initial begin
C c;
c = new;
end

endmodule
21 changes: 21 additions & 0 deletions ivtest/ivltests/sv_named_arg_base_fail2.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Check that an error is reported when trying to bind the same argument by name
// multiple times.

module test;

class B;
function new(integer a, integer b);
$display("FAILED");
endfunction
endclass

class C extends B(.a(1), .a(2)); // This should fail. `a` is provided twice
// as a named argument.
endclass

initial begin
C c;
c = new;
end

endmodule
21 changes: 21 additions & 0 deletions ivtest/ivltests/sv_named_arg_base_fail3.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Check that an error is reported when trying to bind an argument by name that
// is also provided as a positional argument.

module test;

class B;
function new(integer a, integer b);
$display("FAILED");
endfunction
endclass

class C extends B(1, .a(2)); // This should fail. `a` is provided both as a
// positional and named argument.
endclass

initial begin
C c;
c = new;
end

endmodule
21 changes: 21 additions & 0 deletions ivtest/ivltests/sv_named_arg_base_fail4.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Check that an error is reported trying to provide a positional argument to a
// function after a named argument.

module test;

class B;
function new(integer a, integer b);
$display("FAILED");
endfunction
endclass

class C extends B(.a(2), 1); // This should fail. Positional arguments must
// precede named arguments.
endclass

initial begin
C c;
c = new;
end

endmodule
20 changes: 20 additions & 0 deletions ivtest/ivltests/sv_named_arg_base_fail5.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Check that an error is reported when binding an empty value to an argument by
// name and the argument does not have a default value.

module test;

class B;
function new(integer a);
$display("FAILED");
endfunction
endclass

class C extends B(.a()); // This should fail. `a` has no default value.
endclass

initial begin
C c;
c = new;
end

endmodule
28 changes: 28 additions & 0 deletions ivtest/ivltests/sv_named_arg_chained1.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Check that binding task arguments by name is supported.

module test;

class B;
integer val;

function new(integer a, integer b);
val = a + b * 10;
endfunction
endclass

class C extends B;
function new;
super.new(.b(2), .a(1));
endfunction
endclass

initial begin
C c;
c = new;
if (c.val == 21) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule
29 changes: 29 additions & 0 deletions ivtest/ivltests/sv_named_arg_chained2.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Check that binding task arguments by name is supported and that a mix of
// positional and named arguments is supported.

module test;

class B;
integer val;

function new(integer a, integer b, integer c);
val = a + b * 10 + c * 100;
endfunction
endclass

class C extends B;
function new;
super.new(1, .c(3), .b(2));
endfunction
endclass

initial begin
C c;
c = new;
if (c.val == 321) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule
30 changes: 30 additions & 0 deletions ivtest/ivltests/sv_named_arg_chained3.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Check that binding task arguments by name is supported and that an empty
// value can be bound to the name, in which case the default argument value
// should be used.

module test;

class B;
integer val;

function new(integer a, integer b = 2);
val = a + b * 10;
endfunction
endclass

class C extends B;
function new;
super.new(.a(1), .b());
endfunction
endclass

initial begin
C c;
c = new;
if (c.val == 21) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule
24 changes: 24 additions & 0 deletions ivtest/ivltests/sv_named_arg_chained_fail1.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Check that an error is reported when trying to bind an argument by nae that
// does not exist

module test;

class B;
function new(integer a, integer b);
$display("FAILED");
endfunction
endclass

class C extends B;
function new;
super.new(.b(2), .c(1)); // This should fail. `c` is not an arugment of
// the base constructor.
endfunction
endclass

initial begin
C c;
c = new;
end

endmodule
24 changes: 24 additions & 0 deletions ivtest/ivltests/sv_named_arg_chained_fail2.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Check that an error is reported when trying to bind the same argument by name
// multiple times.

module test;

class B;
function new(integer a, integer b);
$display("FAILED");
endfunction
endclass

class C extends B;
function new;
super.new(.a(1), .a(2)); // This should fail. `a` is provided twice as a
// named argument.
endfunction
endclass

initial begin
C c;
c = new;
end

endmodule
24 changes: 24 additions & 0 deletions ivtest/ivltests/sv_named_arg_chained_fail3.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Check that an error is reported when trying to bind an argument by name that
// is also provided as a positional argument.

module test;

class B;
function new(integer a, integer b);
$display("FAILED");
endfunction
endclass

class C extends B;
function new;
super.new(1, .a(2)); // This should fail. `a` is provided both as a
// positional and named argument.
endfunction
endclass

initial begin
C c;
c = new;
end

endmodule
24 changes: 24 additions & 0 deletions ivtest/ivltests/sv_named_arg_chained_fail4.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Check that an error is reported trying to provide a positional argument to a
// function after a named argument.

module test;

class B;
function new(integer a, integer b);
$display("FAILED");
endfunction
endclass

class C extends B;
function new;
super.new(.a(2), 1); // This should fail. Positional arguments must
// precede named arguments.
endfunction
endclass

initial begin
C c;
c = new;
end

endmodule
Loading

0 comments on commit 250c456

Please sign in to comment.