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 1A8A16DDCEE; Tue, 23 Jan 2024 12:10:55 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 1A8A16DDCEE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1706001055; bh=rZ90xZ8uFancZjP8VSMCiovQaxXT1f+DqvELVFsppUA=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=fT1+JOEFDu5CPw/SwNSbBWVTHk5nDCLluka4D9wDP9E6eR9HepaVKuXHZww5uAudE RJpwnuVtfpzhtJ4/tPtMFIU+tWt7jLiLJPWMAP9u/ey0+r99pMicNjZs50y952XXQh vZRi27T39+R8pxbyyMnLLph1wK1Aub0vO5VOowNk= Received: from smtp31.i.mail.ru (smtp31.i.mail.ru [95.163.41.72]) (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 3C8736DDCEE for ; Tue, 23 Jan 2024 12:10:53 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 3C8736DDCEE Received: by smtp31.i.mail.ru with esmtpa (envelope-from ) id 1rSCnz-00DkcI-1y; Tue, 23 Jan 2024 12:10:52 +0300 Message-ID: Date: Tue, 23 Jan 2024 12:10:51 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Sergey Kaplun , Maxim Kokryashkin Cc: tarantool-patches@dev.tarantool.org References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9AE5B4AFB3AE2A5902CFE8E94CF0C73AC3A7B46DE77E1D653182A05F538085040D8106037ECC6B52785F2CB6D6E4CAEB9AF7FCC0A33A803ECD9D8F722FF3ED4B8 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE798E808258C20928CEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637C83F54BD885518138638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8B4D669630D1B23B448CBB6F635D720E0117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC974A882099E279BDA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD182CC0D3CB04F14752D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE9647ADFADE5905B197A342136F30543AD8FC6C240DEA76429C9F4D5AE37F343AA9539A8B242431040A6AB1C7CE11FEE34E7D9683544204AF6136E347CC761E07C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947C1D471462564A2E192E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89F616AD31D0D18CD5CCE5475246E174218B5C8C57E37DE458BEDA766A37F9254B7 X-C1DE0DAB: 0D63561A33F958A5C8F67E3B4130FCF7EC7311A2686059C99185D98B35D05D7CF87CCE6106E1FC07E67D4AC08A07B9B0CE135D2742255B35CB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFA2FDCA16133FC3B0A370BDA7B2BC0A8C477177BC8F8F1DD4D9143D817D209C43686167004DDA272F4BEAD515961AA0A7E663B1F73C7DC583F8FDEF602622EF19E48CAC7CA610320002C26D483E81D6BE0DBAE6F56676BC7117BB6831D7356A2DEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojGSQVxX8i/5XsKi5l18LP4Q== X-Mailru-Sender: C4F68CFF4024C8867DFDF7C7F25884583C527B603926B6536B92C84DC1D661C77CAC9A2E426993C0282EC151BADDC1D3523A6D01B4765B2DFB59E2DDD9FE06B14FA522850F29BC30B0DAF586E7D11B3E67EA787935ED9F1B X-Mras: Ok Subject: Re: [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 Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Sergey! thanks for the patch! see my comments below Sergey On 1/19/24 14:32, Sergey Kaplun wrote: > 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() > + This macro duplicates the similar macro in BuildTestCLib in tarantool-tests suite. Why you don't want to generalize it and reuse in both suites? > +# Use `lib` prefix for loading via FFi and `require()`. Typo: FFi -> FFI > +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 I would rename file to libctest.c or ltest.c (like Roberto do) to highlight that it is a library. > @@ -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