Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix several issues noted in #343 and #347 #353

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/run_test_suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ jobs:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(just an idea: I think that blank line before could also be dropped)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure...why not?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@henry2cox that's the wrong blank line now. My point was about the two consecutive blank lines below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sigh.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@henry2cox looks just right now though 👍

sudo perl -MCPAN -e 'install(Memory::Process)' # no package in Ubuntu

sudo ln -s python3-coverage /usr/bin/coverage # until issue #347 is fixed

- name: make install
run: |-
set -x -o pipefail
Expand Down Expand Up @@ -94,5 +92,5 @@ jobs:
# to fail.
make check |& tee /dev/stderr \
| grep -F ' failed, ' | tee /dev/stderr \
| grep -F -q ', 3 failed, ' \
| grep -F -q ', 2 failed, ' \
|| { echo 'Number of tests expected to fail^^ does not match -- did you break an existing test?' >&2 ; false ; }
2 changes: 1 addition & 1 deletion bin/geninfo
Original file line number Diff line number Diff line change
Expand Up @@ -2630,7 +2630,7 @@ sub intermediate_json_to_info($)
}
if ($conditions && @$conditions) {
#die("unexpected multiple conditions at $line") if scalar(@$conditions) > 1;
#lcovutil::debig(1, "MDCD at $filename:$line\n");
#lcovutil::debug(1, "MCDC at $filename:$line\n");
my $mcdc = $mcdcMap->new_mcdc($fileData, $line);

foreach my $c (@$conditions) {
Expand Down
23 changes: 19 additions & 4 deletions bin/py2lcov
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,19 @@ first line of the function has a non-zero count.
Best practice is to either always specify '--no-functions' or never specify
'--no-functions'.

Note that xml2lcov does not implement the full suite of LCOV features
(e.g., filtering, substitutions, etc.).
py2lcov uses Coverage.py to extract coverage data.
Note that the name of the Coverage.py executable my differ on your platform.
By default, py2lcov uses 'coverage' (which it expects to be in your path).
You can use a different executable, either:
- through your COVERAGE_COMMAND environment variable, or
- via the 'py2lcov --cmd exename ..' command line option.

py2lcov does not implement the full suite of LCOV features (e.g., filtering,
substitutions, etc.).
Please generate the translated LCOV format file and then read the data
back in to lcov to use any of those features.
%(usage)s

Example:
$ export PYCOV_DATA=path/to/pydata

Expand All @@ -98,7 +106,6 @@ Example:
# use differential coverage to see exactly what filtering did
$ genhtml -o html_differential --baseline-file mydata.info filtered.info ...


Deprecated feature:
For backward compatibility, py2lcov also supports translation to LCOV
format from intermediate XML:
Expand All @@ -115,6 +122,12 @@ Example:
'usage' : ProcessFile.usageNote,
}

from_env = ''
cover_cmd = 'coverage'
if 'COVERAGE_COMMAND' in os.environ:
cover_cmd = os.environ['COVERAGE_COMMAND']
from_env = ' (from your COVERAGE_COMMAND environment variable)'

parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog=usageString)
Expand All @@ -141,6 +154,8 @@ Example:
help='tabsize when computing indent')
parser.add_argument('-k', "--keep-going", dest='keepGoing', default=False, action='store_true',
help="ignore errors")
parser.add_argument('--cmd', dest='cover_cmd', default=cover_cmd,
help='executable used to extract python data - e.g., "python3-coverage". Default is "%s"%s.' % (cover_cmd, from_env))
parser.add_argument('inputs', nargs='*',
help="list of python coverage data input files - expected to be XML or Python .dat format")

