From 0c940048927f860d7edb90557806ac534d699877 Mon Sep 17 00:00:00 2001 From: Jicquel Date: Fri, 12 Jan 2024 14:42:26 +0100 Subject: [PATCH 1/2] Fix test coverage visualization for gitlab MR's "changes" tab The coverage generation of the gnatcoll-core's CI rely on `anod`, more specifically `anod build gnatcoll-core -Qcoverage` and `anod test gnatcoll-core -Qcoverage`. The latter will run `run-tests` that generates the coverage files thanks to the `gnatcov coverage` command. The cobertura.xml file is used by the CI to show coverage on MR's "changes" tab. It did not work before this modification, because the sources paths were not relative to the gnatcoll-core repository, but absolute to the gitlab's runner directory. To remove this absolute prefix, --source-root can be given to the `gnatcov coverage` command. This commit adapts `run-tests`, so it can accept this new option that will be passed to `gnatcov`. Co-Authored-By: Jerome Lambourg Issue: #26 Depends-On: eng/shared/anod!2607 --- testsuite/drivers/gnatcov.py | 6 +++++- testsuite/run-tests | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/testsuite/drivers/gnatcov.py b/testsuite/drivers/gnatcov.py index 82579a87..a733e8de 100644 --- a/testsuite/drivers/gnatcov.py +++ b/testsuite/drivers/gnatcov.py @@ -50,7 +50,7 @@ def ensure_clean_dir(dirname): os.mkdir(dirname) -def produce_report(driver, output_dir, formats=['dhtml', 'xml', 'cobertura']): +def produce_report(driver, output_dir, source_root=None, formats=['dhtml', 'xml', 'cobertura']): "Produce a coverage reports." traces_list = os.path.join(driver.env.gnatcov_traces, 'traces.txt') @@ -63,6 +63,8 @@ def produce_report(driver, output_dir, formats=['dhtml', 'xml', 'cobertura']): '-P', 'gnatcoll.gpr', '-XLIBRARY_TYPE=static', '-XGNATCOLL_BUILD_MODE=DEBUG', '--save-checkpoint', checkpoint_file, f'@{traces_list}'] + if source_root: + args.append("--source-root="+source_root) p = Run(args) if p.status: logging.error( @@ -81,6 +83,8 @@ def produce_report(driver, output_dir, formats=['dhtml', 'xml', 'cobertura']): '-P', 'gnatcoll.gpr', '-XLIBRARY_TYPE=static', '-XGNATCOLL_BUILD_MODE=DEBUG', '--checkpoint', checkpoint_file] + if source_root: + args.append("--source-root="+source_root) p = Run(args, output=None) if p.status: logging.error('could not produce the coverage report:\n' diff --git a/testsuite/run-tests b/testsuite/run-tests index 0b288f13..8bef687e 100755 --- a/testsuite/run-tests +++ b/testsuite/run-tests @@ -34,6 +34,13 @@ class MyTestsuite(Testsuite): " If both are specified, only --recompile is used", default=False, action="store_true") + parser.add_argument( + '--source-root', + help="Option specific to the GNATcoverage Cobertura coverage" + + " report: remove the specified prefix from the filenames in" + + " the report. Must be used with the --gnatcov option.", + default=None, + action="store") parser.add_argument( '--valgrind', help="check memory usage with Valgrind (memcheck tool)", @@ -49,6 +56,7 @@ class MyTestsuite(Testsuite): def set_up(self): self.env.gnatcov = self.main.args.gnatcov self.env.valgrind = self.main.args.valgrind + self.env.source_root = self.main.args.source_root # Reject incompatible options incompatible = [name for name in ('gnatcov', 'valgrind') @@ -79,7 +87,7 @@ class MyTestsuite(Testsuite): # If requested, produce coverage reports if self.env.gnatcov: - produce_report(self, self.output_dir) + produce_report(self, self.output_dir, self.env.source_root) super(MyTestsuite, self).tear_down() @property From 2f58eb1b6c0895ac277b994376ac26d93689749c Mon Sep 17 00:00:00 2001 From: Jicquel Date: Fri, 12 Jan 2024 17:48:41 +0100 Subject: [PATCH 2/2] Source the generic CI environment before jobs To benefit from CI features like "Depends-On", the generic CI environment is required. To do so, the image:e3 must be used and the commmand generic_anod_ci must be executed. Co-Authored-By: Jerome Lambourg Issue: #26 Change-Id: I1efdbcb67a3ebf12bb54b10df0a45916ae8531d5 --- .gitlab-ci.yml | 70 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 14 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c633c9dc..6834bcc0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,11 +11,63 @@ stages: - build - test -build: +default: + before_script: | + echo "before script executing..." + + ####################### + ## colored execution ## + ####################### + + exec() { + # dark green + $ + command line + grey + echo -e "\e[0;32m\$ $@\e[0;37m" + $@ + # save the result + res=$? + # back to normal output + echo -e -n "\e[0m" + # make sure we translate the exit code + return $res + } + + # Enable generic CI for building with Anod + + cmd="generic_anod_ci" + + exec eval $cmd + echo "sourcing the generic CI environment" + . /tmp/ci_env.sh + + # generic_anod_ci modifies the rebuild strategy of anod. + # Set it back to full, so we do not rebuild the packages depending + # on gnatcoll-core and contained in GNAT. + exec anod tune --full + exec anod vcs --list + +################ +# JOB TEMPLATE # +################ + +.job_template: services: - - image:sandbox + - image:e3 - cpu:8 - mem:16 + interruptible: true + +.test_template: + extends: .job_template + stage: test + needs: ["build"] + allow_failure: true + +######## +# JOBS # +######## + +build: + extends: .job_template stage: build script: - anod vcs --add-repo gnatcoll-core $CI_PROJECT_DIR @@ -32,12 +84,7 @@ build: - gnatcoll-core-current.tar.gz test: - services: - - image:sandbox - - cpu:8 - - mem:16 - stage: test - allow_failure: true + extends: .test_template script: # unpack the packages - cd $ANOD_DEFAULT_SANDBOX_DIR @@ -63,8 +110,6 @@ test: # We previously prevented the pipeline from halting if a test failed, to make # sure all tests were run. If a test failed now we exit with a non-zero code - if [ ! -z ${FAILED+x} ]; then echo "There was at least one testcase failure" && exit 1; fi - needs: - - job: build artifacts: when: always @@ -74,10 +119,7 @@ test: junit: test.xml build_and_test_coverage: - services: - - image:sandbox - - cpu:8 - - mem:16 + extends: .job_template stage: build script: - anybadge -l Coverage -v "Under Construction" -f coverage.svg -c steelblue