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 3E6906C7D4; Tue, 2 Feb 2021 23:59:27 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 3E6906C7D4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1612299567; bh=7/efQO8rHZAjgA+rBv5qYfA3UhLq2Zn2cytTLlilXwM=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=b47L+qf9nPgF5XcXkXOp7K1e3v80+45A6pM5u9Gp8zjJhcoGbVzmMyX9kFEaA/eGT 9BwZeCpkK8x215R1cwkJhpLhuEk70CiDI/bL5zzNaFD9ny/kF9f+J1XU66vCzmqNB1 xtYNiDSVCfJ38uDp/xxaeC9a43zfZi/r116zZTkM= Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 8DC1763354 for ; Tue, 2 Feb 2021 23:57:52 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8DC1763354 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1l72kB-0005mg-7C; Tue, 02 Feb 2021 23:57:51 +0300 To: Sergey Kaplun , Timur Safin Date: Tue, 2 Feb 2021 23:57:43 +0300 Message-Id: <6a03d693204cacc5791c75e1003efc150abb2979.1612291495.git.imun@tarantool.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD953AC099BC0052A9C3D690943982D6E894AC6DB5C833CB876182A05F53808504026802EC6703483B71CB57B9DC4EA5D02C374AA81F150F573808184FCD689F06A X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7CF4D16325FBE1EEDEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637E893C22CB255350D8638F802B75D45FF5571747095F342E8C7A0BC55FA0FE5FCDAFBC183B389AD44788BBA50AF79FB1AF951200466BF2E3D389733CBF5DBD5E913377AFFFEAFD269A417C69337E82CC2CC7F00164DA146DAFE8445B8C89999729449624AB7ADAF37F6B57BC7E64490611E7FA7ABCAF51C92A417C69337E82CC2CC7F00164DA146DA6F5DAA56C3B73B23C77107234E2CFBA567F23339F89546C55F5C1EE8F4F765FC426E46268278306375ECD9A6C639B01BBD4B6F7A4D31EC0BC0CAF46E325F83A522CA9DD8327EE4931B544F03EFBC4D5789424AA0EF8DE9BAC4224003CC836476C0CAF46E325F83A50BF2EBBBDD9D6B0F05F538519369F3743B503F486389A921A5CC5B56E945C8DA X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C4C7A0BC55FA0FE5FCDAFBC183B389AD44788BBA50AF79FB1AACDBEC076288F312B1881A6453793CE9C32612AADDFBE061C61BE10805914D3804EBA3D8E7E5B87ABF8C51168CD8EBDB791E6C230873D55CDC48ACC2A39D04F89CDFB48F4795C241BDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34BC3EEE75EF3BACCFE8BC1A763EE310A83D001E32A709D930337E8252DD2BA7CAC465FBC283AD33801D7E09C32AA3244CC8B54FD2E9E2E91EE6DB1BDCD88C81C595A9E0DC41E9A4CF927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojCSo1BV1mVLZyxuR7xRkOUA== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822D3D7C13AD08470EFB7B9F7077424241EA7C8D0F45F857DBFE9F1EFEE2F478337FB559BB5D741EB964C8C2C849690F8E70A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit 3/5] test: run LuaJIT tests via CMake 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: Igor Munkin via Tarantool-patches Reply-To: Igor Munkin Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This patch introduces a separate target to run all available tests. The whole testing machinery is reworked much but the existing tests are left mostly unchanged. However, considering the different ways to integrate LuaJIT into the parent project, this machinery provides two new configuration options: * LUAJIT_USE_TEST: there might be a parent project integrating LuaJIT sources in its source tree as a third party library (e.g. https://github.com/tarantool/tarantool), so target can be already reserved there. This option allows to omit target configuration for LuaJIT to respect CMP0002 policy. * LUAJIT_TEST_BINARY: if LuaJIT tests are used in parent project test routine, provide an option to choose which binary (i.e. Lua runtime) to be used for running them. The latter option value is used as a dependency for tests, and its default value is $. Unfortunately older CMake can't expand the generator expression used in DEPENDS section of . As a result the CMake minimum required version is bumped to 3.1 project-wide. For more info see CMake Release notes[1] for 3.1 version. Finally, existing tests are grouped and moved to a separate directory under the root test directory to make the further addition of other available test suites in scope of tarantool/tarantool#4064 and tarantool/tarantool#4473 easier. Tarantool tests are implemented using Tarantool on-board TAP module[2], that is moved to LuaJIT repository with a little changes to save Lua chunks untouched. Other auxiliary files for Tarantool-specific testing (such as *.skipcond, suite.ini), in turn, are removed. [1]: https://cmake.org/cmake/help/latest/release/3.1.html#commands [2]: https://www.tarantool.io/en/doc/latest/reference/reference_lua/tap/ Part of tarantool/tarantool#4862 Signed-off-by: Igor Munkin --- .gitignore | 1 + CMakeLists.txt | 31 +- etc/CMakeLists.txt | 3 +- src/CMakeLists.txt | 7 +- src/host/CMakeLists.txt | 3 +- test/CMakeLists.txt | 31 +- test/gh-4427-ffi-sandwich.skipcond | 7 - test/gh-4427-ffi-sandwich/CMakeLists.txt | 1 - test/lj-flush-on-trace.skipcond | 7 - test/lj-flush-on-trace/CMakeLists.txt | 1 - test/misclib-getmetrics-capi.skipcond | 7 - test/misclib-getmetrics-capi/CMakeLists.txt | 1 - test/misclib-getmetrics-lapi.skipcond | 7 - test/suite.ini | 6 - test/tarantool-tests/CMakeLists.txt | 92 ++++++ .../gh-3196-incorrect-string-length.test.lua | 2 +- .../gh-4427-ffi-sandwich.test.lua | 24 +- .../gh-4427-ffi-sandwich/CMakeLists.txt | 1 + .../gh-4427-ffi-sandwich/libsandwich.c | 0 ...gh-4476-fix-string-find-recording.test.lua | 2 +- ...gh-4773-tonumber-fail-on-NUL-char.test.lua | 2 +- .../lj-494-table-chain-infinite-loop.test.lua | 2 +- ...lj-505-fold-no-strref-for-ptrdiff.test.lua | 2 +- .../lj-524-fold-conv-respect-src-irt.test.lua | 2 +- .../lj-flush-on-trace.test.lua | 24 +- .../lj-flush-on-trace/CMakeLists.txt | 1 + .../lj-flush-on-trace/libflush.c | 0 .../misclib-getmetrics-capi.test.lua | 5 +- .../misclib-getmetrics-capi/CMakeLists.txt | 1 + .../misclib-getmetrics-capi/testgetmetrics.c | 0 .../misclib-getmetrics-lapi.test.lua | 10 +- .../misclib-memprof-lapi.test.lua | 15 +- .../or-232-unsink-64-kptr.test.lua | 0 test/tarantool-tests/tap.lua | 306 ++++++++++++++++++ test/tarantool-tests/utils.lua | 43 +++ test/utils.lua | 33 -- tools/CMakeLists.txt | 2 +- 37 files changed, 569 insertions(+), 113 deletions(-) delete mode 100644 test/gh-4427-ffi-sandwich.skipcond delete mode 100644 test/gh-4427-ffi-sandwich/CMakeLists.txt delete mode 100644 test/lj-flush-on-trace.skipcond delete mode 100644 test/lj-flush-on-trace/CMakeLists.txt delete mode 100644 test/misclib-getmetrics-capi.skipcond delete mode 100644 test/misclib-getmetrics-capi/CMakeLists.txt delete mode 100644 test/misclib-getmetrics-lapi.skipcond delete mode 100644 test/suite.ini create mode 100644 test/tarantool-tests/CMakeLists.txt rename test/{ => tarantool-tests}/gh-3196-incorrect-string-length.test.lua (94%) rename test/{ => tarantool-tests}/gh-4427-ffi-sandwich.test.lua (70%) create mode 100644 test/tarantool-tests/gh-4427-ffi-sandwich/CMakeLists.txt rename test/{ => tarantool-tests}/gh-4427-ffi-sandwich/libsandwich.c (100%) rename test/{ => tarantool-tests}/gh-4476-fix-string-find-recording.test.lua (99%) rename test/{ => tarantool-tests}/gh-4773-tonumber-fail-on-NUL-char.test.lua (95%) rename test/{ => tarantool-tests}/lj-494-table-chain-infinite-loop.test.lua (99%) rename test/{ => tarantool-tests}/lj-505-fold-no-strref-for-ptrdiff.test.lua (96%) rename test/{ => tarantool-tests}/lj-524-fold-conv-respect-src-irt.test.lua (95%) rename test/{ => tarantool-tests}/lj-flush-on-trace.test.lua (70%) create mode 100644 test/tarantool-tests/lj-flush-on-trace/CMakeLists.txt rename test/{ => tarantool-tests}/lj-flush-on-trace/libflush.c (100%) rename test/{ => tarantool-tests}/misclib-getmetrics-capi.test.lua (97%) create mode 100644 test/tarantool-tests/misclib-getmetrics-capi/CMakeLists.txt rename test/{ => tarantool-tests}/misclib-getmetrics-capi/testgetmetrics.c (100%) rename test/{ => tarantool-tests}/misclib-getmetrics-lapi.test.lua (98%) rename test/{ => tarantool-tests}/misclib-memprof-lapi.test.lua (86%) rename test/{ => tarantool-tests}/or-232-unsink-64-kptr.test.lua (100%) create mode 100644 test/tarantool-tests/tap.lua create mode 100644 test/tarantool-tests/utils.lua delete mode 100644 test/utils.lua diff --git a/.gitignore b/.gitignore index a21ee1c..35d2580 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ compile_commands.json install_manifest.txt luajit-parse-memprof luajit.pc +tests.ok diff --git a/CMakeLists.txt b/CMakeLists.txt index 0dba5d8..62ac369 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,8 @@ # --- Initial setup ------------------------------------------------------------ -cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) +# See the rationale below (near LUAJIT_TEST_BINARY variable). +cmake_minimum_required(VERSION 3.1 FATAL_ERROR) project(LuaJIT C) # @@ -259,3 +260,31 @@ add_subdirectory(etc) # --- Tools -------------------------------------------------------------------- add_subdirectory(tools) + +# --- Testing source tree ------------------------------------------------------ + +# Auxiliary options for testing. + +# FIXME: There might be a parent project integrating LuaJIT +# sources in its source tree as a third party library +# (e.g. https://github.com/tarantool/tarantool), so target +# can be already reserved there. This option allows to omit +# target configuration for LuaJIT to respect CMP0002 policy. +option(LUAJIT_USE_TEST "Generate target" ON) + +# FIXME: If LuaJIT is used in parent project, provide an option +# to choose which binary to be used for running LuaJIT tests. +# XXX: This variable is used as a dependency for tests, and its +# default value is $ assigned in +# directory CMakeLists. Unfortunately CMake fails with generator +# expressions expansions used in . +# As a result the minimal required CMake version is set to 3.1. +# For more info see CMake Release notes for 3.1 version. +# https://cmake.org/cmake/help/latest/release/3.1.html#commands +# XXX: This options is moved below source tree processing since +# the default binary target need to be generated. +set(LUAJIT_TEST_BINARY ${LUAJIT_BINARY} CACHE STRING + "Lua implementation to be used for tests. Default is luajit." +) + +add_subdirectory(test) diff --git a/etc/CMakeLists.txt b/etc/CMakeLists.txt index 4a4c3cd..d54fa79 100644 --- a/etc/CMakeLists.txt +++ b/etc/CMakeLists.txt @@ -1,6 +1,7 @@ # Building supplementary materials for LuaJIT. -cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) +# See the rationale in the root CMakeLists.txt. +cmake_minimum_required(VERSION 3.1 FATAL_ERROR) set(LUAJIT_PC_PREFIX ${CMAKE_INSTALL_PREFIX}) if(CMAKE_LIBRARY_ARCHITECTURE) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8ada1a4..209b5f0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,7 +2,8 @@ # Major portions taken verbatim or adapted from the uJIT. # Copyright (C) 2015-2019 IPONWEB Ltd. -cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) +# See the rationale in the root CMakeLists.txt. +cmake_minimum_required(VERSION 3.1 FATAL_ERROR) enable_language(ASM) @@ -329,6 +330,10 @@ else() set(LUAJIT_DEPS luajit_static) endif() +# XXX: The variable is used in testing, so PARENT_SCOPE option +# is obligatory. +set(LUAJIT_BINARY $ PARENT_SCOPE) + add_custom_target(libluajit DEPENDS ${LIBLUAJIT_DEPS}) add_custom_target(luajit ALL DEPENDS libluajit ${LUAJIT_DEPS}) diff --git a/src/host/CMakeLists.txt b/src/host/CMakeLists.txt index fe2de5c..011a630 100644 --- a/src/host/CMakeLists.txt +++ b/src/host/CMakeLists.txt @@ -1,6 +1,7 @@ # Building the toolchain for LuaJIT VM preprocessing. -cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) +# See the rationale in the root CMakeLists.txt. +cmake_minimum_required(VERSION 3.1 FATAL_ERROR) # FIXME: Both minilua and buildvm need to be build with the HOST_* # toolchain. diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ec37580..f05dd90 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,3 +1,28 @@ -add_subdirectory(gh-4427-ffi-sandwich) -add_subdirectory(lj-flush-on-trace) -add_subdirectory(misclib-getmetrics-capi) +# Running various test suites against LuaJIT. + +# See the rationale in the root CMakeLists.txt. +cmake_minimum_required(VERSION 3.1 FATAL_ERROR) + +add_subdirectory(tarantool-tests) + +add_custom_target(${PROJECT_NAME}-test DEPENDS + tarantool-tests +) + +if(LUAJIT_USE_TEST) + if(POLICY CMP0037) + if(CMAKE_VERSION VERSION_LESS 3.11) + # cmake below 3.11 reserves 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 name test reserved in special + # cases and can be used as target name. + cmake_policy(SET CMP0037 NEW) + endif() + endif(POLICY CMP0037) + + add_custom_target(test DEPENDS + ${PROJECT_NAME}-test + ) +endif() diff --git a/test/gh-4427-ffi-sandwich.skipcond b/test/gh-4427-ffi-sandwich.skipcond deleted file mode 100644 index 2a2ec4d..0000000 --- a/test/gh-4427-ffi-sandwich.skipcond +++ /dev/null @@ -1,7 +0,0 @@ -import platform - -# Disabled on FreeBSD due to #4819. -if platform.system() == 'FreeBSD': - self.skip = 1 - -# vim: set ft=python: diff --git a/test/gh-4427-ffi-sandwich/CMakeLists.txt b/test/gh-4427-ffi-sandwich/CMakeLists.txt deleted file mode 100644 index 995c6bb..0000000 --- a/test/gh-4427-ffi-sandwich/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -build_lualib(libsandwich libsandwich.c) diff --git a/test/lj-flush-on-trace.skipcond b/test/lj-flush-on-trace.skipcond deleted file mode 100644 index 2a2ec4d..0000000 --- a/test/lj-flush-on-trace.skipcond +++ /dev/null @@ -1,7 +0,0 @@ -import platform - -# Disabled on FreeBSD due to #4819. -if platform.system() == 'FreeBSD': - self.skip = 1 - -# vim: set ft=python: diff --git a/test/lj-flush-on-trace/CMakeLists.txt b/test/lj-flush-on-trace/CMakeLists.txt deleted file mode 100644 index a90452d..0000000 --- a/test/lj-flush-on-trace/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -build_lualib(libflush libflush.c) diff --git a/test/misclib-getmetrics-capi.skipcond b/test/misclib-getmetrics-capi.skipcond deleted file mode 100644 index 2a2ec4d..0000000 --- a/test/misclib-getmetrics-capi.skipcond +++ /dev/null @@ -1,7 +0,0 @@ -import platform - -# Disabled on FreeBSD due to #4819. -if platform.system() == 'FreeBSD': - self.skip = 1 - -# vim: set ft=python: diff --git a/test/misclib-getmetrics-capi/CMakeLists.txt b/test/misclib-getmetrics-capi/CMakeLists.txt deleted file mode 100644 index e7cc8f8..0000000 --- a/test/misclib-getmetrics-capi/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -build_lualib(testgetmetrics testgetmetrics.c) diff --git a/test/misclib-getmetrics-lapi.skipcond b/test/misclib-getmetrics-lapi.skipcond deleted file mode 100644 index 2a2ec4d..0000000 --- a/test/misclib-getmetrics-lapi.skipcond +++ /dev/null @@ -1,7 +0,0 @@ -import platform - -# Disabled on FreeBSD due to #4819. -if platform.system() == 'FreeBSD': - self.skip = 1 - -# vim: set ft=python: diff --git a/test/suite.ini b/test/suite.ini deleted file mode 100644 index 0b9d5e2..0000000 --- a/test/suite.ini +++ /dev/null @@ -1,6 +0,0 @@ -[default] -core = app -description = Luajit tests -lua_libs = utils.lua -is_parallel = True -pretest_clean = True diff --git a/test/tarantool-tests/CMakeLists.txt b/test/tarantool-tests/CMakeLists.txt new file mode 100644 index 0000000..0be4b34 --- /dev/null +++ b/test/tarantool-tests/CMakeLists.txt @@ -0,0 +1,92 @@ +# Test suite that has been moved from Tarantool repository in +# scope of https://github.com/tarantool/tarantool/issues/4478. + +# 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() + +macro(BuildTestLib lib sources) + add_library(${lib} SHARED EXCLUDE_FROM_ALL ${sources}) + target_include_directories(${lib} PRIVATE + ${LUAJIT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} + ) + set_target_properties(${lib} PROPERTIES + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" + PREFIX "" + ) + + # XXX: This change affects current cmake variable scope and so + # a user should care to don't use it in a top level scope. + # The dynamic libraries are loaded with LuaJIT binary and use + # symbols from it. So it is totally OK to have unresolved + # symbols at build time. + if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set_target_properties(${lib} PROPERTIES + LINK_FLAGS "-undefined dynamic_lookup" + ) + else() + # FIXME: Unfortunately there is no another way to suppress + # this linker option, so just strip it out from the flags. + string(REPLACE "-Wl,--no-undefined" "" + CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}" + ) + endif() + # XXX: Append the lib to be built to the dependecy list. + # Unfortunately, CMake is a crap and there is no other way to + # extend the list in parent scope but join two strings with + # semicolon. If one finds the normal way to make it work, feel + # free to reach me. + set(TESTLIBS "${lib};${TESTLIBS}" PARENT_SCOPE) + # Add the directory where the lib is built to the LUA_CPATH + # environment variable, so interpreter can find and load it. + # XXX: Here we see the other side of the coin. If one joins two + # strings with semicolon, the value automatically becomes the + # list. I have no idea what is wrong with this tool, but I found + # a single working solution to make LUA_CPATH be a string via + # "escaping" the semicolon right in string interpolation. + set(LUA_CPATH "${CMAKE_CURRENT_BINARY_DIR}/?${CMAKE_SHARED_LIBRARY_SUFFIX}\;${LUA_CPATH}" PARENT_SCOPE) + # Also add this directory to LD_LIBRARY_PATH environment + # variable, so FFI machinery can find and load it. + set(LD_LIBRARY_PATH "${CMAKE_CURRENT_BINARY_DIR}:${LD_LIBRARY_PATH}" PARENT_SCOPE) +endmacro() + +add_subdirectory(gh-4427-ffi-sandwich) +add_subdirectory(lj-flush-on-trace) +add_subdirectory(misclib-getmetrics-capi) + +# The part of memory profiler toolchain is located in tools +# directory and auxiliary tests-related modules are located in the +# current directory (but tests are run in the binary directory), +# so LUA_PATH need to be updated. +set(LUA_PATH + "${CMAKE_CURRENT_SOURCE_DIR}/?.lua\;${PROJECT_SOURCE_DIR}/tools/?.lua" +) +set(LUA_TEST_SUFFIX .test.lua) +file(GLOB TEST_DEPS ${CMAKE_CURRENT_SOURCE_DIR}/*${LUA_TEST_SUFFIX}) + +# LUA_CPATH and LD_LIBRARY_PATH variables and also TESTLIBS list +# with dependecies are set in scope of BuildTestLib macro. +add_custom_command( + COMMENT "Running Tarantool tests" + OUTPUT tests.ok + DEPENDS ${LUAJIT_TEST_BINARY} ${TESTLIBS} ${TEST_DEPS} + COMMAND + env + LUA_PATH="${LUA_PATH}\;\;" + LUA_CPATH="${LUA_CPATH}\;\;" + LD_LIBRARY_PATH="${LD_LIBRARY_PATH}" + ${PROVE} ${CMAKE_CURRENT_SOURCE_DIR} + --exec ${LUAJIT_TEST_BINARY} + --ext ${LUA_TEST_SUFFIX} + --failures --shuffle + && touch tests.ok + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} +) + +add_custom_target(tarantool-tests DEPENDS tests.ok) diff --git a/test/gh-3196-incorrect-string-length.test.lua b/test/tarantool-tests/gh-3196-incorrect-string-length.test.lua similarity index 94% rename from test/gh-3196-incorrect-string-length.test.lua rename to test/tarantool-tests/gh-3196-incorrect-string-length.test.lua index f135de7..edb728f 100755 --- a/test/gh-3196-incorrect-string-length.test.lua +++ b/test/tarantool-tests/gh-3196-incorrect-string-length.test.lua @@ -1,4 +1,4 @@ -#!/usr/bin/env tarantool +#!/usr/bin/env luajit -- Miscellaneous test for LuaJIT bugs local tap = require('tap') diff --git a/test/gh-4427-ffi-sandwich.test.lua b/test/tarantool-tests/gh-4427-ffi-sandwich.test.lua similarity index 70% rename from test/gh-4427-ffi-sandwich.test.lua rename to test/tarantool-tests/gh-4427-ffi-sandwich.test.lua index 9d5e50f..e9771e8 100755 --- a/test/gh-4427-ffi-sandwich.test.lua +++ b/test/tarantool-tests/gh-4427-ffi-sandwich.test.lua @@ -1,22 +1,30 @@ -#!/usr/bin/env tarantool +#!/usr/bin/env luajit if #arg == 0 then - require('utils').selfrun(arg, { + + local utils = require('utils') + + -- Disabled on *BSD due to #4819. + utils.skipcond(jit.os == 'BSD', 'Disabled due to #4819') + + utils.selfrun(arg, { { - arg = { + arg = { 1, -- hotloop (arg[1]) 1, -- trigger (arg[2]) }, - res = tostring(3), -- hotloop + trigger + 1 - msg = 'Trace is aborted', + test = 'is', + res = tostring(3), -- hotloop + trigger + 1 + msg = 'Trace is aborted', }, { - arg = { + arg = { 1, -- hotloop (arg[1]) 2, -- trigger (arg[2]) }, - res = 'Lua VM re-entrancy is detected while executing the trace', - msg = 'Trace is recorded', + test = 'like', + res = 'Lua VM re%-entrancy is detected while executing the trace', + msg = 'Trace is recorded', }, }) end diff --git a/test/tarantool-tests/gh-4427-ffi-sandwich/CMakeLists.txt b/test/tarantool-tests/gh-4427-ffi-sandwich/CMakeLists.txt new file mode 100644 index 0000000..5515567 --- /dev/null +++ b/test/tarantool-tests/gh-4427-ffi-sandwich/CMakeLists.txt @@ -0,0 +1 @@ +BuildTestLib(libsandwich libsandwich.c) diff --git a/test/gh-4427-ffi-sandwich/libsandwich.c b/test/tarantool-tests/gh-4427-ffi-sandwich/libsandwich.c similarity index 100% rename from test/gh-4427-ffi-sandwich/libsandwich.c rename to test/tarantool-tests/gh-4427-ffi-sandwich/libsandwich.c diff --git a/test/gh-4476-fix-string-find-recording.test.lua b/test/tarantool-tests/gh-4476-fix-string-find-recording.test.lua similarity index 99% rename from test/gh-4476-fix-string-find-recording.test.lua rename to test/tarantool-tests/gh-4476-fix-string-find-recording.test.lua index fb55680..92a11d5 100755 --- a/test/gh-4476-fix-string-find-recording.test.lua +++ b/test/tarantool-tests/gh-4476-fix-string-find-recording.test.lua @@ -1,4 +1,4 @@ -#!/usr/bin/env tarantool +#!/usr/bin/env luajit local tap = require('tap') diff --git a/test/gh-4773-tonumber-fail-on-NUL-char.test.lua b/test/tarantool-tests/gh-4773-tonumber-fail-on-NUL-char.test.lua similarity index 95% rename from test/gh-4773-tonumber-fail-on-NUL-char.test.lua rename to test/tarantool-tests/gh-4773-tonumber-fail-on-NUL-char.test.lua index a660979..51e3142 100755 --- a/test/gh-4773-tonumber-fail-on-NUL-char.test.lua +++ b/test/tarantool-tests/gh-4773-tonumber-fail-on-NUL-char.test.lua @@ -1,4 +1,4 @@ -#!/usr/bin/env tarantool +#!/usr/bin/env luajit local tap = require('tap') diff --git a/test/lj-494-table-chain-infinite-loop.test.lua b/test/tarantool-tests/lj-494-table-chain-infinite-loop.test.lua similarity index 99% rename from test/lj-494-table-chain-infinite-loop.test.lua rename to test/tarantool-tests/lj-494-table-chain-infinite-loop.test.lua index 314eb29..9c04ef6 100755 --- a/test/lj-494-table-chain-infinite-loop.test.lua +++ b/test/tarantool-tests/lj-494-table-chain-infinite-loop.test.lua @@ -1,4 +1,4 @@ -#!/usr/bin/env tarantool +#!/usr/bin/env luajit local tap = require('tap') diff --git a/test/lj-505-fold-no-strref-for-ptrdiff.test.lua b/test/tarantool-tests/lj-505-fold-no-strref-for-ptrdiff.test.lua similarity index 96% rename from test/lj-505-fold-no-strref-for-ptrdiff.test.lua rename to test/tarantool-tests/lj-505-fold-no-strref-for-ptrdiff.test.lua index a82bafa..6b0d70b 100755 --- a/test/lj-505-fold-no-strref-for-ptrdiff.test.lua +++ b/test/tarantool-tests/lj-505-fold-no-strref-for-ptrdiff.test.lua @@ -1,4 +1,4 @@ -#!/usr/bin/env tarantool +#!/usr/bin/env luajit local tap = require('tap') diff --git a/test/lj-524-fold-conv-respect-src-irt.test.lua b/test/tarantool-tests/lj-524-fold-conv-respect-src-irt.test.lua similarity index 95% rename from test/lj-524-fold-conv-respect-src-irt.test.lua rename to test/tarantool-tests/lj-524-fold-conv-respect-src-irt.test.lua index a232eea..fb92bee 100755 --- a/test/lj-524-fold-conv-respect-src-irt.test.lua +++ b/test/tarantool-tests/lj-524-fold-conv-respect-src-irt.test.lua @@ -1,4 +1,4 @@ -#!/usr/bin/env tarantool +#!/usr/bin/env luajit local tap = require('tap') local ffi = require('ffi') diff --git a/test/lj-flush-on-trace.test.lua b/test/tarantool-tests/lj-flush-on-trace.test.lua similarity index 70% rename from test/lj-flush-on-trace.test.lua rename to test/tarantool-tests/lj-flush-on-trace.test.lua index 0b3ccf4..f9a513f 100755 --- a/test/lj-flush-on-trace.test.lua +++ b/test/tarantool-tests/lj-flush-on-trace.test.lua @@ -1,22 +1,30 @@ -#!/usr/bin/env tarantool +#!/usr/bin/env luajit if #arg == 0 then - require('utils').selfrun(arg, { + + local utils = require('utils') + + -- Disabled on *BSD due to #4819. + utils.skipcond(jit.os == 'BSD', 'Disabled due to #4819') + + utils.selfrun(arg, { { - arg = { + arg = { 1, -- hotloop (arg[1]) 1, -- trigger (arg[2]) }, - res = 'OK', - msg = 'Trace is aborted', + test = 'is', + res = 'OK', + msg = 'Trace is aborted', }, { - arg = { + arg = { 1, -- hotloop (arg[1]) 2, -- trigger (arg[2]) }, - res = 'JIT mode change is detected while executing the trace', - msg = 'Trace is recorded', + test = 'like', + res = 'JIT mode change is detected while executing the trace', + msg = 'Trace is recorded', }, }) end diff --git a/test/tarantool-tests/lj-flush-on-trace/CMakeLists.txt b/test/tarantool-tests/lj-flush-on-trace/CMakeLists.txt new file mode 100644 index 0000000..91a18a6 --- /dev/null +++ b/test/tarantool-tests/lj-flush-on-trace/CMakeLists.txt @@ -0,0 +1 @@ +BuildTestLib(libflush libflush.c) diff --git a/test/lj-flush-on-trace/libflush.c b/test/tarantool-tests/lj-flush-on-trace/libflush.c similarity index 100% rename from test/lj-flush-on-trace/libflush.c rename to test/tarantool-tests/lj-flush-on-trace/libflush.c diff --git a/test/misclib-getmetrics-capi.test.lua b/test/tarantool-tests/misclib-getmetrics-capi.test.lua similarity index 97% rename from test/misclib-getmetrics-capi.test.lua rename to test/tarantool-tests/misclib-getmetrics-capi.test.lua index 1ad6958..c418e9f 100755 --- a/test/misclib-getmetrics-capi.test.lua +++ b/test/tarantool-tests/misclib-getmetrics-capi.test.lua @@ -1,4 +1,7 @@ -#!/usr/bin/env tarantool +#!/usr/bin/env luajit + +-- Disabled on *BSD due to #4819. +require('utils').skipcond(jit.os == 'BSD', 'Disabled due to #4819') local path = arg[0]:gsub('%.test%.lua', '') local suffix = package.cpath:match('?.(%a+);') diff --git a/test/tarantool-tests/misclib-getmetrics-capi/CMakeLists.txt b/test/tarantool-tests/misclib-getmetrics-capi/CMakeLists.txt new file mode 100644 index 0000000..cff0096 --- /dev/null +++ b/test/tarantool-tests/misclib-getmetrics-capi/CMakeLists.txt @@ -0,0 +1 @@ +BuildTestLib(testgetmetrics testgetmetrics.c) diff --git a/test/misclib-getmetrics-capi/testgetmetrics.c b/test/tarantool-tests/misclib-getmetrics-capi/testgetmetrics.c similarity index 100% rename from test/misclib-getmetrics-capi/testgetmetrics.c rename to test/tarantool-tests/misclib-getmetrics-capi/testgetmetrics.c diff --git a/test/misclib-getmetrics-lapi.test.lua b/test/tarantool-tests/misclib-getmetrics-lapi.test.lua similarity index 98% rename from test/misclib-getmetrics-lapi.test.lua rename to test/tarantool-tests/misclib-getmetrics-lapi.test.lua index 3b3d1f8..959293d 100755 --- a/test/misclib-getmetrics-lapi.test.lua +++ b/test/tarantool-tests/misclib-getmetrics-lapi.test.lua @@ -1,9 +1,12 @@ -#!/usr/bin/env tarantool +#!/usr/bin/env luajit -- This is a part of tarantool/luajit testing suite. -- Major portions taken verbatim or adapted from the LuaVela testing suite. -- Copyright (C) 2015-2019 IPONWEB Ltd. +-- Disabled on *BSD due to #4819. +require('utils').skipcond(jit.os == 'BSD', 'Disabled due to #4819') + local tap = require('tap') local test = tap.test("lib-misc-getmetrics") @@ -49,7 +52,10 @@ test:test("gc-allocated-freed", function(subtest) subtest:plan(1) -- Force up garbage collect all dead objects. - collectgarbage("collect") + repeat + local count = collectgarbage("count") + collectgarbage("collect") + until collectgarbage("count") == count -- Bump getmetrics table and string keys allocation. local old_metrics = misc.getmetrics() diff --git a/test/misclib-memprof-lapi.test.lua b/test/tarantool-tests/misclib-memprof-lapi.test.lua similarity index 86% rename from test/misclib-memprof-lapi.test.lua rename to test/tarantool-tests/misclib-memprof-lapi.test.lua index dd484f4..2b97212 100755 --- a/test/misclib-memprof-lapi.test.lua +++ b/test/tarantool-tests/misclib-memprof-lapi.test.lua @@ -8,19 +8,14 @@ test:plan(9) jit.off() jit.flush() --- FIXME: Launch tests with LUA_PATH enviroment variable. -local path = arg[0]:gsub("[^/]+%.test%.lua", "") -local path_suffix = "../tools/?.lua;" -package.path = ("%s%s;"):format(path, path_suffix)..package.path - local table_new = require "table.new" local bufread = require "utils.bufread" local memprof = require "memprof.parse" local symtab = require "utils.symtab" -local TMP_BINFILE = arg[0]:gsub("[^/]+%.test%.lua", "%.%1.memprofdata.tmp.bin") -local BAD_PATH = arg[0]:gsub("[^/]+%.test%.lua", "%1/memprofdata.tmp.bin") +local TMP_BINFILE = arg[0]:gsub(".+/([^/]+)%.test%.lua$", "%.%1.memprofdata.tmp.bin") +local BAD_PATH = arg[0]:gsub(".+/([^/]+)%.test%.lua$", "%1/memprofdata.tmp.bin") local function payload() -- Preallocate table to avoid table array part reallocations. @@ -82,7 +77,7 @@ end -- Not a directory. local res, err, errno = misc.memprof.start(BAD_PATH) -test:ok(res == nil and err:match("Not a directory")) +test:ok(res == nil and err:match("No such file or directory")) test:ok(type(errno) == "number") -- Profiler is running. @@ -125,9 +120,9 @@ local free = fill_ev_type(events, symbols, "free") -- the number of allocations. -- 1 event - alocation of table by itself + 1 allocation -- of array part as far it is bigger than LJ_MAX_COLOSIZE (16). -test:ok(check_alloc_report(alloc, 27, 25, 2)) +test:ok(check_alloc_report(alloc, 22, 20, 2)) -- 100 strings allocations. -test:ok(check_alloc_report(alloc, 32, 25, 100)) +test:ok(check_alloc_report(alloc, 27, 20, 100)) -- Collect all previous allocated objects. test:ok(free.INTERNAL.num == 102) diff --git a/test/or-232-unsink-64-kptr.test.lua b/test/tarantool-tests/or-232-unsink-64-kptr.test.lua similarity index 100% rename from test/or-232-unsink-64-kptr.test.lua rename to test/tarantool-tests/or-232-unsink-64-kptr.test.lua diff --git a/test/tarantool-tests/tap.lua b/test/tarantool-tests/tap.lua new file mode 100644 index 0000000..fd03132 --- /dev/null +++ b/test/tarantool-tests/tap.lua @@ -0,0 +1,306 @@ +--- tap.lua internal file. +--- +--- The Test Anything Protocol vesion 13 producer. +--- + +-- Initializer FFI for check. +local ffi = require('ffi') +local NULL = ffi.new('void *') + +local function indent(chars) + return (' '):rep(chars) +end + +local function traceback(level) + local trace = { } + level = level or 3 + while true do + local info = debug.getinfo(level, 'nSl') + if not info then break end + table.insert(trace, { + source = info.source, + src = info.short_src, + line = info.linedefined or 0, + what = info.what, + name = info.name, + namewhat = info.namewhat, + filename = info.source:sub(1, 1) == '@' and info.source:sub(2) or 'eval', + }) + level = level + 1 + end + return trace +end + +local function diag(test, fmt, ...) + io.write(indent(4 * test.level), ('# %s\n'):format(fmt:format(...))) +end + +local function ok(test, cond, message, extra) + test.total = test.total + 1 + if cond then + io.write(indent(4 * test.level), ('ok - %s\n'):format(message)) + return true + end + + test.failed = test.failed + 1 + io.write(indent(4 * test.level), ('not ok - %s\n'):format(message)) + + -- Dump extra contents added in outer space. + for key, value in pairs(extra or { }) do + io.write(indent(2 + 4 * test.level), ('%s:\t%s\n'):format(key, value)) + end + + if not test.trace then + return false + end + + local trace = traceback() + local tindent = indent(4 + 4 * test.level) + io.write(tindent, ('filename:\t%s\n'):format(trace[#trace].filename)) + io.write(tindent, ('line:\t%s\n'):format(trace[#trace].line)) + for frameno, frame in ipairs(trace) do + io.write(tindent, ('frame #%d\n'):format(frameno)) + local findent = indent(2) .. tindent + for key, value in pairs(frame) do + io.write(findent, ('%s:\t%s\n'):format(key, value)) + end + end + return false +end + +local function fail(test, message, extra) + return ok(test, false, message, extra) +end + +local function skip(test, message, extra) + ok(test, true, message .. ' # skip', extra) +end + +local function cmpdeeply(got, expected, extra) + if type(expected) == 'number' or type(got) == 'number' then + extra.got = got + extra.expected = expected + -- Handle NaN. + if got ~= got and expected ~= expected then + return true + end + return got == expected + end + + if ffi.istype('bool', got) then got = (got == 1) end + if ffi.istype('bool', expected) then expected = (expected == 1) end + + if extra.strict and type(got) ~= type(expected) then + extra.got = type(got) + extra.expected = type(expected) + return false + end + + if type(got) ~= 'table' or type(expected) ~= 'table' then + extra.got = got + extra.expected = expected + return got == expected + end + + local path = extra.path or '/' + local visited_keys = {} + + for i, v in pairs(got) do + visited_keys[i] = true + extra.path = path .. '/' .. i + if not cmpdeeply(v, expected[i], extra) then + return false + end + end + + -- Check if expected contains more keys then got. + for i, v in pairs(expected) do + if visited_keys[i] ~= true and (extra.strict or v ~= NULL) then + extra.expected = 'key ' .. tostring(i) + extra.got = 'nil' + return false + end + end + + extra.path = path + + return true +end + +local function like(test, got, pattern, message, extra) + extra = extra or { } + extra.got = got + extra.expected = pattern + return ok(test, tostring(got):match(pattern) ~= nil, message, extra) +end + +local function unlike(test, got, pattern, message, extra) + extra = extra or { } + extra.got = got + extra.expected = pattern + return ok(test, tostring(got):match(pattern) == nil, message, extra) +end + +local function is(test, got, expected, message, extra) + extra = extra or { } + extra.got = got + extra.expected = expected + local rc = (test.strict == false or type(got) == type(expected)) + and got == expected + return ok(test, rc, message, extra) +end + +local function isnt(test, got, unexpected, message, extra) + extra = extra or { } + extra.got = got + extra.unexpected = unexpected + local rc = (test.strict == true and type(got) ~= type(unexpected)) + or got ~= unexpected + return ok(test, rc, message, extra) +end + +local function is_deeply(test, got, expected, message, extra) + extra = extra or { } + extra.got = got + extra.expected = expected + extra.strict = test.strict + return ok(test, cmpdeeply(got, expected, extra), message, extra) +end + +local function isnil(test, v, message, extra) + return is(test, not v and v == nil and 'nil' or v, 'nil', message, extra) +end + +local function isnumber(test, v, message, extra) + return is(test, type(v), 'number', message, extra) +end + +local function isstring(test, v, message, extra) + return is(test, type(v), 'string', message, extra) +end + +local function istable(test, v, message, extra) + return is(test, type(v), 'table', message, extra) +end + +local function isboolean(test, v, message, extra) + return is(test, type(v), 'boolean', message, extra) +end + +local function isfunction(test, v, message, extra) + return is(test, type(v), 'function', message, extra) +end + +local function isudata(test, v, utype, message, extra) + extra = extra or { } + extra.expected = ('userdata<%s>'):format(utype) + if type(v) ~= 'userdata' then + extra.got = type(v) + return fail(test, message, extra) + end + extra.got = ('userdata<%s>'):format(getmetatable(v)) + return ok(test, getmetatable(v) == utype, message, extra) +end + +local function iscdata(test, v, ctype, message, extra) + extra = extra or { } + extra.expected = ffi.typeof(ctype) + if type(v) ~= 'cdata' then + extra.got = type(v) + return fail(test, message, extra) + end + extra.got = ffi.typeof(v) + return ok(test, ffi.istype(ctype, v), message, extra) +end + +local test_mt + +local function new(parent, name, fun, ...) + local level = parent ~= nil and parent.level + 1 or 0 + local test = setmetatable({ + parent = parent, + name = name, + level = level, + total = 0, + failed = 0, + planned = 0, + trace = parent == nil and true or parent.trace, + strict = false, + }, test_mt) + if fun == nil then + return test + end + test:diag('%s', test.name) + fun(test, ...) + test:diag('%s: end', test.name) + return test:check() +end + +local function plan(test, planned) + test.planned = planned + io.write(indent(4 * test.level), ('1..%d\n'):format(planned)) +end + +local function check(test) + if test.checked then + error('check called twice') + end + test.checked = true + if test.planned ~= test.total then + if test.parent ~= nil then + ok(test.parent, false, 'bad plan', { + planned = test.planned, + run = test.total, + }) + else + diag(test, ('bad plan: planned %d run %d') + :format(test.planned, test.total)) + end + elseif test.failed > 0 then + if test.parent ~= nil then + ok(test.parent, false, 'failed subtests', { + failed = test.failed, + planned = test.planned, + }) + else + diag(test, 'failed subtest: %d', test.failed) + end + else + if test.parent ~= nil then + ok(test.parent, true, test.name) + end + end + return test.planned == test.total and test.failed == 0 +end + +test_mt = { + __index = { + test = new, + plan = plan, + check = check, + diag = diag, + ok = ok, + fail = fail, + skip = skip, + is = is, + isnt = isnt, + isnil = isnil, + isnumber = isnumber, + isstring = isstring, + istable = istable, + isboolean = isboolean, + isfunction = isfunction, + isudata = isudata, + iscdata = iscdata, + is_deeply = is_deeply, + like = like, + unlike = unlike, + } +} + +return { + test = function(...) + io.write('TAP version 13\n') + return new(nil, ...) + end +} diff --git a/test/tarantool-tests/utils.lua b/test/tarantool-tests/utils.lua new file mode 100644 index 0000000..197b138 --- /dev/null +++ b/test/tarantool-tests/utils.lua @@ -0,0 +1,43 @@ +local M = { } + +local tap = require('tap') + +function M.selfrun(arg, checks) + local test = tap.test(arg[0]:match('/?(.+)%.test%.lua')) + + test:plan(#checks) + + local vars = { + LUABIN = arg[-1], + SCRIPT = arg[0], + PATH = arg[0]:gsub('%.test%.lua', ''), + SUFFIX = package.cpath:match('?.(%a+);'), + } + + local cmd = string.gsub('LUA_PATH="/?.lua;$LUA_PATH" ' .. + 'LUA_CPATH="/?.;$LUA_CPATH" ' .. + 'LD_LIBRARY_PATH=:$LD_LIBRARY_PATH ' .. + ' 2>&1