Copilot commented on code in PR #13305:
URL: https://github.com/apache/trafficserver/pull/13305#discussion_r3447686275
##########
ci/coverage:
##########
@@ -16,93 +16,97 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-LCOV=${LCOV:-lcov}
-GENHTML=${GENHTML:-genhtml}
-
-TMPDIR=${TMPDIR:-/tmp}
-BUILDID="org.apache.trafficserver.$$"
-
-SRCROOT=${SRCROOT:-$(cd $(dirname $0)/.. && pwd)} # where the source lives
-OBJROOT=${OBJROOT:-"$TMPDIR/$BUILDID/obj"} # where we are building
-DSTROOT=${DSTROOT:-"$TMPDIR/$BUILDID/dst"} # where we are installing
-
-# Force low make parallelization so that the build can complete in a VM with
-# only a small amount of memory.
-NPROCS=${NPROCS:-2}
-
-mkdir -p $SRCROOT
-mkdir -p $OBJROOT
-mkdir -p $DSTROOT
-
-autogen() {
- (
- cd "$SRCROOT"
- [ configure -nt configure.ac -a Makefile.in -nt Makefile.am ] ||
autoreconf -fi
- )
-}
+# Build ATS with gcov instrumentation, run the unit tests (and optionally
+# autests), and produce a coverage report with gcovr.
+#
+# Usage:
+# ci/coverage [extra cmake args...]
+#
+# Environment overrides:
+# BUILDDIR build tree (default: build-coverage)
+# PREFIX install prefix (default: /tmp/ts-coverage)
+# NPROCS build parallelism (default: nproc)
+# GCOVR gcovr command (default: gcovr, falls back to uvx
gcovr)
+# AUTEST run autests too if set to a -f/--filter argument string,
+# e.g. AUTEST='*/tls/*' or AUTEST=all for the whole suite
+#
+# Requires: cmake, ninja or make, gcc/gcov, and gcovr (pip install gcovr).
+
+set -e
+
+SRCROOT=${SRCROOT:-$(cd "$(dirname "$0")"/.. && pwd)}
+BUILDDIR=${BUILDDIR:-$SRCROOT/build-coverage}
+PREFIX=${PREFIX:-/tmp/ts-coverage}
+NPROCS=${NPROCS:-$(nproc 2>/dev/null || echo 4)}
+
+GCOVR=${GCOVR:-gcovr}
+if ! command -v "${GCOVR%% *}" >/dev/null 2>&1; then
+ if command -v uvx >/dev/null 2>&1; then
+ GCOVR="uvx gcovr"
+ else
+ echo "gcovr not found; install it with 'pip install gcovr'" >&2
+ exit 1
+ fi
+fi
+
+# --coverage instruments compile and link. Atomic profile updates keep the
+# counters sane in ATS's heavily threaded runtime, and absolute paths in the
+# notes files let gcovr resolve sources from any working directory.
+COVERAGE_FLAGS="-g -O0 --coverage -fprofile-update=atomic -fprofile-abs-path"
configure() {
- (
- cd $OBJROOT
- $SRCROOT/configure \
- --prefix=$DSTROOT \
- --enable-debug \
- --enable-coverage \
- --enable-werror \
- --enable-example-plugins \
- --enable-test-tools \
- --enable-experimental-plugins \
- CC="$CC" \
- CXX="$CXX" \
- "$@"
- )
+ cmake -S "$SRCROOT" -B "$BUILDDIR" \
+ -DCMAKE_BUILD_TYPE=Debug \
+ -DCMAKE_INSTALL_PREFIX="$PREFIX" \
+ -DCMAKE_COMPILE_WARNING_AS_ERROR=OFF \
+ -DENABLE_AUTEST=ON \
+ -DBUILD_EXPERIMENTAL_PLUGINS=ON \
+ -DENABLE_EXAMPLE=ON \
+ -DCMAKE_CXX_FLAGS_DEBUG="$COVERAGE_FLAGS" \
+ -DCMAKE_C_FLAGS_DEBUG="$COVERAGE_FLAGS" \
+ "$@"
}
build() {
- ( cd $OBJROOT && $MAKE -j $NPROCS )
- ( cd $OBJROOT && $MAKE install )
+ cmake --build "$BUILDDIR" -j "$NPROCS"
+ cmake --install "$BUILDDIR"
}
-regress() {
- ( cd $OBJROOT && $MAKE check ) && \
- $DSTROOT/bin/traffic_server -k -K -R 1
-}
-
-CC=${CC:-gcc}
-CXX=${CXX:-g++}
-MAKE=${MAKE:-make}
-export CC CXX MAKE
-
-case $VERBOSE in
- Y*) set -x ;;
- y*) set -x ;;
- 1) set -x ;;
- *) set +x ;;
-esac
-
-autogen || exit 1
-configure "$@" || exit 1
-build || exit 1
+run_tests() {
+ # Reset counters so the report reflects exactly this run.
+ find "$BUILDDIR" -name '*.gcda' -delete
-$LCOV --quiet --capture --initial --directory $OBJROOT --output-file
initial.info
+ ctest --test-dir "$BUILDDIR" -j4
-regress
-
-$LCOV --quiet --capture --directory $OBJROOT --output-file tests.info
-
-# The --add-tracefile option refuses to create an output file with
-# --output-file (contrary to documentation). Capture the combined
-# coverage from stdout instead.
-$LCOV \
- --add-tracefile initial.info \
- --add-tracefile tests.info \
-> combined.info
+ if [ -n "$AUTEST" ]; then
+ local filter_args=()
+ if [ "$AUTEST" != all ]; then
+ filter_args=(-f $AUTEST)
+ fi
Review Comment:
`filter_args=(-f $AUTEST)` leaves `$AUTEST` unquoted, so patterns like
`*/tls/*` (the documented example) can be expanded by the shell into many path
arguments before `autest.sh` sees them, changing or breaking the intended
filter.
##########
ci/coverage:
##########
@@ -16,93 +16,97 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-LCOV=${LCOV:-lcov}
-GENHTML=${GENHTML:-genhtml}
-
-TMPDIR=${TMPDIR:-/tmp}
-BUILDID="org.apache.trafficserver.$$"
-
-SRCROOT=${SRCROOT:-$(cd $(dirname $0)/.. && pwd)} # where the source lives
-OBJROOT=${OBJROOT:-"$TMPDIR/$BUILDID/obj"} # where we are building
-DSTROOT=${DSTROOT:-"$TMPDIR/$BUILDID/dst"} # where we are installing
-
-# Force low make parallelization so that the build can complete in a VM with
-# only a small amount of memory.
-NPROCS=${NPROCS:-2}
-
-mkdir -p $SRCROOT
-mkdir -p $OBJROOT
-mkdir -p $DSTROOT
-
-autogen() {
- (
- cd "$SRCROOT"
- [ configure -nt configure.ac -a Makefile.in -nt Makefile.am ] ||
autoreconf -fi
- )
-}
+# Build ATS with gcov instrumentation, run the unit tests (and optionally
+# autests), and produce a coverage report with gcovr.
+#
+# Usage:
+# ci/coverage [extra cmake args...]
+#
+# Environment overrides:
+# BUILDDIR build tree (default: build-coverage)
+# PREFIX install prefix (default: /tmp/ts-coverage)
+# NPROCS build parallelism (default: nproc)
Review Comment:
`BUILDDIR`'s documented default (“build-coverage”) doesn’t match the actual
default (`$SRCROOT/build-coverage`), which can confuse callers and tooling that
relies on the header comments.
##########
ci/coverage:
##########
@@ -16,93 +16,97 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-LCOV=${LCOV:-lcov}
-GENHTML=${GENHTML:-genhtml}
-
-TMPDIR=${TMPDIR:-/tmp}
-BUILDID="org.apache.trafficserver.$$"
-
-SRCROOT=${SRCROOT:-$(cd $(dirname $0)/.. && pwd)} # where the source lives
-OBJROOT=${OBJROOT:-"$TMPDIR/$BUILDID/obj"} # where we are building
-DSTROOT=${DSTROOT:-"$TMPDIR/$BUILDID/dst"} # where we are installing
-
-# Force low make parallelization so that the build can complete in a VM with
-# only a small amount of memory.
-NPROCS=${NPROCS:-2}
-
-mkdir -p $SRCROOT
-mkdir -p $OBJROOT
-mkdir -p $DSTROOT
-
-autogen() {
- (
- cd "$SRCROOT"
- [ configure -nt configure.ac -a Makefile.in -nt Makefile.am ] ||
autoreconf -fi
- )
-}
+# Build ATS with gcov instrumentation, run the unit tests (and optionally
+# autests), and produce a coverage report with gcovr.
+#
+# Usage:
+# ci/coverage [extra cmake args...]
+#
+# Environment overrides:
+# BUILDDIR build tree (default: build-coverage)
+# PREFIX install prefix (default: /tmp/ts-coverage)
+# NPROCS build parallelism (default: nproc)
+# GCOVR gcovr command (default: gcovr, falls back to uvx
gcovr)
+# AUTEST run autests too if set to a -f/--filter argument string,
+# e.g. AUTEST='*/tls/*' or AUTEST=all for the whole suite
+#
+# Requires: cmake, ninja or make, gcc/gcov, and gcovr (pip install gcovr).
+
+set -e
+
+SRCROOT=${SRCROOT:-$(cd "$(dirname "$0")"/.. && pwd)}
+BUILDDIR=${BUILDDIR:-$SRCROOT/build-coverage}
+PREFIX=${PREFIX:-/tmp/ts-coverage}
+NPROCS=${NPROCS:-$(nproc 2>/dev/null || echo 4)}
+
+GCOVR=${GCOVR:-gcovr}
+if ! command -v "${GCOVR%% *}" >/dev/null 2>&1; then
+ if command -v uvx >/dev/null 2>&1; then
+ GCOVR="uvx gcovr"
+ else
+ echo "gcovr not found; install it with 'pip install gcovr'" >&2
+ exit 1
+ fi
+fi
+
+# --coverage instruments compile and link. Atomic profile updates keep the
+# counters sane in ATS's heavily threaded runtime, and absolute paths in the
+# notes files let gcovr resolve sources from any working directory.
+COVERAGE_FLAGS="-g -O0 --coverage -fprofile-update=atomic -fprofile-abs-path"
configure() {
- (
- cd $OBJROOT
- $SRCROOT/configure \
- --prefix=$DSTROOT \
- --enable-debug \
- --enable-coverage \
- --enable-werror \
- --enable-example-plugins \
- --enable-test-tools \
- --enable-experimental-plugins \
- CC="$CC" \
- CXX="$CXX" \
- "$@"
- )
+ cmake -S "$SRCROOT" -B "$BUILDDIR" \
+ -DCMAKE_BUILD_TYPE=Debug \
+ -DCMAKE_INSTALL_PREFIX="$PREFIX" \
+ -DCMAKE_COMPILE_WARNING_AS_ERROR=OFF \
+ -DENABLE_AUTEST=ON \
+ -DBUILD_EXPERIMENTAL_PLUGINS=ON \
+ -DENABLE_EXAMPLE=ON \
+ -DCMAKE_CXX_FLAGS_DEBUG="$COVERAGE_FLAGS" \
+ -DCMAKE_C_FLAGS_DEBUG="$COVERAGE_FLAGS" \
+ "$@"
}
build() {
- ( cd $OBJROOT && $MAKE -j $NPROCS )
- ( cd $OBJROOT && $MAKE install )
+ cmake --build "$BUILDDIR" -j "$NPROCS"
+ cmake --install "$BUILDDIR"
}
-regress() {
- ( cd $OBJROOT && $MAKE check ) && \
- $DSTROOT/bin/traffic_server -k -K -R 1
-}
-
-CC=${CC:-gcc}
-CXX=${CXX:-g++}
-MAKE=${MAKE:-make}
-export CC CXX MAKE
-
-case $VERBOSE in
- Y*) set -x ;;
- y*) set -x ;;
- 1) set -x ;;
- *) set +x ;;
-esac
-
-autogen || exit 1
-configure "$@" || exit 1
-build || exit 1
+run_tests() {
+ # Reset counters so the report reflects exactly this run.
+ find "$BUILDDIR" -name '*.gcda' -delete
-$LCOV --quiet --capture --initial --directory $OBJROOT --output-file
initial.info
+ ctest --test-dir "$BUILDDIR" -j4
Review Comment:
`ctest` parallelism is hard-coded to `-j4`, ignoring `NPROCS`. This can
over-parallelize (and OOM) on small CI runners even when `NPROCS` is tuned down.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]