Skip to content

Commit b95babd

Browse files
esteffinjlhcrawford
authored andcommitted
Improved testing procedure and documentation
Co-authored-by: jlhcrawford <54402133+jlhcrawford@users.noreply.github.com>
1 parent 76388b5 commit b95babd

File tree

8 files changed

+184
-142
lines changed

8 files changed

+184
-142
lines changed

CMakeLists.txt

+48-19
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,44 @@ if (NOT (CMAKE_SIZEOF_VOID_P EQUAL 8))
1919
message(FATAL_ERROR "HElib requires a 64-bit architecture.")
2020
endif ()
2121

22-
# Define standard installation directories (GNU)
23-
include(GNUInstallDirs)
24-
2522
# Use -std=c++14 as default.
2623
set(CMAKE_CXX_STANDARD 14)
2724
# Disable C++ extensions
2825
set(CMAKE_CXX_EXTENSIONS OFF)
2926
# Require full C++ standard
3027
set(CMAKE_CXX_STANDARD_REQUIRED ON)
3128

29+
################################################################################
30+
# #
31+
# FOLDER DEFINITIONS #
32+
# #
33+
################################################################################
34+
35+
# Define standard installation directories (GNU)
36+
include(GNUInstallDirs)
37+
38+
# Location of the cmake extra files
39+
set(HELIB_CMAKE_EXTRA_DIR "${PROJECT_SOURCE_DIR}/cmake")
40+
# Prefix of the header files (directory to be added to the include list)
41+
set(HELIB_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/include")
42+
# Location of helib header files
43+
set(HELIB_HEADER_DIR "${HELIB_INCLUDE_DIR}/helib")
44+
# Location of the source files
45+
set(HELIB_SOURCE_DIR "${PROJECT_SOURCE_DIR}/src")
46+
# Location of the google tests
47+
set(HELIB_TESTS_DIR "${PROJECT_SOURCE_DIR}/tests")
48+
# Location of the directory containing the test binary (runTests).
49+
# Keeping this location relative as it will be changed if PACKAGE_BUILD=ON.
50+
set(HELIB_TEST_BIN_DIR "bin")
51+
52+
# Setting compiler output directories
53+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
54+
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
55+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
56+
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
57+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
58+
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
59+
3260
# GMP minimal version to be used if not PACKAGE_BUILD
3361
set(GMP_MINIMAL_VERSION "6.0.0")
3462
# NTL minimal version to be used if NOT PACKAGE_BUILD
@@ -60,7 +88,7 @@ set_property(CACHE
6088
STRINGS "Debug" "RelWithDebInfo" "Release" "MinSizeRel")
6189

6290
# Path containing FindGMP.cmake and FindNTL.cmake
63-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
91+
list(APPEND CMAKE_MODULE_PATH "${HELIB_CMAKE_EXTRA_DIR}")
6492

6593
option(BUILD_SHARED "Build as shared library" OFF)
6694

@@ -224,16 +252,6 @@ else (PACKAGE_BUILD)
224252
# Checks that at least version NTL_MINIMAL_VERSION is available
225253
find_package(NTL "${NTL_MINIMAL_VERSION}" REQUIRED)
226254

227-
# Setting compiler output directories
228-
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
229-
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
230-
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
231-
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
232-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
233-
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
234-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
235-
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
236-
237255
# Thread enabling checks
238256
# Checking if NTL is built with NTL_THREADS=on
239257
set(ntl_config_file "${NTL_INCLUDE_PATHS}/NTL/config.h")
@@ -295,13 +313,24 @@ if (PACKAGE_BUILD)
295313
-DFETCH_GMP=${FETCH_GMP}
296314
-DENABLE_TEST=${ENABLE_TEST}
297315
-DHELIB_DEBUG=${HELIB_DEBUG}
316+
-DHELIB_CMAKE_EXTRA_DIR=${HELIB_CMAKE_EXTRA_DIR}
317+
-DHELIB_INCLUDE_DIR=${HELIB_INCLUDE_DIR}
318+
-DHELIB_HEADER_DIR=${HELIB_HEADER_DIR}
319+
-DHELIB_SOURCE_DIR=${HELIB_SOURCE_DIR}
320+
-DHELIB_TESTS_DIR=${HELIB_TESTS_DIR}
298321
BUILD_ALWAYS ON)
299322

