Open muneebullashariff opened 8 months ago
https://github.com/svunit/svmock
This section talks about as how to use the SVMock to mock the dependencies to test the uut in isolation. It also shows examples for driver and sequence testing using the pre-defined mocking templates. Furthermore, it talks about writing unit test for coverage groups too Lastly it shows the unit_test for interface and bfm
Went through the SVMock and we should use it for mocking any uvm dependent classes. There are predefined examples as how to verify the uvm_driver, sequence etc using the SVMock and it uses SVUnit as the base so it's a natural step to use SVMock.
Recording my learnings:
VFUNC means has void as the return FUNC means with return
FUNC
First argument is the name of the function Second argument is the return type, if it's non-void Followed by the input arguments. Task is same as void-function
Add the below lines too.
This step can be clubbed with step2 script to make it easy to mimic this type of dependencies.
Also, for frequent mocking dependencies, create the files like done inside
custom_svunit.f
//-parseinfo macro
+incdir+/hwetools/work_area/frontend/muneeb_new/svmock/src
/hwetools/work_area/frontend/muneeb_new/svmock/src/svmock_pkg.sv
runSVUnit -f custom_svunit.f -s questa
Can name it as only svunit.f also for consistency This will allow the runSVUnit to figure out the svmock libraries correctly.
We can even use the below environmental variable to make it easy:
setenv SVMOCK_INSTALL /hwetools/svmock/ Similarly to SVUNIT_INSTALL
Thus, custom_svunit.f file becomes as below:
As shown above, the same function dino has been mapped to 2 different functions, mr_slate and another_mr_slate. This feature allows us to have different implementations for the same function call.
As shown above, while calling the function we need tell which function we are overriding and with new functions (as there are 2 newly mapped functions)
# INFO: [0][bedrock_ut]: rock_quarry_called_instead_pebbles::RUNNING
# ------ test [6] starting ------
# rock_quarry called
# EXPECT_CALL::with_args[0].miscompare bam_bam::barney: (exp:12 act:0)
# ERROR: [0][bedrock_ut]: fail_unless: mock_f.verify() (at /hwetools/work_area/frontend/muneeb_new/test_svmock/bedrock/./bedrock_unit_test.sv line:57)
# INFO: [0][bedrock_ut]: rock_quarry_called_instead_pebbles::FAILED
Experiment 1: The overriding is done, but the old function pebbles is called
As shown above, we are setting the return value for pebbles function as 99 however, we are overriding it with rock_quarry, hence the return value of rock_quarry will be effective, which is Zero
# INFO: [0][bedrock_ut]: rock_quarry_called_with_pebbles_return_value::RUNNING
# ------ test [7] starting ------
# rock_quarry called
# EXPECT_CALL::with_args[0].miscompare bam_bam::barney: (exp:99 act:0)
# ERROR: [0][bedrock_ut]: fail_unless: mock_f.verify() (at /hwetools/work_area/frontend/muneeb_new/test_svmock/bedrock/./bedrock_unit_test.sv line:57)
# INFO: [0][bedrock_ut]: rock_quarry_called_with_pebbles_return_value::FAILED
Experiment 2: Setting the return value for the overridden function - rock_quarry
Even this won't work, because the overridden function is NOT-A-MOCK function, hence the return method won't work.
# INFO: [0][bedrock_ut]: rock_quarry_called_with_pebbles_return_value::RUNNING
# ------ test [7] starting ------
# rock_quarry called
# EXPECT_CALL::with_args[0].miscompare bam_bam::barney: (exp:99 act:0)
# ERROR: [0][bedrock_ut]: fail_unless: mock_f.verify() (at /hwetools/work_area/frontend/muneeb_new/test_svmock/bedrock/./bedrock_unit_test.sv line:57)
# INFO: [0][bedrock_ut]: rock_quarry_called_with_pebbles_return_value::FAILED
# INFO: [0][bedrock_ut]: FAILED (3 of 7 tests passing)
Experiment 3: Only way is to write into the overridden function the return value
# INFO: [0][bedrock_ut]: rock_quarry_called_with_pebbles_return_value::RUNNING
# ------ test [7] starting ------
# rock_quarry called
# INFO: [0][bedrock_ut]: rock_quarry_called_with_pebbles_return_value::PASSED
For interface-class mocking, refer
http://agilesoc.com/2018/07/11/svmock-version-0-1/ pdf file version SVMock Version 0.1 _ AgileSoC.pdf
http://agilesoc.com/2018/07/24/testing-uvm-drivers-without-the-sequencer/ pdf version Testing UVM Drivers (Without The Sequencer) _ AgileSoC.pdf
https://blog.verificationgentleman.com/2016/08/07/testing-uvm-drivers
https://blog.verificationgentleman.com/2016/08/15/testing-uvm-drivers-part-2 https://github.com/verification-gentleman-blog/testing_uvm_drivers_pt2
For more useful macros: https://github.com/tudortimi/vgm_svunit_utils/tree/master
http://agilesoc.com/2018/08/06/unit-testing-uvm-sequences/ Ready made mock for testing uvm-sequences under src/uvm-mock. Unit Testing UVM Sequences _ AgileSoC.pdf
http://agilesoc.com/2012/09/21/svunit-by-example-a-simple-uvm-model/ pdf version SVUnit by Example A Simple UVM Model AgileSoC.pdf
http://agilesoc.com/2012/03/09/uvm-express-step-2-svunit-with-covergroups-and-uvm-agents/ pdf version UVM Express Step 2 SVUnit with Covergroups and UVM Agents AgileSoC.pdf
http://agilesoc.com/2012/02/20/by-example-test-driven-development-of-verification-ip/