Skip to content

Commit

Permalink
Fix last errors with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ashao committed Jun 27, 2024
1 parent 3ce5444 commit 8adce98
Show file tree
Hide file tree
Showing 26 changed files with 187 additions and 86 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@ jobs:
make test-verbose-with-coverage INSTALL_PREFIX=$PWD/install/$LINK_TYPE \
COV_FLAGS="--cov=./src/python/module/smartredis/ --cov-report=xml --cov-append" \
BUILD_FORTRAN=ON BUILD_PYTHON=ON SR_TEST_REDIS_MODE=All SR_TEST_PORT=7000 LINK_TYPE=$LINK_TYPE \
SR_TEST_REDISAI_VER=v${{ matrix.rai_v }} \
INSTALL_PREFIX=$PWD/install/$LINK_TYPE
SR_TEST_REDISAI_VER=v${{ matrix.rai_v }}
# Process and upload code coverage (Python was collected during pytest)
- name: Collect coverage from C/C++/Fortran testers
Expand Down
23 changes: 8 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,27 @@ endif()
## Cmake Modules
include(GNUInstallDirs)
include(ExternalProject)
include(CMakePrintHelpers)
if(BUILD_PYTHON)
include(FetchContent)
endif()
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
include(EnableCoverage)

## Configure the remainder of the builder
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_VISIBILITY_PRESET default)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads)

if(CMAKE_BUILD_TYPE STREQUAL Coverage)
set(CMAKE_BUILD_TYPE Debug)
if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_C_COMPILER_ID STREQUAL "GNU"))
add_compile_options(--coverage)
add_link_options(--coverage)
else()
message(WARNING "A coverage build was specified, but the CMAKE compiler is not GCC")
endif()
endif()

if (BUILD_FORTRAN)
enable_language(Fortran)
set(CMAKE_Fortran_MODULE_DIRECTORY "${CMAKE_INSTALL_PREFIX}/include")
endif()

if(CMAKE_BUILD_TYPE STREQUAL Coverage)
enable_coverage()
endif()

## Include external libraries
## Note: These ExternalProjects need to be installed into the
## SmartRedis install directory since there are variants of the
Expand Down Expand Up @@ -107,7 +102,6 @@ set_target_properties(libhiredis PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${hiredis_source_dir}
)

cmake_print_variables(hiredis_source_dir)
# Define redis++ as an external project
ExternalProject_Add(redis++
GIT_REPOSITORY https://github.com/sewenew/redis-plus-plus.git
Expand Down Expand Up @@ -222,7 +216,6 @@ set(FORTRAN_SRC
include_directories(SYSTEM $<BUILD_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>)

## Build the main SmartRedis library
cmake_print_variables(BUILD_SHARED_LIBS)
set(CLIENT_SRC ${C_CPP_SRC})
add_library(smartredis ${CLIENT_SRC})
add_dependencies(smartredis hiredis redis++)
Expand Down Expand Up @@ -288,7 +281,7 @@ install(EXPORT smartredis-targets
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/smartredis
)
include(CMakePackageConfigHelpers)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.smartredis.cmake.in
configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/Config.smartredis.cmake.in
smartredisConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/smartredis
)
Expand Down Expand Up @@ -325,7 +318,7 @@ if (BUILD_FORTRAN)
FILE smartredis-fortran.cmake
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/smartredis-fortran
)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.smartredis-fortran.cmake.in
configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/Config.smartredis-fortran.cmake.in
smartredis-fortranConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/smartredis-fortran
)
Expand Down
52 changes: 26 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ CWD := $(shell pwd)
# Build variables
NPROC := $(shell nproc 2>/dev/null || python -c "import multiprocessing as mp; print (mp.cpu_count())" 2>/dev/null || echo 4)
INSTALL_PREFIX := $(CWD)/install
TEST_PREFIX := $(CWD)/tests/
TEST_PREFIX := $(CWD)/tests
EXAMPLES_PREFIX := $(CWD)/examples/bin
BUILD_FORTRAN := OFF
BUILD_PYTHON := OFF
Expand Down Expand Up @@ -134,7 +134,7 @@ test-lib: lib

# help: test-lib-with-fortran - Build SmartRedis clients into a dynamic library with least permissive compiler settings
.PHONY: test-lib-with-fortran
test-lib-with-fortran: PEDANTIC=ON
test-lib-with-fortran: PEDANTIC=off
test-lib-with-fortran: lib-with-fortran

# help: test-deps - Make SmartRedis testing dependencies
Expand All @@ -150,7 +150,7 @@ test-deps-gpu: test-deps

