Skip to content

Commit f78330b

Browse files
author
Terry Cojean
committed
Provide support in Ginkgo for Coverage and Sanitizers build.
+ Add a CMake script which simplifies adding new build types to the project + Use this script to provide three new build types: + COVERAGE: relies on gcov and the `--coverage` flag + ASAN: relies on the flag `-fsanitize=address` + TSAN: relies on the flag `-fsanitize=thread` + Add four new steps to the CI system, one for each of the new build types plus valgrind. + Update CI Benchmarking support as it was using the old format. + Add configuration files to simplify using CTest and support CDash. + Document these additions in the Readme.
1 parent 0dc9251 commit f78330b

7 files changed

+394
-9
lines changed

.gitlab-ci.yml

+55-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ stages:
55
- build
66
- test
77
- deploy
8+
- coverage
9+
- valgrind
10+
- threadsanitizer
11+
- addresssanitizer
812
- benchmark-build
913
- benchmark-cuda
1014
- benchmark-omp
@@ -367,6 +371,51 @@ gh-pages:
367371
- schedules
368372

369373

374+
coverage:
375+
stage: coverage
376+
image: localhost:5000/gko-cuda100-gnu7-llvm60
377+
before_script: *default_before_script
378+
script:
379+
- ctest -S cmake/CTestScript.cmake -DCTEST_BUILD_CONFIGURATION=COVERAGE
380+
dependencies: []
381+
# only:
382+
# - master
383+
# - develop
384+
385+
valgrind:
386+
stage: valgrind
387+
image: localhost:5000/gko-cuda100-gnu7-llvm60
388+
before_script: *default_before_script
389+
script:
390+
- ctest -S cmake/CTestScript.cmake -DCTEST_MEMORYCHECK_TYPE=Valgrind
391+
dependencies: []
392+
# only:
393+
# - master
394+
# - develop
395+
396+
threadsanitizer:
397+
stage: threadsanitizer
398+
image: localhost:5000/gko-cuda100-gnu7-llvm60
399+
before_script: *default_before_script
400+
script:
401+
- ctest -S cmake/CTestScript.cmake -DCTEST_BUILD_CONFIGURATION=TSAN -DCTEST_MEMORYCHECK_TYPE=ThreadSanitizer
402+
dependencies: []
403+
# only:
404+
# - master
405+
# - develop
406+
407+
addresssanitizer:
408+
stage: addresssanitizer
409+
image: localhost:5000/gko-cuda100-gnu7-llvm60
410+
before_script: *default_before_script
411+
script:
412+
- ctest -S cmake/CTestScript.cmake -DCTEST_BUILD_CONFIGURATION=ASAN -DCTEST_MEMORYCHECK_TYPE=AddressSanitizer
413+
dependencies: []
414+
# only:
415+
# - master
416+
# - develop
417+
418+
370419
# Benchmark build
371420
.benchmark_before_script_template: &default_benchmark_before_script
372421
# set up identities
@@ -423,6 +472,8 @@ fineci-benchmark-build:
423472
dependencies: []
424473
only:
425474
- schedules
475+
# - develop
476+
# - master
426477

427478

428479
# Benchmark runs
@@ -433,9 +484,10 @@ fineci-benchmark-build:
433484
- |
434485
${SSH_COMMAND} 'tee /dev/stderr | scl enable devtoolset-7 bash' \
435486
>results.json << EOT
487+
module load cuda/cuda-10.0
436488
set -xe
437489
cd ginkgo/build/benchmark
438-
SYSTEM_NAME=${SYSTEM_NAME} make ${EXECUTOR}_benchmark
490+
make benchmark SYSTEM_NAME=${SYSTEM_NAME} EXECUTOR=${EXECUTOR}
439491
tar -czf data.tar.gz results
440492
EOT
441493
# publish them
@@ -455,6 +507,8 @@ fineci-benchmark-build:
455507
dependencies: []
456508
only:
457509
- schedules
510+
# - develop
511+
# - master
458512

459513
fineci-benchmark-cuda:
460514
stage: benchmark-cuda

CMakeLists.txt

+8-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ include(cmake/create_test.cmake)
1010
include(cmake/install_helpers.cmake)
1111
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
1212

