Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example Google Test created #243

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
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
11 changes: 11 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,17 @@ jobs:
build_kind: 'cmake'
generate: 'false'

- run:
name: "Execute the C++ tests"
command: |
# compile the tests (it would probably would be better to do this when
# compiling the rest of Grackle)
cmake -DGRACKLE_BUILD_TESTS=ON -Bbuild
cmake --build build
# execute the tests
cd build
ctest

# TODO: once we merge in GH-#208, we need to issue a new gold standard, and then we should
# issue a followup PR where we uncomment the remainder of this test
test-standalone-pygrackle:
Expand Down
21 changes: 21 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ endif()
cmake_minimum_required(VERSION 3.16)
cmake_policy(SET CMP0077 NEW)
cmake_policy(SET CMP0082 NEW)

mabruzzo marked this conversation as resolved.
Show resolved Hide resolved
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
cmake_policy(SET CMP0135 NEW) # makes automatic dependency downloads more
# robust (& addresses noisy warnings)
endif()

project(Grackle VERSION ${_GRACKLE_VERSION_NO_DEVTAG} LANGUAGES C CXX Fortran)

# Specify that `./cmake` contains cmake modules defining useful functionality
Expand Down Expand Up @@ -184,6 +190,21 @@ endif()
# -----
# (this is where we will add targets for integration tests)

# Add BUILD_TESTS option available
option(GRACKLE_BUILD_TESTS "build Grackle tests using GoogleTest" OFF)

# if desired, setup Grackle's tests that use GoogleTest (this has no impact on
# the tests run via pytest, those are handled outside of cmake)
if(GRACKLE_BUILD_TESTS)
# setup GoogleTest framework (search for an installed copy on the machine
# OR download it & add its compilation to the rest of the build procedure)
include(setup_GTest)
# load CMake's built-in module that defines functions to registering unit
# tests implemented with GoogleTest into CMake's test-runner, CTest
include(GoogleTest)
enable_testing() # enable the test-runner, CTest
add_subdirectory(tests) # declare the recipes for each test
endif()

# Packaging
# ---------
Expand Down
35 changes: 35 additions & 0 deletions cmake/setup_GTest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This file includes logic for setting up GoogleTest
find_package(GTest)
mabruzzo marked this conversation as resolved.
Show resolved Hide resolved

if (NOT GTest_FOUND)
message(STATUS
"Preparing to download GTest from GitHub & configure its build. Don't "
"worry about any mentions of Python in the following text -- that is "
"only used internally by the Google test build"
)

# NOTE: it is idiomatic to use FetchContent with a git hash rather than the
# name of a tag or branch (since the latter 2 can freely change). If we use
# the name of a tag/branch, then CMake will query GitHub on every
# subsequent build to check whether the tag/branch is still the same

include(FetchContent)
FetchContent_Declare(
googletest # the url contains the hash for v1.13.0
URL https://github.com/google/googletest/archive/b796f7d44681514f58a683a3a71ff17c94edb0c1.zip
)

# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

elseif("${CMAKE_VERSION}" VERSION_LESS "3.20")
# CMake's built-in `FindGTest` module imported targets have different names
# in earlier CMake versions
add_library(GTest::gtest ALIAS GTest::GTest)
add_library(GTest::gtest_main ALIAS GTest::Main)
endif()

if (NOT TARGET GTest::gtest_main)
message("Target GTest:: stuff MISSING")
endif()
mabruzzo marked this conversation as resolved.
Show resolved Hide resolved
60 changes: 60 additions & 0 deletions src/clib/c_wrappers/wrap_interpolators_g.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include "grackle_macros.h"

// TODO: FORTRAN_NAME not needed for unit tests
extern void FORTRAN_NAME(interpolate_1d_g)(double *input1,
long long *gridDim,
double *gridPar1, double *dgridPar1,
long long *dataSize, double *dataField,
double *value);

extern void FORTRAN_NAME(interpolate_2d_g)(double *input1, double *input2,
long long *gridDim,
double *gridPar1, double *dgridPar1,
double *gridPar2, double *dgridPar2,
long long *dataSize, double *dataField,
double *value);

extern void FORTRAN_NAME(interpolate_3d_g)(double *input1, double *input2, double *input3,
long long *gridDim,
double *gridPar1, double *dgridPar1,
double *gridPar2, double *dgridPar2,
double *gridPar3, double *dgridPar3,
long long *dataSize, double *dataField,
double *value);

extern void FORTRAN_NAME(interpolate_3dz_g)(double *input1, double *input2, double *input3,
long long *gridDim,
double *gridPar1, double *dgridPar1,
double *gridPar2, long long *index2,
double *gridPar3, double *dgridPar3,
long long *dataSize, double *dataField,
int *end_int,
double *value);

extern void FORTRAN_NAME(interpolate_2df3d_g)(double *input1, double *input3,
long long *gridDim,
double *gridPar1, double *dgridPar1,
long long *index2,
double *gridPar3, double *dgridPar3,
long long *dataSize, double *dataField,
double *value);

extern void FORTRAN_NAME(interpolate_4d_g)(double *input1, double *input2, double *input3, double *input4,
long long *gridDim,
double *gridPar1, double *dgridPar1,
double *gridPar2, double *dgridPar2,
double *gridPar3, double *dgridPar3,
double *gridPar4, double *dgridPar4,
long long *dataSize, double *dataField,
double *value);

extern void FORTRAN_NAME(interpolate_5d_g)(double *input1, double *input2, double *input3, double *input4, double *input5,
long long *gridDim,
double *gridPar1, double *dgridPar1,
double *gridPar2, double *dgridPar2,
double *gridPar3, double *dgridPar3,
double *gridPar4, double *dgridPar4,
double *gridPar5, double *dgridPar5,
long long *dataSize, double *dataField,
double *value);

1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(unit)
15 changes: 15 additions & 0 deletions tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# declare testdeps to bundle together dependencies used by all tests
# ------------------------------------------------------------------
add_library(testdeps INTERFACE)
target_link_libraries(testdeps INTERFACE Grackle::Grackle GTest::gtest_main)

# short-term hack to let tests invoke Fortran functions from C
target_compile_definitions(testdeps INTERFACE "$<$<PLATFORM_ID:Linux,Darwin>:LINUX>")
target_include_directories(testdeps INTERFACE ${PROJECT_SOURCE_DIR}/src/clib)

# start declaring targets for tests
# ---------------------------------
add_executable(runInterpolationTests test_unit_interpolators_g.cpp)
target_link_libraries(runInterpolationTests testdeps)

gtest_discover_tests(runInterpolationTests)
Loading