Expand Down Expand Up @@ -176,7 +191,7 @@ Example:
while os.path.exists(xml):
xml = base + '.xml%d' % suffix
suffix += 1
cmd = 'COVERAGE_FILE=%s coverage xml -o %s' % (f, xml)
cmd = 'COVERAGE_FILE=%s %s xml -o %s' % (f, args.cover_cmd, xml)
try:
#x = subprocess.run(cmd, capture_output=True, shell=True, check=True)
x = subprocess.run(cmd, shell=True, check=True, stdout=True, stderr=True)
Expand Down
2 changes: 1 addition & 1 deletion scripts/gitversion
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ if (!GetOptions("--compare" => \$compare,
}

if ($compare) {
print $class->compare_version(@ARGV) . "\n";
exit $class->compare_version(@ARGV);
} else {
print $class->extract_version(@ARGV) . "\n";
}
Expand Down
15 changes: 8 additions & 7 deletions tests/gendiffcov/simple/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ fi
# test filter with differing version
$COVER $LCOV_TOOL $EXTRA_GCOV_OPTS $BASE_OPTS --version-script "$GET_VERSION_EXE --md5 --allow-missing" --output filt2.info --filter branch,line -a baseline2.info $IGNORE
if [ 0 == $? ] ; then
echo "ERROR: filter with mismatched version did not fail"
echo "ERROR: filter with mismatched version did not fail 2"
status=1
if [ 0 == $KEEP_GOING ] ; then
exit 1
Expand Down Expand Up @@ -1598,8 +1598,9 @@ if [ 0 == $? ] ; then
fi

# skip both errors
echo genhtml $DIFFCOV_OPTS --output-directory ./usage --rc memory_percentage --rc -memory_percentage=50 baseline_orig.info --ignore usage
$COVER $GENHTML_TOOL $DIFFCOV_OPTS --output-directory ./usage --rc memory_percentage --rc percent=5 baseline_orig.info --ignore usage $IGNORE
# ignore version error which might happen if timestamp is included
echo genhtml $DIFFCOV_OPTS --output-directory ./usage --rc memory_percentage --rc -memory_percentage=50 baseline_orig.info --ignore usage,version
$COVER $GENHTML_TOOL $DIFFCOV_OPTS --output-directory ./usage --rc memory_percentage --rc percent=5 baseline_orig.info --ignore usage,version $IGNORE
if [ 0 != $? ] ; then
echo "ERROR: didn't ignore errors"
status=1
Expand All @@ -1609,8 +1610,8 @@ if [ 0 != $? ] ; then
fi

# skip both errors - but check total message count
echo genhtml $DIFFCOV_OPTS --output-directory ./expect_err --rc memory_percentage --rc -memory_percentage=50 baseline_orig.info --ignore usage --expect usage:1
$COVER $GENHTML_TOOL $DIFFCOV_OPTS --output-directory ./expect_err --rc memory_percentage --rc percent=5 baseline_orig.info --ignore usage $IGNORE --expect usage:1 2>&1 | tee expect_err.log
echo genhtml $DIFFCOV_OPTS --output-directory ./expect_err --rc memory_percentage --rc -memory_percentage=50 baseline_orig.info --ignore usage,version --expect usage:1
$COVER $GENHTML_TOOL $DIFFCOV_OPTS --output-directory ./expect_err --rc memory_percentage --rc percent=5 baseline_orig.info --ignore usage,version $IGNORE --expect usage:1 2>&1 | tee expect_err.log
if [ 0 == ${PIPESTATUS[0]} ] ; then
echo "ERROR: didn't catch expect count error"
status=1
Expand All @@ -1621,8 +1622,8 @@ fi
grep -E "ERROR:.*count.*'usage' constraint .+ is not true" expect_err.log

# now skip the count message too
echo genhtml $DIFFCOV_OPTS --output-directory ./expect --rc memory_percentage --rc -memory_percentage=50 baseline_orig.info --ignore usage,count --rc expect_message_count=usage:1 --msg-log
$COVER $GENHTML_TOOL $DIFFCOV_OPTS --output-directory ./expect --rc memory_percentage --rc percent=5 baseline_orig.info --ignore usage,count $IGNORE --rc expect_message_count=usage:1 --msg-log 2>&1 | tee expect.log
echo genhtml $DIFFCOV_OPTS --output-directory ./expect --rc memory_percentage --rc -memory_percentage=50 baseline_orig.info --ignore usage,version,count --rc expect_message_count=usage:1 --msg-log
$COVER $GENHTML_TOOL $DIFFCOV_OPTS --output-directory ./expect --rc memory_percentage --rc percent=5 baseline_orig.info --ignore usage,version,count $IGNORE --rc expect_message_count=usage:1 --msg-log 2>&1 | tee expect.log
if [ 0 != ${PIPESTATUS[0]} ] ; then
echo "ERROR: didn't skip expect count error"
status=1
Expand Down
24 changes: 24 additions & 0 deletions tests/lcov/merge/functionBug_1.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
TN:
SF: my_file.cpp
FN:9,25,is_within_phase_offset_tolerance(Ouster1DriverConfig const&, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000l> >, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000l> >)
FNDA:0,is_within_phase_offset_tolerance(Ouster1DriverConfig const&, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000l> >, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000l> >)
FNF:1
FNH:0
BRDA:12,0,0,-
BRDA:12,0,1,-
BRDA:25,0,0,-
BRDA:25,0,1,-
BRDA:25,0,2,-
BRDA:25,0,3,-
BRF:6
BRH:0
DA:12,0
DA:15,0
DA:18,0
DA:22,0
DA:23,0
DA:24,0
DA:25,0
LF:7
LH:0
end_of_record
28 changes: 28 additions & 0 deletions tests/lcov/merge/functionBug_2.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
TN:
SF: my_file.cpp
FN:11,26,is_within_phase_offset_tolerance(Ouster1DriverConfig const&, std::chrono::duration<long, std::ratio<1l, 1000l> >, std::chrono::duration<long, std::ratio<1l, 1000l> >)
FNDA:1885,is_within_phase_offset_tolerance(Ouster1DriverConfig const&, std::chrono::duration<long, std::ratio<1l, 1000l> >, std::chrono::duration<long, std::ratio<1l, 1000l> >)
FNF:1
FNH:1
BRDA:12,0,0,1
BRDA:12,0,1,1884
BRDA:25,0,0,248
BRDA:25,0,1,1636
BRDA:25,1,2,210
BRDA:25,1,3,1426
BRF:6
BRH:6
DA:12,1885
DA:13,1
DA:15,1
DA:18,1884
DA:20,1884
DA:21,1884
DA:22,1884
DA:23,1884
DA:24,1884
DA:25,1884
DA:26,1885
LF:11
LH:11
end_of_record
3 changes: 2 additions & 1 deletion tests/lcov/merge/merge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ if [ "${VER[0]}" -lt 5 ] ; then
FILTER='--filter branch'
fi

rm -rf *.txt* *.json dumper* intersect*.info* diff*.info* cover_db
rm -f *.txt* *.json dumper* intersect*.info gen.info func.info inconsistent.info diff* *.log
rm -rf cover_db

if [ "x$COVER" != 'x' ] && [ 0 != $LOCAL_COVERAGE ] ; then
cover -delete
Expand Down
40 changes: 23 additions & 17 deletions tests/py2lcov/py2lcov.sh
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,27 @@ if [[ 1 == $CLEAN_ONLY ]] ; then
exit 0
fi

which coverage
CMD='coverage'
which $CMD
if [ 0 != $? ] ; then
CMD='python3-coverage' # ubuntu?
fi
which $CMD
if [ 0 != $? ] ; then
echo "cannot find 'coverage' or 'python3-coverage'"
echo "unable to run py2lcov - please install python Coverage.py package"
exit 1
fi

# some corner cases:
COVERAGE_FILE=./functions.dat coverage run --branch ./test.py
COVERAGE_FILE=./functions.dat $CMD run --branch ./test.py
if [ 0 != $? ] ; then
echo "coverage functions failed"
if [ 0 == $KEEP_GOING ] ; then
exit 1
fi
fi
eval ${PYCOV} ${PY2LCOV_TOOL} -o functions.info functions.dat $VERSION
eval ${PYCOV} ${PY2LCOV_TOOL} -o functions.info --cmd $CMD functions.dat $VERSION
if [ 0 != $? ] ; then
echo "py2lcov failed function example"
if [ 0 == $KEEP_GOING ] ; then
Expand Down Expand Up @@ -208,7 +214,7 @@ fi


# legacy mode: run with intermediate XML file
COVERAGE_FILE=./functions.dat coverage xml -o functions.xml
COVERAGE_FILE=./functions.dat $CMD xml -o functions.xml
if [ 0 != $? ] ; then
echo "coverage xml failed"
exit 1
Expand All @@ -232,7 +238,7 @@ if [ 0 != $? ] ; then
fi

# run again, generating checksum data...
eval ${PYCOV} ${PY2LCOV_TOOL} -o checksum.info functions.dat $VERSION --checksum
eval ${PYCOV} ${PY2LCOV_TOOL} --cmd $CMD -o checksum.info functions.dat $VERSION --checksum
if [ 0 != $? ] ; then
echo "py2lcov failed function example"
if [ 0 == $KEEP_GOING ] ; then
Expand Down Expand Up @@ -262,7 +268,7 @@ fi


# run without generating function data:
eval ${PYCOV} ${PY2LCOV_TOOL} functions.dat -o no_functions.info $VERSION --no-function
eval ${PYCOV} ${PY2LCOV_TOOL} functions.dat --cmd $CMD -o no_functions.info $VERSION --no-function
if [ 0 != $? ] ; then
echo "coverage no_functions failed"
if [ 0 == $KEEP_GOING ] ; then
Expand All @@ -279,7 +285,7 @@ if [ 0 != $COUNT ] ; then
fi

# run without extracting version
eval ${PYCOV} ${PY2LCOV_TOOL} functions.dat -o no_version.info
eval ${PYCOV} ${PY2LCOV_TOOL} functions.dat --cmd $CMD -o no_version.info
if [ 0 != $? ] ; then
echo "coverage no_functions failed"
if [ 0 == $KEEP_GOING ] ; then
Expand All @@ -296,7 +302,7 @@ if [ 0 != $COUNT ] ; then
fi

# test exclusion
eval ${PYCOV} ${PY2LCOV_TOOL} -o excl.info --exclude test.py functions.dat
eval ${PYCOV} ${PY2LCOV_TOOL} -o excl.info --cmd $CMD --exclude test.py functions.dat
if [ 0 != $? ] ; then
echo "coverage no_functions failed"
if [ 0 == $KEEP_GOING ] ; then
Expand Down Expand Up @@ -330,7 +336,7 @@ if [ 0 != $? ] ; then
fi

# some usage errors
eval ${PYCOV} ${PY2LCOV_TOOL} functions.dat -o paramErr.info ${VERSION},-x
eval ${PYCOV} ${PY2LCOV_TOOL} functions.dat -o paramErr.info --cmd $CMD ${VERSION},-x
if [ 0 == $? ] ; then
echo "coverage version did not see error"
if [ 0 == $KEEP_GOING ] ; then
Expand All @@ -339,7 +345,7 @@ if [ 0 == $? ] ; then
fi

# run again with --keep-going flag - should generate same result as we see without version script
eval ${PYCOV} ${PY2LCOV_TOOL} functions.dat -o keepGoing.info ${VERSION},-x --keep-going --verbose
eval ${PYCOV} ${PY2LCOV_TOOL} functions.dat -o keepGoing.info --cmd $CMD ${VERSION},-x --keep-going --verbose
if [ 0 != $? ] ; then
echo "keepGoing version saw error"
if [ 0 == $KEEP_GOING ] ; then
Expand All @@ -359,9 +365,9 @@ fi
# can't run this unless we have a new enough 'coverage' version
# to support the --data-file input
if [[ "${PYCOV}" =~ "COVERAGE_FILE=" || "${PY2LCOV_TOOL}" =~ "COVERAGE_FILE=" ]] ; then
${LCOV_HOME}/bin/py2lcov -o missing.info
${LCOV_HOME}/bin/py2lcov -o missing.info --cmd $CMD
else
eval ${PYCOV} ${PY2LCOV_TOOL} -o missing.info
eval ${PYCOV} ${PY2LCOV_TOOL} -o missing.info --cmd $CMD
fi
if [ 0 == $? ] ; then
echo "did not see error with missing input data"
Expand All @@ -371,7 +377,7 @@ if [ 0 == $? ] ; then
fi

# usage error:
eval ${PYCOV} ${PY2LCOV_TOOL} -o noFile.info run.dat y.xml
eval ${PYCOV} ${PY2LCOV_TOOL} -o noFile.info run.dat y.xml --cmd $CMD
if [ 0 == $? ] ; then
echo "did not see error with missing input file"
if [ 0 == $KEEP_GOING ] ; then
Expand All @@ -380,7 +386,7 @@ if [ 0 == $? ] ; then
fi

# usage error:
eval ${PYCOV} ${PY2LCOV_TOOL} -o badArg.info --noSuchParam run_help.dat
eval ${PYCOV} ${PY2LCOV_TOOL} -o badArg.info --noSuchParam run_help.dat --cmd $CMD
if [ 0 == $? ] ; then
echo "did not see error with unsupported param"
if [ 0 == $KEEP_GOING ] ; then
Expand All @@ -392,10 +398,10 @@ fi
# to support the --data-file input
if [[ "${PYCOV}" =~ "COVERAGE_FILE=" || "${PY2LCOV_TOOL}" =~ "COVERAGE_FILE=" ]] ; then
# can't generate coverage report for this feature...
COVERAGE_FILE=functions.dat ${LCOV_HOME}/bin/py2lcov -o fromEnv.info
COVERAGE_FILE=functions.dat ${LCOV_HOME}/bin/py2lcov -o fromEnv.info --cmd $CMD
else
# get input from environment var:
eval COVERAGE_FILE=functions.dat ${PYCOV} ${PY2LCOV_TOOL} -o fromEnv.info
eval COVERAGE_FILE=functions.dat ${PYCOV} ${PY2LCOV_TOOL} -o fromEnv.info --cmd $CMD
fi

if [ 0 != $? ] ; then
Expand Down Expand Up @@ -480,6 +486,6 @@ echo "Tests passed"
if [[ "x$COVER" != "x" && $LOCAL_COVERAGE == 1 ]] ; then
cover
${LCOV_HOME}/bin/perl2lcov -o perlcov.info --testname py2lcov $VERSION ./cover_db
${PY2LCOV_TOOL} -o pycov.info --testname py2lcov $VERSION ${PYCOV_DB}
${PY2LCOV_TOOL} -o pycov.info --testname py2lcov --cmd $CMD $VERSION ${PYCOV_DB}
${GENHTML_TOOL} -o pycov pycov.info perlcov.info --flat --show-navigation --show-proportion --branch $VERSION $ANNOTATE --ignore inconsistent,version
fi