MXS-2152: Add rudimentary test coverage collection

If the build is configred with -DGCOV=Y, a HTML report of code coverage is
generated in the log publish directory.
This commit is contained in:
Markus Mäkelä 2019-05-06 07:11:09 +03:00
parent 45f508a376
commit c0b238a9e7
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
3 changed files with 27 additions and 4 deletions

View File

@ -97,9 +97,9 @@ else
grep "release 6" /etc/redhat-release
if [ $? -ne 0 ]
then
# Installed for REST API and MaxCtrl unit tests
# EPEL is installed for REST API and MaxCtrl unit tests (docker-compose etc.) and GCOV report generation (lcov)
sudo yum -y install docker epel-release
sudo yum -y install docker-compose
sudo yum -y install docker-compose lcov
sudo groupadd docker
sudo usermod -a -G docker `whoami`
sudo sed -i 's/--selinux-enabled/--selinux-enabled=false/' /etc/sysconfig/docker

View File

@ -141,8 +141,7 @@ if(CMAKE_VERSION VERSION_GREATER 2.6)
endif()
if(GCOV)
set(FLAGS "${FLAGS} -fprofile-arcs -ftest-coverage" CACHE STRING "Compilation flags" FORCE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lgcov")
set(FLAGS "${FLAGS} --coverage -O0 -g" CACHE STRING "Compilation flags" FORCE)
endif()
if(PROFILE)

View File

@ -56,6 +56,12 @@ export mdbci_config_name=`echo ${mdbci_config_name} | sed "s/?//g"`
export provider=`mdbci show provider $box --silent 2> /dev/null`
export backend_box=${backend_box:-"centos_7_"$provider}
export sshuser=`mdbci ssh --command 'whoami' --silent $mdbci_config_name/maxscale_000 2> /dev/null | tr -d '\r'`
export IP=`mdbci show network $mdbci_config_name/maxscale_000 --silent 2> /dev/null`
export sshkey=`mdbci show keyfile $mdbci_config_name/maxscale_000 --silent 2> /dev/null | sed 's/"//g'`
export scpopt="-i $sshkey -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ConnectTimeout=120 "
export sshopt="$scpopt $sshuser@$IP"
mdbci destroy ${mdbci_config_name}
. ${script_dir}/configure_log_dir.sh
@ -63,6 +69,17 @@ mdbci destroy ${mdbci_config_name}
ulimit -c unlimited
cd ${script_dir}/../../
if [[ "$cmake_flags" =~ "GCOV=Y" ]]
then
echo "Building MaxScale from source on maxscale_000"
rsync -avz --delete -e "ssh $scpopt" ${script_dir}/../../ $sshuser@$IP:/tmp/MaxScale/
ssh $sshopt "/tmp/MaxScale/BUILD/install_build_deps.sh"
ssh $sshopt "mkdir /tmp/build && cd /tmp/build && cmake ../MaxScale -DCMAKE_INSTALL_PREFIX=/usr -DGCOV=Y && make && sudo make install"
ssh $sshopt "sudo chmod -R a+rwx /tmp/build"
ssh $sshopt "sudo systemctl daemon-reload"
fi
mkdir build && cd build
cmake .. -DBUILD_SYSTEM_TESTS=Y -DBUILDNAME=${mdbci_config_name} -DCMAKE_BUILD_TYPE=Debug
cd maxscale-system-test
@ -82,6 +99,13 @@ if [ ! -z "${named_test}" ] ; then
else
ctest -VV ${test_set}
fi
if [[ "$cmake_flags" =~ "GCOV=Y" ]]
then
ssh $sshopt "cd /tmp/build && lcov --gcov-tool=$(command -v gcov) -c -d . -o lcov.info && genhtml -o /tmp/gcov-report/ lcov.info"
rsync -avz --delete -e "ssh $scpopt" $sshuser@$IP:/tmp/gcov-report/ ./${logs_publish_dir}
fi
cp core.* ${logs_publish_dir}
${script_dir}/copy_logs.sh
cd $dir