Skip to content

Commit 1c73d35

Browse files
committed
emit coverage instance for each concurrent block.
1 parent 72a6e44 commit 1c73d35

13 files changed

+322
-5
lines changed

nvc.1

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,47 @@ to
11031103
.Bd -literal -offset indent
11041104
fold TB_TOP_LIB.TB_TOP.DUT.I_CPU_DATAPATH.I_INSTR_CACHE UNIT_TEST_LIB.CACHE_UNIT_TEST.DUT
11051105
.Ed
1106+
.Ss Code coverage limitations
1107+
When part of the design hierarchy is formed by an if-generate-else or
1108+
case-generate statement, the hierarchical path of implicit block statements
1109+
for each of the if-else branches / case choices is the same unless
1110+
user uses alternative label for the branch or choice. Therefore code
1111+
coverage items in such distinc blocks will have equal hierarchical path.
1112+
Consider following example:
1113+
.Bd -literal -offset indent
1114+
my_gen : case (op_kind) generate
1115+
when op_add => x <= a + b;
1116+
when op_sub => x <= a - b;
1117+
end generate my_gen;
1118+
.Ed
1119+
Both assign statements above have the following hierarchical path:
1120+
.Bd -literal -offset indent
1121+
<PLACE_IN_HIER>.MY_GEN._P0._SO
1122+
.Ed
1123+
When merging code coverage and generating code coverage report, NVC recognizes
1124+
these two coverage items are distinc despite their equal hierarchical path.
1125+
NVC distinguishes these two coverage items based on different location in the
1126+
source code. NVC does not merge such two items, and displays them separately
1127+
in the code coverage items (no aliasing will occur). However, since these two
1128+
coverage items have equal hierarchical paths, it is not possible to distinguish
1129+
them in the exclude file. Either both or none can be excluded.
1130+
Consider another example:
1131+
.Bd -literal -offset indent
1132+
my_gen : case (op_kind) generate
1133+
when op_add => my_inst : entity work.ent
1134+
generic map (op => op_add);
1135+
when op_sub => my_inst : entity work.ent
1136+
generic map (op => op_sub);
1137+
end generate my_gen;
1138+
.Ed
1139+
The two instances will have completely equal hierarchical paths. Since
1140+
they are both implemented by the same entity, all coverage items between
1141+
the two of them will have equal hierarchical paths as well as locations
1142+
in the source code. Coverage data from these two instances will alias
1143+
and NVC will merge them together. To guarantee fine-grained exlude possibility
1144+
or prevent aliasing in corner-cases, it is recommended to use alternative
1145+
labels for branches / choices of if-generage-else and case-generate
1146+
statements.
11061147
.Ss Additional Information
11071148
In coverage specification file and Exclude file
11081149
.Ql <ENTITY_NAME>

src/common.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ bool is_concurrent_block(tree_t t)
695695
case T_BLOCK:
696696
case T_IF_GENERATE:
697697
case T_FOR_GENERATE:
698+
case T_CASE_GENERATE:
698699
return true;
699700
default:
700701
return false;

src/cov/cov-data.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,8 +1007,7 @@ cover_scope_t *cover_create_instance(cover_data_t *data, cover_scope_t *parent,
10071007
parent->name = parent->hier = lib_name(lib_work());
10081008
}
10091009

1010-
// TODO: do not emit scopes for components
1011-
assert(tree_kind(unit) == T_ARCH);
1010+
assert(is_concurrent_block(unit));
10121011
assert(tree_kind(block) == T_BLOCK);
10131012

10141013
cover_scope_t *s = xcalloc(sizeof(cover_scope_t));
@@ -1165,7 +1164,8 @@ static void cover_merge_scope(cover_scope_t *old_s, cover_scope_t *new_s)
11651164
if (n_old_visits == old_s->items.count)
11661165
break;
11671166