13+
include(cmake/build_type_helpers.cmake)
14+
1315
# Ginkgo configuration options
1416
option(GINKGO_DEVEL_TOOLS "Add development tools to the build system" ON)
1517
option(GINKGO_BUILD_TESTS "Generate build files for unit tests" ON)
@@ -37,11 +39,13 @@ endif()
3739

3840

3941
if(GINKGO_BUILD_TESTS)
40-
set(MEMORYCHECK_SUPPRESSIONS_FILE
41-
"${Ginkgo_SOURCE_DIR}/dev_tools/valgrind/suppressions.supp"
42-
CACHE FILEPATH "" FORCE)
43-
include(CTest)
42+
# Configure CTest
43+
configure_file(
44+
${CMAKE_CURRENT_LIST_DIR}/cmake/CTestCustom.cmake.in
45+
${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake @ONLY)
46+
4447
enable_testing()
48+
include(CTest)
4549
endif()
4650

4751

CTestConfig.cmake

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
set(CTEST_PROJECT_NAME "Ginkgo Project")
2+
set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC")
3+
4+
set(CTEST_DROP_METHOD "http")
5+
set(CTEST_DROP_SITE "my.cdash.org")
6+
set(CTEST_DROP_LOCATION "/submit.php?project=Ginkgo+Project")
7+
set(CTEST_DROP_SITE_CDASH TRUE)

README.md

+38-4
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,15 @@ Ginkgo adds the following additional switches to control what is being built:
8989
Ginkgo's documentation. The default is `OFF`.
9090
* `-DGINKGO_EXPORT_BUILD_DIR={ON, OFF}` adds the Ginkgo build directory to the
9191
CMake package registry. The default is `OFF`.
92-
* `-DCMAKE_INSTALL_PREFIX=path` sets the installation path for `make install`.
93-
The default value is usually something like `/usr/local`
9492
* `-DGINKGO_VERBOSE_LEVEL=integer` sets the verbosity of Ginkgo.
9593
* `0` disables all output in the main libraries,
9694
* `1` enables a few important messages related to unexpected behavior (default).
95+
* `-DCMAKE_INSTALL_PREFIX=path` sets the installation path for `make install`.
96+
The default value is usually something like `/usr/local`
97+
* `-DCMAKE_BUILD_TYPE=type` specifies which configuration will be used for
98+
this build of Ginkgo. There are no default. Supported values are CMake's
99+
standard build types such as `DEBUG` and `RELEASE` and the Ginkgo specific
100+
`COVERAGE`, `ASAN` (AddressSanitizer) and `TSAN` (ThreadSanitizer) types.
97101
* `-DBUILD_SHARED_LIBS={ON, OFF}` builds ginkgo as shared libraries (`OFF`)
98102
or as dynamic libraries (`ON`), default is `ON`
99103
* `-DCMAKE_CUDA_HOST_COMPILER=path` instructs the build system to explicitly
@@ -156,9 +160,11 @@ Ginkgo to try to use an external version of a package. For this, set the CMake
156160
option `-DGINKGO_USE_EXTERNAL_<package>=ON`.
157161

158162
### Running the unit tests
159-
160163
You need to compile ginkgo with `-DGINKGO_BUILD_TESTS=ON` option to be able to run the
161-
tests. Use the following command inside the build folder to run all tests:
164+
tests.
165+
166+
#### Using make test
167+
After configuring Ginkgo, use the following command inside the build folder to run all tests:
162168

163169
```sh
164170
make test
@@ -180,6 +186,34 @@ run the following from the build folder:
180186

181187
where `path/to/test` is the path returned by `make test`.
182188

189+
190+
#### Using CTest
191+
The tests can also be ran through CTest from the command line, for example when
192+
in a configured build directory:
193+
194+
```sh
195+
ctest -T start -T build -T test -T submit
196+
```
197+
198+
Will start a new test campaign (usually in `Experimental` mode), build Ginkgo
199+
with the set configuration, run the tests and submit the results to our CDash
200+
dashboard.
201+
202+
203+
Another option is to use Ginkgo's CTest script which is configured to build
204+
Ginkgo with default settings, runs the tests and submits the test to our CDash
205+
dashboard automatically.
206+
207+
To run the script, use the following command:
208+
209+
```sh
210+
ctest -S cmake/CTestScript.cmake
211+
```
212+
213+
The default settings are for our own CI system. Feel free to configure the
214+
script before launching it through variables or by directly changing its values.
215+
A documentation can be found in the script itself.
216+
183217
### Running the benchmarks
184218

185219
In addition to the unit tests designed to verify correctness, Ginkgo also

cmake/CTestCustom.cmake.in

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
list(APPEND CTEST_CUSTOM_COVERAGE_EXCLUDE
2+
# Exclude list set by cmake
3+
@CUSTOM_COVERAGE_EXCLUDE@
4+
5+
# Exclude try_compile sources from coverage results:
6+
"/CMakeFiles/CMakeTmp/"
7+
8+
"third_party"
9+
10+
"test"
11+
12+
"c\\+\\+"
13+
)
14+
15+
set(CTEST_SOURCE_DIRECTORY "@Ginkgo_SOURCE_DIR@" CACHE STRING "" FORCE)
16+
set(CTEST_BINARY_DIRECTORY "@Ginkgo_BINARY_DIR@" CACHE STRING "" FORCE)
17+
18+
set(CTEST_MEMORYCHECK_COMMAND_OPTIONS "--trace-children=yes --leak-check=full")
19+
set(CTEST_MEMORYCHECK_SUPPRESSIONS_FILE "@Ginkgo_SOURCE_DIR@/dev_tools/valgrind/suppressions.supp")
20+
21+
set(CTEST_COVERAGE_EXTRA_FLAGS "-p")

cmake/CTestScript.cmake

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#.rst:
2+
# Ginkgo CTestScript
3+
# -------
4+
#
5+
# Runs our tests through CTest, with support for Coverage or memory checking.
6+
#
7+
# This script provides a full CTest run whith result submission to Ginkgo's
8+
# CDash dashboard. The supported runs are:
9+
# + With or without coverage, requires the gcov tool.
10+
# + With or without address sanitizers.
11+
# + With or without thread sanitizers.
12+
# + With or without valgrind, requires the valgrind tool.
13+
#
14+
# Note that only one of these can be ran at once, as the build types
15+
# conflict. Ginkgo is always configured with CUDA, OpenMP and Reference
16+
# support. The results are always sent to the dashboard:
17+
# https://my.cdash.org/index.php?project=Ginkgo+Project
18+
#
19+
# Running the script
20+
# ^^^^^^^^^^^^^^^^^^
21+
#
22+
# To run the script, launch the command `ctest -S cmake/CTestScript.cmake`
23+
# from the Ginkgo's source directory. The default settings are for the CI
24+
# system's DEBUG tests run. To configure the script use standard CMake `-D`
25+
# parameters. For example, the following command runs coverage.
26+
#
27+
# `ctest -S cmake/CTestScript.cmake -DCTEST_BUILD_CONFIGURATION=COVERAGE`
28+
#
29+
# Instead, this runs the ThreadSanitizer:
30+
#
31+
# `ctest -S cmake/CTestScript.cmake -DCTEST_BUILD_CONFIGURATION=TSAN
32+
# -DCTEST_MEMORYCHECK_TYPE=ThreadSanitizer`
33+
#
34+
# Input Variables
35+
# ^^^^^^^^^^^^^^^^
36+
#
37+
# This script can be configured with the following input variables:
38+
#
39+
# ``CTEST_SOURCE_DIRECTORY``
40+
# Where the sources are located. By default, the current directory.
41+
#
42+
# ``CTEST_BINARY_DIRECTORY``
43+
# In which directory should the sources be builts. Default, `./build`.
44+
#
45+
# ``CTEST_SITE``
46+
# A string to describe the machine this is ran on. Default FineCI.
47+
#
48+
# ``CTEST_CMAKE_GENERATOR``
49+
# Which generator should be used for the build. Default `Unix Makefiles`
50+
#
51+
# ``CTEST_BUILD_CONFIGURATION``
52+
# Which configuration should Ginkgo be built with. Default `DEBUG`.
53+
# The supported values are: COVERAGE, ASAN, TSAN, DEBUG and RELEASE.
54+
#
55+
# ``CTEST_TEST_MODEL``
56+
# Which CTest test model should be used. Default `Continuous`.
57+
# The supported values are the same as CTest's, namely:
58+
# Experimental, Nightly, Continuous.
59+
#
60+
# ``CTEST_BUILD_NAME``
61+
# The name of the build being ran. Default: `CTEST_BUILD_CONFIGURATION`
62+
#
63+
# ``CTEST_MEMORYCHECK_TYPE``
64+
# Whether memorycheck should be ran. Default: `None`. Supported values are:
65+
# Valgrind, ThreadSanitizer, AddressSanitizer and None.
66+
#
67+
68+
if (NOT DEFINED CTEST_SOURCE_DIRECTORY)
69+
set(CTEST_SOURCE_DIRECTORY ".")
70+
endif()
71+
72+
if (NOT DEFINED CTEST_BINARY_DIRECTORY)
73+
set(CTEST_BINARY_DIRECTORY "./build")
74+
endif()
75+
76+
if (NOT DEFINED CTEST_SITE)
77+
set(CTEST_SITE "Linux-FineCI")
78+
endif()
79+
80+
if (NOT DEFINED CTEST_CMAKE_GENERATOR)
81+
set(CTEST_CMAKE_GENERATOR "Unix Makefiles")
82+
endif()
83+
84+
# Supported: COVERAGE, ASAN, TSAN, DEBUG and RELEASE
85+
if (NOT DEFINED CTEST_BUILD_CONFIGURATION)
86+
set(CTEST_BUILD_CONFIGURATION "DEBUG")
87+
endif()
88+
89+
if (NOT DEFINED CTEST_TEST_MODEL)
90+
set(CTEST_TEST_MODEL "Continuous")
91+
endif()
92+
93+
if (NOT DEFINED CTEST_BUILD_NAME)
94+
set(CTEST_BUILD_NAME "${CTEST_BUILD_CONFIGURATION}")
95+
endif()
96+
97+
#Supported: Valgrind, ThreadSanitizer, AddressSanitizer.
98+
if (NOT DEFINED CTEST_MEMORYCHECK_TYPE)
99+
set(CTEST_MEMORYCHECK_TYPE "None")
100+
endif()
101+
102+
# Find coverage and valgrind tools
103+
if(CTEST_MEMORYCHECK_TYPE STREQUAL "Valgrind")
104+
find_program(CTEST_MEMORYCHECK_COMMAND valgrind)
105+
set(CTEST_BUILD_NAME "Valgrind")
106+
endif()
107+
108+
if(CTEST_BUILD_CONFIGURATION STREQUAL "COVERAGE")
109+
find_program(CTEST_COVERAGE_COMMAND gcov)
110+
endif()
111+
112+
include(ProcessorCount)
113+
ProcessorCount(PROC_COUNT)
114+
if(NOT PROC_COUNT EQUAL 0)
115+
if(NOT WIN32)
116+
set(CTEST_BUILD_FLAGS "-j${PROC_COUNT}")
117+
endif(NOT WIN32)
118+
endif()
119+
120+
ctest_start("${CTEST_TEST_MODEL}")
121+
ctest_submit(PARTS Start)
122+
123+
ctest_configure(BUILD "${CTEST_BINARY_DIRECTORY}" OPTIONS "-DGINKGO_BUILD_REFERENCE=ON;-DGINKGO_BUILD_OMP=ON;-DGINKGO_BUILD_CUDA=ON;-DCMAKE_BUILD_TYPE=${CTEST_BUILD_CONFIGURATION}" APPEND)
124+
ctest_submit(PARTS Configure)
125+
126+
ctest_read_custom_files( ${CTEST_BINARY_DIRECTORY} )
127+
128+
ctest_build(BUILD "${CTEST_BINARY_DIRECTORY}" APPEND)
129+
ctest_submit(PARTS Build)
130+
131+
ctest_test(BUILD "${CTEST_BINARY_DIRECTORY}" APPEND)
132+
ctest_submit(PARTS Test)
133+
134+
if (CTEST_BUILD_CONFIGURATION STREQUAL "COVERAGE")
135+
ctest_coverage(BUILD "${CTEST_BINARY_DIRECTORY}" APPEND)
136+
ctest_submit(PARTS Coverage)
137+
endif()
138+
139+
if(NOT CTEST_MEMORYCHECK_TYPE STREQUAL "None")
140+
ctest_memcheck(BUILD "${CTEST_BINARY_DIRECTORY}" APPEND)
141+
ctest_submit(PARTS MemCheck)
142+
endif()
143+

0 commit comments

Comments
 (0)