Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ on:
- "off"
default: "on"

code-coverage:
description: "Test code coverage is gathered when on"
type: choice
options:
- "on"
- "off"
default: "on"

forever-pause:
description: "Length of a period during which tomcats are run and stopped (MODCLUSTER-736 test)"
type: number
Expand Down Expand Up @@ -305,6 +313,7 @@ jobs:
FOREVER_PAUSE: ${{ inputs.forever-pause || 100 }}
ITERATION_COUNT: ${{ inputs.iteration-count || 2 }}
TOMCAT_CYCLE_COUNT: ${{ inputs.tomcat-cycle-count || 2 }}
CODE_COVERAGE: ${{ inputs.code-coverage || 'on' }}
steps:
- name: Checkout
uses: actions/checkout@v6
Expand Down Expand Up @@ -342,6 +351,17 @@ jobs:
path: |
test/logs/*
retention-days: 7
- name: Print the coverage summary
if: ${{ env.CODE_COVERAGE == 'on' }}
run: cat test/coverage/test-coverage.txt
# Preserve coverage data if defined
- name: Preserve coverage files
if: ${{ env.CODE_COVERAGE == 'on' }}
uses: actions/upload-artifact@v4
with:
name: Coverage ${{ matrix.os }}
path: test/coverage/*
retention-days: 7

perl-tests:
runs-on: ubuntu-latest
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ test/httpd/mod_proxy_cluster
# Log files
**/*.log

# Coverage files
test/coverage/
*.gcno
*.gcda
*.gcov

# build files
*.slo
*.so
Expand Down
6 changes: 6 additions & 0 deletions native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ ELSE()
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -p -O1 -std=gnu99 -fPIC -Wall -Wextra")
ENDIF()

OPTION(ENABLE_COVERAGE "Enable code coverage instrumentation" OFF)
IF(ENABLE_COVERAGE)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage -O0 -g -fprofile-update=atomic")
SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} --coverage")
ENDIF()

SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/modules)
SET(PROJECT_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
Expand Down
21 changes: 8 additions & 13 deletions test/httpd/Containerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM fedora:44 AS builder

ARG HTTPD_SOURCES="https://dlcdn.apache.org/httpd/httpd-2.4.68.tar.gz"
ARG ENABLE_COVERAGE=""

RUN dnf install gcc apr-devel apr-util-devel openssl-devel pcre-devel redhat-rpm-config autoconf wcstools -y
RUN dnf install gcc apr-devel apr-util-devel openssl-devel pcre-devel redhat-rpm-config wcstools cmake -y

ENV HTTPD=${HTTPD_SOURCES}

Expand All @@ -29,27 +30,21 @@ RUN sed -i 's/\(Listen 80\)/#\1/' /usr/local/apache2/conf/httpd.conf
# httpd is installed in /usr/local/apache2/bin/
# build and install mod_proxy_cluster *.so files.
WORKDIR /native
RUN for m in advertise mod_proxy_cluster balancers mod_manager; \
do \
cd $m; \
echo "Building $m"; \
./buildconf; \
./configure --with-apxs=/usr/local/apache2/bin/apxs; \
make clean; \
make || exit 1; \
cp *.so /usr/local/apache2/modules; \
cd $OLDPWD; \
done;

RUN mkdir build || true

RUN cd build && rm -rf * && cmake .. -DAPACHE_INCLUDE_DIR=/usr/local/apache2/include -DENABLE_COVERAGE=${ENABLE_COVERAGE:-OFF} && make && for f in modules/*.so; do ln -s "$PWD/$f" /usr/local/apache2/$f; done;

RUN rm -rf /test/httpd/mod_proxy_cluster

FROM fedora:44

ENV CONF=httpd/mod_proxy_cluster.conf

RUN dnf install pcre apr-util wcstools -y
RUN dnf install pcre apr-util wcstools gcc gcovr lcov -y

COPY --from=builder /usr/local/apache2 /usr/local/apache2
COPY --from=builder /native /native

COPY --from=builder /test /test

Expand Down
2 changes: 1 addition & 1 deletion test/httpd/mod_proxy_cluster.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ ProxyPreserveHost On
Listen 8090
ManagerBalancerName mycluster
WSUpgradeHeader websocket
ServerName httpd-mod_proxy_cluster

<VirtualHost *:8090>
ServerName httpd-mod_proxy_cluster
EnableMCMPReceive
<Location />
# For podman, this gets changed to IP in httpd/run.sh
Expand Down
10 changes: 9 additions & 1 deletion test/httpd/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ if [ ! -z "$MPC_NAME" ]; then
sed -i "s/ServerName httpd-mod_proxy_cluster/ServerName ${MPC_NAME}/g" /usr/local/apache2/conf/$FILECONF
fi

# start apache httpd server in foreground
# start apache httpd server
echo "Starting httpd..."
if [ "$ENABLE_COVERAGE" = "1" ]; then
# Let the unprivileged worker children create/merge .gcda files in the
# root-owned build tree: 777 for directory traversal + file creation, and
# umask 0 so gcov creates the .gcda files world-writable (0666). umask is
# inherited across fork(), so every worker gets it.
chmod -R 777 /native
umask 0
fi
/usr/local/apache2/bin/apachectl start
tail -f /usr/local/apache2/logs/error_log
23 changes: 21 additions & 2 deletions test/includes/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,28 @@ 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 is_enabled "$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 cp ${httpd_cont}:/usr/local/apache2/logs/access_log "logs/${2:-$1}-httpd_access.log" 2> /dev/null || true
fi

if is_enabled "$CODE_COVERAGE"; then
f=$(echo ${2:-$1} | sed 's/ /-/g')

docker exec ${httpd_cont} mkdir -p /coverage
docker exec ${httpd_cont} sh -c "/usr/local/apache2/bin/apachectl stop"
sleep 2 # wait for the coverage dump, just to be sure
docker exec ${httpd_cont} sh -c "cd /native && gcovr --gcov-ignore-parse-errors=negative_hits.warn_once_per_file --json /coverage/coverage-$f.json > /coverage/coverage-$f.log 2>&1"
docker exec ${httpd_cont} sh -c "lcov --capture --directory /native/build --ignore-errors gcov,negative --exclude '/usr/local/*' --output-file /coverage/coverage-$f.info > /coverage/coverage-lcov-$f.log 2>&1"

for cf in $(docker exec ${httpd_cont} ls /coverage/); do
docker cp ${httpd_cont}:/coverage/$cf $PWD/coverage/$cf > /dev/null
done
fi

# Clean all after run
httpd_remove > /dev/null 2>&1
tomcat_all_remove > /dev/null 2>&1
Expand Down Expand Up @@ -66,7 +82,9 @@ 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 ${CODE_COVERAGE:+--build-arg ENABLE_COVERAGE=ON} \
-f httpd/Containerfile httpd/
}

# Build and run httpd container
Expand All @@ -83,6 +101,7 @@ httpd_start() {
--ulimit nofile=65536:65536 --name ${MPC_NAME:-httpd-mod_proxy_cluster} \
-e MPC_NAME=${MPC_NAME:-httpd-mod_proxy_cluster} \
-e CONF=${MPC_CONF:-httpd/mod_proxy_cluster.conf} \
${CODE_COVERAGE:+-e ENABLE_COVERAGE=1} \
$HTTPD_IMG

httpd_wait_until_ready
Expand Down
27 changes: 25 additions & 2 deletions test/testsuite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,18 @@ if [ ! -d logs ]; then
mkdir logs
fi

if [ $CODE_COVERAGE ]; then
if [ ! -d coverage ]; then
mkdir coverage
fi
rm -f coverage/*
fi

. includes/common.sh

if [ ! -d tomcat/target ]; then
echo "Missing dependencies. Please run setup-dependencies.sh and then try again"
exit 4
exit 4
fi

echo -n "Creating docker containers..."
Expand Down Expand Up @@ -108,7 +115,7 @@ res=$(expr $res + $?)
echo -n "Cleaning containers if any..."
httpd_remove > /dev/null 2>&1
tomcat_all_remove > /dev/null 2>&1
echo " Done"
echo " Done"

if [ $res -eq 0 ]; then
echo "Tests finished successfully!"
Expand All @@ -117,4 +124,20 @@ else
res=1
fi

if [ $CODE_COVERAGE ]; then
echo "Generating test coverage..."
MPC_CONF=httpd/mod_lbmethod_cluster.conf httpd_start > /dev/null 2>&1
docker exec $MPC_NAME mkdir -p /coverage

for f in coverage/*.json coverage/*.info; do
[ -e "$f" ] && docker cp $f $MPC_NAME:/coverage/ > /dev/null
done

docker exec $MPC_NAME sh -c 'cd /native && gcovr --gcov-ignore-parse-errors=negative_hits.warn_once_per_file --add-tracefile "/coverage/coverage-*.json" --txt /coverage/test-coverage.txt --html-details /coverage/test-coverage.html > /coverage/test-coverage.log 2>&1'
docker exec $MPC_NAME sh -c 'cd /coverage && mkdir -p lcov && genhtml --ignore-errors negative,empty *.info --output-directory lcov > /coverage/lcov/test-coverage-lcov.log 2>&1'
docker cp $MPC_NAME:/coverage/ . > /dev/null

httpd_remove > /dev/null 2>&1
fi

exit $res
3 changes: 1 addition & 2 deletions test/usealias/mod_proxy_cluster.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ LoadModule proxy_cluster_module modules/mod_proxy_cluster.so
UseAlias On
ProxyPreserveHost On


Listen 8090
ManagerBalancerName mycluster
WSUpgradeHeader websocket
ServerName httpd-mod_proxy_cluster

<VirtualHost *:8090>
ServerName httpd-mod_proxy_cluster
EnableMCMPReceive
<Location />
# For podman, this gets changed to IP in httpd/run.sh
Expand Down
Loading