1168-
if ((new->hier == old->hier) && (new->flags == old->flags)) {
1167+
if ((new->hier == old->hier) && (new->flags == old->flags) &&
1168+
(loc_eq(&new->loc, &old->loc))) {
11691169
assert(new->kind == old->kind);
11701170
#ifdef COVER_DEBUG_MERGE
11711171
printf("Merging coverage item: %s\n", istr(old->hier));

src/lower.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13262,7 +13262,7 @@ lower_unit_t *lower_instance(unit_registry_t *ur, lower_unit_t *parent,
1326213262
lu->cscope = cover_create_instance(cover, parent->parent->cscope,
1326313263
parent->container, unit);
1326413264
}
13265-
else if (tree_kind(unit) == T_ARCH)
13265+
else if (is_concurrent_block(unit))
1326613266
lu->cscope = cover_create_instance(cover, parent->cscope, block, unit);
1326713267
else
1326813268
lu->cscope = cover_create_scope(cover, parent->cscope, block, NULL);

test/regress/cover27.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
set -xe
2+
3+
nvc -a $TESTDIR/regress/cover27.vhd -e -gG_PAR=0 --cover=statement --cover-file=cover27_a.ncdb cover27 -r
4+
nvc --cover-export --format=xml -o cover27_a.xml cover27_a.ncdb
5+
6+
nvc -a $TESTDIR/regress/cover27.vhd -e -gG_PAR=1 --cover=statement --cover-file=cover27_b.ncdb cover27 -r
7+
nvc --cover-export --format=xml -o cover27_b.xml cover27_b.ncdb
8+
9+
nvc -a $TESTDIR/regress/cover27.vhd -e -gG_PAR=2 --cover=statement --cover-file=cover27_c.ncdb cover27 -r
10+
nvc --cover-export --format=xml -o cover27_c.xml cover27_c.ncdb
11+
12+
nvc -a $TESTDIR/regress/cover27.vhd -e -gG_PAR=3 --cover=statement --cover-file=cover27_d.ncdb cover27 -r
13+
nvc --cover-export --format=xml -o cover27_d.xml cover27_d.ncdb
14+
15+
nvc --cover-merge cover27*.ncdb --output=merged.covdb
16+
nvc --cover-report --output=html merged.covdb 2>&1 | tee out.txt
17+
18+
diff -u $TESTDIR/regress/gold/cover27.txt out.txt
19+
diff -u $TESTDIR/regress/gold/cover27_a.xml cover27_a.xml
20+
diff -u $TESTDIR/regress/gold/cover27_b.xml cover27_b.xml
21+
diff -u $TESTDIR/regress/gold/cover27_c.xml cover27_c.xml
22+
diff -u $TESTDIR/regress/gold/cover27_d.xml cover27_d.xml

test/regress/cover27.vhd

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
library ieee;
2+
use ieee.std_logic_1164.all;
3+
4+
entity cover27 is
5+
generic (
6+
G_PAR : integer
7+
);
8+
end entity;
9+
10+
architecture test of cover27 is
11+
12+
signal a,b,c,d,e,f : std_logic;
13+
signal vec : std_logic_vector(3 downto 0);
14+
15+
begin
16+
17+
G_IF_GEN : if (G_PAR = 0) generate
18+
a <= '0';
19+
elsif (G_PAR = 1) generate
20+
b <= '0';
21+
end generate;
22+
23+
T_FOR_GEN : for i in 0 to 3 generate
24+
vec(i) <= a when (i = 0) else
25+
b when (i = 1) else
26+
c when (i = 2) else
27+
d;
28+
end generate;
29+
30+
G_CASE_GEN : case (G_PAR) generate
31+
when 0 => c <= '1';
32+
when G_CASE_1: 1 => d <= '0';
33+
when G_CASE_2: 2 => e <= '1';
34+
when 3 => f <= '0';
35+
end generate;
36+
37+
end architecture;

test/regress/gold/cover27.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
** Note: Code coverage report folder: html.
2+
** Note: Code coverage report contains: covered, uncovered, excluded coverage details.
3+
** Note: code coverage results for: WORK.COVER27
4+
** Note: statement: 100.0 % (10/10)
5+
** Note: branch: N.A.
6+
** Note: toggle: N.A.
7+
** Note: expression: N.A.
8+
** Note: FSM state: N.A.
9+
** Note: functional: N.A.

test/regress/gold/cover27_a.xml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0"?>
2+
<scope name="WORK" file="../test/regress/cover27.vhd">
3+
<scope name="COVER27" block_name="COVER27-TEST" line="10">
4+
<scope name="G_IF_GEN" block_name="G_IF_GEN" line="17">
5+
<scope name="_P0" line="18">
6+
<scope name="_S0">
7+
<statement hier="WORK.COVER27.G_IF_GEN._P0._S0" data="1"/>
8+
</scope>
9+
</scope>
10+
</scope>
11+
<scope name="T_FOR_GEN(0)" block_name="T_FOR_GEN" line="23">
12+
<scope name="_P0" line="24">
13+
<scope name="_S0">
14+
<scope name="_S0">
15+
<statement hier="WORK.COVER27.T_FOR_GEN(0)._P0._S0._S0" data="2"/>
16+
</scope>
17+
</scope>
18+
</scope>
19+
</scope>
20+
<scope name="T_FOR_GEN(1)" block_name="T_FOR_GEN" line="23">
21+
<scope name="_P0" line="24">
22+
<scope name="_S0">
23+
<scope name="_S0" line="25">
24+
<statement hier="WORK.COVER27.T_FOR_GEN(1)._P0._S0._S0" data="2"/>
25+
</scope>
26+
</scope>
27+
</scope>
28+
</scope>
29+
<scope name="T_FOR_GEN(2)" block_name="T_FOR_GEN" line="23">
30+
<scope name="_P0" line="24">
31+
<scope name="_S0">
32+
<scope name="_S0" line="26">
33+
<statement hier="WORK.COVER27.T_FOR_GEN(2)._P0._S0._S0" data="2"/>
34+
</scope>
35+
</scope>
36+
</scope>
37+
</scope>
38+
<scope name="T_FOR_GEN(3)" block_name="T_FOR_GEN" line="23">
39+
<scope name="_P0" line="24">
40+
<scope name="_S0">
41+
<scope name="_S0" line="27">
42+
<statement hier="WORK.COVER27.T_FOR_GEN(3)._P0._S0._S0" data="2"/>
43+
</scope>
44+
</scope>
45+
</scope>
46+
</scope>
47+
<scope name="G_CASE_GEN" block_name="G_CASE_GEN" line="31">
48+
<scope name="_P0">
49+
<scope name="_S0">
50+
<statement hier="WORK.COVER27.G_CASE_GEN._P0._S0" data="1"/>
51+
</scope>
52+
</scope>
53+
</scope>
54+
</scope>
55+
</scope>

test/regress/gold/cover27_b.xml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0"?>
2+
<scope name="WORK" file="../test/regress/cover27.vhd">
3+
<scope name="COVER27" block_name="COVER27-TEST" line="10">
4+
<scope name="G_IF_GEN" block_name="G_IF_GEN" line="17">
5+
<scope name="_P0" line="20">
6+
<scope name="_S0">
7+
<statement hier="WORK.COVER27.G_IF_GEN._P0._S0" data="1"/>
8+
</scope>
9+
</scope>
10+
</scope>
11+
<scope name="T_FOR_GEN(0)" block_name="T_FOR_GEN" line="23">
12+
<scope name="_P0" line="24">
13+
<scope name="_S0">
14+
<scope name="_S0">
15+
<statement hier="WORK.COVER27.T_FOR_GEN(0)._P0._S0._S0" data="2"/>
16+
</scope>
17+
</scope>
18+
</scope>
19+
</scope>
20+
<scope name="T_FOR_GEN(1)" block_name="T_FOR_GEN" line="23">
21+
<scope name="_P0" line="24">
22+
<scope name="_S0">
23+
<scope name="_S0" line="25">
24+
<statement hier="WORK.COVER27.T_FOR_GEN(1)._P0._S0._S0" data="2"/>
25+
</scope>
26+
</scope>
27+
</scope>
28+
</scope>
29+
<scope name="T_FOR_GEN(2)" block_name="T_FOR_GEN" line="23">
30+
<scope name="_P0" line="24">
31+
<scope name="_S0">
32+
<scope name="_S0" line="26">
33+
<statement hier="WORK.COVER27.T_FOR_GEN(2)._P0._S0._S0" data="2"/>
34+
</scope>
35+
</scope>
36+
</scope>
37+
</scope>
38+
<scope name="T_FOR_GEN(3)" block_name="T_FOR_GEN" line="23">
39+
<scope name="_P0" line="24">
40+
<scope name="_S0">
41+
<scope name="_S0" line="27">
42+
<statement hier="WORK.COVER27.T_FOR_GEN(3)._P0._S0._S0" data="2"/>
43+
</scope>
44+
</scope>
45+
</scope>
46+
</scope>
47+
<scope name="G_CASE_1" block_name="G_CASE_1" line="32">
48+
<scope name="_P0">
49+
<scope name="_S0">
50+
<statement hier="WORK.COVER27.G_CASE_1._P0._S0" data="1"/>
51+
</scope>
52+
</scope>
53+
</scope>
54+
</scope>
55+
</scope>

test/regress/gold/cover27_c.xml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0"?>
2+
<scope name="WORK" file="../test/regress/cover27.vhd">
3+
<scope name="COVER27" block_name="COVER27-TEST" line="10">
4+
<scope name="T_FOR_GEN(0)" block_name="T_FOR_GEN" line="23">
5+
<scope name="_P0" line="24">
6+
<scope name="_S0">
7+
<scope name="_S0">
8+
<statement hier="WORK.COVER27.T_FOR_GEN(0)._P0._S0._S0" data="1"/>
9+
</scope>
10+
</scope>
11+
</scope>
12+
</scope>
13+
<scope name="T_FOR_GEN(1)" block_name="T_FOR_GEN" line="23">
14+
<scope name="_P0" line="24">
15+
<scope name="_S0">
16+
<scope name="_S0" line="25">
17+
<statement hier="WORK.COVER27.T_FOR_GEN(1)._P0._S0._S0" data="1"/>
18+
</scope>
19+
</scope>
20+
</scope>
21+
</scope>
22+
<scope name="T_FOR_GEN(2)" block_name="T_FOR_GEN" line="23">
23+
<scope name="_P0" line="24">
24+
<scope name="_S0">
25+
<scope name="_S0" line="26">
26+
<statement hier="WORK.COVER27.T_FOR_GEN(2)._P0._S0._S0" data="1"/>
27+
</scope>
28+
</scope>
29+
</scope>
30+
</scope>
31+
<scope name="T_FOR_GEN(3)" block_name="T_FOR_GEN" line="23">
32+
<scope name="_P0" line="24">
33+
<scope name="_S0">
34+
<scope name="_S0" line="27">
35+
<statement hier="WORK.COVER27.T_FOR_GEN(3)._P0._S0._S0" data="1"/>
36+
</scope>
37+
</scope>
38+
</scope>
39+
</scope>
40+
<scope name="G_CASE_2" block_name="G_CASE_2" line="33">
41+
<scope name="_P0">
42+
<scope name="_S0">
43+
<statement hier="WORK.COVER27.G_CASE_2._P0._S0" data="1"/>
44+
</scope>
45+
</scope>
46+
</scope>
47+
</scope>
48+
</scope>

test/regress/gold/cover27_d.xml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0"?>
2+
<scope name="WORK" file="../test/regress/cover27.vhd">
3+
<scope name="COVER27" block_name="COVER27-TEST" line="10">
4+
<scope name="T_FOR_GEN(0)" block_name="T_FOR_GEN" line="23">
5+
<scope name="_P0" line="24">
6+
<scope name="_S0">
7+
<scope name="_S0">
8+
<statement hier="WORK.COVER27.T_FOR_GEN(0)._P0._S0._S0" data="1"/>
9+
</scope>
10+
</scope>
11+
</scope>
12+
</scope>
13+
<scope name="T_FOR_GEN(1)" block_name="T_FOR_GEN" line="23">
14+
<scope name="_P0" line="24">
15+
<scope name="_S0">
16+
<scope name="_S0" line="25">
17+
<statement hier="WORK.COVER27.T_FOR_GEN(1)._P0._S0._S0" data="1"/>
18+
</scope>
19+
</scope>
20+
</scope>
21+
</scope>
22+
<scope name="T_FOR_GEN(2)" block_name="T_FOR_GEN" line="23">
23+
<scope name="_P0" line="24">
24+
<scope name="_S0">
25+
<scope name="_S0" line="26">
26+
<statement hier="WORK.COVER27.T_FOR_GEN(2)._P0._S0._S0" data="1"/>
27+
</scope>
28+
</scope>
29+
</scope>
30+
</scope>
31+
<scope name="T_FOR_GEN(3)" block_name="T_FOR_GEN" line="23">
32+
<scope name="_P0" line="24">
33+
<scope name="_S0">
34+
<scope name="_S0" line="27">
35+
<statement hier="WORK.COVER27.T_FOR_GEN(3)._P0._S0._S0" data="1"/>
36+
</scope>
37+
</scope>
38+
</scope>
39+
</scope>
40+
<scope name="G_CASE_GEN" block_name="G_CASE_GEN" line="34">
41+
<scope name="_P0">
42+
<scope name="_S0">
43+
<statement hier="WORK.COVER27.G_CASE_GEN._P0._S0" data="1"/>
44+
</scope>
45+
</scope>
46+
</scope>
47+
</scope>
48+
</scope>

test/regress/gold/issue906.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<toggle hier="WORK.ISSUE906.Y(3).BIN_0_TO_1" data="1"/>
1818
<toggle hier="WORK.ISSUE906.Y(3).BIN_1_TO_0" data="0"/>
1919
</scope>
20-
<scope name="B" line="11">
20+
<scope name="B" block_name="B" line="11">
2121
<scope name="P" line="12">
2222
</scope>
2323
<scope name="Q" line="13">

test/regress/testlist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,3 +1111,4 @@ agg11 normal,2008
11111111
agg12 normal,2008
11121112
agg13 normal,2008
11131113
agg14 normal,2008
1114+
cover27 shell

0 commit comments

Comments
 (0)