Task based verification is more flexible over all the above approaches. All the operations in are done using takes and functions. The task based BFM is extremely efficient if the device under test performs many calculations. Each task or function focuses on one single functionality. Verification of DUT using the task based testbench is faster. Using tasks makes it possible to describe structural testbenchs. These tasks can be ported without much effort.
EXAMPLE: task write(inputinteger data,inputinteger address);
begin @(posedge clock);
read_write = 1;
address = $random;
data = $random;
end endtask
task read(inputinteger address,outputinteger data);
begin @(posedge clock);
read_write = 0;
address = $random;
// Do some operation to get data
end endtask
Now lets see how to develop the senarious.
1) 10 write operations.
initial repeat(10)
write($random,$random);
2) 10 read operations
initial repeat(10)
read($random,data);
3) Alternate read and write operations.
initial repeat(10)
begin write($random,$random);
read($random,data);
end