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


##########
ci/coverage:
##########
@@ -16,93 +16,110 @@
 #  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" \
-      "$@"
-  )
+  # Enabling autest pulls in Python3/uv/nc and the proxy-verifier toolchain at
+  # configure time, so only ask for it when AUTEST actually selects a run.
+  local autest_args=()
+  if [ -n "$AUTEST" ]; then
+    autest_args=(-DENABLE_AUTEST=ON)
+  fi
+
+  cmake -S "$SRCROOT" -B "$BUILDDIR" \
+    -DCMAKE_BUILD_TYPE=Debug \
+    -DCMAKE_INSTALL_PREFIX="$PREFIX" \
+    -DCMAKE_COMPILE_WARNING_AS_ERROR=OFF \
+    -DBUILD_TESTING=ON \
+    "${autest_args[@]}" \
+    -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
+    # autest.sh already aims --sandbox at a per-build-tree path under /tmp, so
+    # concurrent coverage runs in separate build trees don't trample each 
other.
+    (cd "$BUILDDIR/tests" && ./autest.sh "${filter_args[@]}")

Review Comment:
   And we better use a --sandbox actually...the default sandbox typically has 
unix domain socket path too long issues.



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