Skip to content

Commit 739f85f

Browse files
committed
Fix coverage measurement on macos-26
1 parent f13ecc1 commit 739f85f

6 files changed

Lines changed: 50 additions & 27 deletions

File tree

.github/workflows/boxes.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ jobs:
6262
steps:
6363
- uses: actions/checkout@v6
6464

65-
# We need to use GNU grep, sed, and xargs on macOS
65+
# We need GNU userland tools and a real GCC/gcov pair on macOS
6666
- name: add-packages
6767
run: |
6868
brew trust coverallsapp/coveralls
69-
brew install flex bison diffutils lcov cmocka grep gnu-sed findutils
69+
brew install flex bison diffutils lcov cmocka gcc grep gnu-sed findutils
70+
echo "CC=$(printf '%s\n' /opt/homebrew/bin/gcc-[0-9]* | sort -t- -k2,2n | tail -n 1)" >> "$GITHUB_ENV"
71+
echo "GCOV_TOOL=$(printf '%s\n' /opt/homebrew/bin/gcov-[0-9]* | sort -t- -k2,2n | tail -n 1)" >> "$GITHUB_ENV"
7072
echo '/opt/homebrew/opt/grep/libexec/gnubin' >> $GITHUB_PATH
7173
echo '/opt/homebrew/opt/gnu-sed/libexec/gnubin' >> $GITHUB_PATH
7274
echo '/opt/homebrew/opt/findutils/libexec/gnubin' >> $GITHUB_PATH

src/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#====================================================================================================================
1515

1616

17-
CC = gcc
17+
CC ?= gcc
1818

1919
OUT_DIR = ../out
2020
SRC_DIR = ../src

test/test-sunny-days-all.sh

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ declare -r COVERAGE_FILE=${COVERAGE_DIR}/coverage.info
3131
# Command Line Options
3232
declare opt_coverage=false
3333

34+
declare branchCoverage=lcov_branch_coverage
35+
declare -a lcovArgs=(--ignore-errors unused)
36+
declare -a lcovCaptureArgs=()
37+
declare -ar lcovExcludeArgs=(--exclude '*/lex.yy.c' --exclude '*/parser.c' --exclude '*/lexer.l' --exclude '*/parser.y')
38+
39+
if [[ $(uname) == "Darwin" ]]; then
40+
branchCoverage=branch_coverage
41+
lcovArgs+=(--rc derive_function_end_line=0)
42+
fi
43+
44+
if [[ -n "${GCOV_TOOL:-}" ]]; then
45+
lcovCaptureArgs+=(--gcov-tool "${GCOV_TOOL}")
46+
fi
47+
3448
# Global Variables
3549
declare result=0
3650
declare success=0
@@ -93,16 +107,6 @@ function get_executable_name()
93107
}
94108

95109

96-
function get_coverage_option()
97-
{
98-
local coverageOption=lcov_branch_coverage
99-
if [[ $(uname) == "Darwin" ]]; then
100-
coverageOption=branch_coverage
101-
fi
102-
echo ${coverageOption}
103-
}
104-
105-
106110
function list_designs()
107111
{
108112
${boxesBinary} -f ../boxes-config -q '(all)' | grep -v ' (alias)'
@@ -195,7 +199,7 @@ function measure_coverage()
195199
mkdir -p "${COVERAGE_DIR}"
196200
cp ${OUT_DIR}/*.gc* "${COVERAGE_DIR}"
197201
lcov --capture --directory "${COVERAGE_DIR}" --base-directory "${SRC_DIR}" --test-name SunnyDayTests \
198-
--quiet --exclude '*/lex.yy.c' --exclude '*/parser.c' --rc "${branchCoverage}=1" \
202+
--quiet "${lcovCaptureArgs[@]}" "${lcovExcludeArgs[@]}" "${lcovArgs[@]}" --rc "${branchCoverage}=1" \
199203
--output-file "${COVERAGE_FILE}"
200204
echo -n " Coverage: "
201205
lcov --summary "${COVERAGE_FILE}" 2>&1 | grep 'lines...' | grep -oP '\d+\.\d*%'
@@ -222,9 +226,6 @@ clear_gcda_traces
222226
declare boxesBinary
223227
boxesBinary=$(get_executable_name)
224228

225-
declare branchCoverage
226-
branchCoverage=$(get_coverage_option)
227-
228229
echo "Performing sunny-day tests on all box designs"
229230

230231
mkdir -p ${TEST_DIR}

test/testrunner.sh

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ declare opt_coverage_per_test=false
3030
declare opt_suite=false
3131
declare opt_testCase=""
3232

33+
declare branchCoverage=lcov_branch_coverage
34+
declare -a lcovArgs=(--ignore-errors unused)
35+
declare -a lcovCaptureArgs=()
36+
declare -ar lcovExcludeArgs=(--exclude '*/lex.yy.c' --exclude '*/parser.c' --exclude '*/lexer.l' --exclude '*/parser.y')
37+
38+
if [[ $(uname) == "Darwin" ]]; then
39+
branchCoverage=branch_coverage
40+
lcovArgs+=(--rc derive_function_end_line=0)
41+
fi
42+
43+
if [[ -n "${GCOV_TOOL:-}" ]]; then
44+
lcovCaptureArgs+=(--gcov-tool "${GCOV_TOOL}")
45+
fi
46+
3347

3448
function print_usage()
3549
{
@@ -111,7 +125,8 @@ function cov_baseline()
111125
if [ ! -f ${BASELINE_FILE} ]; then
112126
echo "Creating coverage baseline ..."
113127
lcov --capture --initial --no-recursion --directory ${OUT_DIR} --base-directory ${SRC_DIR} \
114-
--exclude '*/lex.yy.c' --exclude '*/parser.c' --output-file ${BASELINE_FILE}
128+
"${lcovCaptureArgs[@]}" "${lcovExcludeArgs[@]}" "${lcovArgs[@]}" --rc "${branchCoverage}=1" \
129+
--output-file ${BASELINE_FILE}
115130
echo -e "Coverage baseline created in ${BASELINE_FILE}\n"
116131
fi
117132
fi
@@ -160,7 +175,7 @@ function measure_coverage()
160175
mkdir -p "${testResultsDir}"
161176
cp ${OUT_DIR}/*.gc* "${testResultsDir}"
162177
lcov --capture --directory "${testResultsDir}" --base-directory ${SRC_DIR} --test-name "${tcBaseName}" --quiet \
163-
--exclude '*/lex.yy.c' --exclude '*/parser.c' --rc "${branchCoverage}=1" \
178+
"${lcovCaptureArgs[@]}" "${lcovExcludeArgs[@]}" "${lcovArgs[@]}" --rc "${branchCoverage}=1" \
164179
--output-file "${testResultsDir}/coverage.info"
165180
echo -n " Coverage: "
166181
lcov --summary "${testResultsDir}/coverage.info" 2>&1 | grep 'lines...' | grep -oP '\d+\.\d*%'
@@ -174,7 +189,7 @@ function consolidate_coverage()
174189
echo -e "\nConsolidating test coverage ..."
175190
pushd ${OUT_DIR}/test-results || exit 1
176191
find . -name "*.info" | xargs printf -- '--add-tracefile %s\n' | xargs --exit \
177-
lcov --rc "${branchCoverage}=1" --exclude '*/lex.yy.c' --exclude '*/parser.c' \
192+
lcov --rc "${branchCoverage}=1" "${lcovExcludeArgs[@]}" "${lcovArgs[@]}" \
178193
--output-file ../${COVERAGE_FILE} --add-tracefile ../${BASELINE_FILE}
179194
popd || exit 1
180195
echo ""
@@ -305,10 +320,6 @@ check_prereqs
305320
cov_baseline
306321

307322
declare tcBaseName=${opt_testCase%.txt}
308-
declare branchCoverage=lcov_branch_coverage
309-
if [[ $(uname) == "Darwin" ]]; then
310-
branchCoverage=branch_coverage
311-
fi
312323

313324
# Execute the entire test suite
314325
if [ ${opt_suite} == true ]; then
@@ -317,7 +328,7 @@ if [ ${opt_suite} == true ]; then
317328
execute_suite
318329

319330
if [ ${opt_coverage_per_test} == false ]; then
320-
tcBaseName=black-box-all
331+
tcBaseName=black_box_all
321332
measure_coverage
322333
fi
323334
if [ ${opt_coverage} == true ]; then

utest/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#____________________________________________________________________________________________________________________
1414
#====================================================================================================================
1515

16-
CC = gcc
16+
CC ?= gcc
1717

1818
OUT_DIR = ../out
1919
SRC_DIR = ../src

utest/report.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,17 @@ declare -r testResultsDir=${OUT_DIR}/test-results/${tcBaseName}
2323
declare -r testReportDir=${OUT_DIR}/report-utest
2424

2525
declare branchCoverage=lcov_branch_coverage
26+
declare -a lcovArgs=(--ignore-errors unused)
27+
declare -a lcovCaptureArgs=()
28+
declare -ar lcovExcludeArgs=(--exclude '*/lex.yy.c' --exclude '*/parser.c' --exclude '*/lexer.l' --exclude '*/parser.y')
29+
2630
if [[ $(uname) == "Darwin" ]]; then
2731
branchCoverage=branch_coverage
32+
lcovArgs+=(--rc derive_function_end_line=0)
33+
fi
34+
35+
if [[ -n "${GCOV_TOOL:-}" ]]; then
36+
lcovCaptureArgs+=(--gcov-tool "${GCOV_TOOL}")
2837
fi
2938

3039
if test -n "$(find "${OUT_DIR}" -maxdepth 1 -name '*.gcda' -print -quit)" \
@@ -35,7 +44,7 @@ then
3544
mkdir -p "${testReportDir}"
3645
cp "${OUT_DIR}"/*.gc* "${testResultsDir}"
3746
lcov --capture --directory "${testResultsDir}" --base-directory "${SRC_DIR}" --test-name ${tcBaseName} --quiet \
38-
--exclude '*/lex.yy.c' --exclude '*/parser.c' --rc "${branchCoverage}=1" \
47+
"${lcovCaptureArgs[@]}" "${lcovExcludeArgs[@]}" "${lcovArgs[@]}" --rc "${branchCoverage}=1" \
3948
--output-file "${testResultsDir}/coverage.info"
4049
echo -n "[ Coverage ] "
4150
genhtml --title "Boxes / Unit Tests" --branch-coverage --legend --output-directory "${testReportDir}" \

0 commit comments

Comments
 (0)