From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id BCEA09A492D; Tue, 12 Mar 2024 10:07:32 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org BCEA09A492D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1710227252; bh=oK5ecaVKR49hooTGZgJIej6iXsF1NFHqqcSsEgL/0nY=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=pQ/dwnlwy+YaK2F+E7My2jXHvpUMP8HnFhXZE7mRFXFSnxvEM1E0XXTp6jy9Ivr6m zd9ZmcHQkj8EZOG5IDOXwGY9C/pvVhUPK8coInm8ZYSc8oaGeYXNq4l/rmgfjxpScy JIVAFk/ZhmP5eTDVXxXQLaw8nFxg5k/CsPty63wg= Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 9A4589A4901 for ; Tue, 12 Mar 2024 10:07:31 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 9A4589A4901 Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-513173e8191so5298688e87.1 for ; Tue, 12 Mar 2024 00:07:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710227250; x=1710832050; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=H3y3m0J/gwLTKRbKnT9r5rvs+AyuK+rkt8lQwuoaxd8=; b=tJG/FbplqKA2nsWGeXEyvv6srcuzX7wBE8/tMxtVCVclAgUKBPLlBFkpxEaWQG7CWV dze83uIehil5TmI0ApC9SoFIqWeW6nWBMvT/heBoOGlMbApLT/ERTdOF8ecpYGwymcvN Vmt5k3WklDspO4bSSGZRwdcQEPmS81fzpG2YZH9M00ZmSoO5lM5eqyy6WeyB1WhcKkbv fLe4sdYM3b194XUlt1X3kQYVtCufoCKz9Oh623N2mXS9b3oQ2WqOfdR8c/ObHWq9Uw4V +f1Cne8W+ZP6eV7J723+5ycWqEBRNbwapZLREIpMP0wCN6SBS+OkYIcMP7kyoR3eIMhe +5wg== X-Gm-Message-State: AOJu0YxSVWALtHRu65gFxuBY38/vxBlubb0XdEyx72EZPddcFL1OIpDF jKlLLS/JQc6J8tPiDxa416oB+TODUfO6O3rkaL/mwUnEMsGrHfBvGm6+NkN4 X-Google-Smtp-Source: AGHT+IGpXziI0ro0dWtI9N/0wSoXFYYTI0y912YeIzfKGKP1o0zZ34TCh+KWV1pbtRcVi/MRnLdQjA== X-Received: by 2002:ac2:5547:0:b0:513:5e6b:a191 with SMTP id l7-20020ac25547000000b005135e6ba191mr5009223lfk.50.1710227249654; Tue, 12 Mar 2024 00:07:29 -0700 (PDT) Received: from pony.mail.msk ([2a00:1148:b0ba:16:a1ae:9dcc:f7d7:beee]) by smtp.gmail.com with ESMTPSA id b9-20020ac247e9000000b0051358cc2ea0sm1443085lfp.197.2024.03.12.00.07.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 00:07:28 -0700 (PDT) To: tarantool-patches@dev.tarantool.org, Sergey Kaplun , max.kokryashkin@gmail.com, Igor Munkin Date: Tue, 12 Mar 2024 10:06:54 +0300 Message-Id: <62428a61c98eee87dfc91f2d8972988d80589d3e.1710226958.git.sergeyb@tarantool.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH luajit][v3] cmake: replace prove with CTest X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: Sergey Bronnikov The patch replaces the main test runner `prove(1)` with CTest, see [1] and [2]. Build and test steps looks the same as before: $ cmake -S . -B build $ cmake --build build --parallel $ cmake --build build --target [LuaJIT-test, test] CMake targets lua-Harness-tests, LuaJIT-tests, PUC-Rio-Lua-5.1-tests, tarantool-tests and tarantool-c-tests are still functional. One could use `ctest` tool: $ ctest --print-labels Test project All Labels: LuaJIT PUC-Rio-Lua-5.1 lua-Harness tarantool tarantool-c $ ctest # Run all tests. $ ctest -L tarantool # Run tests in tarantool-tests dir. $ ctest -L tarantool-c # Run tests in tarantool-c-tests dir. $ ctest -L lua-Harness # Run tests in lua-Harness-tests dir. $ ctest -L luajit # Run tests in LuaJIT-tests dir. $ ctest -L PUC-Rio-Lua-5.1 # Run tests in PUC-Rio-Lua-5.1-tests dir. $ ctest --rerun-fail $ ctest --output-on-failure The benefits are: - less external dependencies, `prove(1)` is gone, `ctest` is a part of CMake - running tests by test title - extended test running options in comparison to prove(1) - unified test output (finally!) Note that it is not possible to attach targets to the automatically generated `test` target. It means that target `test` is now executing `LuaJIT-test`, but not `LuaJIT-lint`. Note that the testsuites in `test/LuaJIT-tests` and `test/PUC-Rio-Lua-5.1` directories have their own test runners written in Lua and currently CTest runs these testsuites as single tests. In the future we could change these test runners to specify tests from outside, and after this we could run tests separately by CTest in these test suites. Note that it is not possible to add dependencies to `add_test()` in CMake, see [3]. CMake 3.7 introduces FIXTURES_REQUIRED [4] and FIXTURES_SETUP [5], but these test properties cannot be used - used CMake version is lower. This workarounded by introducing a special test for each testsuite that executes a target that builds test dependencies. 1. https://cmake.org/cmake/help/latest/manual/ctest.1.html 2. https://cmake.org/cmake/help/book/mastering-cmake/chapter/Testing%20With%20CMake%20and%20CTest.html 3. https://gitlab.kitware.com/cmake/cmake/-/issues/8774 4. https://cmake.org/cmake/help/latest/prop_test/FIXTURES_REQUIRED.html 5. https://cmake.org/cmake/help/latest/prop_test/FIXTURES_SETUP.html --- Changes v3: - rebased to master - applied fixes suggested by Igor Munkin PR: https://github.com/tarantool/tarantool/pull/9286 Branch: https://github.com/tarantool/luajit/tree/ligurio/enable_test_target .gitignore | 2 + CMakeLists.txt | 11 ++++ test/CMakeLists.txt | 78 +++++++++++++++-------- test/LuaJIT-tests/CMakeLists.txt | 40 +++++++----- test/LuaJIT-tests/src/CMakeLists.txt | 2 +- test/PUC-Rio-Lua-5.1-tests/CMakeLists.txt | 25 +++++--- test/lua-Harness-tests/CMakeLists.txt | 48 ++++++++------ test/tarantool-c-tests/CMakeLists.txt | 56 ++++++++-------- test/tarantool-tests/CMakeLists.txt | 62 ++++++++---------- 9 files changed, 194 insertions(+), 130 deletions(-) diff --git a/.gitignore b/.gitignore index dc5ea5fc..dd1f8888 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,9 @@ .ninja_log CMakeCache.txt CMakeFiles +CTestTestfile.cmake Makefile +Testing build.ninja cmake_install.cmake cmake_uninstall.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f5e2afb..6b2f855f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -345,6 +345,13 @@ set(LUAJIT_TEST_BINARY ${LUAJIT_BINARY} CACHE STRING "Lua implementation to be used for tests. Default is 'luajit'." ) +# If LuaJIT is used in a parent project, provide an option +# to choose what dependencies to be used for running and building +# LuaJIT tests. +set(LUAJIT_TEST_DEPS "luajit-main" CACHE STRING + "A list of target dependencies to be used for tests." +) + # FIXME: If LuaJIT is used in parent project, provide an option # to pass Lua code to be run before tests are started. # XXX: Attentive reader might point to LUA_INIT environment @@ -362,6 +369,10 @@ set(LUAJIT_TEST_INIT "${PROJECT_SOURCE_DIR}/test/luajit-test-init.lua" CACHE STR "Lua code need to be run before tests are started." ) +# XXX: Enable testing via CTest. Since CTest expects to find a +# test file in the build directory root, this command should be in +# the source directory root (hence, in this CMakeLists.txt). +enable_testing() add_subdirectory(test) # --- Misc rules --------------------------------------------------------------- diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3ad5d15f..90aaead2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -77,35 +77,63 @@ separate_arguments(LUAJIT_TEST_COMMAND) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(AddTestLib) +# TEST_FLAGS is used by CMake targets in test suites. +# XXX: CMake 3.17 introduces CMAKE_CTEST_ARGUMENTS that contains CTest options +# and is used by `test` target. +set(TEST_FLAGS + --output-on-failure + --schedule-random + --parallel ${CMAKE_BUILD_PARALLEL_LEVEL} +) +if(CMAKE_VERBOSE_MAKEFILE) + list(APPEND TEST_FLAGS --verbose) +endif() + +function(add_test_suite_target target) + set(prefix ARG) + set(noValues) + set(singleValues LABEL) + set(multiValues DEPENDS) + + # FIXME: if we update to CMake >= 3.5, can remove this line. + include(CMakeParseArguments) + cmake_parse_arguments(${prefix} + "${noValues}" + "${singleValues}" + "${multiValues}" + ${ARGN}) + + set(_DEPS_TARGET ${target}-deps) + + add_custom_target(${_DEPS_TARGET} DEPENDS ${ARG_DEPENDS}) + + add_test(${_DEPS_TARGET} + ${CMAKE_COMMAND} + --build ${CMAKE_BINARY_DIR} + --target ${_DEPS_TARGET} + ) + + message(STATUS "Add test suite ${ARG_LABEL}") + + add_custom_target(${target} + COMMAND ${CMAKE_CTEST_COMMAND} -L ${ARG_LABEL} ${TEST_FLAGS} + DEPENDS ${_DEPS_TARGET} + ) + + unset(_DEPS_TARGET) +endfunction() + add_subdirectory(LuaJIT-tests) add_subdirectory(PUC-Rio-Lua-5.1-tests) add_subdirectory(lua-Harness-tests) add_subdirectory(tarantool-c-tests) add_subdirectory(tarantool-tests) -add_custom_target(${PROJECT_NAME}-test DEPENDS - LuaJIT-tests - PUC-Rio-Lua-5.1-tests - lua-Harness-tests - tarantool-c-tests - tarantool-tests +add_custom_target(${PROJECT_NAME}-test + COMMAND ${CMAKE_CTEST_COMMAND} ${TEST_FLAGS} + DEPENDS tarantool-c-tests-deps + tarantool-tests-deps + lua-Harness-tests-deps + PUC-Rio-Lua-5.1-tests-deps + LuaJIT-tests-deps ) - -if(LUAJIT_USE_TEST) - if(POLICY CMP0037) - if(CMAKE_VERSION VERSION_LESS 3.11) - # CMake below 3.11 reserves the name 'test'. Use old policy. - # https://cmake.org/cmake/help/v3.11/release/3.11.html#other-changes - cmake_policy(SET CMP0037 OLD) - else() - # Starting from CMake 3.11 the name 'test' is reserved in - # special cases and can be used as a target name. - cmake_policy(SET CMP0037 NEW) - endif() - endif(POLICY CMP0037) - - add_custom_target(test DEPENDS - ${PROJECT_NAME}-test - ${PROJECT_NAME}-lint - ) -endif() diff --git a/test/LuaJIT-tests/CMakeLists.txt b/test/LuaJIT-tests/CMakeLists.txt index a0fb5440..1080987a 100644 --- a/test/LuaJIT-tests/CMakeLists.txt +++ b/test/LuaJIT-tests/CMakeLists.txt @@ -3,17 +3,13 @@ cmake_minimum_required(VERSION 3.1 FATAL_ERROR) add_subdirectory(src) -add_custom_target(LuaJIT-tests - DEPENDS ${LUAJIT_TEST_BINARY} LuaJIT-tests-libs -) - make_lua_path(LUA_CPATH PATHS ${CMAKE_CURRENT_BINARY_DIR}/src/?${CMAKE_SHARED_LIBRARY_SUFFIX} ) set(LUAJIT_TESTS_ENV - "LUA_CPATH=\"${LUA_CPATH}\"" + "LUA_CPATH=${LUA_CPATH}\;\;" ) set(LD_LIBRARY_PATH "${CMAKE_CURRENT_BINARY_DIR}/src/:") @@ -50,10 +46,11 @@ if(LUAJIT_USE_ASAN) if(CMAKE_C_COMPILER_ID STREQUAL "GNU") LibRealPath(LIB_ASAN libasan.so) # XXX: Don't use " " (separator in LD_PRELOAD) in `list()`. - # ";" will expand to " " as we want. - list(APPEND LUAJIT_TESTS_ENV LD_PRELOAD="${LIB_ASAN};${LIB_STDCPP}") + # ";" will expand to " " as we want after wrapping + # LUAJIT_TESTS_ENV by double quotes. + list(APPEND LUAJIT_TESTS_ENV LD_PRELOAD=${LIB_ASAN};${LIB_STDCPP}) else() - list(APPEND LUAJIT_TESTS_ENV LD_PRELOAD="${LIB_STDCPP}") + list(APPEND LUAJIT_TESTS_ENV LD_PRELOAD=${LIB_STDCPP}) endif() endif() @@ -64,12 +61,25 @@ if(LUAJIT_NO_UNWIND) set(LUAJIT_TEST_TAGS_EXTRA +internal_unwinder) endif() -add_custom_command(TARGET LuaJIT-tests - COMMENT "Running LuaJIT-tests" - COMMAND - env - ${LUAJIT_TESTS_ENV} - ${LUAJIT_TEST_COMMAND} ${CMAKE_CURRENT_SOURCE_DIR}/test.lua - +slow +ffi +bit +jit ${LUAJIT_TEST_TAGS_EXTRA} +set(TEST_SUITE_NAME "LuaJIT-tests") + +# XXX: The call produces both test and target +# as a side effect. +add_test_suite_target(LuaJIT-tests + LABEL ${TEST_SUITE_NAME} + DEPENDS ${LUAJIT_TEST_DEPS} LuaJIT-tests-deps-libs +) + +# The test suite has its own test runner +# (test/LuaJIT-tests/test.lua), it is not possible to run these +# tests one-by-one by CTest. +add_test(NAME "test/LuaJIT-tests" + COMMAND ${LUAJIT_TEST_COMMAND} ${CMAKE_CURRENT_SOURCE_DIR}/test.lua + +slow +ffi +bit +jit ${LUAJIT_TEST_TAGS_EXTRA} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) +set_tests_properties("test/LuaJIT-tests" PROPERTIES + LABELS ${TEST_SUITE_NAME} + ENVIRONMENT "${LUAJIT_TESTS_ENV}" + DEPENDS LuaJIT-tests-deps +) diff --git a/test/LuaJIT-tests/src/CMakeLists.txt b/test/LuaJIT-tests/src/CMakeLists.txt index 2f90da86..f0e639e1 100644 --- a/test/LuaJIT-tests/src/CMakeLists.txt +++ b/test/LuaJIT-tests/src/CMakeLists.txt @@ -6,4 +6,4 @@ AddTestLib(libctest libctest.c) enable_language(CXX) AddTestLib(libcpptest libcpptest.cpp) -add_custom_target(LuaJIT-tests-libs DEPENDS ${TESTLIBS}) +add_custom_target(LuaJIT-tests-deps-libs DEPENDS ${TESTLIBS}) diff --git a/test/PUC-Rio-Lua-5.1-tests/CMakeLists.txt b/test/PUC-Rio-Lua-5.1-tests/CMakeLists.txt index 98277f9a..af89bfe5 100644 --- a/test/PUC-Rio-Lua-5.1-tests/CMakeLists.txt +++ b/test/PUC-Rio-Lua-5.1-tests/CMakeLists.txt @@ -34,17 +34,26 @@ add_subdirectory(libs) # But, unfortunately, depends on specific PUC-Rio # Lua 5.1 internal headers and should be adapted for LuaJIT. -add_custom_target(PUC-Rio-Lua-5.1-tests - DEPENDS ${LUAJIT_TEST_BINARY} PUC-Rio-Lua-5.1-tests-prepare +set(TEST_SUITE_NAME "PUC-Rio-Lua-5.1-tests") + +# XXX: The call produces both test and target +# as a side effect. +add_test_suite_target(PUC-Rio-Lua-5.1-tests + LABEL ${TEST_SUITE_NAME} + DEPENDS ${LUAJIT_TEST_DEPS} PUC-Rio-Lua-5.1-tests-prepare ) -add_custom_command(TARGET PUC-Rio-Lua-5.1-tests - COMMENT "Running PUC-Rio Lua 5.1 tests" - COMMAND - env - LUA_PATH="${LUA_PATH}" - ${LUAJIT_TEST_COMMAND} ${CMAKE_CURRENT_SOURCE_DIR}/all.lua +# The test suite has its own test runner +# (test/PUC-Rio-Lua-5.1-tests/all.lua), it is not possible +# to run these tests one-by-one by CTest. +add_test(NAME "test/PUC-Rio-Lua-5.1" + COMMAND ${LUAJIT_TEST_COMMAND} ${CMAKE_CURRENT_SOURCE_DIR}/all.lua WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) +set_tests_properties("test/PUC-Rio-Lua-5.1" PROPERTIES + ENVIRONMENT "LUA_PATH=${LUA_PATH}\;\;" + LABELS ${TEST_SUITE_NAME} + DEPENDS PUC-Rio-Lua-5.1-tests-deps +) # vim: expandtab tabstop=2 shiftwidth=2 diff --git a/test/lua-Harness-tests/CMakeLists.txt b/test/lua-Harness-tests/CMakeLists.txt index f748a8fd..d454ba41 100644 --- a/test/lua-Harness-tests/CMakeLists.txt +++ b/test/lua-Harness-tests/CMakeLists.txt @@ -4,12 +4,6 @@ # See the rationale in the root CMakeLists.txt cmake_minimum_required(VERSION 3.1 FATAL_ERROR) -find_program(PROVE prove) -if(NOT PROVE) - message(WARNING "`prove' is not found, so lua-Harness-tests target is not generated") - return() -endif() - # Tests create temporary files (see 303-package.t and 411-luajit.t # for example) to be required. Also, they require some files from # the original test source directory. @@ -20,23 +14,35 @@ make_lua_path(LUA_PATH ${LUAJIT_SOURCE_DIR}/?.lua ${LUAJIT_BINARY_DIR}/?.lua ) -set(LUA_TEST_FLAGS --failures --shuffle) -if(CMAKE_VERBOSE_MAKEFILE) - list(APPEND LUA_TEST_FLAGS --verbose) -endif() +set(TEST_SUITE_NAME "lua-Harness-tests") -add_custom_target(lua-Harness-tests DEPENDS ${LUAJIT_TEST_BINARY}) -add_custom_command(TARGET lua-Harness-tests - COMMENT "Running lua-Harness tests" - COMMAND - env - 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} +# XXX: The call produces both test and target +# as a side effect. +add_test_suite_target(lua-Harness-tests + LABEL ${TEST_SUITE_NAME} + DEPENDS ${LUAJIT_TEST_DEPS} ) +file(GLOB tests ${CMAKE_CURRENT_SOURCE_DIR} "*.t") +foreach(test_path ${tests}) + get_filename_component(test_name ${test_path} NAME) + # FIXME: By default GLOB lists directories. + # Directories are omitted in the result if LIST_DIRECTORIES + # is set to false. New in version CMake 3.3. + if (${test_name} STREQUAL ${TEST_SUITE_NAME}) + continue() + endif (${test_name} STREQUAL ${TEST_SUITE_NAME}) + set(test_title "test/${TEST_SUITE_NAME}/${test_name}") + add_test(NAME ${test_title} + COMMAND ${LUAJIT_TEST_COMMAND} -l profile_luajit21 ${test_path} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + set_tests_properties(${test_title} PROPERTIES + ENVIRONMENT "LUA_PATH=${LUA_PATH}\;" + LABELS ${TEST_SUITE_NAME} + DEPENDS lua-Harness-tests-deps + ) +endforeach() + # vim: expandtab tabstop=2 shiftwidth=2 diff --git a/test/tarantool-c-tests/CMakeLists.txt b/test/tarantool-c-tests/CMakeLists.txt index 4b1d8832..2de4a0c8 100644 --- a/test/tarantool-c-tests/CMakeLists.txt +++ b/test/tarantool-c-tests/CMakeLists.txt @@ -1,15 +1,4 @@ -find_program(PROVE prove) -if(NOT PROVE) - message(WARNING "`prove' is not found, so tarantool-c-tests target is not generated") - return() -endif() - set(C_TEST_SUFFIX .c_test) -set(C_TEST_FLAGS --failures --shuffle) - -if(CMAKE_VERBOSE_MAKEFILE) - list(APPEND C_TEST_FLAGS --verbose) -endif() # Build libtest. @@ -49,20 +38,35 @@ foreach(test_source ${tests}) LIST(APPEND TESTS_COMPILED ${exe}) endforeach() -add_custom_target(tarantool-c-tests - DEPENDS libluajit libtest ${TESTS_COMPILED} -) +set(TEST_SUITE_NAME "tarantool-c-tests") -add_custom_command(TARGET tarantool-c-tests - COMMENT "Running Tarantool C tests" - COMMAND - ${PROVE} - ${CMAKE_CURRENT_BINARY_DIR} - --ext ${C_TEST_SUFFIX} - --jobs ${CMAKE_BUILD_PARALLEL_LEVEL} - # Report any TAP parse errors, if any, since test module is - # maintained by us. - --parse - ${C_TEST_FLAGS} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} +# XXX: The call produces both test and target +# as a side effect. +add_test_suite_target(tarantool-c-tests + LABEL ${TEST_SUITE_NAME} + DEPENDS ${LUAJIT_TEST_DEPS} libluajit libtest ${TESTS_COMPILED} ) + +# XXX: Note that we cannot glob generated files in CMake, see +# https://stackoverflow.com/questions/44076307/cmake-globbing-generated-files +# To workaround this, we glob source files and generated tests +# with paths to executable binaries. +file(GLOB tests ${CMAKE_CURRENT_SOURCE_DIR} "*.test.c") +foreach(test_path ${tests}) + get_filename_component(test_name ${test_path} NAME_WE) + # FIXME: By default GLOB lists directories. + # Directories are omitted in the result if LIST_DIRECTORIES + # is set to false. New in version CMake 3.3. + if (${test_name} STREQUAL ${TEST_SUITE_NAME}) + continue() + endif (${test_name} STREQUAL ${TEST_SUITE_NAME}) + set(test_title "test/${TEST_SUITE_NAME}/${test_name}${C_TEST_SUFFIX}") + add_test(NAME ${test_title} + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${test_name}${C_TEST_SUFFIX} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + set_tests_properties(${test_title} PROPERTIES + LABELS ${TEST_SUITE_NAME} + DEPENDS tarantool-c-tests-deps + ) +endforeach() diff --git a/test/tarantool-tests/CMakeLists.txt b/test/tarantool-tests/CMakeLists.txt index e6d12984..bb41e53b 100644 --- a/test/tarantool-tests/CMakeLists.txt +++ b/test/tarantool-tests/CMakeLists.txt @@ -4,19 +4,13 @@ # See the rationale in the root CMakeLists.txt. cmake_minimum_required(VERSION 3.1 FATAL_ERROR) -find_program(PROVE prove) -if(NOT PROVE) - message(WARNING "`prove' is not found, so tarantool-tests target is not generated") - return() -endif() - -add_custom_target(tarantool-tests +add_custom_target(tarantool-tests-deps-libs DEPENDS ${LUAJIT_TEST_BINARY} ) macro(BuildTestCLib lib sources) AddTestLib(${lib} ${sources}) - add_dependencies(tarantool-tests ${lib}) + add_dependencies(tarantool-tests-deps-libs ${lib}) # Add the directory where the lib is built to the list with # entries for LUA_CPATH environment variable, so LuaJIT can find # and load it. See the comment about extending the list in the @@ -60,21 +54,14 @@ make_lua_path(LUA_PATH ${PROJECT_SOURCE_DIR}/tools/?.lua ${LUAJIT_SOURCE_DIR}/?.lua ${LUAJIT_BINARY_DIR}/?.lua + ${PROJECT_BINARY_DIR}/src/?.lua ) + # Update LUA_CPATH with the library paths collected within # macro. make_lua_path(LUA_CPATH PATHS ${LUA_CPATHS}) set(LUA_TEST_SUFFIX .test.lua) -set(LUA_TEST_FLAGS --failures --shuffle) -set(LUA_TEST_ENV - "LUA_PATH=\"${LUA_PATH}\"" - "LUA_CPATH=\"${LUA_CPATH}\"" -) - -if(CMAKE_VERBOSE_MAKEFILE) - list(APPEND LUA_TEST_FLAGS --verbose) -endif() # XXX: Since the auxiliary libraries are built as a dynamically # loaded modules on MacOS instead of shared libraries as it is @@ -110,22 +97,29 @@ else() list(APPEND LUA_TEST_ENV_MORE LD_LIBRARY_PATH=${LD_LIBRARY_PATH}) endif() -# LUA_CPATH and LD_LIBRARY_PATH variables and also dependencies -# list with libraries are set in scope of BuildTestLib macro. -add_custom_command(TARGET tarantool-tests - COMMENT "Running Tarantool tests" - COMMAND - # XXX: We can't move everything to the "inner" env, since there - # are some issues with escaping ';' for different shells. As - # a result LUA_PATH/LUA_CPATH variables are set via the "outer" - # env, since they are not stripped by SIP like LD_*/DYLD_* are. - env - ${LUA_TEST_ENV} - ${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} +set(TEST_SUITE_NAME "tarantool-tests") + +# XXX: The call produces both test and target +# as a side effect. +add_test_suite_target(tarantool-tests + LABEL ${TEST_SUITE_NAME} + DEPENDS ${LUAJIT_TEST_DEPS} tarantool-tests-deps-libs ) +# LUA_CPATH and LD_LIBRARY_PATH variables and also TESTLIBS list +# with dependencies are set in scope of BuildTestLib macro. +set(TEST_ENV "LUA_PATH=${LUA_PATH};\;\;;LUA_CPATH=${LUA_CPATH}\;\;;${LUA_TEST_ENV_MORE}") +file(GLOB_RECURSE tests ${CMAKE_CURRENT_SOURCE_DIR} "*${LUA_TEST_SUFFIX}") +foreach(test_path ${tests}) + get_filename_component(test_name ${test_path} NAME) + set(test_title "test/tarantool-tests/${test_name}") + add_test(NAME ${test_title} + COMMAND ${LUAJIT_TEST_COMMAND} ${test_path} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + set_tests_properties(${test_title} PROPERTIES + ENVIRONMENT "${TEST_ENV}" + LABELS ${TEST_SUITE_NAME} + DEPENDS tarantool-tests-deps + ) +endforeach() -- 2.34.1