mbits-mirafra / axi4_avip

MIT License
22 stars 25 forks source link

APB Agent #93

Open mahadevaswamy05 opened 1 year ago

mahadevaswamy05 commented 1 year ago
mahadevaswamy05 commented 1 year ago

1 Here is the uut file for the APB_AGENT file

APB_AGENT

class apb_coverage_agent extends uvm_agent; ```systemverilog `ifndef __APB_COVERAGE_AGENT_SV__ `define __APB_COVERAGE_AGENT_SV__ `include "uvm_macros.svh" `include "apb_mon.sv" `include "apb_coverage.sv" import uvm_pkg::*; class apb_coverage_agent extends uvm_agent; `uvm_component_utils(apb_coverage_agent) virtual apb_if.passive_slv bfm; apb_mon monitor; apb_coverage coverage; function new(string name = "apb_coverage_agent", uvm_component parent = null); super.new(name, parent); endfunction function void build_phase(uvm_phase phase); if( !uvm_config_db#(virtual apb_if.passive_slv)::get( this, "", "bfm", bfm)) begin `uvm_fatal("ENV", "BFM not set") end monitor = apb_mon#(8,32)::type_id::create({ get_name() , "::monitor" }, this); coverage = apb_coverage::type_id::create({ get_name() , "::coverage" }, this); endfunction function void connect_phase(uvm_phase phase); monitor.bfm = bfm; monitor.ap.connect(coverage.analysis_export); endfunction endclass `endif ```

mahadevaswamy05 commented 1 year ago
APB_AGENT_UNIT_TEST_file

```systemverilog `include "svunit_defines.svh" `include "apb_coverage_agent.sv" `include "apb_if.sv" module apb_coverage_agent_unit_test; import svunit_pkg::svunit_testcase; import svunit_uvm_mock_pkg::*; string name = "apb_coverage_agent_ut"; svunit_testcase svunit_ut; logic clk; initial begin clk = 1; forever #`CLK_PERIOD clk = ~clk; end apb_if bfm(.clk(clk)); virtual apb_if.mstr bfm_mstr; //=================================== // This is the UUT that we're // running the Unit Tests on //=================================== apb_coverage_agent my_apb_coverage_agent; //=================================== // Build //=================================== function void build(); svunit_ut = new(name); bfm_mstr = bfm; my_apb_coverage_agent = new({ name , "::my_apb_coverage_agent" }, null); uvm_config_db#(virtual apb_if.passive_slv):: set( uvm_root::get(), { name , "::my_apb_coverage_agent" }, "bfm", bfm); //----------------------- // deactivate by default //----------------------- svunit_deactivate_uvm_component(my_apb_coverage_agent); endfunction //=================================== // Setup for running the Unit Tests //=================================== task setup(); svunit_ut.setup(); //---------------------- // activate for testing //---------------------- svunit_activate_uvm_component(my_apb_coverage_agent); bfm_mstr.async_reset(); //--------------------- // start the component //--------------------- svunit_uvm_test_start(); endtask //=================================== // Here we deconstruct anything we // need after running the Unit Tests //=================================== task teardown(); svunit_ut.teardown(); //-------------------- // stop the component //-------------------- svunit_uvm_test_finish(); //--------------------------------------- // deactivate at the end of unit testing //--------------------------------------- svunit_deactivate_uvm_component(my_apb_coverage_agent); 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 //------------------------------------- // Test: members_not_null // // verify the bfm, monitor and coverage // are all present //------------------------------------- `SVTEST(members_not_null) `FAIL_IF(my_apb_coverage_agent.bfm == null); `FAIL_IF(my_apb_coverage_agent.monitor == null); `FAIL_IF(my_apb_coverage_agent.coverage == null); `FAIL_IF(my_apb_coverage_agent.monitor.bfm == null); `SVTEST_END //--------------------------------------- // Test: connectivity // // do a write and make sure the coverage // model is sampled properly //--------------------------------------- `SVTEST(connectivity) `FAIL_IF(my_apb_coverage_agent.coverage.cg.kind_cp.get_coverage() != 0); `FAIL_IF(my_apb_coverage_agent.coverage.cg.addr_max_cp.get_coverage() != 0); `FAIL_IF(my_apb_coverage_agent.coverage.cg.data_min_cp.get_coverage() != 0); bfm_mstr.write('hfc, 0); // NOTE: for some reason, the coverage stats for kind_cp with vcs aren't // returned properly. that's why I have this commented out. //`FAIL_IF(my_apb_coverage_agent.coverage.cg.kind_cp.get_coverage() != 50); `FAIL_IF(my_apb_coverage_agent.coverage.cg.addr_max_cp.get_coverage() != 100); `FAIL_IF(my_apb_coverage_agent.coverage.cg.data_min_cp.get_coverage() != 100); `SVTEST_END `SVUNIT_TESTS_END endmodule

mahadevaswamy05 commented 1 year ago

3. Using this below command we are running the code runSVUnit -uvm -define CLK_PERIOD=5ns -s questa

mahadevaswamy05 commented 1 year ago

4. We are exploring the first test now which present in the unit test template file

`SVTEST(members_not_null)

    `FAIL_IF(my_apb_coverage_agent.bfm == null);
    `FAIL_IF(my_apb_coverage_agent.monitor == null);
    `FAIL_IF(my_apb_coverage_agent.coverage == null);
    `FAIL_IF(my_apb_coverage_agent.monitor.bfm == null);

  `SVTEST_END
mahadevaswamy05 commented 1 year ago

5. Secondly, we are exploring the second test it's about the write method.

 `SVTEST(connectivity)

    `FAIL_IF(my_apb_coverage_agent.coverage.cg.kind_cp.get_coverage() != 0);
    `FAIL_IF(my_apb_coverage_agent.coverage.cg.addr_max_cp.get_coverage() != 0);
    `FAIL_IF(my_apb_coverage_agent.coverage.cg.data_min_cp.get_coverage() != 0);

    bfm_mstr.write('hfc, 0);

    // NOTE: for some reason, the coverage stats for kind_cp with vcs aren't
    //       returned properly. that's why I have this commented out.
    //`FAIL_IF(my_apb_coverage_agent.coverage.cg.kind_cp.get_coverage() != 50);
    `FAIL_IF(my_apb_coverage_agent.coverage.cg.addr_max_cp.get_coverage() != 100);
    `FAIL_IF(my_apb_coverage_agent.coverage.cg.data_min_cp.get_coverage() != 100);

  `SVTEST_END
muneebullashariff commented 1 year ago

This example shows as how we can even perform the connectivity checks.