From 575349b17bccb07eb104ac9c1287b21455107012 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 14 Apr 2024 16:47:36 +0100 Subject: [PATCH] If/case statements do not count for statement coverage --- src/cov/cov-data.c | 4 +--- src/cov/cov-export.c | 1 + test/questa.sh | 7 ++++--- test/regress/gold/cover1.txt | 2 +- test/regress/gold/cover15.txt | 2 +- test/regress/gold/cover21.txt | 2 +- test/regress/gold/cover5.txt | 10 +++++----- test/regress/gold/cover9.txt | 12 +----------- test/test_lower.c | 15 +++++++-------- 9 files changed, 22 insertions(+), 33 deletions(-) diff --git a/src/cov/cov-data.c b/src/cov/cov-data.c index 72f4af35..5d167f3e 100644 --- a/src/cov/cov-data.c +++ b/src/cov/cov-data.c @@ -63,7 +63,6 @@ static const struct { bool cover_is_stmt(tree_t t) { switch (tree_kind(t)) { - case T_IF: case T_WHILE: case T_NEXT: case T_EXIT: @@ -73,8 +72,7 @@ bool cover_is_stmt(tree_t t) case T_RETURN: case T_FOR: case T_PCALL: - case T_FCALL: - case T_CASE: + case T_PROT_PCALL: return true; // Static waits are introduced during simp pass. These are hidden diff --git a/src/cov/cov-export.c b/src/cov/cov-export.c index 0a66c7a3..360c68ba 100644 --- a/src/cov/cov-export.c +++ b/src/cov/cov-export.c @@ -126,6 +126,7 @@ static void cobertura_export_scope(cobertura_report_t *report, { cobertura_line_t *l = cobertura_get_line(class, &(t->loc)); l->branch = true; + l->hits += t->data; if (t->data > 0) l->bflags |= t->flags; } diff --git a/test/questa.sh b/test/questa.sh index c89777b4..f39d89b3 100755 --- a/test/questa.sh +++ b/test/questa.sh @@ -1,4 +1,4 @@ -#!/bin/sh -ex +#!/bin/bash -ex vlib work @@ -6,8 +6,9 @@ root=$(git rev-parse --show-toplevel) regress=$root/test/regress plusopt=+acc vsimopt= +cover=false -if false; then +if $cover; then plusopt+=" +cover" vsimopt+=" -coverage" fi @@ -22,7 +23,7 @@ fi rm -f /tmp/questa.do -if false; then +if $cover; then echo "coverage save -onexit $1.ucdb" >>/tmp/questa.do fi diff --git a/test/regress/gold/cover1.txt b/test/regress/gold/cover1.txt index 1ccf429d..539d8441 100644 --- a/test/regress/gold/cover1.txt +++ b/test/regress/gold/cover1.txt @@ -1,5 +1,5 @@ ** Note: code coverage results for: WORK.COVER1 -** Note: statement: 97.7 % (42/43) +** Note: statement: 97.3 % (36/37) ** Note: branch: N.A. ** Note: toggle: N.A. ** Note: expression: N.A. diff --git a/test/regress/gold/cover15.txt b/test/regress/gold/cover15.txt index 6a4b32dd..d9422e51 100644 --- a/test/regress/gold/cover15.txt +++ b/test/regress/gold/cover15.txt @@ -1,7 +1,7 @@ ** Note: Code coverage report folder: html. ** Note: Code coverage report contains: covered, uncovered, excluded coverage details. ** Note: code coverage results for: WORK.COVER15 -** Note: statement: 85.7 % (12/14) +** Note: statement: 84.6 % (11/13) ** Note: branch: 62.5 % (5/8) ** Note: toggle: N.A. ** Note: expression: N.A. diff --git a/test/regress/gold/cover21.txt b/test/regress/gold/cover21.txt index 2bdd845f..69a71bdf 100644 --- a/test/regress/gold/cover21.txt +++ b/test/regress/gold/cover21.txt @@ -1,7 +1,7 @@ ** Note: Code coverage report folder: html. ** Note: Code coverage report contains: covered, uncovered, excluded coverage details. ** Note: code coverage results for: WORK.COVER21 -** Note: statement: 100.0 % (13/13) +** Note: statement: 100.0 % (12/12) ** Note: branch: 100.0 % (2/2) ** Note: toggle: 83.3 % (5/6) ** Note: expression: 100.0 % (2/2) diff --git a/test/regress/gold/cover5.txt b/test/regress/gold/cover5.txt index 40780314..7b1ede61 100644 --- a/test/regress/gold/cover5.txt +++ b/test/regress/gold/cover5.txt @@ -1,7 +1,7 @@ ** Note: Code coverage report folder: html. ** Note: Code coverage report contains: covered, uncovered, excluded coverage details. ** Note: code coverage results for: WORK.COVER5 -** Note: statement: 42.9 % (9/21) +** Note: statement: 36.8 % (7/19) ** Note: branch: 14.3 % (2/14) ** Note: toggle: 3.1 % (1/32) ** Note: expression: 14.3 % (2/14) @@ -10,7 +10,7 @@ ** Note: Code coverage report folder: html. ** Note: Code coverage report contains: covered, uncovered, excluded coverage details. ** Note: code coverage results for: WORK.COVER5 -** Note: statement: 47.6 % (10/21) +** Note: statement: 42.1 % (8/19) ** Note: branch: 28.6 % (4/14) ** Note: toggle: 6.2 % (2/32) ** Note: expression: 28.6 % (4/14) @@ -19,7 +19,7 @@ ** Note: Code coverage report folder: html. ** Note: Code coverage report contains: covered, uncovered, excluded coverage details. ** Note: code coverage results for: WORK.COVER5 -** Note: statement: 52.4 % (11/21) +** Note: statement: 47.4 % (9/19) ** Note: branch: 42.9 % (6/14) ** Note: toggle: 9.4 % (3/32) ** Note: expression: 42.9 % (6/14) @@ -28,7 +28,7 @@ ** Note: Code coverage report folder: html. ** Note: Code coverage report contains: covered, uncovered, excluded coverage details. ** Note: code coverage results for: WORK.COVER5 -** Note: statement: 57.1 % (12/21) +** Note: statement: 52.6 % (10/19) ** Note: branch: 50.0 % (7/14) ** Note: toggle: 12.5 % (4/32) ** Note: expression: 50.0 % (7/14) @@ -37,7 +37,7 @@ ** Note: Code coverage report folder: html. ** Note: Code coverage report contains: covered, uncovered, excluded coverage details. ** Note: code coverage results for: WORK.COVER5 -** Note: statement: 100.0 % (21/21) +** Note: statement: 100.0 % (19/19) ** Note: branch: 92.9 % (13/14) ** Note: toggle: 28.1 % (9/32) ** Note: expression: 92.9 % (13/14) diff --git a/test/regress/gold/cover9.txt b/test/regress/gold/cover9.txt index deff25a7..36c5d2e3 100644 --- a/test/regress/gold/cover9.txt +++ b/test/regress/gold/cover9.txt @@ -48,16 +48,6 @@ | 5 | exclude WORK.COVER9.SUB_BLOCK_INST.* | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -** Note: excluding statement: 'WORK.COVER9.SUB_BLOCK_INST.AND_GATE._S0' - > data/cover9_ef1.txt:5 - | - 5 | exclude WORK.COVER9.SUB_BLOCK_INST.* - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -** Warning: statement: 'WORK.COVER9.SUB_BLOCK_INST.AND_GATE._S0' already covered! - > data/cover9_ef1.txt:5 - | - 5 | exclude WORK.COVER9.SUB_BLOCK_INST.* - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ** Note: excluding expression: 'WORK.COVER9.SUB_BLOCK_INST.AND_GATE._S0._B0._E0' bins: BIN_TRUE, BIN_FALSE > data/cover9_ef1.txt:5 | @@ -261,7 +251,7 @@ ** Note: Code coverage report folder: html. ** Note: Code coverage report contains: covered, uncovered, excluded coverage details. ** Note: code coverage results for: WORK.COVER9 -** Note: statement: 100.0 % (29/29) +** Note: statement: 100.0 % (26/26) ** Note: branch: 100.0 % (10/10) ** Note: toggle: 79.4 % (27/34) ** Note: expression: 100.0 % (22/22) diff --git a/test/test_lower.c b/test/test_lower.c index e1aed4c2..5a2d0b39 100644 --- a/test/test_lower.c +++ b/test/test_lower.c @@ -1945,7 +1945,6 @@ START_TEST(test_cover) { VCODE_OP_COVER_STMT, .tag = 9 }, { VCODE_OP_CONST, .value = 1 }, { VCODE_OP_STORE, .name = "V" }, - { VCODE_OP_COVER_STMT, .tag = 10 }, { VCODE_OP_VAR_UPREF, .hops = 1, .name = "S" }, { VCODE_OP_LOAD_INDIRECT }, { VCODE_OP_RESOLVED }, @@ -1954,11 +1953,11 @@ START_TEST(test_cover) { VCODE_OP_CONST, .value = 1 }, { VCODE_OP_CONST, .value = 2 }, { VCODE_OP_SELECT }, - { VCODE_OP_COVER_EXPR, .tag = 11 }, + { VCODE_OP_COVER_EXPR, .tag = 10 }, { VCODE_OP_CONST, .value = 10 }, { VCODE_OP_CMP, .cmp = VCODE_CMP_GT }, { VCODE_OP_SELECT }, - { VCODE_OP_COVER_EXPR, .tag = 12 }, + { VCODE_OP_COVER_EXPR, .tag = 11 }, { VCODE_OP_OR }, { VCODE_OP_NOT }, { VCODE_OP_NOT }, @@ -1974,15 +1973,15 @@ START_TEST(test_cover) { VCODE_OP_CONST, .value = 32 }, { VCODE_OP_SELECT }, { VCODE_OP_ADD }, - { VCODE_OP_COVER_EXPR, .tag = 13 }, + { VCODE_OP_COVER_EXPR, .tag = 12 }, { VCODE_OP_COND, .target = 2, .target_else = 3 } }; CHECK_BB(1); EXPECT_BB(2) = { - { VCODE_OP_COVER_BRANCH, .tag = 14 }, - { VCODE_OP_COVER_STMT, .tag = 16 }, + { VCODE_OP_COVER_BRANCH, .tag = 13 }, + { VCODE_OP_COVER_STMT, .tag = 15 }, { VCODE_OP_CONST, .value = 2 }, { VCODE_OP_STORE, .name = "V" }, { VCODE_OP_JUMP, .target = 4 } @@ -1991,7 +1990,7 @@ START_TEST(test_cover) CHECK_BB(2); EXPECT_BB(3) = { - { VCODE_OP_COVER_BRANCH, .tag = 15 }, + { VCODE_OP_COVER_BRANCH, .tag = 14 }, { VCODE_OP_JUMP, .target = 4 } }; @@ -2004,7 +2003,7 @@ START_TEST(test_cover) { VCODE_OP_CONST, .value = 0 }, { VCODE_OP_CONST, .value = 1 }, { VCODE_OP_SCHED_WAVEFORM }, - { VCODE_OP_COVER_STMT, .tag = 17 }, + { VCODE_OP_COVER_STMT, .tag = 16 }, { VCODE_OP_WAIT, .target = 5 } }; -- 2.39.2