mbits-mirafra / axi4_avip

MIT License
22 stars 23 forks source link

APB Coverage #94

Open mahadevaswamy05 opened 10 months ago

mahadevaswamy05 commented 10 months ago
mahadevaswamy05 commented 10 months ago

-The code is for the coverage uut file

image
apb_coverage

```systemverilog `ifndef __APB_COVERAGE_SV__ `define __APB_COVERAGE_SV__ `include "uvm_macros.svh" `include "apb_xaction.sv" import uvm_pkg::*; class apb_coverage extends uvm_subscriber #(apb_xaction); `uvm_component_utils(apb_coverage) local apb_xaction sampled_obj; covergroup cg; addr_min_cp : coverpoint sampled_obj.addr { bins min = { 0 }; } addr_max_cp : coverpoint sampled_obj.addr { bins max = { 'hfc }; } addr_bins_cp : coverpoint sampled_obj.addr { bins b [16] = { [1:'hf8] }; } data_min_cp : coverpoint sampled_obj.data { bins min = { 0 }; } data_max_cp : coverpoint sampled_obj.data { bins max = { 'hffff_ffff }; } data_bins_cp : coverpoint sampled_obj.data { bins b [32] = { [1:'hffff_fffe] }; } kind_cp : coverpoint sampled_obj.kind; option.per_instance = 1; endgroup; function new(string name = "apb_coverage", uvm_component parent = null); super.new(name, parent); cg = new(); endfunction function void write(apb_xaction t); sampled_obj = t; cg.sample(); endfunction function uvm_sequence_item get_sampled_obj(); return sampled_obj; endfunction endclass `endif ```

mahadevaswamy05 commented 10 months ago

2. -The code is for the coverage unit test template file

apb_coverage_unit_test

