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 110319DC60E; Mon, 29 Jan 2024 13:50:26 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 110319DC60E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1706525426; bh=GUJ5IUhRL3rr4lBouLN8Rx9srUH/c8hPpV2u32HNYVM=; 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=mcklxHdt+9B7SiwSu4CK8awJ97HKLztbu64cX8HeVgu36gjDlHSriVGV/jth5E89M 5tQ1fTlW2yYX68Wt+rK7cI1NWJyexd8XuokghniEUVxuLraMxVNM9xOlOozErBX7Xb YvYJ3/1ee4GsmOoFgwe/XOxigfMLhTT97lF31pN0= Received: from smtp32.i.mail.ru (smtp32.i.mail.ru [95.163.41.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 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 2E7D09C202A for ; Mon, 29 Jan 2024 13:49:24 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2E7D09C202A Received: by smtp32.i.mail.ru with esmtpa (envelope-from ) id 1rUPCd-0000000BQ6r-24BD; Mon, 29 Jan 2024 13:49:23 +0300 To: Maxim Kokryashkin , Sergey Bronnikov Date: Mon, 29 Jan 2024 13:45:02 +0300 Message-ID: <5967cedfd0e3e597b34d9b873fba883c7a209518.1706520765.git.skaplun@tarantool.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD96A58C36AA2E99649E4D9784A2E51F17D0BDB9DDD3E04C36B182A05F538085040B7748104B87BF44C33594132A326AF8B9EC2D639C77B4777DCA417647058147805836D1F9953231F X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7850A3F981F25E362EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637CDE631A26C8A2C128638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8BC5A166DD8F6EBADBE1BF1E404F07B8E0724291E3EBBD8BECC7F00164DA146DAFE8445B8C89999728AA50765F790063798EAA0EED4DE4A60389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC87AE820D2C17D0E56F6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947C6D3A1509E1113711C0837EA9F3D197644AD6D5ED66289B523666184CF4C3C14F6136E347CC761E07725E5C173C3A84C3269F8DEB129E7B36BA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CF27ED053E960B195E1DD303D21008E298D5E8D9A59859A8B6B372FE9A2E580EFC725E5C173C3A84C37727919777A35F2B35872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-C1DE0DAB: 0D63561A33F958A566CA90B0F2FA9F735002B1117B3ED696EA68FB785A576D643E67C18142C611B7823CB91A9FED034534781492E4B8EEADFB12F4B11BB5604FC79554A2A72441328621D336A7BC284946AD531847A6065A535571D14F44ED41 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF2085B95D5A76D75DF186E295B0E9FC595E1C58F38712D491FD611793CEB1ABD8A161E968D9DBB3498FB01E7B8BF01A69460540E35BBD92F2B718120DE96C5CC59737917FA254C309C226CC413062362A913E6812662D5F2A5EAB5682573093F7837F15F2B5E4A70B33F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojmd9AG1X07oSSCCjgcUtQ+Q== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A769EF655EC7F808E53333594132A326AF8B9EC2D639C77B4777B7CBEF92542CD7C88B0A2698F12F5C9EC77752E0C033A69E86920BD37369036789A8C6A0E60D2BB63A5DB60FBEB33A8A0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v2 luajit 02/26] test: prepare lauxilarily libs for LuaJIT-tests 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 Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This patch adds rules to build C and C++ libs from the directory. Also, it allows these libraries to be loaded via `require()` (since `luaL_openlib()` evolves global state). The name of "ctest" library is changed to "libctest" to allow it to be loaded via both `ffi.load()` and `require()`. "cpptest" library is renamed to "libcpptest" for consistency. Part of tarantool/tarantool#9398 --- test/LuaJIT-tests/CMakeLists.txt | 29 +++++++++++++++++-- test/LuaJIT-tests/src/CMakeLists.txt | 17 +++++++++++ .../src/{cpptest.cpp => libcpptest.cpp} | 4 +-- test/LuaJIT-tests/src/{ctest.c => libctest.c} | 4 +-- test/LuaJIT-tests/test.lua | 7 +++-- 5 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 test/LuaJIT-tests/src/CMakeLists.txt rename test/LuaJIT-tests/src/{cpptest.cpp => libcpptest.cpp} (96%) rename test/LuaJIT-tests/src/{ctest.c => libctest.c} (99%) diff --git a/test/LuaJIT-tests/CMakeLists.txt b/test/LuaJIT-tests/CMakeLists.txt index 9cd76ee9..c52bcc71 100644 --- a/test/LuaJIT-tests/CMakeLists.txt +++ b/test/LuaJIT-tests/CMakeLists.txt @@ -1,12 +1,35 @@ # See the rationale in the root CMakeLists.txt cmake_minimum_required(VERSION 3.1 FATAL_ERROR) -add_custom_target(LuaJIT-tests DEPENDS ${LUAJIT_TEST_BINARY}) +add_subdirectory(src) + +add_custom_target(LuaJIT-tests + DEPENDS ${LUAJIT_TEST_BINARY} LuaJIT-tests-prepare +) + +make_lua_path(LUA_CPATH + PATHS + ${CMAKE_CURRENT_BINARY_DIR}/src/?${CMAKE_SHARED_LIBRARY_SUFFIX} +) + +set(LUAJIT_TESTS_ENV + "LUA_CPATH=\"${LUA_CPATH}\"" +) + +set(LD_LIBRARY_PATH "${CMAKE_CURRENT_BINARY_DIR}/src/:") + +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + list(APPEND LUAJIT_TESTS_ENV DYLD_LIBRARY_PATH="${LD_LIBRARY_PATH}") +else() + list(APPEND LUAJIT_TESTS_ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}") +endif() add_custom_command(TARGET LuaJIT-tests COMMENT "Running LuaJIT-tests" COMMAND - ${LUAJIT_TEST_COMMAND} ${CMAKE_CURRENT_SOURCE_DIR}/test.lua - +slow +ffi +bit +jit + env + ${LUAJIT_TESTS_ENV} + ${LUAJIT_TEST_COMMAND} ${CMAKE_CURRENT_SOURCE_DIR}/test.lua + +slow +ffi +bit +jit WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) diff --git a/test/LuaJIT-tests/src/CMakeLists.txt b/test/LuaJIT-tests/src/CMakeLists.txt new file mode 100644 index 00000000..fb14d6d9 --- /dev/null +++ b/test/LuaJIT-tests/src/CMakeLists.txt @@ -0,0 +1,17 @@ +# See the rationale in the root CMakeLists.txt. +cmake_minimum_required(VERSION 3.1 FATAL_ERROR) + +# Build additional C/C++ libraries for tests. +macro(BuildTestLib lib sources) + AddTestLib(${lib} ${sources}) + list(APPEND TESTLIBS ${lib}) +endmacro() + +# Use `lib` prefix for loading via FFI and `require()`. +BuildTestLib(libctest libctest.c) +enable_language(CXX) +BuildTestLib(libcpptest libcpptest.cpp) + +add_custom_target(LuaJIT-tests-prepare DEPENDS ${TESTLIBS}) + +# vim: expandtab tabstop=2 shiftwidth=2 diff --git a/test/LuaJIT-tests/src/cpptest.cpp b/test/LuaJIT-tests/src/libcpptest.cpp similarity index 96% rename from test/LuaJIT-tests/src/cpptest.cpp rename to test/LuaJIT-tests/src/libcpptest.cpp index a5893ed6..cdfb5e32 100644 --- a/test/LuaJIT-tests/src/cpptest.cpp +++ b/test/LuaJIT-tests/src/libcpptest.cpp @@ -121,9 +121,9 @@ static luaL_Reg ct_funcs[] = { }; extern "C" { -LUA_API int luaopen_cpptest(lua_State *L) +LUA_API int luaopen_libcpptest(lua_State *L) { - luaL_register(L, "cpptest", ct_funcs); + luaL_register(L, "libcpptest", ct_funcs); return 1; } } diff --git a/test/LuaJIT-tests/src/ctest.c b/test/LuaJIT-tests/src/libctest.c similarity index 99% rename from test/LuaJIT-tests/src/ctest.c rename to test/LuaJIT-tests/src/libctest.c index e99f2306..aa95b57b 100644 --- a/test/LuaJIT-tests/src/ctest.c +++ b/test/LuaJIT-tests/src/libctest.c @@ -332,8 +332,8 @@ static luaL_Reg ct_funcs[] = { {NULL, NULL} }; -LUA_API int luaopen_ctest(lua_State *L) +LUA_API int luaopen_libctest(lua_State *L) { - luaL_register(L, "ctest", ct_funcs); + luaL_register(L, "libctest", ct_funcs); return 1; } diff --git a/test/LuaJIT-tests/test.lua b/test/LuaJIT-tests/test.lua index b064eff7..f2450222 100644 --- a/test/LuaJIT-tests/test.lua +++ b/test/LuaJIT-tests/test.lua @@ -297,8 +297,11 @@ local function append_tree_to_plan(test_tree, opts, plan, prefix) end local function seal_globals() - local sealed_mt = {__newindex = function() - error("Tests should not mutate global state", 3) + local sealed_mt = {__newindex = function(_, k) + -- Allow to load C/C++ libraries for the test. + if k ~= "libctest" and k ~= "libcpptest" then + error("Tests should not mutate global state", 3) + end end} local function seal(t) if getmetatable(t) then return end -- 2.43.0