2026-06-05 15:35:01 +02:00
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain
// SPDX-FileCopyrightText: 2026 Wilson Snyder
// SPDX-License-Identifier: CC0-1.0
// Test transition bins: simple 2-value, 3-value sequences, array bins,
// and multi-value items in transition steps.
// verilog_format: off
`define stop $stop
`define checkr(gotv,expv) do if ((gotv) != (expv)) begin $write("%%Error: %s:%0d: got=%f exp=%f\n", `__FILE__,`__LINE__, (gotv), (expv)); `stop; end while(0);
// verilog_format: on
module t ;
logic [ 2 : 0 ] state ;
covergroup cg ;
// Simple 2-value transitions
cp_trans2: coverpoint state {
2026-06-06 00:36:55 +02:00
bins trans1 = ( 0 = > 1 ) ; bins trans2 = ( 1 = > 2 ) ; bins trans3 = ( 2 = > 3 ) ;
2026-06-05 15:35:01 +02:00
}
// 3-value sequence transitions
cp_trans3: coverpoint state {
2026-06-06 00:36:55 +02:00
bins seq_a = ( 0 = > 1 = > 2 ) ; bins seq_b = ( 2 = > 3 = > 4 ) ;
2026-06-05 15:35:01 +02:00
}
// Array bins: creates a separate bin per listed transition
cp_array: coverpoint state {
bins arr [ ] = ( 0 = > 1 ) , ( 1 = > 2 ) , ( 2 = > 3 ) ;
}
// Multi-value item (comma list) in transition: matches 1 or 2 in second step
cp_multi_item: coverpoint state {
bins multi = ( 0 = > 1 , 2 ) ; // second element is a two-value list
}
// Repetition-type bins: goto ([->N]) and non-consecutive ([=N]) repetition
cp_reptype: coverpoint state {
2026-06-06 00:36:55 +02:00
bins goto_bin = ( 0 = > 1 [ - > 2 ] ) ; // goto repetition - currently matched as simple (0=>1)
2026-06-05 15:35:01 +02:00
bins noncons_bin = ( 2 [ = 1 ] = > 3 ) ; // non-consecutive repetition - currently matched as simple (2=>3)
}
endgroup
2026-06-12 17:40:48 +02:00
// Non-convertible coverpoint (it has a transition bin) that also carries a value-array bin,
// so the legacy array codegen path (which converted coverpoints bypass) is still exercised.
covergroup cg_legacy ;
cp_mix: coverpoint state {
bins tr = ( 0 = > 1 ) ;
bins vals [ ] = { 2 , [ 4 : 5 ] } ; // discrete + range elements (both legacy array paths)
}
endgroup
2026-06-05 15:35:01 +02:00
cg cg_inst = new ;
2026-06-12 17:40:48 +02:00
cg_legacy cg_legacy_inst = new ;
2026-06-05 15:35:01 +02:00
initial begin
// Drive sequence 0->1->2->3->4 which hits all bins
2026-06-06 00:36:55 +02:00
state = 0 ;
cg_inst . sample ( ) ;
2026-06-05 15:35:01 +02:00
`checkr ( cg_inst . get_inst_coverage ( ) , 0.0 ) ;
2026-06-06 00:36:55 +02:00
state = 1 ;
cg_inst . sample ( ) ; // 0=>1: trans1, seq_a pos1, arr[0=>1], multi
state = 2 ;
cg_inst . sample ( ) ; // 1=>2: trans2, seq_a done, arr[1=>2]
state = 3 ;
cg_inst . sample ( ) ; // 2=>3: trans3, seq_b pos1, arr[2=>3]
state = 4 ;
cg_inst . sample ( ) ; // 3=>4: seq_b done
2026-06-05 15:35:01 +02:00
`checkr ( cg_inst . get_inst_coverage ( ) , 100.0 ) ;
2026-06-12 17:40:48 +02:00
// cg_legacy: exercise legacy array codegen (non-convertible coverpoint)
state = 0 ; cg_legacy_inst . sample ( ) ;
state = 1 ; cg_legacy_inst . sample ( ) ; // 0=>1: tr
state = 2 ; cg_legacy_inst . sample ( ) ; // vals
state = 3 ; cg_legacy_inst . sample ( ) ; // vals
2026-06-05 15:35:01 +02:00
$write ( " *-* All Finished *-* \n " ) ;
$finish ;
end
endmodule