From c0b238a9e72a7bb43472ccfbc9f759a63264de9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Mon, 6 May 2019 07:11:09 +0300 Subject: [PATCH] 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. --- BUILD/install_build_deps.sh | 4 ++-- CMakeLists.txt | 3 +-- maxscale-system-test/mdbci/run_test.sh | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/BUILD/install_build_deps.sh b/BUILD/install_build_deps.sh index 7f8bc44ad..55342045c 100755 --- a/BUILD/install_build_deps.sh +++ b/BUILD/install_build_deps.sh @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index a9baffe64..7c7e88931 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/maxscale-system-test/mdbci/run_test.sh b/maxscale-system-test/mdbci/run_test.sh index 049d0a5ab..e16508601 100755 --- a/maxscale-system-test/mdbci/run_test.sh +++ b/maxscale-system-test/mdbci/run_test.sh @@ -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