From 2f110896e75b8f57476a0f8b92636325c0381372 Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Sun, 4 May 2025 18:28:15 +0100 Subject: [PATCH] CI: restore JUnit output processing in Jenkinsfile via wrapper which modifies the environment per test Workaround for https://github.com/google/gtest-parallel/pull/89 --- Jenkinsfile | 2 +- test/CMakeLists.txt | 3 ++- test/integration/wrapper.py | 49 +++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100755 test/integration/wrapper.py diff --git a/Jenkinsfile b/Jenkinsfile index 1d8f594b..980d8434 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -24,7 +24,7 @@ timestamps { } } stage('Integration test') { - withEnv(['GTEST_OUTPUT=xml:integration-test.xml']) { + withEnv(['GTEST_OUTPUT=xml:integration-XXX-test.xml']) { sh 'make install' sh 'make inttest' } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 780a7fb6..827cdb86 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -102,6 +102,7 @@ add_custom_target(inttest COMMAND # znc-buildmod should use the correct compiler. # https://bugs.gentoo.org/699258 is an example of how it can go wrong. ${CMAKE_COMMAND} -E env MAKEFLAGS= CXX=${CMAKE_CXX_COMPILER} + "INTTEST_BIN=${CMAKE_CURRENT_BINARY_DIR}/integration/inttest" "${PROJECT_SOURCE_DIR}/third_party/gtest-parallel/gtest-parallel" - "${CMAKE_CURRENT_BINARY_DIR}/integration/inttest") + "${CMAKE_CURRENT_SOURCE_DIR}/integration/wrapper.py") add_dependencies(inttest inttest_bin) diff --git a/test/integration/wrapper.py b/test/integration/wrapper.py new file mode 100755 index 00000000..47138988 --- /dev/null +++ b/test/integration/wrapper.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2004-2025 ZNC, see the NOTICE file for details. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# The purpose of this file is to fix environment in the parallel execution of +# the test with filenames of test results - otherwise all of them write to the +# same file, so it races and produces invalid data + +# See also: https://github.com/google/gtest-parallel/pull/89 + +import os +import sys +import re +import random + +flag = re.compile(r'--gtest_filter=(.*)') + +test = '' +for arg in sys.argv: + m = flag.search(arg) + if m: + test = m[1] + break + +# TODO: perhaps it should be hash of test name instead? +pid = os.getpid() +rand = random.randint(0, 1000) +value = f'{pid}-{rand}' +for var in ['GTEST_OUTPUT']: + if var in os.environ: + os.environ[var] = os.environ[var].replace('XXX', value) + +binary = os.environ['INTTEST_BIN'] +sys.argv[0] = binary + +os.execv(binary, sys.argv)