// // verilator_coverage annotation // DESCRIPTION: Verilator: Verilog Test module // // This file ONLY is placed under the Creative Commons Public Domain, for // any use, without warranty, 2024 by Wilson Snyder. // SPDX-License-Identifier: CC0-1.0 class cls; rand int x; endclass module t (/*AUTOARG*/ // Inputs clk ); input clk; integer cyc; initial cyc=1; logic [63:32] cyc2; always_comb cyc2 = cyc; integer some_int; integer other_int; logic some_bool; wire t1 = cyc[0]; wire t2 = cyc[1]; wire t3 = cyc[2]; wire t4 = cyc[3]; localparam bit ONE = 1'b1; localparam bit ZERO = 1'b0; function automatic bit invert(bit x); %000005 return ~x; -000004 point: comment=(x==0) => 1 hier=top.t -000005 point: comment=(x==1) => 0 hier=top.t endfunction function automatic bit and_oper(bit a, bit b); %000005 return a & b; -000004 point: comment=(a==0) => 0 hier=top.t -000002 point: comment=(a==1 && b==1) => 1 hier=top.t -000005 point: comment=(b==0) => 0 hier=top.t endfunction localparam int NUM_INTFS = 4; intf the_intfs [NUM_INTFS-1:0] (); genvar intf_i; for (intf_i = 0; intf_i < NUM_INTFS; intf_i++) begin always_comb the_intfs[intf_i].t = cyc[intf_i]; end always @ (posedge clk) begin cyc <= cyc + 1; %000004 if ((~cyc[0] && cyc[1]) || (~cyc[2] && cyc[3])) $write(""); -000002 point: comment=(cyc[0]==0 && cyc[1]==1) => 1 hier=top.t -000002 point: comment=(cyc[0]==1 && cyc[2]==1) => 0 hier=top.t -000004 point: comment=(cyc[0]==1 && cyc[3]==0) => 0 hier=top.t -000002 point: comment=(cyc[1]==0 && cyc[2]==1) => 0 hier=top.t -000003 point: comment=(cyc[1]==0 && cyc[3]==0) => 0 hier=top.t -000002 point: comment=(cyc[2]==0 && cyc[3]==1) => 1 hier=top.t %000004 if ((~cyc2[32] && cyc2[33]) || (~cyc2[34] && cyc2[35])) $write(""); -000002 point: comment=(cyc2[32]==0 && cyc2[33]==1) => 1 hier=top.t -000002 point: comment=(cyc2[32]==1 && cyc2[34]==1) => 0 hier=top.t -000004 point: comment=(cyc2[32]==1 && cyc2[35]==0) => 0 hier=top.t -000002 point: comment=(cyc2[33]==0 && cyc2[34]==1) => 0 hier=top.t -000003 point: comment=(cyc2[33]==0 && cyc2[35]==0) => 0 hier=top.t -000002 point: comment=(cyc2[34]==0 && cyc2[35]==1) => 1 hier=top.t %000004 if ((~the_intfs[0].t && the_intfs[1].t) || (~the_intfs[2].t && the_intfs[3].t)) $write(""); -000002 point: comment=(the_intfs[0].t==0 && the_intfs[1].t==1) => 1 hier=top.t -000002 point: comment=(the_intfs[0].t==1 && the_intfs[2].t==1) => 0 hier=top.t -000004 point: comment=(the_intfs[0].t==1 && the_intfs[3].t==0) => 0 hier=top.t -000002 point: comment=(the_intfs[1].t==0 && the_intfs[2].t==1) => 0 hier=top.t -000003 point: comment=(the_intfs[1].t==0 && the_intfs[3].t==0) => 0 hier=top.t -000002 point: comment=(the_intfs[2].t==0 && the_intfs[3].t==1) => 1 hier=top.t %000004 if ((~t1 && t2) || (~t3 && t4)) $write(""); -000002 point: comment=(t1==0 && t2==1) => 1 hier=top.t -000002 point: comment=(t1==1 && t3==1) => 0 hier=top.t -000004 point: comment=(t1==1 && t4==0) => 0 hier=top.t -000002 point: comment=(t2==0 && t3==1) => 0 hier=top.t -000003 point: comment=(t2==0 && t4==0) => 0 hier=top.t -000002 point: comment=(t3==0 && t4==1) => 1 hier=top.t %000005 if (t3 && (t1 == t2)) $write(""); -000005 point: comment=((t1 == t2)==0) => 0 hier=top.t -000005 point: comment=(t3==0) => 0 hier=top.t -000002 point: comment=(t3==1 && (t1 == t2)==1) => 1 hier=top.t %000005 if (123 == (124 - 32'(t1 || t2))) $write(""); -000002 point: comment=(t1==0 && t2==0) => 0 hier=top.t -000005 point: comment=(t1==1) => 1 hier=top.t -000004 point: comment=(t2==1) => 1 hier=top.t %000004 some_int <= (t2 || t3) ? 345 : 567; -000003 point: comment=(t2==0 && t3==0) => 0 hier=top.t -000004 point: comment=(t2==1) => 1 hier=top.t -000004 point: comment=(t3==1) => 1 hier=top.t %000005 some_bool <= t1 && t2; -000004 point: comment=(t1==0) => 0 hier=top.t -000002 point: comment=(t1==1 && t2==1) => 1 hier=top.t -000005 point: comment=(t2==0) => 0 hier=top.t %000005 if (t1 & t2) $write(""); -000004 point: comment=(t1==0) => 0 hier=top.t -000002 point: comment=(t1==1 && t2==1) => 1 hier=top.t -000005 point: comment=(t2==0) => 0 hier=top.t %000004 if ((!t1 && t2) | (~t3 && t4)) $write(""); -000002 point: comment=(t1==0 && t2==1) => 1 hier=top.t -000002 point: comment=(t1==1 && t3==1) => 0 hier=top.t -000004 point: comment=(t1==1 && t4==0) => 0 hier=top.t -000002 point: comment=(t2==0 && t3==1) => 0 hier=top.t -000003 point: comment=(t2==0 && t4==0) => 0 hier=top.t -000002 point: comment=(t3==0 && t4==1) => 1 hier=top.t %000003 if (t1 ^ t2) $write(""); -000002 point: comment=(t1==0 && t2==0) => 0 hier=top.t -000002 point: comment=(t1==0 && t2==1) => 1 hier=top.t -000003 point: comment=(t1==1 && t2==0) => 1 hier=top.t -000002 point: comment=(t1==1 && t2==1) => 0 hier=top.t %000005 if (~(t1 & t2)) $write(""); -000004 point: comment=(t1==0) => 1 hier=top.t -000002 point: comment=(t1==1 && t2==1) => 0 hier=top.t -000005 point: comment=(t2==0) => 1 hier=top.t %000004 if (t1 -> t2) $write(""); -000004 point: comment=(t1==0) => 1 hier=top.t -000003 point: comment=(t1==1 && t2==0) => 0 hier=top.t -000004 point: comment=(t2==1) => 1 hier=top.t %000003 if (t1 <-> t2) $write(""); -000002 point: comment=(t1==0 && t2==0) => 1 hier=top.t -000002 point: comment=(t1==0 && t2==1) => 0 hier=top.t -000003 point: comment=(t1==1 && t2==0) => 0 hier=top.t -000002 point: comment=(t1==1 && t2==1) => 1 hier=top.t %000005 if (&cyc[2:0]) $write(""); -000004 point: comment=(cyc[2:0][0]==0) => 0 hier=top.t -000001 point: comment=(cyc[2:0][0]==1 && cyc[2:0][1]==1 && cyc[2:0][2]==1) => 1 hier=top.t -000005 point: comment=(cyc[2:0][1]==0) => 0 hier=top.t -000005 point: comment=(cyc[2:0][2]==0) => 0 hier=top.t %000007 if (&cyc[3:2]) $write(""); -000005 point: comment=(cyc[3:2][0]==0) => 0 hier=top.t -000000 point: comment=(cyc[3:2][0]==1 && cyc[3:2][1]==1) => 1 hier=top.t -000007 point: comment=(cyc[3:2][1]==0) => 0 hier=top.t %000005 if (|cyc[2:0]) $write(""); -000001 point: comment=(cyc[2:0][0]==0 && cyc[2:0][1]==0 && cyc[2:0][2]==0) => 0 hier=top.t -000005 point: comment=(cyc[2:0][0]==1) => 1 hier=top.t -000004 point: comment=(cyc[2:0][1]==1) => 1 hier=top.t -000004 point: comment=(cyc[2:0][2]==1) => 1 hier=top.t %000002 if (^cyc[2:0]) $write(""); -000001 point: comment=(cyc[2:0][0]==0 && cyc[2:0][1]==0 && cyc[2:0][2]==0) => 0 hier=top.t -000001 point: comment=(cyc[2:0][0]==0 && cyc[2:0][1]==0 && cyc[2:0][2]==1) => 1 hier=top.t -000001 point: comment=(cyc[2:0][0]==0 && cyc[2:0][1]==1 && cyc[2:0][2]==0) => 1 hier=top.t -000001 point: comment=(cyc[2:0][0]==0 && cyc[2:0][1]==1 && cyc[2:0][2]==1) => 0 hier=top.t -000002 point: comment=(cyc[2:0][0]==1 && cyc[2:0][1]==0 && cyc[2:0][2]==0) => 1 hier=top.t -000001 point: comment=(cyc[2:0][0]==1 && cyc[2:0][1]==0 && cyc[2:0][2]==1) => 0 hier=top.t -000001 point: comment=(cyc[2:0][0]==1 && cyc[2:0][1]==1 && cyc[2:0][2]==0) => 0 hier=top.t -000001 point: comment=(cyc[2:0][0]==1 && cyc[2:0][1]==1 && cyc[2:0][2]==1) => 1 hier=top.t %000005 if (|cyc[2:0] || cyc[3]) $write(""); -000000 point: comment=(cyc[2:0][0]==0 && cyc[2:0][1]==0 && cyc[2:0][2]==0 && cyc[3]==0) => 0 hier=top.t -000005 point: comment=(cyc[2:0][0]==1) => 1 hier=top.t -000004 point: comment=(cyc[2:0][1]==1) => 1 hier=top.t -000004 point: comment=(cyc[2:0][2]==1) => 1 hier=top.t -000002 point: comment=(cyc[3]==1) => 1 hier=top.t %000005 if (t1 & t2 & 1'b1) $write(""); -000000 point: comment=(1'h1==0) => 0 hier=top.t -000004 point: comment=(t1==0) => 0 hier=top.t -000002 point: comment=(t1==1 && t2==1 && 1'h1==1) => 1 hier=top.t -000005 point: comment=(t2==0) => 0 hier=top.t %000009 if (t1 & t2 & 1'b0) $write(""); -000009 point: comment=(1'h0==0) => 0 hier=top.t -000004 point: comment=(t1==0) => 0 hier=top.t -000000 point: comment=(t1==1 && t2==1 && 1'h0==1) => 1 hier=top.t -000005 point: comment=(t2==0) => 0 hier=top.t %000005 if (t1 & t2 & ONE) $write(""); -000000 point: comment=(ONE==0) => 0 hier=top.t -000004 point: comment=(t1==0) => 0 hier=top.t -000002 point: comment=(t1==1 && t2==1 && ONE==1) => 1 hier=top.t -000005 point: comment=(t2==0) => 0 hier=top.t %000009 if (t1 & t2 & ZERO) $write(""); -000009 point: comment=(ZERO==0) => 0 hier=top.t -000004 point: comment=(t1==0) => 0 hier=top.t -000000 point: comment=(t1==1 && t2==1 && ZERO==1) => 1 hier=top.t -000005 point: comment=(t2==0) => 0 hier=top.t %000005 if (t1 && t2) begin -000004 point: comment=(t1==0) => 0 hier=top.t -000002 point: comment=(t1==1 && t2==1) => 1 hier=top.t -000005 point: comment=(t2==0) => 0 hier=top.t $write(""); %000003 end else if (t1 || t2) begin -000002 point: comment=(t1==0 && t2==0) => 0 hier=top.t -000003 point: comment=(t1==1) => 1 hier=top.t -000002 point: comment=(t2==1) => 1 hier=top.t $write(""); end %000005 if (invert(t1) && t2) $write(""); -000005 point: comment=(invert(t1)==0) => 0 hier=top.t -000002 point: comment=(invert(t1)==1 && t2==1) => 1 hier=top.t -000005 point: comment=(t2==0) => 0 hier=top.t if (and_oper(t1, t2)) $write(""); %000005 if (t2 && t3) begin -000005 point: comment=(t2==0) => 0 hier=top.t -000002 point: comment=(t2==1 && t3==1) => 1 hier=top.t -000005 point: comment=(t3==0) => 0 hier=top.t %000001 if (t1 && t2) $write(""); -000001 point: comment=(t1==0) => 0 hier=top.t -000001 point: comment=(t1==1 && t2==1) => 1 hier=top.t -000000 point: comment=(t2==0) => 0 hier=top.t end if (0 == 1) begin for (int loop_var = 0; loop_var < 1; loop_var++) begin %000000 if (cyc[loop_var] && t2) $write(""); -000000 point: comment=(cyc[loop_var[4:0]+:1]==0) => 0 hier=top.t -000000 point: comment=(cyc[loop_var[4:0]+:1]==1 && t2==1) => 1 hier=top.t -000000 point: comment=(t2==0) => 0 hier=top.t end end // stop at the first layer even if there's more to find %000007 if ((cyc[3+32'(t1 && t2)+:2] == cyc[5+32'(t3 || t4)+:2]) || cyc[31]) $write(""); -000002 point: comment=((cyc[(32'sh3 + (t1 && t2))[4:0]+:2] == cyc[(32'sh5 + (t3 || t4))[4:0]+:2])==0 && cyc[31]==0) => 0 hier=top.t -000007 point: comment=((cyc[(32'sh3 + (t1 && t2))[4:0]+:2] == cyc[(32'sh5 + (t3 || t4))[4:0]+:2])==1) => 1 hier=top.t -000000 point: comment=(cyc[31]==1) => 1 hier=top.t // impossible branches and redundant terms %000005 if ((t1 && t2) && ~(t1 && t3) && (t1 || t4)) $write(""); -000003 point: comment=(t1==0 && t4==0) => 0 hier=top.t -000004 point: comment=(t1==0) => 0 hier=top.t -000000 point: comment=(t1==1 && t2==1 && t3==0 && t4==1) => 1 hier=top.t -000001 point: comment=(t1==1 && t2==1 && t3==0) => 1 hier=top.t -000002 point: comment=(t1==1 && t3==1) => 0 hier=top.t -000005 point: comment=(t2==0) => 0 hier=top.t %000005 if ((cyc[0] && cyc[1]) && ~(cyc[0] && cyc[2]) && (cyc[0] || cyc[3])) $write(""); -000003 point: comment=(cyc[0]==0 && cyc[3]==0) => 0 hier=top.t -000004 point: comment=(cyc[0]==0) => 0 hier=top.t -000000 point: comment=(cyc[0]==1 && cyc[1]==1 && cyc[2]==0 && cyc[3]==1) => 1 hier=top.t -000001 point: comment=(cyc[0]==1 && cyc[1]==1 && cyc[2]==0) => 1 hier=top.t -000002 point: comment=(cyc[0]==1 && cyc[2]==1) => 0 hier=top.t -000005 point: comment=(cyc[1]==0) => 0 hier=top.t // demonstrate current limitations of term matching scheme %000005 if ((cyc[0] && cyc[1]) && ~(cyc[1-1] && cyc[2]) && (cyc[2-2] || cyc[3])) $write(""); -000002 point: comment=(cyc[(32'sh1 - 32'sh1)[4:0]+:1]==1 && cyc[2]==1) => 0 hier=top.t -000003 point: comment=(cyc[(32'sh2 - 32'sh2)[4:0]+:1]==0 && cyc[3]==0) => 0 hier=top.t -000004 point: comment=(cyc[0]==0) => 0 hier=top.t -000000 point: comment=(cyc[0]==1 && cyc[1]==1 && cyc[(32'sh1 - 32'sh1)[4:0]+:1]==0 && cyc[(32'sh2 - 32'sh2)[4:0]+:1]==1) => 1 hier=top.t -000000 point: comment=(cyc[0]==1 && cyc[1]==1 && cyc[(32'sh1 - 32'sh1)[4:0]+:1]==0 && cyc[3]==1) => 1 hier=top.t -000001 point: comment=(cyc[0]==1 && cyc[1]==1 && cyc[2]==0 && cyc[(32'sh2 - 32'sh2)[4:0]+:1]==1) => 1 hier=top.t -000000 point: comment=(cyc[0]==1 && cyc[1]==1 && cyc[2]==0 && cyc[3]==1) => 1 hier=top.t -000005 point: comment=(cyc[1]==0) => 0 hier=top.t //verilator coverage_off if (t1 && t2) $write(""); //verilator coverage_on if ((~t1 && t2) %000004 || -000002 point: comment=(t1==0 && t2==1) => 1 hier=top.t -000002 point: comment=(t1==1 && t3==1) => 0 hier=top.t -000004 point: comment=(t1==1 && t4==0) => 0 hier=top.t -000002 point: comment=(t2==0 && t3==1) => 0 hier=top.t -000003 point: comment=(t2==0 && t4==0) => 0 hier=top.t -000002 point: comment=(t3==0 && t4==1) => 1 hier=top.t (~t3 && t4)) $write(""); // intentionally testing wonkified expression terms if ( cyc[ 0 %000005 ] & -000004 point: comment=(cyc[0]==0) => 0 hier=top.t -000002 point: comment=(cyc[0]==1 && cyc[1]==1) => 1 hier=top.t -000005 point: comment=(cyc[1]==0) => 0 hier=top.t cyc [1]) $write(""); // for now each ternary condition is considered in isolation %000005 other_int <= t1 ? t2 ? 1 : 2 : 3; -000004 point: comment=(t1==0) => 0 hier=top.t -000005 point: comment=(t1==1) => 1 hier=top.t // no expression coverage for multi-bit expressions if ((cyc[1:0] & cyc[3:2]) == 2'b11) $write(""); // truth table is too large if (^cyc[6:0]) $write(""); // this one is too big even for t_cover_expr_max if (^cyc) $write(""); if (cyc==9) begin $write("*-* All Finished *-*\n"); $finish; end end always_comb begin %000005 if (t1 && t2) $write(""); -000005 point: comment=(t1==0) => 0 hier=top.t -000002 point: comment=(t1==1 && t2==1) => 1 hier=top.t -000005 point: comment=(t2==0) => 0 hier=top.t end logic ta, tb, tc; initial begin cls obj = new; cls null_obj = null; int q[5]; int qv[$]; q = '{1, 2, 2, 4, 3}; // lambas not handled // NB: there is a bug w/ tracing find_first (maybe lambdas in general?) // tracing_off does not work around the bug qv = q.find_first with (item[0] & item[1]); ta = '1; tb = '0; tc = '0; %000001 while (ta || tb || tc) begin -000001 point: comment=(ta==0 && tb==0 && tc==0) => 0 hier=top.t -000000 point: comment=(ta==1) => 1 hier=top.t -000000 point: comment=(tb==1) => 1 hier=top.t -000000 point: comment=(tc==1) => 1 hier=top.t tc = tb; tb = ta; ta = '0; end if (!bit'(obj.randomize() with {x < 100;})) $write(""); if (null_obj != null && null_obj.x == 5) $write(""); end sub the_sub_1 (.p(t1), .q(t2)); sub the_sub_2 (.p(t3), .q(t4)); // TODO -- non-process expressions sub the_sub_3 (.p(t1 ? t2 : t3), .q(t4)); // TODO // pragma for expr coverage off / on // investigate cover point sorting in annotated source // consider reporting don't care terms // // Branches which are statically impossible to reach are still reported. // E.g. // -000000 point: comment=(t1=1 && t2=1 && 1'h0=1) => 1 hier=top.t // These could potentially be pruned, but they currently follow suit for // what branch coverage does. Perhaps a switch should be added to not // count statically impossible things. endmodule module sub ( input p, input q ); always_comb begin ~000019 if (p && q) $write(""); +000017 point: comment=(p==0) => 0 hier=top.t.the_sub_* -000002 point: comment=(p==1 && q==1) => 1 hier=top.t.the_sub_* +000019 point: comment=(q==0) => 0 hier=top.t.the_sub_* end endmodule interface intf(); logic t; endinterface