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 C6D3574D940; Fri, 19 Jan 2024 14:37:33 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C6D3574D940 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1705664253; bh=WD+h72MFSScWFfwQ8bkDw6cHLSm7rEbG0STLo9cwrow=; 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=uGHkeBye8T/SVSk0NjJC7ebDJlHJISFCxtofzYe65yP6j6ZRzqh62/gNodOn8sqXj +vUXXQECEaMWnzAjMJEaMrJTa1sv3Scqid55EWvCnSKFvY0nx39hfm+vF7F3JbWNff EKmP5PnsHlAkziJD+zYy6QA2n80/EnTXBLyl0gVA= Received: from smtp16.i.mail.ru (smtp16.i.mail.ru [95.163.41.69]) (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 C49DC74D940 for ; Fri, 19 Jan 2024 14:37:02 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C49DC74D940 Received: by smtp16.i.mail.ru with esmtpa (envelope-from ) id 1rQnBG-00FDC7-0C; Fri, 19 Jan 2024 14:37:02 +0300 To: Maxim Kokryashkin , Sergey Bronnikov Date: Fri, 19 Jan 2024 14:32:24 +0300 Message-ID: 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: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9AE5B4AFB3AE2A5903BF75383F3F9E5C7DFDDEC3DF03165DE182A05F538085040ADE3CF727A00AC2575E2E7030894E2DA13ED0AAD7EA1D4836FE5366ED7E78AAE X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE71107D7B19CDFFE90EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006378D6424E594306CB78638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D82635CAC550AA026A3EBA6E8F852A40FC117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC1BE95B8C87527B4BA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735201E561CDFBCA1751FCB629EEF1311BF91D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269176DF2183F8FC7C0406C186E56A1B26068655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7CA819EB9AE8EA3DE343847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: 0D63561A33F958A57E6AF458D41A5CEF3DE3FD803DF40A2F096BB258E19250E2F87CCE6106E1FC07E67D4AC08A07B9B05E3BF8C76DC23F749C5DF10A05D560A950611B66E3DA6D700B0A020F03D25A0997E3FB2386030E77 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF66D68B3ED471AA70F067596F7FB99252975217CC8B2812470B618383D1A7496986260C86DC1AF1466197189FEE4B1C7AC58E51DE97513B2CA5A06E9FBCEEA9D5A74DFFEFA5DC0E7F02C26D483E81D6BE5EF9655DD6DEA7D65774BB76CC95456EEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojJsr4kcGAUCNfj0+iUIEGBw== X-DA7885C5: 478A482A26C6647222358C9D20223E7BAC200DAF2192FF5442E163B22A507E83262E2D401490A4A0DB037EFA58388B346E8BC1A9835FDE71 X-Mailru-Sender: 689FA8AB762F7393590D8C940224AE33109120292257A8FD6FB48B4683CCB6800FBE9A32752B8C9C2AA642CC12EC09F1FB559BB5D741EB962F61BD320559CF1EFD657A8799238ED55FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit 01/25] 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()`. Part of tarantool/tarantool#9398 --- test/LuaJIT-tests/CMakeLists.txt | 29 +++++++++++++++++--- test/LuaJIT-tests/src/CMakeLists.txt | 40 ++++++++++++++++++++++++++++ test/LuaJIT-tests/src/ctest.c | 4 +-- test/LuaJIT-tests/test.lua | 7 +++-- 4 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 test/LuaJIT-tests/src/CMakeLists.txt 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..f07b3b6d --- /dev/null +++ b/test/LuaJIT-tests/src/CMakeLists.txt @@ -0,0 +1,40 @@ +# 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) + add_library(${lib} SHARED EXCLUDE_FROM_ALL ${sources}) + target_include_directories(${lib} PRIVATE + ${LUAJIT_SOURCE_DIR} + ) + set_target_properties(${lib} PROPERTIES + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" + PREFIX "" + ) + # XXX: 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" + ) + elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") + # XXX: This is necessary mostly for openSUSE builds, see also + # https://bugzilla.suse.com/show_bug.cgi?id=1012388. + # Just strip out the linker flag to suppress this linker + # option. + string(REPLACE "-Wl,--no-undefined" "" + CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}" + ) + endif() + list(APPEND TESTLIBS ${lib}) +endmacro() + +# Use `lib` prefix for loading via FFi and `require()`. +BuildTestLib(libctest ctest.c) +enable_language(CXX) +BuildTestLib(cpptest cpptest.cpp) + +add_custom_target(LuaJIT-tests-prepare DEPENDS ${TESTLIBS}) + +# vim: expandtab tabstop=2 shiftwidth=2 diff --git a/test/LuaJIT-tests/src/ctest.c b/test/LuaJIT-tests/src/ctest.c index e99f2306..aa95b57b 100644 --- a/test/LuaJIT-tests/src/ctest.c +++ b/test/LuaJIT-tests/src/ctest.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..749a27e7 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 ~= "cpptest" then + error("Tests should not mutate global state", 3) + end end} local function seal(t) if getmetatable(t) then return end -- 2.43.0