Open mahadevaswamy05 opened 10 months ago
-The code is for the coverage uut file
cg.sample();
```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 ```
2. -The code is for the coverage unit test template file
```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)
//
3 Now we are exploring each test in the apb_coverage_unit_test
apb_xaction a, b;
data = 0, addr = 0, kind = write
.apb_coverage my_apb_coverage.
a
transaction_handle, for example, my_apb_coverage.write(a);
b
. a
is equal to b
or not, if a
is not equal to b
then the test will fail. because we are using FAIL_IF(!a.compare(b));
but Here a
and b
are the same that's why, the test will set the status as passed. FAIL_IF(my_apb_coverage.cg.addr_min_cp.get_coverage() != 100);
is False because we are checking !=100
but it's equal to 100% that's why the test will set the status as passed. FAIL_IF(my_apb_coverage.cg.data_min_cp.get_coverage() != 100);
is False because we are checking !=100
but it's equal to 100% that's why the test will set the status as passed. FAIL_IF(my_apb_coverage.cg.kind_cp.get_coverage() != 50);
are checking !=50
but it's equal to 50% that's why the test will set the status as passed. start
method. `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
Using this below command we are running the particular test.
runSVUnit -uvm -define CLK_PERIOD=5ns --filter apb_coverage_ut.write_method -s questa
you can see the below test is getting passed and all values are getting covered.
4. Now we are exploring second test in the apb_coverage_unit_test
addr = 'hfc
, data = 0
, kind = write.`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
'hfc
addr_max_cp :
coverpoint sampled_obj.addr {
bins max = { 'hfc };
}
**- 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)
5. Now we are exploring the third test in the apb_coverage_unit_test
$rtoi
converts real values to an integer type by truncating the real value (for example,123.45 becomes 123)In the last FAIL_IF condition we are checking address signals coverage, Here
given the condition FAIL_IF(my_apb_coverage.cg.addr_bins_cp.get_coverage() != 100);
is False because we are checking !=100 but it's equal to 100% that's why the test will set the status as passed.
`SVTEST(addr_bins_cpi)
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
- The below snippet for the uut file coverage code
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
6.. Now we are exploring the fourth test in the apb_coverage_unit_test
apb_xaction a
data = 'hffff_ffff
, kind == WRITE
;a
transaction_handle, for example, my_apb_coverage.write(a);FAIL_IF(my_apb_coverage.cg.data_max_cp.get_coverage() != 100);
is False because we are checking !=100 but it's equal to 100% that's why the test will set the status as passed. `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
a
transaction_handle, for example, my_apb_coverage.write(a);FAIL_IF(my_apb_coverage.cg.kind_cp.get_coverage() != 50);
is False because we are checking !=50
but it's equal to 50
% that's why the test will set the status as passed.`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
-8. Using the below command we are the running the all test
runSVUnit -uvm -define CLK_PERIOD=5ns -s questa