Copilot commented on code in PR #13305:
URL: https://github.com/apache/trafficserver/pull/13305#discussion_r3455813929


##########
ci/coverage:
##########
@@ -16,93 +16,100 @@
 #  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: $SRCROOT/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
+run_tests() {
+  # Reset counters so the report reflects exactly this run.
+  find "$BUILDDIR" -name '*.gcda' -delete
+
+  ctest --test-dir "$BUILDDIR" -j "$NPROCS"
+
+  if [ -n "$AUTEST" ]; then
+    local filter_args=()
+    if [ "$AUTEST" != all ]; then
+      # Quote the pattern: autest fnmatches it against each test's full path
+      # (e.g. '*/tls/*'), so it must reach autest verbatim, not be 
glob-expanded
+      # by the shell first.
+      filter_args=(-f "$AUTEST")
+    fi
+    (cd "$BUILDDIR/tests" && ./autest.sh --sandbox /tmp/sb-coverage 
"${filter_args[@]}")

Review Comment:
   The autest sandbox path is hard-coded to `/tmp/sb-coverage`. Concurrent runs 
(e.g., multiple CI jobs or local runs in parallel) can trample each other’s 
sandboxes and produce flaky failures or mixed coverage data. Use a per-run 
sandbox path (PID or mktemp) and create it before invoking `autest.sh`.



##########
ci/coverage:
##########
@@ -16,93 +16,100 @@
 #  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: $SRCROOT/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 \

Review Comment:
   `configure()` forces `-DENABLE_AUTEST=ON`, but the script describes autests 
as optional. With `ENABLE_AUTEST` enabled, the top-level CMakeLists requires 
Python3/uv/nc, so `ci/coverage` will fail to configure even when `AUTEST` is 
unset. Also, because the script always runs `ctest`, it should explicitly set 
`-DBUILD_TESTING=ON` to avoid generating an empty report if a caller passes 
`-DBUILD_TESTING=OFF` (or if defaults change).



-- 
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]

Reply via email to