From e68a65862d12e244e4211962feb7dab7ac24ece6 Mon Sep 17 00:00:00 2001 From: Tudor Timi Date: Sun, 14 Apr 2019 19:34:25 +0200 Subject: [PATCH] Add possibility to mock interface classes --- src/svmock_defines.svh | 8 ++- test/mocks/mock_interface_class.sv | 13 +++++ test/ut/inteface_class_unit_test.sv | 80 +++++++++++++++++++++++++++++ test/ut/ut_pkg.sv | 1 + 4 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 test/mocks/mock_interface_class.sv create mode 100644 test/ut/inteface_class_unit_test.sv diff --git a/src/svmock_defines.svh b/src/svmock_defines.svh index a14f7ad..5c9764d 100644 --- a/src/svmock_defines.svh +++ b/src/svmock_defines.svh @@ -2,14 +2,18 @@ // MOCK CLASS MACROS //------------------- -`define SVMOCK(MOCK,ORIGINAL=HAS_NO_PARENT) \ +`define SVMOCK(MOCK,ORIGINAL=HAS_NO_PARENT,RELATION=extends) \ `define MOCK``_``ORIGINAL \ +`define MOCK``_``RELATION \ `define MOCKTYPE MOCK``_``ORIGINAL \ +`ifdef MOCK``_implements \ +`define MOCKTYPE_HAS_NO_PARENT \ +`endif \ `ifdef MOCK``_HAS_NO_PARENT \ `define MOCKTYPE_HAS_NO_PARENT \ class MOCK; \ `else \ -class MOCK extends ORIGINAL; \ +class MOCK RELATION ORIGINAL; \ `endif \ typedef MOCK PARENT; \ __mocker __mockers [$]; \ diff --git a/test/mocks/mock_interface_class.sv b/test/mocks/mock_interface_class.sv new file mode 100644 index 0000000..2045c32 --- /dev/null +++ b/test/mocks/mock_interface_class.sv @@ -0,0 +1,13 @@ +interface class some_interface_class; + + pure virtual function void vfunc0; + +endclass + + + +`SVMOCK(mock_interface_class, some_interface_class, implements) + + `SVMOCK_VFUNC0(vfunc0) + +`SVMOCK_END diff --git a/test/ut/inteface_class_unit_test.sv b/test/ut/inteface_class_unit_test.sv new file mode 100644 index 0000000..8bf6c5b --- /dev/null +++ b/test/ut/inteface_class_unit_test.sv @@ -0,0 +1,80 @@ +`include "svunit_defines.svh" +`include "svmock_defines.svh" + +import ut_pkg::*; + +module interface_class_unit_test; + import svunit_pkg::svunit_testcase; + + string name = "interface_class_ut"; + svunit_testcase svunit_ut; + + + //=================================== + // This is the UUT that we're + // running the Unit Tests on + //=================================== + mock_interface_class ut; + + + //=================================== + // Build + //=================================== + function void build(); + svunit_ut = new(name); + + ut = new(/* New arguments if needed */); + endfunction + + + //=================================== + // Setup for running the Unit Tests + //=================================== + task setup(); + svunit_ut.setup(); + /* Place Setup Code Here */ + + ut.clear(); + endtask + + + //=================================== + // Here we deconstruct anything we + // need after running the Unit Tests + //=================================== + task teardown(); + svunit_ut.teardown(); + /* Place Teardown Code Here */ + + endtask + + + //=================================== + // All tests are defined between the + // SVUNIT_TESTS_BEGIN/END macros + // + // Each individual test must be + // defined between `SVTEST(_NAME_) + // `SVTEST_END + // + // i.e. + // `SVTEST(mytest) + // + // `SVTEST_END + //=================================== + `SVUNIT_TESTS_BEGIN + + //----------- + // Functions + //----------- + + `SVTEST(vfunc0) + `EXPECT_CALL(ut, vfunc0).exactly(1); + + ut.vfunc0(); + `FAIL_UNLESS(ut.verify()); + `SVTEST_END + + `SVUNIT_TESTS_END + +endmodule diff --git a/test/ut/ut_pkg.sv b/test/ut/ut_pkg.sv index b4cc832..4e0a1ee 100644 --- a/test/ut/ut_pkg.sv +++ b/test/ut/ut_pkg.sv @@ -8,4 +8,5 @@ package ut_pkg; `include "mock_call.sv" `include "mock_second_no_parent.sv" `include "mock_second.sv" + `include "mock_interface_class.sv" endpackage