Skip to content

Commit

Permalink
setup CI action and rework GTest integration
Browse files Browse the repository at this point in the history
  • Loading branch information
chistopher committed Oct 11, 2023
1 parent 8d0100b commit 8a6647c
Show file tree
Hide file tree
Showing 16 changed files with 106 additions and 82 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml
name: CMake on multiple platforms

on:
push:
branches: [ "dev", "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
fail-fast: false

# Set up a matrix to run the following 3 configurations:
# 1. <Windows, Release, latest MSVC compiler toolchain on the default runner image, default generator>
# 2. <Linux, Release, latest GCC compiler toolchain on the default runner image, default generator>
# 3. <Linux, Release, latest Clang compiler toolchain on the default runner image, default generator>
#
# To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list.
matrix:
os: [ubuntu-latest, windows-latest]
build_type: [Release, Debug]
c_compiler: [gcc, clang, cl]
include:
- os: windows-latest
c_compiler: cl
cpp_compiler: cl
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
- os: ubuntu-latest
c_compiler: clang
cpp_compiler: clang++
exclude:
- os: windows-latest
c_compiler: gcc
- os: windows-latest
c_compiler: clang
- os: ubuntu-latest
c_compiler: cl

steps:
- uses: actions/checkout@v3

- if: matrix.c_compiler == 'clang'
name: install OpenMP
run: sudo apt-get install -y libomp-dev

- name: Configure CMake
run: >
cmake -B build
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DOPTION_BUILD_TESTS=ON
-DOPTION_BUILD_BENCHMARKS=ON
-DOPTION_BUILD_EXAMPLES=ON
-DOPTION_BUILD_DOCS=ON
-S ${{ github.workspace }}
- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: cmake --build build --config ${{ matrix.build_type }}

- name: Test
working-directory: build
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest --build-config ${{ matrix.build_type }}
41 changes: 0 additions & 41 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# Include modules provided by cmake
include(GenerateExportHeader)
include(GoogleTest)
include(FetchContent)
enable_testing()


Expand Down
26 changes: 6 additions & 20 deletions source/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,15 @@
#

# Build google benchmark
download_project(PROJ googlebenchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG master
UPDATE_DISCONNECTED 1
FetchContent_Declare(
benchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.8.3
FIND_PACKAGE_ARGS
)

set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
set(BUILD_SHARED_LIBS OFF)
add_subdirectory(
${googlebenchmark_SOURCE_DIR}
${googlebenchmark_BINARY_DIR})

# configure targets
foreach(target benchmark benchmark_main)
set_target_properties(${target} PROPERTIES
FOLDER "${IDE_FOLDER}"
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}
)
endforeach()

FetchContent_MakeAvailable(benchmark)

# add onw benchmarks
add_subdirectory(bmi-benchmarks)
Expand Down
2 changes: 1 addition & 1 deletion source/benchmarks/bmi-benchmarks/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static void BM_deposit(benchmark::State& state) {

for(auto _ : state) {
for(const auto& c: values) {
const auto x = Impl::deposit(c);
auto x = Impl::deposit(c);
benchmark::DoNotOptimize(x);
}
}
Expand Down
7 changes: 2 additions & 5 deletions source/benchmarks/math-benchmarks/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ double pow1000(double x) { return pow(1000.0, x);}
const T step = 1e10; \
for(auto _ : state) { \
benchmark::DoNotOptimize(x); \
const auto tmp = X(x); \
auto tmp = X(x); \
benchmark::DoNotOptimize(tmp); \
} \
} \
Expand Down Expand Up @@ -64,9 +64,6 @@ struct EdgeProbBase {
EdgeProbBase(double T, double R, double maxProb) : m_T(T), m_R(R), m_maxProb(maxProb) {}

bool operator() (const Point& a, const Point& b, double uni_rnd) const noexcept {
benchmark::DoNotOptimize(a);
benchmark::DoNotOptimize(b);
benchmark::DoNotOptimize(uni_rnd);
return false;
}

Expand Down Expand Up @@ -120,7 +117,7 @@ static void BM_edge_prob(benchmark::State& state) {
for(auto _ : state) {
i = i < n - 2 ? i + 2 : 0;

const auto is_edge = base(points[i], points[i+1], dist_prob(prng));
auto is_edge = base(points[i], points[i+1], dist_prob(prng));
benchmark::DoNotOptimize(is_edge);
}
}
Expand Down
17 changes: 12 additions & 5 deletions source/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,28 @@
#


# Get gtest/gmock
include(FetchContent)
# Get gtest
FetchContent_Declare(
GTest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.14.0
FIND_PACKAGE_ARGS
)


# # Prevent GoogleTest from overriding our compiler/linker options when building with Visual Studio
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # Prevent GoogleTest from overriding our compiler/linker options when building with Visual Studio
set(INSTALL_GTEST OFF)
set(BUILD_GMOCK OFF) # see bug https://github.com/google/googletest/issues/4384
# since CMake 3.24 this tries a find_package(GTest) which should find GTest installed with `sudo apt install libgtest-dev`
# earlier CMake or a failed find_package(GTest) call lead to a download in the build dir
FetchContent_MakeAvailable(GTest)

# windows needs gtest.dll in PATH. Installed versions should have this, but downloaded do not.
# To find DLL at test runtime (and during gtest_discover_tests()), we generate the gtest.dll in the same dir as the test .exe
# see https://github.com/google/googletest/issues/3565
if(WIN32)
set_target_properties(gtest PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
set_target_properties(gtest_main PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
endif()

add_subdirectory(girgs-test)
add_subdirectory(hypergirgs-test)
2 changes: 1 addition & 1 deletion source/tests/girgs-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ target_link_libraries(${target}
PRIVATE
${DEFAULT_LIBRARIES}
${META_PROJECT_NAME}::girgs
GTest::gmock
GTest::gtest
)


Expand Down
2 changes: 1 addition & 1 deletion source/tests/girgs-test/Generator_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <cmath>
#include <numeric>

#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include <girgs/Generator.h>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#include <random>

#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include <girgs/SpatialTreeCoordinateHelper.h>

Expand Down
4 changes: 2 additions & 2 deletions source/tests/girgs-test/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <cmath>

double distance(const std::vector<double>& a, const std::vector<double>& b) {
Expand All @@ -16,6 +16,6 @@ double distance(const std::vector<double>& a, const std::vector<double>& b) {

int main(int argc, char* argv[])
{
::testing::InitGoogleMock(&argc, argv);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
2 changes: 1 addition & 1 deletion source/tests/hypergirgs-test/AngleHelper_test.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#include <random>

#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include <hypergirgs/AngleHelper.h>
#include <hypergirgs/Generator.h>
Expand Down
2 changes: 1 addition & 1 deletion source/tests/hypergirgs-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ target_link_libraries(${target}
PRIVATE
${DEFAULT_LIBRARIES}
${META_PROJECT_NAME}::hypergirgs
GTest::gmock_main
GTest::gtest_main
)


Expand Down
2 changes: 1 addition & 1 deletion source/tests/hypergirgs-test/HyperbolicTree_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <cmath>
#include <numeric>

#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include <hypergirgs/HyperbolicTree.h>
#include <hypergirgs/Generator.h>
Expand Down
2 changes: 1 addition & 1 deletion source/tests/hypergirgs-test/Point_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include <hypergirgs/Point.h>
#include <hypergirgs/Generator.h>
Expand Down
2 changes: 1 addition & 1 deletion source/tests/hypergirgs-test/RadiusLayer_test.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#include <random>

#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include <hypergirgs/RadiusLayer.h>

Expand Down

0 comments on commit 8a6647c

Please sign in to comment.