<- Click here to Toggle

Home » Resources » SystemVerilog Coverage API » Real Time Coverage Access

SystemVerilog Coverage API - Real Time Coverage Access

This section describes the mechanisms through which SystemVerilog code can query and control coverage information. Coverage information is provided by means of a number of built-in system functions using a number of predefined constants to describe the types of coverage and the control actions to be performed.

Predefined coverage constants in SystemVerilog

The following predefined ‘define s represent basic real-time coverage capabilities accessible directly from SystemVerilog.

*)Coverage control
‘define SV_COV_START 0
‘define SV_COV_STOP 1
‘define SV_COV_RESET 2
‘define SV_COV_CHECK 3

*)Scope definition (hierarchy traversal/accumulation type)
‘define SV_COV_MODULE 10
‘define SV_COV_HIER 11

*)Coverage type identification
‘define SV_COV_ASSERTION 20
‘define SV_COV_FSM_STATE 21

*) Status results
‘define SV_COV_OVERFLOW -2
‘define SV_COV_ERROR -1

Built-in coverage access system functions

$coverage_control

$coverage_control(control_constant,
coverage_type,
scope_def,
modules_or_instance)

This function is used to control or query coverage availability in the specified portion of the hierarchy. The following control options are available:

‘SV_COV_START

If possible, starts collecting coverage information in the specified hierarchy. No effect if coverage is already being collected.

‘SV_COV_STOP

Stops collecting coverage information in the specified hierarchy. No effect if coverage is not being collected.

‘SV_COV_RESET

Resets all available coverage information in the specified hierarchy. No effect if coverage not available.

‘SV_COV_CHECK

Checks if coverage information can be obtained from the specified hierarchy. Note the possibility of having coverage information does imply that coverage is being collected, as the coverage could have been stopped.

he return value is a ‘define name, with the value indicating the success of the action.

‘SV_COV_OK

On a check operation denotes that coverage is fully available in the specified hierarchy.

‘SV_COV_ERROR

On all operations means that the control operation failed without any effect, typically due to errors in arguments, such as a non-existing module.

‘SV_COV_NOCOV

On a check or start operation, denotes that coverage is not available at any point in the specified hierarchy.

‘SV_COV_PARTIAL

On a check or start operation, denotes that coverage is only partially available in the specified hierarchy.

The hierarchies being controlled or queried are specified as follows.

‘SV_MODULE_COV, "unique module def name"

Provides coverage of all instances of the given module (the unique module name is a string), excluding any child instances in the instances of the given module.

‘SV_COV_HIER, "module name"

provides coverage of all instances of the given module, including all the hierarchy below

If coverage is enabled on all instances

$coverage_control(‘SV_COV_CHECK, ‘SV_COV_TOGGLE, ‘SV_COV_HIER, $root)

Checks all instances to verify they have coverage and, in this case, returns ‘SV_COV_OK.

$coverage_control(‘SV_COV_RESET, ‘SV_COV_TOGGLE, ‘SV_COV_MODULE, "DUT")

Resets coverage collection on both instances of the DUT, specifically, $root.tb.unit1 and

$root.tb.unit2, but leaves coverage unaffected in all other instances.

$coverage_control(‘SV_COV_RESET, ‘SV_COV_TOGGLE, ‘SV_COV_MODULE, "DUT")

Resets coverage collection on both instances of the DUT, specifically, $root.tb.unit1 and

$root.tb.unit2, but leaves coverage unaffected in all other instances.

$coverage_control(‘SV_COV_START, ‘SV_COV_TOGGLE, ‘SV_COV_HIER, "DUT")

Starts coverage on all instances of the module DUT and of all hierarchy(ies) below those instances. In this design, coverage is started for the instances $root.tb.unit1, $root.tb.unit1.comp , $root.tb.unit1.ctrl , $root.tb.unit2 , $root.tb.unit2.comp , and $root.tb.unit2.ctrl .

$coverage_get_max

$coverage_get_max(coverage_type, scope_def, modules_or_instance)

This function obtains the value representing 100% coverage for the specified coverage type over the specified portion of the hierarchy. This value shall remain constant across the duration of the simulation.

The return value is an integer, with the following meanings.

-2 (‘SV_COV_OVERFLOW)

The value exceeds a number that can be represented as an integer.

The return value is an integer, with the following meanings.

-2 (‘SV_COV_OVERFLOW)

The value exceeds a number that can be represented as an integer.

0 (‘SV_COV_NOCOV)

No coverage is available for that coverage type on that/those hierarchy(ies).

+pos_num

The maximum coverage number (where pos_num > 0), which is the sum of all coverable items of that

type over the given hierarchy(ies).