forked from BOINC/boinc
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests: add unit testing framework using googletest
* enable coverage reports from gcc and disable optimizations via option to configure * install googletest library into buildcache * script to compile and run unit tests using cmake * first set of unit tests originaly contributed by Keith Uplinger There are several hardcoded paths and assumptions made in order to get this working on Travis CI. New tooling is using cmake for cross platform builds and as such is not easy to use with an autotools based system. It's not ideal but better than nothing.
- Loading branch information
1 parent
99716be
commit 6dbf55f
Showing
16 changed files
with
443 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/bin/bash | ||
|
||
# This file is part of BOINC. | ||
# http://boinc.berkeley.edu | ||
# Copyright (C) 2019 University of California | ||
# | ||
# BOINC is free software; you can redistribute it and/or modify it | ||
# under the terms of the GNU Lesser General Public License | ||
# as published by the Free Software Foundation, | ||
# either version 3 of the License, or (at your option) any later version. | ||
# | ||
# BOINC is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
# See the GNU Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with BOINC. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
# Script to build a googletest library for BOINC | ||
|
||
# Usage: | ||
# cd [path]/googletest-release-1.8.1/ | ||
# source path_to_this_script [--clean] [--prefix PATH] | ||
# | ||
# the --clean argument will force a full rebuild. | ||
# if --prefix is given as absolute path the library is installed into there | ||
|
||
doclean="" | ||
debug_flag="" | ||
lprefix="" | ||
cmdline_prefix="" | ||
while [[ $# -gt 0 ]]; do | ||
key="$1" | ||
case $key in | ||
-clean|--clean) | ||
doclean="yes" | ||
;; | ||
-prefix|--prefix) | ||
lprefix="$2" | ||
cmdline_prefix="--prefix=${lprefix}" | ||
shift | ||
;; | ||
esac | ||
shift # past argument or value | ||
done | ||
|
||
cd googletest | ||
autoreconf -i -f | ||
if [ $? -ne 0 ]; then cd ..; return 1; fi | ||
./configure "${cmdline_prefix}" | ||
if [ $? -ne 0 ]; then cd ..; return 1; fi | ||
if [ "${doclean}" = "yes" ]; then | ||
make clean | ||
fi | ||
make | ||
if [ $? -ne 0 ]; then cd ..; return 1; fi | ||
|
||
# make install is not supported so copy files manually | ||
if [ "x${lprefix}" != "x" ]; then | ||
mkdir -p ${lprefix}/lib ${lprefix}/include ${lprefix}/bin | ||
(cp -r lib/.libs/*.a ${lprefix}/lib && cp -r include/gtest ${lprefix}/include && cp scripts/gtest-config ${lprefix}/bin) | ||
if [ $? -ne 0 ]; then cd ..; return 1; fi | ||
fi | ||
|
||
cd .. | ||
return 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/bin/bash | ||
|
||
# This file is part of BOINC. | ||
# http://boinc.berkeley.edu | ||
# Copyright (C) 2019 University of California | ||
# | ||
# BOINC is free software; you can redistribute it and/or modify it | ||
# under the terms of the GNU Lesser General Public License | ||
# as published by the Free Software Foundation, | ||
# either version 3 of the License, or (at your option) any later version. | ||
# | ||
# BOINC is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
# See the GNU Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with BOINC. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
# Script to execute googletest based unit tests for BOINC | ||
|
||
# Usage: | ||
# ./tests/executeUnitTests.sh [--report-coverage] | ||
# | ||
# if --report-coverage is given the test coverage will be reported to codecov.io | ||
|
||
# check working directory because the script needs to be called like: ./tests/executeUnitTests.sh | ||
if [ ! -d "tests" ]; then | ||
echo "start this script in the source root directory" | ||
exit 1 | ||
fi | ||
|
||
ROOTDIR=$(pwd) | ||
CI_RUN="${TRAVIS:-false}" | ||
report="" | ||
while [[ $# -gt 0 ]]; do | ||
key="$1" | ||
case $key in | ||
--report-coverage) | ||
report="yes" | ||
;; | ||
*) | ||
echo "unrecognized option $key" | ||
;; | ||
esac | ||
shift # past argument or value | ||
done | ||
|
||
command -v cmake >/dev/null 2>&1 || { echo >&2 "cmake is needed but not installed. Aborting."; exit 1; } | ||
|
||
if [ "${report}" = "yes" ]; then | ||
command -v gcov >/dev/null 2>&1 || { echo >&2 "gcov (lcov) is needed but not installed. Aborting."; exit 1; } | ||
command -v codecov >/dev/null 2>&1 || { echo >&2 "codecov (pip install codecov) is needed but not installed. Aborting."; exit 1; } | ||
fi | ||
|
||
cd tests || exit 1 | ||
if [ -d "gtest" ]; then | ||
rm -rf gtest | ||
if [ $? -ne 0 ]; then cd ..; exit 1; fi | ||
fi | ||
mkdir gtest | ||
if [ $? -ne 0 ]; then cd ..; exit 1; fi | ||
cd gtest | ||
cmake ../unit-tests | ||
if [ $? -ne 0 ]; then cd ../..; exit 1; fi | ||
make | ||
if [ $? -ne 0 ]; then cd ../..; exit 1; fi | ||
|
||
for T in lib sched; do | ||
[ -d "${T}" ] && ./${T}/test_${T}; | ||
done | ||
|
||
cd ../.. | ||
if [ "${report}" = "yes" ]; then | ||
for T in lib sched; do | ||
[ -d "${T}" ] && gcov -lp *.o >/dev/null; | ||
done | ||
codecov -X gcov | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
cmake_minimum_required(VERSION 2.8) | ||
|
||
project(BOINC_unit_testing) | ||
enable_testing() | ||
|
||
set (CMAKE_CXX_STANDARD 11) | ||
set (CMAKE_CXX_FLAGS "-g -Wall -Wextra -Werror --coverage") | ||
|
||
|
||
find_package(Threads REQUIRED) | ||
|
||
# There is no easy way to interface with the autotools driven build system in boinc | ||
# so the paths below are hardcoded and are mainly suited for building on Travis CI | ||
# TODO: make paths configurable and generate them from boinc make or switch boinc to cmake | ||
|
||
include_directories(BEFORE "${PROJECT_SOURCE_DIR}/../../3rdParty/buildCache/linux/include") | ||
include_directories("${PROJECT_SOURCE_DIR}/../..") | ||
include_directories("${PROJECT_SOURCE_DIR}/../../sched") | ||
include_directories("${PROJECT_SOURCE_DIR}/../../db") | ||
include_directories("${PROJECT_SOURCE_DIR}/../../lib") | ||
include_directories("${PROJECT_SOURCE_DIR}/../../tools") | ||
include_directories("/usr/include/mariadb") | ||
include_directories("/usr/include/mariadb/mysql") | ||
|
||
|
||
find_library(GTEST_MAIN_LIB libgtest_main.a PATHS ${PROJECT_SOURCE_DIR}/../../3rdParty/buildCache/linux/lib NO_DEFAULT_PATH) | ||
message(STATUS "gtest_main_lib: ${GTEST_MAIN_LIB}") | ||
find_library(GTEST_LIB gtest PATHS ${PROJECT_SOURCE_DIR}/../../3rdParty/buildCache/linux/lib NO_DEFAULT_PATH) | ||
message(STATUS "gtest_lib: ${GTEST_LIB}") | ||
find_library(SCHED_LIB libsched.a PATHS ${PROJECT_SOURCE_DIR}/../../sched NO_DEFAULT_PATH) | ||
find_library(BOINC_CRYPT_LIB libboinc_crypt.a PATHS ${PROJECT_SOURCE_DIR}/../../lib NO_DEFAULT_PATH) | ||
find_library(BOINC_LIB libboinc.a PATHS ${PROJECT_SOURCE_DIR}/../../lib NO_DEFAULT_PATH) | ||
find_library(MYSQL_LIB NAMES mariadb mysql) | ||
message(STATUS "mysql_lib: ${MYSQL_LIB}") | ||
|
||
add_subdirectory(lib) | ||
add_subdirectory(sched) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
file(GLOB SRCS *.cpp) | ||
|
||
add_executable(test_lib ${SRCS}) | ||
|
||
TARGET_LINK_LIBRARIES(test_lib "${GTEST_LIB}" "${SCHED_LIB}" "${BOINC_CRYPT_LIB}" "${BOINC_LIB}" "${GTEST_MAIN_LIB}" pthread) | ||
|
||
add_test(NAME test_lib COMMAND test_lib) |
Oops, something went wrong.