Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Bronnikov via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Sergey Kaplun <skaplun@tarantool.org>,
	Maxim Kokryashkin <m.kokryashkin@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH luajit 01/25] test: prepare lauxilarily libs for LuaJIT-tests
Date: Tue, 23 Jan 2024 12:10:51 +0300	[thread overview]
Message-ID: <ab37a2c0-d9cb-49c7-beac-646a3899e22c@tarantool.org> (raw)
In-Reply-To: <b74f5b343bfc9a0163f5ef5e31bdec41b2c5a734.1705661401.git.skaplun@tarantool.org>

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
> <LuaJIT-tests/src/> 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

  reply	other threads:[~2024-01-23  9:10 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-19 11:32 [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 01/25] test: prepare lauxilarily libs for LuaJIT-tests Sergey Kaplun via Tarantool-patches
2024-01-23  9:10   ` Sergey Bronnikov via Tarantool-patches [this message]
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 02/25] test: separate LuaJIT helpers from ffi_util.inc Sergey Kaplun via Tarantool-patches
2024-01-23  9:17   ` Sergey Bronnikov via Tarantool-patches
2024-01-23 12:35     ` Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 03/25] test: enable <ffi_arith_ptr.lua> in LuaJIT-tests Sergey Kaplun via Tarantool-patches
2024-01-23  9:21   ` Sergey Bronnikov via Tarantool-patches
2024-01-23 13:10     ` Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 04/25] test: enable <ffi_bitfield.lua> " Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 05/25] test: enable <ffi_call.lua> " Sergey Kaplun via Tarantool-patches
2024-01-23  9:32   ` Sergey Bronnikov via Tarantool-patches
2024-01-23 12:46     ` Sergey Kaplun via Tarantool-patches
2024-01-24 11:05       ` Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 06/25] test: enable <ffi_callback.lua> " Sergey Kaplun via Tarantool-patches
2024-01-23  9:36   ` Sergey Bronnikov via Tarantool-patches
2024-01-23 12:01     ` Sergey Bronnikov via Tarantool-patches
2024-01-23 12:58     ` Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 07/25] test: enable <ffi_const.lua> " Sergey Kaplun via Tarantool-patches
2024-01-23  9:38   ` Sergey Bronnikov via Tarantool-patches
2024-01-23 11:59     ` Sergey Bronnikov via Tarantool-patches
2024-01-23 12:52       ` Sergey Kaplun via Tarantool-patches
2024-01-23 12:49     ` Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 08/25] test: enable <ffi_convert.lua> " Sergey Kaplun via Tarantool-patches
2024-01-23  9:39   ` Sergey Bronnikov via Tarantool-patches
2024-01-23 12:51     ` Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 09/25] test: enable <ffi_enum.lua> " Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 10/25] test: enable <ffi_gcstep_recursive.lua> Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 11/25] test: enable <ffi_jit_arith.lua> in LuaJIT-tests Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 12/25] test: enable <ffi_jit_call.lua> " Sergey Kaplun via Tarantool-patches
2024-01-24 14:43   ` Sergey Bronnikov via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 13/25] test: enable <ffi_jit_conv.lua> " Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 14/25] test: enable <ffi_lex_number.lua> " Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 15/25] test: enable <ffi_metatype.lua> " Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 16/25] test: enable <ffi_new.lua> " Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 17/25] test: enable <ffi_parse_array.lua> " Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 18/25] test: enable <ffi_parse_basic.lua> " Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 19/25] test: enable <ffi_parse_cdef.lua> " Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 20/25] test: enable <ffi_parse_struct.lua> LuaJIT test Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 21/25] test: enable <ffi_tabov.lua> " Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 22/25] test: enable <lightud.lua> " Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 23/25] test: enable <api_call.lua> " Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 24/25] test: enable <catch_wrap.lua> " Sergey Kaplun via Tarantool-patches
2024-01-19 11:32 ` [Tarantool-patches] [PATCH luajit 25/25] test: enable <catch_cpp.lua> " Sergey Kaplun via Tarantool-patches
2024-01-23  9:01 ` [Tarantool-patches] [PATCH luajit 00/25] More tests from LuaJIT-tests, part 1 Sergey Bronnikov via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ab37a2c0-d9cb-49c7-beac-646a3899e22c@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=m.kokryashkin@tarantool.org \
    --cc=sergeyb@tarantool.org \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH luajit 01/25] test: prepare lauxilarily libs for LuaJIT-tests' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox