[Asterisk-code-review] CI: Add support for coverage processing. (asterisk[16])

Corey Farrell asteriskteam at digium.com
Fri Jul 20 10:51:01 CDT 2018


Corey Farrell has uploaded this change for review. ( https://gerrit.asterisk.org/9557


Change subject: CI: Add support for coverage processing.
......................................................................

CI: Add support for coverage processing.

Enable coverage with `./tests/CI/buildAsterisk.sh --coverage`.  This
will cause Asterisk to be compiled with coverage support.  It also
initializes 'before' coverage data for all sources.

./tests/CI/processCoverage.sh is used to process the coverage and
generate HTML reports.

Fix utils/check_expr2 which failed to compiled with coverage enabled.

Change-Id: I890f7d5665087426ad7d3e363187691b9afc2222
---
M tests/CI/buildAsterisk.sh
M tests/CI/ci.functions
A tests/CI/processCoverage.sh
M utils/Makefile
4 files changed, 63 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/57/9557/1

diff --git a/tests/CI/buildAsterisk.sh b/tests/CI/buildAsterisk.sh
index 9840d85..5262c8f 100755
--- a/tests/CI/buildAsterisk.sh
+++ b/tests/CI/buildAsterisk.sh
@@ -28,6 +28,10 @@
 
 [ x"$OUTPUT_DIR" != x ] && mkdir -p "$OUTPUT_DIR" 2&> /dev/null
 
+if [ -z $LCOV_DIR ]; then
+	LCOV_DIR="${OUTPUT_DIR:+${OUTPUT_DIR}/}lcov"
+fi
+
 if [ x"$CACHE_DIR" != x ] ; then
 	mkdir -p "$CACHE_DIR/sounds $CACHE_DIR/externals" 2&> /dev/null
 fi
@@ -63,6 +67,9 @@
 common_config_args="--prefix=/usr ${_libdir:+--libdir=${_libdir}} --sysconfdir=/etc --with-pjproject-bundled"
 common_config_args+=" ${CACHE_DIR:+--with-sounds-cache=${CACHE_DIR}/sounds --with-externals-cache=${CACHE_DIR}/externals}"
 common_config_args+=" --enable-dev-mode"
+if [ $COVERAGE -eq 1 ] ; then
+	common_config_args+=" --enable-coverage"
+fi
 export WGET_EXTRA_ARGS="--quiet"
 
 runner ./configure ${common_config_args} > ${OUTPUT_DIR:+${OUTPUT_DIR}/}configure.txt
@@ -91,6 +98,21 @@
 
 runner ${MAKE} -j8 || runner ${MAKE} -j1 NOISY_BUILD=yes
 
+runner rm -f ${LCOV_DIR}/*.info
+if [ $COVERAGE -eq 1 ] ; then
+	runner mkdir -p ${LCOV_DIR}
+
+	# Zero counter data
+	runner lcov --quiet --directory . --zerocounters
+
+	# Branch coverage is not supported by --initial.  Disable to suppresses a notice
+	# printed if it was enabled in lcovrc.
+	# This initial capture ensures any module which was built but never loaded is
+	# reported with 0% coverage for all sources.
+	runner lcov --quiet --directory . --no-external --capture --initial --rc lcov_branch_coverage=0 \
+		--output-file ${LCOV_DIR}/initial.info
+fi
+
 ALEMBIC=$(which alembic 2>/dev/null || : )
 if [ x"$ALEMBIC" = x ] ; then
 	echo "Alembic not installed"
diff --git a/tests/CI/ci.functions b/tests/CI/ci.functions
index 67616c2..662acb0 100644
--- a/tests/CI/ci.functions
+++ b/tests/CI/ci.functions
@@ -25,6 +25,6 @@
 done
 
 runner() {
-	( set -x ; ${@} )
+	( set -x ; "${@}" )
 }
 
diff --git a/tests/CI/processCoverage.sh b/tests/CI/processCoverage.sh
new file mode 100755
index 0000000..a0953e5
--- /dev/null
+++ b/tests/CI/processCoverage.sh
@@ -0,0 +1,39 @@
+#!/usr/bin/env bash
+
+CIDIR=$(dirname $(readlink -fn $0))
+source $CIDIR/ci.functions
+
+if [ -z $LCOV_DIR ]; then
+	LCOV_DIR="${OUTPUT_DIR:+${OUTPUT_DIR}/}lcov"
+fi
+
+if [ -z $COVERAGE_DIR ]; then
+	COVERAGE_DIR="${OUTPUT_DIR:+${OUTPUT_DIR}/}coverage"
+fi
+
+if [ -z $ASTERISK_VERSION ]; then
+	ASTERISK_VERSION=$(./build_tools/make_version .)
+fi
+
+# Capture counter data from testing
+runner lcov --no-external --capture --directory . --output-file ${LCOV_DIR}/tested.info > /dev/null
+
+# Combine initial and tested data.
+runner lcov \
+	--add-tracefile ${LCOV_DIR}/initial.info \
+	--add-tracefile ${LCOV_DIR}/tested.info \
+	--output-file ${LCOV_DIR}/combined.info > /dev/null
+
+# We don't care about coverage reporting for tests, utils or third-party.
+runner lcov --remove ${LCOV_DIR}/combined.info \
+		"${PWD}/main/dns_test.*" \
+		"${PWD}/main/test.*" \
+		"${PWD}/tests/*" \
+		"${PWD}/utils/*" \
+		"${PWD}/third-party/*" \
+	--output-file ${LCOV_DIR}/filtered.info > /dev/null
+
+# Generate HTML coverage report.
+runner mkdir -p ${COVERAGE_DIR}
+runner genhtml --prefix ${PWD} --ignore-errors source ${LCOV_DIR}/filtered.info \
+	--legend --title "Asterisk ${ASTERISK_VERSION}" --output-directory=${COVERAGE_DIR} > /dev/null
diff --git a/utils/Makefile b/utils/Makefile
index 6bd33da..2ec1b91 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -183,7 +183,7 @@
 	$(ECHO_PREFIX) echo "   [CC] ast_expr2.c -> ast_expr2z.o"
 	$(CC) -g -c -I$(ASTTOPDIR)/include -DSTANDALONE2 $(ASTTOPDIR)/main/ast_expr2.c -o ast_expr2z.o
 	$(ECHO_PREFIX) echo "   [LD] ast_expr2fz.o ast_expr2z.o  -> check_expr2"
-	$(CC) -g -o check_expr2 ast_expr2fz.o ast_expr2z.o astmm.o -lm
+	$(CC) -g -o check_expr2 ast_expr2fz.o ast_expr2z.o astmm.o -lm $(_ASTLDFLAGS)
 	$(ECHO_PREFIX) echo "   [RM] ast_expr2fz.o ast_expr2z.o"
 	rm ast_expr2z.o ast_expr2fz.o
 	./check_expr2 expr2.testinput

-- 
To view, visit https://gerrit.asterisk.org/9557
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-MessageType: newchange
Gerrit-Change-Id: I890f7d5665087426ad7d3e363187691b9afc2222
Gerrit-Change-Number: 9557
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180720/b62f672d/attachment-0001.html>


More information about the asterisk-code-review mailing list