300-
if (ENABLE_TEST)
301-
add_test(NAME helib_check
302-
COMMAND ${CMAKE_MAKE_PROGRAM} test
303-
WORKING_DIRECTORY "${DEPENDENCIES_FOLDER}/Build/helib_external")
304-
endif (ENABLE_TEST)
323+
if (ENABLE_TEST)
324+
# Tests for PACKAGE_BUILD are located in
325+
# ${DEPENDENCIES_FOLDER}/Build/helib_external/${HELIB_TEST_BIN_DIR}.
326+
# Update its location and add the tests to cmake to avoid re-creating
327+
# their targets (as they are already built by ExternalProject_Add)
328+
set(HELIB_TEST_BIN_DIR
329+
"${DEPENDENCIES_FOLDER}/Build/helib_external/${HELIB_TEST_BIN_DIR}")
330+
set(ONLY_ADD_TEST ON)
331+
add_subdirectory("${HELIB_TESTS_DIR}" tests)
332+
unset(ONLY_ADD_TEST)
333+
endif (ENABLE_TEST)
305334

306335
# To install copy the whole PACKAGE_DIR directory to the defined prefix
307336
install(

INSTALL.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ make -j16
8080
4. (optional) If step 2 was performed with `-DENABLE_TEST=ON`, HElib tests can
8181
be run as follows:
8282
```
83-
ctest -R helib_check
83+
ctest
8484
```
8585
Detailed HElib-specific test logs can be found in
86-
`dependencies/Build/helib_external/Testing/Temporary/LastTest.log`.
86+
`Testing/Temporary/LastTest.log`.
8787

8888
5. (optional) Run the install step, to copy the folder `helib_pack` to
8989
`${CMAKE_INSTALL_PREFIX}` (in this example `/home/alice/helib_install`):

TESTS.md

+14-10
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@
55
downloaded and the correct targets will be defined for cmake.
66
2. To compile them, `make` as normal from a build directory.
77
3. The entire set of tests can be run with:
8-
- `./bin/runTests`. The parameters `noPrint`, `dry` and `verbose` can be
9-
specified as before, but they will apply to all tests which are run.
8+
- `./bin/runTests` or `./dependencies/Build/helib_external/bin/runTests` if
9+
`PACKAGE_BUILD=ON`. The parameters `noPrint`, `dry` and `verbose` can be
10+
specified as before, but they will apply to all tests which are run.
1011
- `ctest`. In this case the output will be significantly less verbose and
11-
therefore less helpful in the case of a failure. The parameter
12-
`--output-on-failure` will display the output of each test that happened
13-
to fail. It's possible to run tests in parallel by using
14-
`-j<number of concurrent tests>`
12+
therefore less helpful in the case of a failure. The parameter
13+
`--output-on-failure` can be added to display the output of each test that
14+
happened to fail. It is also possible to run tests in parallel by using
15+
`-j<number of concurrent tests>`. Detailed output of the tests (as if run
16+
directly with `runTests`) can be found in
17+
`Testing/Temporary/LastTest.log`.
1518
- `make test`, which will run the tests through `ctest`. In this case no
16-
arguments can be passed.
19+
arguments can be passed. Detailed output of the tests (as if run directly
20+
with `runTests`) can be found in `Testing/Temporary/LastTest.log`.
1721

1822
## Running a subset of the tests
1923

@@ -23,7 +27,7 @@ tests, for example, one simply runs
2327
```
2428
./bin/runTests --gtest_filter='*PolyEval*'
2529
```
26-
To list all the tests, use `./bin/runTests --gtest_list_tests`. More details
30+
To list all the tests, use `./bin/runTests --gtest_list_tests`. More details
2731
on this filtering can be found in Google's documentation [here][1].
2832

2933
It is also possible to run a specific test using `ctest` by adding the argument
@@ -32,8 +36,8 @@ simply runs
3236
```
3337
ctest -R "PolyEval"
3438
```
35-
More details on this filtering can be found in `ctest` documentation
36-
`ctest --help`.
39+
To list all the tests, use `ctest -N`. More details on this filtering can be
40+
found in the `ctest` documentation `ctest --help`.
3741

3842
## Changing parameters
3943

dependencies/gmp/CMakeLists.txt

+1-7
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,7 @@ ExternalProject_Add(
6161
# LOG_TEST ON
6262
)
6363

64-
if (ENABLE_TEST)
65-
set(test_path "${DEPENDENCIES_FOLDER}/Source/gmp_fetched")
66-
add_test(NAME gmp_check
67-
COMMAND ${CMAKE_MAKE_PROGRAM} check
68-
WORKING_DIRECTORY ${test_path})
69-
unset(test_path)
70-
endif (ENABLE_TEST)
64+
# No tests will be performed for GMP
7165

7266
# Removed due to rpath delay
7367
# add_dependencies(gmp_external gmp_fetched)

dependencies/ntl/CMakeLists.txt

+1-7
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,7 @@ ExternalProject_Add(
100100
# LOG_TEST ON
101101
)
102102

103-
if (ENABLE_TEST)
104-
set(test_path "${DEPENDENCIES_FOLDER}/Source/ntl_fetched/src")
105-
add_test(NAME ntl_check
106-
COMMAND ${CMAKE_MAKE_PROGRAM} check
107-
WORKING_DIRECTORY ${test_path})
108-
unset(test_path)
109-
endif (ENABLE_TEST)
103+
# No tests will be performed for NTL
110104

111105
# Removing static library libntl.a.
112106
set(ntl_static_lib

src/CMakeLists.txt

+19-10
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,8 @@ project(helib
1616
VERSION 1.1.0
1717
LANGUAGES CXX)
1818

19-
# Location of the header files
20-
set(PROJECT_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/../include")
21-
# Location of the google tests
22-
set(PROJECT_TESTS_DIR "${PROJECT_SOURCE_DIR}/../tests")
23-
# Location of helib headers
24-
set(HELIB_HEADER_DIR "${PROJECT_INCLUDE_DIR}/helib")
19+
# Globals HELIB_CMAKE_EXTRA_DIR, HELIB_INCLUDE_DIR, HELIB_HEADER_DIR,
20+
# HELIB_SOURCE_DIR and HELIB_TESTS_DIR are previously set and forwarded here.
2521

2622
# We assume enable threads is passed correctly (already checked)
2723
if (HELIB_REQUIRES_PTHREADS)
@@ -30,6 +26,16 @@ endif (HELIB_REQUIRES_PTHREADS)
3026

3127
include(GNUInstallDirs)
3228

29+
if (PACKAGE_BUILD)
30+
# Setting compiler output directories if not inherited from above (if PACKAGE_BUILD=ON)
31+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
32+
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
33+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
34+
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
35+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
36+
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
37+
endif (PACKAGE_BUILD)
38+
3339
# Setting up cmake install directories
3440
if (WIN32 AND NOT CYGWIN)
3541
set(CMAKE_INSTALL_CMAKEDIR "CMake")
@@ -49,7 +55,7 @@ configure_file(version.in.cpp
4955
if (ENABLE_TEST)
5056
# Download and unpack googletest at configure time
5157
message(STATUS "Setting up googletest framework")
52-
configure_file("${PROJECT_SOURCE_DIR}/../cmake/gtest.cmake"
58+
configure_file("${HELIB_CMAKE_EXTRA_DIR}/gtest.cmake"
5359
"${CMAKE_CURRENT_BINARY_DIR}/googletest-download/CMakeLists.txt")
5460
execute_process(
5561
COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
@@ -247,7 +253,7 @@ target_include_directories(
247253
PUBLIC # NOTE: The includes must be kept in this order to avoid cmake
248254
# looking for HElib in /usr/local/include
249255
# Headers used from source/build location:
250-
"$<BUILD_INTERFACE:${PROJECT_INCLUDE_DIR}>"
256+
"$<BUILD_INTERFACE:${HELIB_INCLUDE_DIR}>"
251257
# Adding CMAKE_CURRENT_BINARY_DIR to include files to access the
252258
# auto-generated version.h file.
253259
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
@@ -301,7 +307,10 @@ if (BUILD_SHARED)
301307
endif (BUILD_SHARED)
302308

303309
if (ENABLE_TEST)
304-
add_subdirectory("${PROJECT_TESTS_DIR}" tests)
310+
# Add tests target (so they will be built) and all tests to cmake.
311+
set(ONLY_ADD_TEST OFF)
312+
add_subdirectory("${HELIB_TESTS_DIR}" tests)
313+
unset(ONLY_ADD_TEST)
305314
endif (ENABLE_TEST)
306315

307316
# Installing helib
@@ -332,7 +341,7 @@ write_basic_package_version_file(
332341

333342
# Generating the basic helibConfig.cmake file
334343
configure_package_config_file(
335-
${PROJECT_SOURCE_DIR}/../cmake/helibConfig.cmake.in
344+
${HELIB_CMAKE_EXTRA_DIR}/helibConfig.cmake.in
336345
${CMAKE_CURRENT_BINARY_DIR}/helibConfig.cmake
337346
INSTALL_DESTINATION ${CMAKE_INSTALL_CMAKEDIR})
338347

0 commit comments

Comments
 (0)