Skip to content

Commit fd06bc1

Browse files
committed
Limit CPU usage in tests
Without these rules `ctest --parallel` would massively overuse resources: With `N` being the number of CPU cores up to `N` CMake instances would be spawned in parallel. Each of these CMake instances would again spawn up to `N` build jobs. The resulting `N * N` job jobs easily overload any CPU.
1 parent 44faec3 commit fd06bc1

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

tests/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
include(platforms.cmake)
22

3+
cmake_host_system_information(RESULT _logical_cores QUERY NUMBER_OF_LOGICAL_CORES)
4+
set(CTEST_RESOURCE_SPEC_FILE "${CMAKE_BINARY_DIR}/CTestResources.json")
5+
configure_file(CTestResources.json.in "${CTEST_RESOURCE_SPEC_FILE}")
6+
37
function(arduino_cli_toolchain_add_test NAME)
48
cmake_parse_arguments(_TEST "" "" "SKIP" ${ARGN})
59

@@ -36,6 +40,7 @@ function(arduino_cli_toolchain_add_test NAME)
3640
set_tests_properties(
3741
"${_test_name}/configure" PROPERTIES
3842
FIXTURES_SETUP "${_test_name}/configure"
43+
RESOURCE_GROUPS "cpu-cores:1"
3944
DISABLED "${_test_disabled}"
4045
LABELS "${_board_name}")
4146

@@ -52,6 +57,7 @@ function(arduino_cli_toolchain_add_test NAME)
5257
"${_test_name}/reconfigure" PROPERTIES
5358
FIXTURES_REQUIRED "${_test_name}/configure"
5459
FIXTURES_SETUP "${_test_name}/reconfigure"
60+
RESOURCE_GROUPS "cpu-cores:1"
5561
DISABLED "${_test_disabled}"
5662
LABELS "${_board_name}")
5763

@@ -63,6 +69,7 @@ function(arduino_cli_toolchain_add_test NAME)
6369
set_tests_properties(
6470
"${_test_name}/build" PROPERTIES
6571
FIXTURES_REQUIRED "${_test_name}/reconfigure"
72+
RESOURCE_GROUPS "cpu-cores:${_logical_cores}"
6673
DISABLED "${_test_disabled}"
6774
LABELS "${_board_name}")
6875
endforeach()

tests/CTestResources.json.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"version": {"major": 1, "minor": 0},
3+
"local": [{
4+
"cpu-cores": [{"id": "0", "slots": ${_logical_cores} }]
5+
}]
6+
}

0 commit comments

Comments
 (0)