From 902861904ae39a3430d5cf0218283c6c66592144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Chlup?= Date: Mon, 6 Jan 2025 11:10:44 +0100 Subject: [PATCH 01/11] test: Add custom flags support for HTTPD container --- test/httpd/Containerfile | 18 ++++++++++-------- test/httpd/run.sh | 3 --- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/test/httpd/Containerfile b/test/httpd/Containerfile index 17ff736ba..559f88121 100644 --- a/test/httpd/Containerfile +++ b/test/httpd/Containerfile @@ -1,11 +1,18 @@ FROM fedora:41 ARG HTTPD_SOURCES="https://dlcdn.apache.org/httpd/httpd-2.4.63.tar.gz" +ARG CFLAGS="" +ARG LFLAGS="" +ARG HTTPD_DEFAULT_FLAGS="--enable-proxy --enable-proxy-http --enable-proxy-ajp --enable-proxy-wstunnel --enable-proxy-hcheck --with-port=8000" +ARG HTTPD_EXTRA_FLAGS="" -RUN yum install gcc wget apr-devel apr-util-devel openssl-devel pcre-devel redhat-rpm-config wcstools git autoconf -y +RUN yum install gcc wget apr-devel apr-util-devel openssl-devel pcre-devel redhat-rpm-config wcstools git autoconf gcovr -y ENV CONF=httpd/mod_proxy_cluster.conf ENV HTTPD=${HTTPD_SOURCES} +ENV CFLAGS="${CFLAGS}" +ENV LDFLAGS="${LDFLAGS}" +ENV HTTPD_FLAGS="${HTTPD_DEFAULT_FLAGS} ${HTTPD_EXTRA_FLAGS}" # make sure you have copy of the local repository at place # (our function "httpd_create" takes care of that) @@ -17,12 +24,7 @@ RUN mkdir httpd RUN tar xvf $(filename $HTTPD) --strip 1 -C httpd RUN ls WORKDIR /httpd -RUN ./configure --enable-proxy \ - --enable-proxy-http \ - --enable-proxy-ajp \ - --enable-proxy-wstunnel \ - --enable-proxy-hcheck \ - --with-port=8000 +RUN ./configure ${HTTPD_FLAGS} RUN make RUN make install @@ -37,7 +39,7 @@ RUN for m in advertise mod_proxy_cluster balancers mod_manager; \ ./configure --with-apxs=/usr/local/apache2/bin/apxs; \ make clean; \ make || exit 1; \ - cp *.so /usr/local/apache2/modules; \ + for f in *.so; do ln -s "$PWD/$f" /usr/local/apache2/modules/$f; done; \ cd $OLDPWD; \ done; diff --git a/test/httpd/run.sh b/test/httpd/run.sh index 0579e7642..88789cf7e 100755 --- a/test/httpd/run.sh +++ b/test/httpd/run.sh @@ -1,8 +1,5 @@ #!/bin/sh -pwd -ls -lt - # wget and copy the prepared conf file and include it cd /test/ if [ -f $CONF ]; then From 2e230f8b27d7e966211e7579f9a4d9ecd76fca78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Chlup?= Date: Mon, 6 Jan 2025 11:14:29 +0100 Subject: [PATCH 02/11] test: Add support for custom httpd flags to the testsuite --- test/includes/common.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/includes/common.sh b/test/includes/common.sh index 919405530..12d7db36a 100644 --- a/test/includes/common.sh +++ b/test/includes/common.sh @@ -29,6 +29,7 @@ run_test() { docker logs $httpd_cont > "logs/${2:-$1}-httpd.log" 2>&1 docker cp ${httpd_cont}:/usr/local/apache2/logs/access_log "logs/${2:-$1}-httpd_access.log" 2> /dev/null || true fi + # Clean all after run httpd_remove > /dev/null 2>&1 tomcat_all_remove > /dev/null 2>&1 @@ -54,7 +55,11 @@ httpd_create() { done cp -r ../native ../test /tmp/mod_proxy_cluster/ mv /tmp/mod_proxy_cluster httpd/ - docker build -t $HTTPD_IMG -f httpd/Containerfile httpd/ + + docker build -t $HTTPD_IMG --build-arg CFLAGS="$MPC_CFLAGS" \ + --build-arg LDFLAGS="$MPC_LDFLAGS" \ + --build-arg HTTPD_EXTRA_FLAGS="$HTTPD_EXTRA_FLAGS" \ + -f httpd/Containerfile httpd/ } # Build and run httpd container From 9961fe2f72e7d90150fbbf603d3294f74d5f3b60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Chlup?= Date: Mon, 6 Jan 2025 12:34:54 +0100 Subject: [PATCH 03/11] test: Add coverage support into the testsuite Through CODE_COVERAGE variable --- test/httpd/run.sh | 2 ++ test/includes/common.sh | 23 +++++++++++++++++++++-- test/testsuite.sh | 22 ++++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/test/httpd/run.sh b/test/httpd/run.sh index 88789cf7e..117dc7efc 100755 --- a/test/httpd/run.sh +++ b/test/httpd/run.sh @@ -11,6 +11,8 @@ else exit 1 fi +mkdir /coverage + # start apache httpd server in foreground echo "Starting httpd..." /usr/local/apache2/bin/apachectl start diff --git a/test/includes/common.sh b/test/includes/common.sh index 12d7db36a..5f833301c 100644 --- a/test/includes/common.sh +++ b/test/includes/common.sh @@ -4,6 +4,12 @@ IMG=${IMG:-mod_proxy_cluster-testsuite-tomcat} HTTPD_IMG=${HTTPD_IMG:-mod_proxy_cluster-testsuite-httpd} MPC_NAME=${MPC_NAME:-httpd-mod_proxy_cluster} +if [ $CODE_COVERAGE ]; then + MPC_CFLAGS="$MPC_CFLAGS --coverage -fprofile-arcs -ftest-coverage -g -O0" + MPC_LDFLAGS="$MPC_LDFLAGS -lgcov" + HTTPD_EXTRA_FLAGS="$HTTPD_EXTRA_FLAGS --enable-debugger-mode" +fi + # Runs a test file ($1) under given name ($2, if given) run_test() { local ret=0 @@ -23,13 +29,26 @@ run_test() { echo " NOK" ret=1 fi + + local httpd_cont=$(docker ps -a | grep $HTTPD_IMG | cut -f 1 -d' ') # preserve httpd's logs too if DEBUG if [ $DEBUG ]; then - local httpd_cont=$(docker ps -a | grep $HTTPD_IMG | cut -f 1 -d' ') - docker logs $httpd_cont > "logs/${2:-$1}-httpd.log" 2>&1 + docker logs ${httpd_cont} > "logs/${2:-$1}-httpd.log" 2>&1 docker cp ${httpd_cont}:/usr/local/apache2/logs/access_log "logs/${2:-$1}-httpd_access.log" 2> /dev/null || true fi + if [ $CODE_COVERAGE ]; then + docker exec ${httpd_cont} /usr/local/apache2/bin/apachectl stop + # preserve the coverage files + # docker has problems with names containing spaces + f=$(echo ${2:-1} | sed 's/ /-/g') + docker exec ${httpd_cont} sh -c "cd /native; gcovr --gcov-ignore-errors=no_working_dir_found --json /coverage/coverage-$f.json" + + for f in $(docker exec ${httpd_cont} ls /coverage/); do + docker cp -q ${httpd_cont}:/coverage/$f $PWD/coverage/$f + done + fi + # Clean all after run httpd_remove > /dev/null 2>&1 tomcat_all_remove > /dev/null 2>&1 diff --git a/test/testsuite.sh b/test/testsuite.sh index de307743b..abfc89f62 100644 --- a/test/testsuite.sh +++ b/test/testsuite.sh @@ -36,6 +36,14 @@ if [ ! -d logs ]; then mkdir logs fi +if [ $CODE_COVERAGE ]; then + if [ ! -d coverage ]; then + mkdir coverage + fi + + rm coverage/* +fi + . includes/common.sh if [ ! -d tomcat/target ]; then @@ -114,4 +122,18 @@ else res=1 fi +# if we're interessed in code coverage, run an httpd container with the already obtained +# coverage files and generate the report from within the container with all the sources +if [ $CODE_COVERAGE ]; then + echo "Generating test coverage..." + httpd_start > /dev/null 2>&1 + docker exec $MPC_NAME /usr/local/apache2/bin/apachectl stop + for f in $(ls coverage/*.json); do + docker cp -q $f $MPC_NAME:/coverage/ + done + docker exec $MPC_NAME sh -c 'cd /native; gcovr --add-tracefile "/coverage/coverage-*.json" --html-details /coverage/test-coverage.html' + docker cp $MPC_NAME:/coverage/ . + httpd_remove +fi + exit $res From f1f54f2aa654a4c936eac5c7afbae97e183c2f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Chlup?= Date: Mon, 6 Jan 2025 12:35:35 +0100 Subject: [PATCH 04/11] Add coverage directory to gitignore --- .gitignore | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index 3092828bf..c7665aa2c 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,12 @@ test/httpd/mod_proxy_cluster # Log files **/*.log +# Coverage files +test/coverage/ +*.gcno +*.gcda +*.gcov + # build files *.slo *.so From 9cd6195c2cfc3225ec91287c010c5e2519d25f90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Chlup?= Date: Tue, 14 Jan 2025 10:34:48 +0100 Subject: [PATCH 05/11] ci: Generate coverage report for the testsuite Install gcc package that provides gcovr --- .github/workflows/ci.yml | 12 ++++++++++-- test/testsuite.sh | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d6b6a5e6..e597d11c5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -227,6 +227,7 @@ jobs: FOREVER_PAUSE: 100 ITERATION_COUNT: 2 TOMCAT_CYCLE_COUNT: 2 + CODE_COVERAGE: 1 steps: - name: Checkout uses: actions/checkout@v4 @@ -253,9 +254,16 @@ jobs: if: always() with: name: Test logs - path: | - test/logs/* + path: test/logs/* retention-days: 7 + # Preserve coverage data if defined + - name: Preserve coverage files + if: env.CODE_COVERAGE + uses: actions/upload-artifact@v4 + with: + name: Coverage + path: test/coverage/* + retention-days: 7 perl-tests: runs-on: ubuntu-latest diff --git a/test/testsuite.sh b/test/testsuite.sh index abfc89f62..51f562b8d 100644 --- a/test/testsuite.sh +++ b/test/testsuite.sh @@ -128,11 +128,14 @@ if [ $CODE_COVERAGE ]; then echo "Generating test coverage..." httpd_start > /dev/null 2>&1 docker exec $MPC_NAME /usr/local/apache2/bin/apachectl stop + for f in $(ls coverage/*.json); do docker cp -q $f $MPC_NAME:/coverage/ done + docker exec $MPC_NAME sh -c 'cd /native; gcovr --add-tracefile "/coverage/coverage-*.json" --html-details /coverage/test-coverage.html' docker cp $MPC_NAME:/coverage/ . + httpd_remove fi From 5d3620b522580ba7a22c48b5a840cd12bfe6a711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Chlup?= Date: Tue, 14 Jan 2025 09:51:13 +0100 Subject: [PATCH 06/11] test: Fix testsuite.sh indentation, clean test/logs/ before each run --- test/testsuite.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/testsuite.sh b/test/testsuite.sh index 51f562b8d..30ca46d44 100644 --- a/test/testsuite.sh +++ b/test/testsuite.sh @@ -34,6 +34,7 @@ fi if [ ! -d logs ]; then mkdir logs + rm logs/* fi if [ $CODE_COVERAGE ]; then @@ -53,11 +54,11 @@ fi echo -n "Creating docker containers..." if [ ! -z ${DEBUG+x} ]; then - httpd_create || exit 2 - tomcat_create || exit 3 + httpd_create || exit 2 + tomcat_create || exit 3 else - httpd_create > /dev/null 2>&1 || exit 2 - tomcat_create > /dev/null 2>&1 || exit 3 + httpd_create > /dev/null 2>&1 || exit 2 + tomcat_create > /dev/null 2>&1 || exit 3 fi echo " Done" From 34e56008dbf0981fa6698ebef15f3418783862f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Chlup?= Date: Tue, 14 Jan 2025 11:26:20 +0100 Subject: [PATCH 07/11] test: Use log files for gcovr output, redirect docker cp output to /dev/null This is necessary because `podman cp` doesn't know `-q` flag --- test/includes/common.sh | 4 ++-- test/testsuite.sh | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/includes/common.sh b/test/includes/common.sh index 5f833301c..77a6e682a 100644 --- a/test/includes/common.sh +++ b/test/includes/common.sh @@ -42,10 +42,10 @@ run_test() { # preserve the coverage files # docker has problems with names containing spaces f=$(echo ${2:-1} | sed 's/ /-/g') - docker exec ${httpd_cont} sh -c "cd /native; gcovr --gcov-ignore-errors=no_working_dir_found --json /coverage/coverage-$f.json" + docker exec ${httpd_cont} sh -c "cd /native; gcovr --gcov-ignore-errors=no_working_dir_found --json /coverage/coverage-$f.json > /coverage/coverage-$f.log 2>&1" for f in $(docker exec ${httpd_cont} ls /coverage/); do - docker cp -q ${httpd_cont}:/coverage/$f $PWD/coverage/$f + docker cp ${httpd_cont}:/coverage/$f $PWD/coverage/$f > /dev/null done fi diff --git a/test/testsuite.sh b/test/testsuite.sh index 30ca46d44..c28e9ed20 100644 --- a/test/testsuite.sh +++ b/test/testsuite.sh @@ -131,11 +131,11 @@ if [ $CODE_COVERAGE ]; then docker exec $MPC_NAME /usr/local/apache2/bin/apachectl stop for f in $(ls coverage/*.json); do - docker cp -q $f $MPC_NAME:/coverage/ + docker cp $f $MPC_NAME:/coverage/ > /dev/null done - docker exec $MPC_NAME sh -c 'cd /native; gcovr --add-tracefile "/coverage/coverage-*.json" --html-details /coverage/test-coverage.html' - docker cp $MPC_NAME:/coverage/ . + docker exec $MPC_NAME sh -c 'cd /native; gcovr --add-tracefile "/coverage/coverage-*.json" --html-details /coverage/test-coverage.html > /coverage/test-coverage.log 2>&1' + docker cp $MPC_NAME:/coverage/ . > /dev/null httpd_remove fi From 563ce5633481274ba27b0c7673a283f1f1765905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Chlup?= Date: Tue, 14 Jan 2025 16:01:40 +0100 Subject: [PATCH 08/11] test: Add lcov coverage report as well --- test/httpd/Containerfile | 2 +- test/includes/common.sh | 1 + test/testsuite.sh | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/httpd/Containerfile b/test/httpd/Containerfile index 559f88121..5993aa867 100644 --- a/test/httpd/Containerfile +++ b/test/httpd/Containerfile @@ -6,7 +6,7 @@ ARG LFLAGS="" ARG HTTPD_DEFAULT_FLAGS="--enable-proxy --enable-proxy-http --enable-proxy-ajp --enable-proxy-wstunnel --enable-proxy-hcheck --with-port=8000" ARG HTTPD_EXTRA_FLAGS="" -RUN yum install gcc wget apr-devel apr-util-devel openssl-devel pcre-devel redhat-rpm-config wcstools git autoconf gcovr -y +RUN yum install gcc wget apr-devel apr-util-devel openssl-devel pcre-devel redhat-rpm-config wcstools git autoconf gcovr lcov -y ENV CONF=httpd/mod_proxy_cluster.conf ENV HTTPD=${HTTPD_SOURCES} diff --git a/test/includes/common.sh b/test/includes/common.sh index 77a6e682a..ce6a44b35 100644 --- a/test/includes/common.sh +++ b/test/includes/common.sh @@ -43,6 +43,7 @@ run_test() { # docker has problems with names containing spaces f=$(echo ${2:-1} | sed 's/ /-/g') docker exec ${httpd_cont} sh -c "cd /native; gcovr --gcov-ignore-errors=no_working_dir_found --json /coverage/coverage-$f.json > /coverage/coverage-$f.log 2>&1" + docker exec ${httpd_cont} sh -c "cd /native; lcov --capture --directory . --output-file /coverage/coverage-$f.info" for f in $(docker exec ${httpd_cont} ls /coverage/); do docker cp ${httpd_cont}:/coverage/$f $PWD/coverage/$f > /dev/null diff --git a/test/testsuite.sh b/test/testsuite.sh index c28e9ed20..ffb5c09e4 100644 --- a/test/testsuite.sh +++ b/test/testsuite.sh @@ -130,11 +130,12 @@ if [ $CODE_COVERAGE ]; then httpd_start > /dev/null 2>&1 docker exec $MPC_NAME /usr/local/apache2/bin/apachectl stop - for f in $(ls coverage/*.json); do + for f in $(ls coverage/*.json coverage/*.info); do docker cp $f $MPC_NAME:/coverage/ > /dev/null done docker exec $MPC_NAME sh -c 'cd /native; gcovr --add-tracefile "/coverage/coverage-*.json" --html-details /coverage/test-coverage.html > /coverage/test-coverage.log 2>&1' + docker exec $MPC_NAME sh -c 'cd /coverage; mkdir lcov; genhtml *.info --output-directory lcov' docker cp $MPC_NAME:/coverage/ . > /dev/null httpd_remove From 0a6710717bac4514ffd36269f6d0cfa7c37b2182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Chlup?= Date: Wed, 22 Jan 2025 14:38:13 +0100 Subject: [PATCH 09/11] WIP --- test/httpd/Containerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/httpd/Containerfile b/test/httpd/Containerfile index 5993aa867..dfa89a449 100644 --- a/test/httpd/Containerfile +++ b/test/httpd/Containerfile @@ -2,7 +2,7 @@ FROM fedora:41 ARG HTTPD_SOURCES="https://dlcdn.apache.org/httpd/httpd-2.4.63.tar.gz" ARG CFLAGS="" -ARG LFLAGS="" +ARG LDFLAGS="" ARG HTTPD_DEFAULT_FLAGS="--enable-proxy --enable-proxy-http --enable-proxy-ajp --enable-proxy-wstunnel --enable-proxy-hcheck --with-port=8000" ARG HTTPD_EXTRA_FLAGS="" From b8cc2ba01d38a750c1696e92fb5cb92e2c7cae59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Chlup?= Date: Wed, 22 Jan 2025 15:10:27 +0100 Subject: [PATCH 10/11] WIP silence output --- test/includes/common.sh | 2 +- test/testsuite.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/includes/common.sh b/test/includes/common.sh index ce6a44b35..c95dfde7a 100644 --- a/test/includes/common.sh +++ b/test/includes/common.sh @@ -43,7 +43,7 @@ run_test() { # docker has problems with names containing spaces f=$(echo ${2:-1} | sed 's/ /-/g') docker exec ${httpd_cont} sh -c "cd /native; gcovr --gcov-ignore-errors=no_working_dir_found --json /coverage/coverage-$f.json > /coverage/coverage-$f.log 2>&1" - docker exec ${httpd_cont} sh -c "cd /native; lcov --capture --directory . --output-file /coverage/coverage-$f.info" + docker exec ${httpd_cont} sh -c "cd /native; lcov --capture --directory . --output-file /coverage/coverage-$f.info > /coverage/coverage-lcov-$f.log 2>&1" for f in $(docker exec ${httpd_cont} ls /coverage/); do docker cp ${httpd_cont}:/coverage/$f $PWD/coverage/$f > /dev/null diff --git a/test/testsuite.sh b/test/testsuite.sh index ffb5c09e4..195667fba 100644 --- a/test/testsuite.sh +++ b/test/testsuite.sh @@ -135,7 +135,7 @@ if [ $CODE_COVERAGE ]; then done docker exec $MPC_NAME sh -c 'cd /native; gcovr --add-tracefile "/coverage/coverage-*.json" --html-details /coverage/test-coverage.html > /coverage/test-coverage.log 2>&1' - docker exec $MPC_NAME sh -c 'cd /coverage; mkdir lcov; genhtml *.info --output-directory lcov' + docker exec $MPC_NAME sh -c 'cd /coverage; mkdir lcov; genhtml *.info --output-directory lcov > /coverage/lcov/test-coverage-lcov.log 2>&1' docker cp $MPC_NAME:/coverage/ . > /dev/null httpd_remove From 74a18487c4f691cd3b526ac85c7205f1277c63cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Chlup?= Date: Thu, 20 Mar 2025 10:00:50 +0100 Subject: [PATCH 11/11] Add -fPIC --- test/includes/common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/includes/common.sh b/test/includes/common.sh index c95dfde7a..7c63243bc 100644 --- a/test/includes/common.sh +++ b/test/includes/common.sh @@ -5,7 +5,7 @@ HTTPD_IMG=${HTTPD_IMG:-mod_proxy_cluster-testsuite-httpd} MPC_NAME=${MPC_NAME:-httpd-mod_proxy_cluster} if [ $CODE_COVERAGE ]; then - MPC_CFLAGS="$MPC_CFLAGS --coverage -fprofile-arcs -ftest-coverage -g -O0" + MPC_CFLAGS="$MPC_CFLAGS --coverage -fprofile-arcs -ftest-coverage -fPIC -g -O0" MPC_LDFLAGS="$MPC_LDFLAGS -lgcov" HTTPD_EXTRA_FLAGS="$HTTPD_EXTRA_FLAGS --enable-debugger-mode" fi