```systemverilog `include "svunit_defines.svh" `include "apb_coverage.sv" module apb_coverage_unit_test; import svunit_pkg::svunit_testcase; import svunit_uvm_mock_pkg::*; string name = "apb_coverage_ut"; svunit_testcase svunit_ut; //=================================== // This is the UUT that we're // running the Unit Tests on //=================================== apb_coverage my_apb_coverage; //=================================== // Build //=================================== function void build(); svunit_ut = new(name); my_apb_coverage = new({ name , "::my_apb_coverage" }, null); //----------------------- // deactivate by default //----------------------- svunit_deactivate_uvm_component(my_apb_coverage); endfunction //=================================== // Setup for running the Unit Tests //=================================== task setup(); svunit_ut.setup(); //---------------------- // activate for testing //---------------------- svunit_activate_uvm_component(my_apb_coverage); //--------------------- // 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); 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: write_method /// // verify the write_method sets the // local obj to be sampled and that // the addr_min_cp and data_min_cp are // sampled correctly //------------------------------------- `SVTEST(write_method) apb_xaction a, b; a = apb_xaction::type_id::create(); void'(a.randomize() with { addr == 0; data == 0; kind == WRITE; }); my_apb_coverage.write(a); $cast(b, my_apb_coverage.get_sampled_obj()); `FAIL_IF(!a.compare(b)); //not never same `FAIL_IF(my_apb_coverage.cg.addr_min_cp.get_coverage() != 100); //100 % `FAIL_IF(my_apb_coverage.cg.data_min_cp.get_coverage() != 100); //100 `FAIL_IF(my_apb_coverage.cg.kind_cp.get_coverage() != 50); my_apb_coverage.cg.start(); `SVTEST_END //------------------------------------- // Test: addr_max_cp // // verify the bin for addr == fc //------------------------------------- `SVTEST(addr_max_cp) apb_xaction a; a = apb_xaction::type_id::create(); void'(a.randomize() with { addr == 'hfc; data == 0; kind == WRITE; }); my_apb_coverage.write(a); `FAIL_IF(my_apb_coverage.cg.addr_max_cp.get_coverage() != 100); `SVTEST_END // Test: addr_bins_cp //------------------------------------- // verify 16 bins for addr between // 1 //------------------------------------- // 1:'hf8 `SVTEST(addr_bins_cp) apb_xaction a; a = apb_xaction::type_id::create(); void'(a.randomize() with { addr == 1; data == 0; kind == WRITE; }); my_apb_coverage.write(a); `FAIL_IF($rtoi(my_apb_coverage.cg.addr_bins_cp.get_coverage()) != (100/16)); for (int i=1; i<16; i+=1) begin a.addr += 'hf8/16; my_apb_coverage.write(a); `FAIL_IF($rtoi(my_apb_coverage.cg.addr_bins_cp.get_coverage()) != ((i+1) * 100/16)); end `FAIL_IF(my_apb_coverage.cg.addr_bins_cp.get_coverage() != 100); `SVTEST_END //------------------------------------- // Test: data_max_cp // // verify the bin for data == ffff_ffff //------------------------------------- `SVTEST(data_max_cp) apb_xaction a; a = apb_xaction::type_id::create(); void'(a.randomize() with { data == 'hffff_ffff; kind == WRITE; }); my_apb_coverage.write(a); `FAIL_IF(my_apb_coverage.cg.data_max_cp.get_coverage() != 100); `SVTEST_END //------------------------------------- // Test: data_bins_cp // // verify 32 bins for data between // 1:'hffff_fffe //------------------------------------- `SVTEST(data_bins_cp) apb_xaction a; a = apb_xaction::type_id::create(); void'(a.randomize() with { data == 1; kind == WRITE; }); my_apb_coverage.write(a); `FAIL_IF($rtoi(my_apb_coverage.cg.data_bins_cp.get_coverage()) != (100/32)); for (int i=1; i<32; i+=1) begin a.data += 'hffff_fffe/32; my_apb_coverage.write(a); `FAIL_IF($rtoi(my_apb_coverage.cg.data_bins_cp.get_coverage()) != ((i+1) * 100/32)); end `FAIL_IF(my_apb_coverage.cg.data_bins_cp.get_coverage() != 100); `SVTEST_END //------------------------------------- // Test: kind_cp // // verify the kind for read and write //------------------------------------- `SVTEST(kind_cp) apb_xaction a; my_apb_coverage.cg.kind_cp.start(); a = apb_xaction::type_id::create(); void'(a.randomize() with { kind == READ; } ); my_apb_coverage.write(a); `FAIL_IF(my_apb_coverage.cg.kind_cp.get_coverage() != 100); `SVTEST_END `SVUNIT_TESTS_END endmodule ```

mahadevaswamy05 commented 10 months ago

3 Now we are exploring each test in the apb_coverage_unit_test

  `SVTEST(write_method)
    apb_xaction a, b;

    a = apb_xaction::type_id::create();
    void'(a.randomize() with { addr == 0;
                               data == 0;
                               kind == WRITE;
                             });

    my_apb_coverage.write(a);

    $cast(b, my_apb_coverage.get_sampled_obj());
    `FAIL_IF(!a.compare(b)); //not never same
    `FAIL_IF(my_apb_coverage.cg.addr_min_cp.get_coverage() != 100); //100 %
    `FAIL_IF(my_apb_coverage.cg.data_min_cp.get_coverage() != 100); //100
    `FAIL_IF(my_apb_coverage.cg.kind_cp.get_coverage() != 50);

    my_apb_coverage.cg.start();
  `SVTEST_END

- The below snippet for the uut file coverage code.

data_min_cp :
      coverpoint sampled_obj.data {
        bins min = { 0 };
      }
addr_min_cp :
      coverpoint sampled_obj.addr {
        bins min = { 0 };
      }
kind_cp :
      coverpoint sampled_obj.kind;

- Output for this test

Image

mahadevaswamy05 commented 10 months ago

4. Now we are exploring second test in the apb_coverage_unit_test

`SVTEST(addr_max_cp)
    apb_xaction a;

    a = apb_xaction::type_id::create();
    void'(a.randomize() with { addr == 'hfc;
                               data == 0;
                               kind == WRITE;
                             });

    my_apb_coverage.write(a);

    `FAIL_IF(my_apb_coverage.cg.addr_max_cp.get_coverage() != 100);
    `SVTEST_END

**- Output for this test**
- Using this below command we are running the particular test.

`runSVUnit -uvm -define CLK_PERIOD=5ns --filter apb_coverage_ut.addr_max_cp -s questa
`
- you can see the below test output picture it's getting passed and the address signal value is getting covered.

![image](https://github.com/mbits-mirafra/axi4_avip/assets/106074838/3133445a-4217-468d-8939-e7cc10e289f9)
mahadevaswamy05 commented 10 months ago

5. Now we are exploring the third test in the apb_coverage_unit_test

 addr_bins_cp :
      coverpoint sampled_obj.addr {
        bins b [16] = { [1:'hf8] };
      }

runSVUnit -uvm -define CLK_PERIOD=5ns --filter apb_coverage_ut.addr_bins_cpi -s questa

image

mahadevaswamy05 commented 10 months ago

6.. Now we are exploring the fourth test in the apb_coverage_unit_test

 `SVTEST(data_max_cp)
    apb_xaction a;

    a = apb_xaction::type_id::create();
    void'(a.randomize() with { data == 'hffff_ffff;
                               kind == WRITE;
                             });

    my_apb_coverage.write(a);

    `FAIL_IF(my_apb_coverage.cg.data_max_cp.get_coverage() != 100);

  `SVTEST_END

- The below snippet for the uut file coverage code

 data_max_cp :
      coverpoint sampled_obj.data {
        bins max = { 'hffff_ffff };
      }

runSVUnit -uvm -define CLK_PERIOD=5ns --filter apb_coverage_ut.data_max_cp -s questa

image

mahadevaswamy05 commented 10 months ago
  1. Now we are exploring the fifth test in the apb_coverage_unit_test it's about read.
`SVTEST(kind_cp)
    apb_xaction a;

    my_apb_coverage.cg.kind_cp.start();

    a = apb_xaction::type_id::create();
    void'(a.randomize() with { kind == READ; } );

    my_apb_coverage.write(a);

    `FAIL_IF(my_apb_coverage.cg.kind_cp.get_coverage() != 50);

  `SVTEST_END
  kind_cp :
 coverpoint sampled_obj.kind;

- Using the below command we are running the particular test.

runSVUnit -uvm -define CLK_PERIOD=5ns --filter apb_coverage_ut.kind_cp -s questa

image

mahadevaswamy05 commented 10 months ago

-8. Using the below command we are the running the all test

runSVUnit -uvm -define CLK_PERIOD=5ns -s questa