Skip to content

Commit

Permalink
build: configure parallel jobs
Browse files Browse the repository at this point in the history
lua-Harness and tarantool testsuites uses a prove(1) for running tests.
prove(1) allows to run tests in parallel with option "--jobs" [1].

In CMake it is not possible to get a number of parallel jobs in CMake
passed by user with option "-j", but it allows to pass a number of
parallel jobs with environment variable CMAKE_BUILD_PARALLEL_LEVEL [2]
on configuration phase. We use a value set by that environment variable
and set it to a number of CPU threads when it was not specified by user.
Number of CPU threads detected using builtin CMake function [3].

NOTE: CMAKE_BUILD_PARALLEL_LEVEL has been added in a version 3.12.

1. https://perldoc.perl.org/prove
2. https://cmake.org/cmake/help/latest/envvar/CMAKE_BUILD_PARALLEL_LEVEL.html
3. https://cmake.org/cmake/help/latest/module/ProcessorCount.html
  • Loading branch information
ligurio committed Jul 1, 2022
1 parent 62cb24b commit 62acf60
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ endif()
set(LUAJIT_TEST_COMMAND "${LUAJIT_TEST_BINARY} -e dofile[[${LUAJIT_TEST_INIT}]]")
separate_arguments(LUAJIT_TEST_COMMAND)

set(CMAKE_BUILD_PARALLEL_LEVEL $ENV{CMAKE_BUILD_PARALLEL_LEVEL})
if(NOT CMAKE_BUILD_PARALLEL_LEVEL)
include(ProcessorCount)
ProcessorCount(N)
# Function ProcessorCount() is guaranteed to return a positive integer (>=1)
# if it succeeds. It returns 0 if there's a problem determining the processor
# count.
if(NOT N EQUAL 0)
set(CMAKE_BUILD_PARALLEL_LEVEL ${N})
endif()
endif()
message(STATUS "Using CMAKE_BUILD_PARALLEL_LEVEL: ${CMAKE_BUILD_PARALLEL_LEVEL}")

add_subdirectory(LuaJIT-tests)
add_subdirectory(PUC-Rio-Lua-5.1-tests)
add_subdirectory(lua-Harness-tests)
Expand Down
1 change: 1 addition & 0 deletions test/lua-Harness-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ add_custom_command(TARGET lua-Harness-tests
LUA_PATH="${LUA_PATH}\;"
${PROVE} ${CMAKE_CURRENT_SOURCE_DIR}
--exec '${LUAJIT_TEST_COMMAND} -l profile_luajit21'
--jobs ${CMAKE_BUILD_PARALLEL_LEVEL}
${LUA_TEST_FLAGS}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
Expand Down
1 change: 1 addition & 0 deletions test/tarantool-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ add_custom_command(TARGET tarantool-tests
${PROVE} ${CMAKE_CURRENT_SOURCE_DIR}
--exec 'env ${LUA_TEST_ENV_MORE} ${LUAJIT_TEST_COMMAND}'
--ext ${LUA_TEST_SUFFIX}
--jobs ${CMAKE_BUILD_PARALLEL_LEVEL}
${LUA_TEST_FLAGS}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
Expand Down

0 comments on commit 62acf60

Please sign in to comment.