# help: build-tests - build all tests (C, C++, Fortran)
.PHONY: build-tests
build-tests: test-lib
build-tests: test-lib-with-fortran
build-tests: build-unit-test-cpp
build-tests: build-test-cpp
build-tests: build-test-c
Expand All @@ -173,7 +173,7 @@ build-test-cpp: catch2
build-unit-test-cpp: test-lib
build-unit-test-cpp: catch2
@cmake -S tests/cpp/unit-tests -B build/$(BUILD_TYPE)/tests/$(LINK_TYPE)/cpp/unit-tests \
-DBUILD_TYPE=$(BUILD_TYPE) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) \
-DCMAKE_INSTALL_PREFIX=$(TEST_PREFIX)/cpp \
-Dsmartredis_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis
@cmake --build build/$(BUILD_TYPE)/tests/$(LINK_TYPE)/cpp/unit-tests -- -j $(NPROC)
Expand All @@ -183,7 +183,7 @@ build-unit-test-cpp: catch2
.PHONY: build-test-c
build-test-c: test-lib
@cmake -S tests/c -B build/$(BUILD_TYPE)/tests/$(LINK_TYPE)/c \
-DBUILD_TYPE=$(BUILD_TYPE) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) \
-Dsmartredis_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis \
-DCMAKE_INSTALL_PREFIX=$(TEST_PREFIX)/c
@cmake --build build/$(BUILD_TYPE)/tests/$(LINK_TYPE)/c -- -j $(NPROC)
Expand All @@ -193,9 +193,9 @@ build-test-c: test-lib
# help: build-test-fortran - build the Fortran tests
.PHONY: build-test-fortran
build-test-fortran: BUILD_FORTRAN=ON
build-test-fortran: test-lib
build-test-fortran: test-lib-with-fortran
@cmake -S tests/fortran -B build/$(BUILD_TYPE)/tests/$(LINK_TYPE)/fortran \
-DBUILD_TYPE=$(BUILD_TYPE) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) \
-DCMAKE_INSTALL_PREFIX=$(TEST_PREFIX)/fortran \
-Dsmartredis_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis \
-Dsmartredis-fortran_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis-fortran
Expand All @@ -206,7 +206,7 @@ build-test-fortran: test-lib
# help: build-examples - build all examples (serial, parallel)
.PHONY: build-examples
build-examples: lib
@cmake -S examples -B build/$(BUILD_TYPE)/examples/$(LINK_TYPE) -DBUILD_TYPE=$(BUILD_TYPE) \
@cmake -S examples -B build/$(BUILD_TYPE)/examples/$(LINK_TYPE) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
-DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -DBUILD_FORTRAN=$(BUILD_FORTRAN) \
-DCMAKE_INSTALL_PREFIX=$(EXAMPLES_PREFIX) \
-Dsmartredis_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis \
Expand All @@ -219,7 +219,7 @@ build-examples: lib
.PHONY: build-example-serial
build-example-serial: lib
@cmake -S examples/serial -B build/$(BUILD_TYPE)/examples/$(LINK_TYPE)/serial \
-DBUILD_TYPE=$(BUILD_TYPE) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -DBUILD_FORTRAN=$(BUILD_FORTRAN) \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -DBUILD_FORTRAN=$(BUILD_FORTRAN) \
-DCMAKE_INSTALL_PREFIX=$(EXAMPLES_PREFIX) \
-Dsmartredis_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis \
-Dsmartredis-fortran_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis-fortran
Expand All @@ -230,7 +230,7 @@ build-example-serial: lib
.PHONY: build-example-parallel
build-example-parallel: lib
@cmake -S examples/parallel -B build/$(BUILD_TYPE)/examples/$(LINK_TYPE)/parallel \
-DBUILD_TYPE=$(BUILD_TYPE) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -DBUILD_FORTRAN=$(BUILD_FORTRAN) \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -DBUILD_FORTRAN=$(BUILD_FORTRAN) \
-DCMAKE_INSTALL_PREFIX=$(EXAMPLES_PREFIX) \
-Dsmartredis_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis \
-Dsmartredis-fortran_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis-fortran
Expand Down Expand Up @@ -345,7 +345,7 @@ define run_smartredis_tests_with_standalone_server
echo "Running standalone tests" && \
PYTHONFAULTHANDLER=1 python -m pytest $(SR_TEST_PYTEST_FLAGS) $(COV_FLAGS) \
$(SKIP_DOCKER) $(SKIP_PYTHON) $(SKIP_FORTRAN) \
--bin-path $(TEST_PREFIX) --build-fortran $(BUILD_FORTRAN) $(1) ; \
--bin-path $(2) --build-fortran $(BUILD_FORTRAN) $(1) ; \
(testresult=$$?; \
echo "Shutting down standalone Redis server" && \
python utils/launch_redis.py --port $(SR_TEST_PORT) --nodes 1 --stop && \
Expand All @@ -365,7 +365,7 @@ define run_smartredis_tests_with_clustered_server
echo "Running clustered tests" && \
PYTHONFAULTHANDLER=1 python -s -m pytest $(SR_TEST_PYTEST_FLAGS) $(COV_FLAGS) \
$(SKIP_DOCKER) $(SKIP_PYTHON) $(SKIP_FORTRAN) \
--bin-path $(TEST_PREFIX) --build-fortran $(BUILD_FORTRAN) $(1) ; \
--bin-path $(2) --build-fortran $(BUILD_FORTRAN) $(1) ; \
(testresult=$$?; \
echo "Shutting down clustered Redis server" && \
python utils/launch_redis.py --port $(SR_TEST_PORT) \
Expand All @@ -388,7 +388,7 @@ define run_smartredis_tests_with_uds_server
echo "Running standalone tests with Unix Domain Socket connection" && \
PYTHONFAULTHANDLER=1 python -m pytest $(SR_TEST_PYTEST_FLAGS) $(COV_FLAGS) \
$(SKIP_DOCKER) $(SKIP_PYTHON) $(SKIP_FORTRAN) \
--bin-path $(TEST_PREFIX) --build-fortran $(BUILD_FORTRAN) $(1) ; \
--bin-path $(2) --build-fortran $(BUILD_FORTRAN) $(1) ; \
(testresult=$$?; \
echo "Shutting down standalone Redis server with Unix Domain Socket support" && \
python utils/launch_redis.py --port $(SR_TEST_PORT) --nodes 1 \
Expand All @@ -403,16 +403,16 @@ endef
define run_smartredis_tests_with_server
$(if $(or $(filter $(SR_TEST_REDIS_MODE),Standalone),
$(filter $(SR_TEST_REDIS_MODE),All)),
$(call run_smartredis_tests_with_standalone_server,$(1))
$(call run_smartredis_tests_with_standalone_server,$(1),$(2))
)
$(if $(or $(filter $(SR_TEST_REDIS_MODE),Clustered),
$(filter $(SR_TEST_REDIS_MODE),All)),
$(call run_smartredis_tests_with_clustered_server,$(1))
$(call run_smartredis_tests_with_clustered_server,$(1),$(2))
)
$(if $(or $(filter $(SR_TEST_REDIS_MODE),UDS),
$(filter $(SR_TEST_REDIS_MODE),All)),
$(if $(filter-out $(shell uname -s),Darwin),
$(call run_smartredis_tests_with_uds_server,$(1)),
$(call run_smartredis_tests_with_uds_server,$(1),$(2)),
@echo "Skipping: Unix Domain Socket is not supported on MacOS"
)
)
Expand All @@ -424,15 +424,15 @@ test: test-deps
test: build-tests
test: SR_TEST_PYTEST_FLAGS := -vv
test:
@$(call run_smartredis_tests_with_server,./tests)
@$(call run_smartredis_tests_with_server,./tests, $(TEST_PREFIX))

# help: test-verbose - Build and run all tests [verbosely]
.PHONY: test-verbose
test-verbose: test-deps
test-verbose: build-tests
test-verbose: SR_TEST_PYTEST_FLAGS := -vv -s
test-verbose:
@$(call run_smartredis_tests_with_server,./tests)
@$(call run_smartredis_tests_with_server,./tests, $(TEST_PREFIX))

# help: test-verbose-with-coverage - Build and run all tests [verbose-with-coverage]
.PHONY: test-verbose-with-coverage
Expand All @@ -441,29 +441,29 @@ test-verbose-with-coverage: test-deps
test-verbose-with-coverage: build-tests
test-verbose-with-coverage: SR_TEST_PYTEST_FLAGS := -vv -s
test-verbose-with-coverage:
@$(call run_smartredis_tests_with_server,./tests)
@$(call run_smartredis_tests_with_server,./tests, $(TEST_PREFIX))

# help: test-c - Build and run all C tests
.PHONY: test-c
test-c: build-test-c
test-c: SR_TEST_PYTEST_FLAGS := -vv -s
test-c:
@$(call run_smartredis_tests_with_server,./tests/c)
@$(call run_smartredis_tests_with_server,./tests/c, $(TEST_PREFIX))

# help: test-cpp - Build and run all C++ tests
.PHONY: test-cpp
test-cpp: build-test-cpp
test-cpp: build-unit-test-cpp
test-cpp: SR_TEST_PYTEST_FLAGS := -vv -s
test-cpp:
@$(call run_smartredis_tests_with_server,./tests/cpp)
@$(call run_smartredis_tests_with_server,./tests/cpp, $(TEST_PREFIX))

# help: unit-test-cpp - Build and run unit tests for C++
.PHONY: unit-test-cpp
unit-test-cpp: build-unit-test-cpp
unit-test-cpp: SR_TEST_PYTEST_FLAGS := -vv -s
unit-test-cpp:
@$(call run_smartredis_tests_with_server,./tests/cpp/unit-tests)
@$(call run_smartredis_tests_with_server,./tests/cpp/unit-tests, $(TEST_PREFIX))

# help: test-py - run python tests
.PHONY: test-py
Expand All @@ -472,15 +472,15 @@ test-py: BUILD_PYTHON := ON
test-py: lib
test-py: SR_TEST_PYTEST_FLAGS := -vv
test-py:
@$(call run_smartredis_tests_with_server,./tests/python)
@$(call run_smartredis_tests_with_server,./tests/python, $(TEST_PREFIX))

# help: test-fortran - run fortran tests
.PHONY: test-fortran
test-fortran: BUILD_FORTRAN := ON
test-fortran: build-test-fortran
test-fortran: SR_TEST_PYTEST_FLAGS := -vv -s
test-fortran:
@$(call run_smartredis_tests_with_server,./tests/fortran)
@$(call run_smartredis_tests_with_server,./tests/fortran, $(TEST_PREFIX))

# help: testpy-cov - run python tests with coverage
.PHONY: testpy-cov
Expand All @@ -489,15 +489,15 @@ testpy-cov: BUILD_PYTHON := ON
testpy-cov: SR_TEST_PYTEST_FLAGS := -vv
testpy-cov: COV_FLAGS := --cov=./src/python/module/smartredis/
testpy-cov:
@$(call run_smartredis_tests_with_server,./tests/python)
@$(call run_smartredis_tests_with_server,./tests/python, $(TEST_PREFIX))

# help: test-examples - Build and run all examples
.PHONY: test-examples
test-examples: test-deps
test-examples: build-examples
testpy-cov: SR_TEST_PYTEST_FLAGS := -vv -s
test-examples:
@$(call run_smartredis_tests_with_server,./examples)
@$(call run_smartredis_tests_with_server,./examples,$(EXAMPLES_PREFIX))


############################################################################
Expand Down
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions cmake/EnableCoverage.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function(enable_coverage)
if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_C_COMPILER_ID STREQUAL "GNU"))
set(CMAKE_BUILD_TYPE Debug)
add_compile_options(--coverage)
add_link_options(--coverage)
link_libraries(gcov)
message(WARNING "Enabling coverage with debug")
else()
message(WARNING "A coverage build was specified, but the CMAKE compiler is not GCC")
endif()
endfunction()
5 changes: 5 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ def pytest_addoption(parser):
def bin_path(request):
return pathlib.Path(request.config.getoption("--bin-path"))

# Fixture to retrieve the build type setting
@pytest.fixture(scope="module")
def build_fortran(request):
return pathlib.Path(request.config.getoption("--build-fortran"))

@pytest.fixture()
def execute_cmd():
def _execute_cmd(cmd_list, run_path=pathlib.Path.cwd()):
Expand Down
9 changes: 8 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,17 @@
cmake_minimum_required(VERSION 3.13)
project(SmartRedis-Examples)

# Add our custom module(s) stored in smartredis/cmake
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/../cmake")
include(EnableCoverage)
if(CMAKE_BUILD_TYPE STREQUAL Coverage)
enable_coverage()
endif()

# Enable language support for the examples
enable_language(C)
enable_language(CXX)
if (SR_FORTRAN)
if (BUILD_FORTRAN)
enable_language(Fortran)
endif()

Expand Down
11 changes: 9 additions & 2 deletions examples/parallel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,19 @@ project(SmartRedis-Examples-Parallel)

# Enable language support for the examples
enable_language(CXX)
if (SR_FORTRAN)
if (BUILD_FORTRAN)
enable_language(Fortran)
endif()

# Add our custom module(s) stored in smartredis/cmake
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/../../cmake")
include(EnableCoverage)
if(CMAKE_BUILD_TYPE STREQUAL Coverage)
enable_coverage()
endif()

# Bring in subdirectories
add_subdirectory(cpp)
if (SR_FORTRAN)
if (BUILD_FORTRAN)
add_subdirectory(fortran)
endif()
8 changes: 8 additions & 0 deletions examples/parallel/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ project(SmartRedis-Examples-Parallel-Cpp)
# Enable language support for the examples
enable_language(CXX)

# Add our custom module(s) stored in smartredis/cmake
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/../../../cmake")
include(EnableCoverage)
if(CMAKE_BUILD_TYPE STREQUAL Coverage)
enable_coverage()
endif()

# Configure the build
set(CMAKE_CXX_STANDARD 17)
# Locate dependencies
Expand All @@ -55,4 +62,5 @@ foreach(EXECUTABLE ${EXECUTABLES})
MPI::MPI_CXX
smartredis
)
install(TARGETS ${EXECUTABLE}_cpp_parallel RUNTIME DESTINATION parallel/cpp)
endforeach()
Loading

0 comments on commit 8adce98

Please sign in to comment.