[Tarantool-patches] [PATCH luajit 3/5] test: run LuaJIT tests via CMake

Timur Safin tsafin at tarantool.org
Mon Feb 8 18:05:40 MSK 2021


Some code changes proposals below...

: From: Igor Munkin <imun at tarantool.org>
: Subject: [PATCH luajit 3/5] test: run LuaJIT tests via CMake
: 
: 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}
: +  )
...
: +  # 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)

I don't like this. It reminds me of bad examples of this note
in the libev code like "this is so uncontrollably lame" which
actually distract users. We should rather put comments in more
neutral way (IMVHO). 

: +  # 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)

I liked you introduced globs for test files addition (blow), 
but unfortunately you didn't complete this with subdirectory addition

Please see my proposed patch (with reworded comments and new macro) here https://gist.github.com/tsafin/6c7505c0c764ab2b474667bf0d65fb45.

: +
: +# 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)

The major part of suggested patch is like this one:

--------------------------------------------------
-add_subdirectory(gh-4427-ffi-sandwich)
-add_subdirectory(lj-flush-on-trace)
-add_subdirectory(misclib-getmetrics-capi)
+macro(add_all_subdirectories)
+    file(GLOB entries RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*")
+    foreach(entry ${entries})
+        if (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${entry})
+            add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${entry})
+        endif()
+    endforeach()
+endmacro()
+
+add_all_subdirectories()
-------------------------------------------------

Regards,
Timur



More information about the Tarantool-patches mailing list