Add regression test for return in tasks

Check support for using the return statement in a task.
 * That it is possible to exit form a task using the `return` statement
   without affecting other concurrently running instances of the same task
 * That it is possible to use return in a named block in a task
 * That using a return value in a task results in a elaboration error
 * Returning from inside a parallel block in a task results in a
   elaboration error

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-02-06 15:27:24 +01:00
parent 730c9c28b2
commit d1aecf452c
9 changed files with 110 additions and 0 deletions

View File

@ -0,0 +1,31 @@
// Check that it is possible to exit from a task using the return statement with
// affecting other concurrently running instances of the same task.
module test;
task automatic t(input integer a, output integer b);
if (a == 0) begin
b = 1;
return;
end
#10
b = 100;
endtask
integer b1;
integer b2;
initial begin
fork
t(0, b1);
t(1, b2);
join
if (b1 == 1 && b2 == 100) begin
$display("PASSED");
end else begin
$display("FAILED b1=%0d, b2=%0d", b1, b2);
end
end
endmodule

View File

@ -0,0 +1,22 @@
// Check that it is possible to return from a named sub-block of a task using a
// `return` statement.
module test;
task t(input integer a);
begin : subblock
if (a == 1) begin : condition
return;
end
end
$display("FAILED");
$finish;
endtask
initial begin
t(1);
#10
$display("PASSED");
end
endmodule

View File

@ -0,0 +1,15 @@
// Check that using a return value when using the return statement in a task
// results in an error.
module test;
task t;
return 10; // This is an error, tasks can not have return values.
endtask
initial begin
t();
$display("FAILED");
end
endmodule

View File

@ -0,0 +1,18 @@
// Check that using a return statment inside a parallel block in a task results
// in an error.
module test;
task t;
fork
// This is an error it is not possible to return from inside a parallel block
return;
join
endtask
initial begin
t();
$display("FAILED");
end
endmodule

View File

@ -36,3 +36,7 @@ struct_packed_write_read2 vvp_tests/struct_packed_write_read2.json
sv_foreach9 vvp_tests/sv_foreach9.json
sv_foreach10 vvp_tests/sv_foreach10.json
sdf_header vvp_tests/sdf_header.json
task_return1 vvp_tests/task_return1.json
task_return2 vvp_tests/task_return2.json
task_return_fail1 vvp_tests/task_return_fail1.json
task_return_fail2 vvp_tests/task_return_fail2.json

View File

@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "task_return1.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "task_return2.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "task_return_fail1.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "task_return_fail2.v",
"iverilog-args" : [ "-g2005-sv" ]
}