diff --git a/qt6-after/qt6-migrated-legatus/Lts/DDS/DTC/generic_dtc.h b/qt6-after/qt6-migrated-legatus/Lts/DDS/DTC/generic_dtc.h index 4bb45a5e6..d50e3ad46 100644 --- a/qt6-after/qt6-migrated-legatus/Lts/DDS/DTC/generic_dtc.h +++ b/qt6-after/qt6-migrated-legatus/Lts/DDS/DTC/generic_dtc.h @@ -59,13 +59,12 @@ class GenericDtc using BaseClass::takeAlive; using BaseClass::takeDisposed; using BaseClass::SubscriberCallback; - bool setSubscriberCallback(const typename BaseClass::SubscriberCallback& callback) override { return BaseClass::setSubscriberCallback(callback); } - bool readAlive(TopicType& data) { return BaseClass::readAlive(data); } - bool takeAlive(TopicType& data) { return BaseClass::takeAlive(data); } - bool takeDisposed(TopicType& data) { return BaseClass::takeDisposed(data); } - bool hasSamples() const { return BaseClass::hasSamples(); } - DRO_OBJECT* dataReader() const override { return BaseClass::dataReader(); } - bool waitForHistoricalData(int timeoutMSec) { return BaseClass::waitForHistoricalData(timeoutMSec); } + // NOTE: the methods of GenericDtcSC are deliberately NOT overridden here. + // They stay pure and are implemented by the concrete classes in + // generic_dtc_impl.h; calls through this class dispatch virtually. + // One-line forwarders like `return BaseClass::readAlive(data);` must not be + // re-introduced: they are a latent infinite recursion at runtime and an + // undefined pure-virtual symbol at link time at -O0 (e.g. coverage builds). }; template @@ -82,13 +81,12 @@ class GenericDtcSampleInfo using BaseClass::takeAlive; using BaseClass::takeDisposed; using BaseClass::SubscriberCallback; - bool setSubscriberCallback(const typename BaseClass::SubscriberCallback& callback) override { return BaseClass::setSubscriberCallback(callback); } - bool readAlive(TopicType& data) { return BaseClass::readAlive(data); } - bool takeAlive(TopicType& data) { return BaseClass::takeAlive(data); } - bool takeDisposed(TopicType& data) { return BaseClass::takeDisposed(data); } - bool hasSamples() const { return BaseClass::hasSamples(); } - DRO_OBJECT* dataReader() const override { return BaseClass::dataReader(); } - bool waitForHistoricalData(int timeoutMSec) { return BaseClass::waitForHistoricalData(timeoutMSec); } + // NOTE: the methods of GenericDtcSC are deliberately NOT overridden here. + // They stay pure and are implemented by the concrete classes in + // generic_dtc_impl.h; calls through this class dispatch virtually. + // One-line forwarders like `return BaseClass::readAlive(data);` must not be + // re-introduced: they are a latent infinite recursion at runtime and an + // undefined pure-virtual symbol at link time at -O0 (e.g. coverage builds). }; template @@ -105,13 +103,12 @@ class Ddtc using BaseClass::takeAlive; using BaseClass::takeDisposed; using BaseClass::SubscriberCallback; - bool setSubscriberCallback(const typename BaseClass::SubscriberCallback& callback) override { return BaseClass::setSubscriberCallback(callback); } - bool readAlive(TopicType& data) { return BaseClass::readAlive(data); } - bool takeAlive(TopicType& data) { return BaseClass::takeAlive(data); } - bool takeDisposed(TopicType& data) { return BaseClass::takeDisposed(data); } - bool hasSamples() const { return BaseClass::hasSamples(); } - DRO_OBJECT* dataReader() const override { return BaseClass::dataReader(); } - bool waitForHistoricalData(int timeoutMSec) { return BaseClass::waitForHistoricalData(timeoutMSec); } + // NOTE: the methods of GenericDtcSC are deliberately NOT overridden here. + // They stay pure and are implemented by the concrete classes in + // generic_dtc_impl.h; calls through this class dispatch virtually. + // One-line forwarders like `return BaseClass::readAlive(data);` must not be + // re-introduced: they are a latent infinite recursion at runtime and an + // undefined pure-virtual symbol at link time at -O0 (e.g. coverage builds). }; template @@ -128,12 +125,11 @@ class DdtcSampleInfo using BaseClass::takeAlive; using BaseClass::takeDisposed; using BaseClass::SubscriberCallback; - bool setSubscriberCallback(const typename BaseClass::SubscriberCallback& callback) override { return BaseClass::setSubscriberCallback(callback); } - bool readAlive(TopicType& data) { return BaseClass::readAlive(data); } - bool takeAlive(TopicType& data) { return BaseClass::takeAlive(data); } - bool takeDisposed(TopicType& data) { return BaseClass::takeDisposed(data); } - bool hasSamples() const { return BaseClass::hasSamples(); } - DRO_OBJECT* dataReader() const override { return BaseClass::dataReader(); } - bool waitForHistoricalData(int timeoutMSec) { return BaseClass::waitForHistoricalData(timeoutMSec); } + // NOTE: the methods of GenericDtcSC are deliberately NOT overridden here. + // They stay pure and are implemented by the concrete classes in + // generic_dtc_impl.h; calls through this class dispatch virtually. + // One-line forwarders like `return BaseClass::readAlive(data);` must not be + // re-introduced: they are a latent infinite recursion at runtime and an + // undefined pure-virtual symbol at link time at -O0 (e.g. coverage builds). }; } // namespace DTC diff --git a/qt6-after/qt6-migrated-legatus/README.md b/qt6-after/qt6-migrated-legatus/README.md index 414d8408c..c58db27e9 100644 --- a/qt6-after/qt6-migrated-legatus/README.md +++ b/qt6-after/qt6-migrated-legatus/README.md @@ -252,12 +252,28 @@ in-tree flow calls `new_docker_build.sh` (the Release 2 driver). See ## Step 6 — Code coverage (lcov) -`--run-coverage` is available and is mutually exclusive with -`--run-jenkins-builder`. In the current tree it only passes -`-DRUN_COVERAGE=ON` / `-DCOVERAGE_OUTPUT_DIR` to the configure — those -variables are not consumed by any `CMakeLists.txt` yet, so no lcov -data is collected. The option is kept for the (still to be wired) -coverage step. +`--run-coverage` builds the whole Release 2 scope instrumented +(`-O0 -g --coverage`, overriding the RelWithDebInfo flags), runs the +ctest suite and collects an lcov report inside the container +(lcov + genhtml ship in the `legatus-qt6:1.0` image): + +```bash +./new_docker_build.sh --run-coverage +``` + +The report is written to +`/coverage///` (default: +`coverage/guez/26.04/`), next to `qt-migration-legatus/` and outside +the tree: + +- `html/index.html` — browser report (line + branch coverage) +- `coverage.info` — lcov tracefile, filtered to `qt-migration-legatus/*` +- `coverage_summary.txt` — totals (line / branch hit rate) + +`--coverage-output-dir DIR` moves the report; `DIR` must be an absolute +path under the pipeline root (relative values are ignored and the +default above is used). The option is mutually exclusive with +`--run-jenkins-builder`. ## Options reference @@ -279,8 +295,8 @@ The main ones: | `--run-jenkins-builder` | off | produce the DEB packages (Step 4) | | `--package-output-dir DIR` | `./packages-out` | pass-through (see Step 4 note) | | `--lts-version / --project / --build-number / --build-tag` | `1.0` / `guez` / `1` / `manual-build` | package metadata | -| `--run-coverage` | off | coverage flag pass-through (Step 6) | -| `--coverage-output-dir DIR` | `./coverage-out` | pass-through (see Step 6) | +| `--run-coverage` | off | instrument with `-O0 --coverage`, run ctest, collect the lcov report (Step 6); mutually exclusive with `--run-jenkins-builder` | +| `--coverage-output-dir DIR` | `/coverage//` | report dir — only absolute paths under the pipeline root are honored (Step 6) | Environment overrides: `BUILD_GROUP1/3/5/6`, `RUN_CTEST`, `TESTS_ONLY`, `USE_PREBUILT_IMAGE`, `DOCKER_IMAGE`, `CMAKE_BUILD_FLAGS`, @@ -302,6 +318,14 @@ Environment overrides: `BUILD_GROUP1/3/5/6`, `RUN_CTEST`, `TESTS_ONLY`, `QT_PLUGIN_PATH` from Step 3). - **`GrantleeParserSmoke`: `ktexttemplate_defaulttags` not found** → run ctest/tests with the system plugin dir prepended (Step 3). +- **Coverage build fails to link with `undefined reference` to + `DTC::GenericDtcSC<...>::readAlive(...)` etc.** — a call to a pure + virtual function only links at `-O1` and above (GCC rewrites it to + `__cxa_pure_virtual`); at `-O0` the raw symbol stays undefined. This + was triggered by the one-line forwarders in + `Lts/DDS/DTC/generic_dtc.h`, which have been removed: the concrete + classes in `generic_dtc_impl.h` implement every method `final`, so + the forwarders were dead code (and a latent infinite recursion). - **Stale build tree** → the driver always recreates `../build/`; for manual builds delete `../build/` and rerun Step 2 if CMake behaves oddly. diff --git a/qt6-after/qt6-migrated-legatus/new_docker_build.sh b/qt6-after/qt6-migrated-legatus/new_docker_build.sh index c47c8bbb2..ac89218a9 100755 --- a/qt6-after/qt6-migrated-legatus/new_docker_build.sh +++ b/qt6-after/qt6-migrated-legatus/new_docker_build.sh @@ -48,8 +48,11 @@ Packages (DEB, via in-tree rpmbuild/make_rpm_ubuntu26_release2.py): --build-tag TAG Build tag for the package (default: manual-build) Coverage (lcov): - --run-coverage Coverage build + lcov report (README.md Step 6) - --coverage-output-dir DIR Directory for coverage output (default: ./coverage-out) + --run-coverage Build with -O0 --coverage, run ctest and collect + the lcov report (README.md Step 6) + --coverage-output-dir DIR Report dir (default: /coverage/ + //; honored when it is an absolute + path under the pipeline root) Environment overrides: BUILD_GROUP1/3/5/6, RUN_CTEST, TESTS_ONLY, USE_PREBUILT_IMAGE, DOCKER_IMAGE, CMAKE_BUILD_FLAGS, DOCKER_MOUNT_ROOT, @@ -261,6 +264,26 @@ BUILD_DIR="../build" log_info "Using build directory: ${BUILD_DIR}" rm -rf "${BUILD_DIR}" mkdir -p "${BUILD_DIR}" +# Make it absolute: later steps (ctest/coverage) cd elsewhere and must +# still find the build tree. +BUILD_DIR="$(cd "${BUILD_DIR}" && pwd)" + +# Coverage instrumentation (lcov): override the release flags with +# -O0 --coverage when RUN_COVERAGE=ON. +COV_CMAKE_ARGS=() +if [[ "${RUN_COVERAGE}" == "ON" ]]; then + log_info "Coverage mode: instrumenting with -O0 --coverage" + # The build type is RelWithDebInfo, so the config-specific flag variables + # are CMAKE_{C,CXX}_FLAGS_RELWITHDEBINFO (NOT *_RELEASE - those apply to + # the Release build type only). + COV_CMAKE_ARGS=( + "-DCMAKE_C_FLAGS_RELWITHDEBINFO=-O0 -g --coverage -DNDEBUG -fPIC" + "-DCMAKE_CXX_FLAGS_RELWITHDEBINFO=-O0 -g --coverage -DNDEBUG -fPIC" + "-DCMAKE_EXE_LINKER_FLAGS=--coverage" + "-DCMAKE_SHARED_LINKER_FLAGS=--coverage" + ) +fi + cmake -B "${BUILD_DIR}" \ -G Ninja \ -DBUILD_TESTING=ON \ @@ -281,6 +304,7 @@ cmake -B "${BUILD_DIR}" \ -DBUILD_TAG="${BUILD_TAG}" \ -DRUN_COVERAGE="${RUN_COVERAGE}" \ -DCOVERAGE_OUTPUT_DIR="${COVERAGE_OUTPUT_DIR}" \ + "${COV_CMAKE_ARGS[@]}" \ '"${CMAKE_BUILD_FLAGS}"' \ . @@ -327,6 +351,55 @@ if [[ "${RUN_CTEST}" == "ON" ]] && [[ "${TESTS_ONLY}" != "ON" ]]; then cd .. fi +# Code coverage (lcov): collect the tracefile, filter it down to the +# migrated tree, generate the browsable report and the scope summary. +if [[ "${RUN_COVERAGE}" == "ON" ]]; then + log_info "Collecting code coverage (lcov)..." + OS_VERSION=$(eval $(grep "^VERSION_ID=" /etc/os-release) && echo "$VERSION_ID") + COV_DIR="${DOCKER_MOUNT_ROOT}/coverage/${PROJECT}/${OS_VERSION}" + # Honor --coverage-output-dir when it is an absolute path under the + # pipeline root (the only place the host can see it inside the container). + case "${COVERAGE_OUTPUT_DIR}" in + /*) + if [[ "${COVERAGE_OUTPUT_DIR}" == "${MIGRATE_PIPELINE_ROOT}"/* ]]; then + COV_DIR="${DOCKER_MOUNT_ROOT}${COVERAGE_OUTPUT_DIR#"${MIGRATE_PIPELINE_ROOT}"}" + fi + ;; + esac + rm -rf "${COV_DIR}" + mkdir -p "${COV_DIR}" + cd "${BUILD_DIR}" + # gcov data quirks under -O0 (exception-tag mismatches, inlined-lambda + # consistency checks, ...): suppressed so the steps below don't abort. + LCOV_IGNORE_ERRORS="mismatch,unused,source,category,version,gcov,corrupt,unsupported,inconsistent,count" + # 1) capture all instrumented objects under the build tree + lcov --capture --directory . \ + --output-file "${COV_DIR}/coverage_raw.info" \ + --rc branch_coverage=1 \ + --ignore-errors="${LCOV_IGNORE_ERRORS}" \ + || die "lcov capture failed" + # 2) keep only the migrated-tree sources (drops Qt, RTI, system paths) + lcov --extract "${COV_DIR}/coverage_raw.info" "${DOCKER_MOUNT_ROOT}/qt-migration-legatus/*" \ + --output-file "${COV_DIR}/coverage.info" \ + --rc branch_coverage=1 \ + --ignore-errors="${LCOV_IGNORE_ERRORS}" \ + || die "lcov extract failed" + rm -f "${COV_DIR}/coverage_raw.info" + # 3) browsable report (line + branch coverage per file) + genhtml "${COV_DIR}/coverage.info" \ + --output-directory "${COV_DIR}/html" \ + --branch-coverage \ + --title "Legatus Qt6 Release 2 - code coverage" \ + --ignore-errors="${LCOV_IGNORE_ERRORS}" \ + || die "genhtml failed" + # 4) whole-scope totals + lcov --summary "${COV_DIR}/coverage.info" --rc branch_coverage=1 \ + --ignore-errors="${LCOV_IGNORE_ERRORS}" \ + > "${COV_DIR}/coverage_summary.txt" + log_info "Coverage report: ${COV_DIR} (html/index.html, coverage.info, coverage_summary.txt)" + cat "${COV_DIR}/coverage_summary.txt" +fi + # DEB Package Production (in-tree rpmbuild) if [[ "${RUN_JENKINS_BUILDER}" == "ON" ]]; then log_info "=== DEB Package Production (in-tree rpmbuild) ==="