Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Maxim Kokryashkin <m.kokryashkin@tarantool.org>,
	Sergey Bronnikov <sergeyb@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH luajit 5/7] test: shrink LUA_CPATH and {DY}LD_LIBRARY_PATH
Date: Mon, 23 Sep 2024 10:18:51 +0300	[thread overview]
Message-ID: <ca4407f106d36cc7441a0709c4c243b2abacce4a.1727074292.git.skaplun@tarantool.org> (raw)
In-Reply-To: <cover.1727074292.git.skaplun@tarantool.org>

This patch sets the unique value of each of these variables for each of
the tests and only where they are needed. Also, it drops the comment
about SIP [1] tricks since it is obsolete after
29897567ee5ed57e961c730432c056a3dbaa8f09 ("test: stop using
utils.selfrun in tests").

[1]: https://support.apple.com/en-us/HT204899

Resolves tarantool/tarantool#9898
---
 test/tarantool-tests/CMakeLists.txt | 110 ++++++++++++++++------------
 1 file changed, 63 insertions(+), 47 deletions(-)

diff --git a/test/tarantool-tests/CMakeLists.txt b/test/tarantool-tests/CMakeLists.txt
index a1339100..6f1b1ae1 100644
--- a/test/tarantool-tests/CMakeLists.txt
+++ b/test/tarantool-tests/CMakeLists.txt
@@ -8,14 +8,13 @@ add_custom_target(tarantool-tests-libs
 macro(BuildTestCLib lib sources)
   AddTestLib(${lib} ${sources})
   add_dependencies(tarantool-tests-libs ${lib})
-  # Add the directory where the lib is built to the list with
-  # entries for LUA_CPATH environment variable, so LuaJIT can find
-  # and load it. See the comment about extending the list in the
-  # parent scope few lines above.
-  set(LUA_CPATHS "${CMAKE_CURRENT_BINARY_DIR}/?${CMAKE_SHARED_LIBRARY_SUFFIX};${LUA_CPATHS}" 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)
+  # Add libraries to the list to be proceeded with after test
+  # targets are created.
+  # XXX: Workaround for profilers c-related tests, see the comment
+  # below.
+  if(NOT "${CMAKE_CURRENT_BINARY_DIR}" MATCHES profilers)
+    set(CLIB_DIRS "${CMAKE_CURRENT_BINARY_DIR};${CLIB_DIRS}" PARENT_SCOPE)
+  endif()
 endmacro()
 
 # FIXME: This is used only due to ancient CMake requirements.
@@ -76,46 +75,8 @@ make_lua_path(LUA_PATH
     ${LUAJIT_BINARY_DIR}/?.lua
 )
 
-# Update LUA_CPATH with the library paths collected within
-# <BuildTestLib> macro.
-make_lua_path(LUA_CPATH PATHS ${LUA_CPATHS})
-
 set(LUA_TEST_SUFFIX .test.lua)
 
-# XXX: Since the auxiliary libraries are built as a dynamically
-# loaded modules on MacOS instead of shared libraries as it is
-# done on Linux and BSD, another environment variable should be
-# used to guide <ffi.load> while searching the extension.
-# XXX: Be noticed that we shouldn't use `"` here to wrap
-# the variable's content. If we do this, the variable value will
-# contain `"` at the beginning and the end, so this `"` at the
-# beginning will be treated as the directory for the first entry
-# (the last subdirectory added).
-if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
-  # XXX: Apple tries their best to "protect their users from
-  # malware". As a result SIP (see the link[1] below) has been
-  # designed and released. Now, Apple developers are so protected,
-  # that they can load nothing being not installed in the system,
-  # since some programs sanitize the environment before they start
-  # child processes. Specifically, environment variables starting
-  # with DYLD_ and LD_ are unset for child process started by
-  # other programs (like `ctest` using for launching tests).
-  # For more info, see the docs[2] below.
-  #
-  # These environment variables are used by FFI machinery to find
-  # the proper shared library, hence we can still tweak testing
-  # environment before calling <ffi.load>. However, the value
-  # can't be passed via the standard environment variable, so we
-  # use ENVIRONMENT property in `set_tests_properties` to get
-  # around SIP magic tricks.
-  #
-  # [1]: https://support.apple.com/en-us/HT204899
-  # [2]: https://developer.apple.com/library/archive/documentation/Security/Conceptual/System_Integrity_Protection_Guide/RuntimeProtections/RuntimeProtections.html
-  list(APPEND LUA_TEST_ENV_MORE DYLD_LIBRARY_PATH=${LD_LIBRARY_PATH})
-else()
-  list(APPEND LUA_TEST_ENV_MORE LD_LIBRARY_PATH=${LD_LIBRARY_PATH})
-endif()
-
 # Some tests use `LD_PRELOAD` to mock system calls (like
 # <lj-802-panic-at-mcode-protfail.test.lua> overwrites
 # `mprotect()`. When compiling with ASan support under GCC, it is
@@ -152,12 +113,67 @@ foreach(test_path ${tests})
     # LUA_CPATH and LD_LIBRARY_PATH variables and also
     # dependencies list with libraries are set in scope of
     # BuildTestLib macro.
-    ENVIRONMENT "LUA_PATH=${LUA_PATH};LUA_CPATH=${LUA_CPATH};${LUA_TEST_ENV_MORE}"
+    ENVIRONMENT "LUA_PATH=${LUA_PATH};${LUA_TEST_ENV_MORE}"
     LABELS ${TEST_SUITE_NAME}
     DEPENDS tarantool-tests-deps
   )
 endforeach()
 
+# We use the following naming convention: the name of the
+# directory containing the C library to be loaded should match the
+# prefix of the test itself. The same library may be used in
+# several tests. See <lj-1166-error-stitch*>, for example.
+foreach(clib_dir ${CLIB_DIRS})
+  get_filename_component(clib_dir_prefix ${clib_dir} NAME)
+  file(GLOB_RECURSE tests_using_clib
+    RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+    "${clib_dir_prefix}*${LUA_TEST_SUFFIX}"
+  )
+  foreach(test_name ${tests_using_clib})
+    set(test_title "test/${TEST_SUITE_NAME}/${test_name}")
+    # Add the directory where the library is built to the list
+    # with entries for the LUA_CPATH environment variable, so
+    # LuaJIT can find and load it.
+    AppendTestEnvVar(${test_title}
+      LUA_CPATH "${clib_dir}/?${CMAKE_SHARED_LIBRARY_SUFFIX}\;"
+    )
+    # Also, add this directory to the LD_LIBRARY_PATH environment
+    # variable so FFI machinery can find and load it.
+    # XXX: Be noticed that we shouldn't use `"` here to wrap the
+    # variable's content. If we do this, the variable value will
+    # contain `"` at the beginning and the end, so this `"` at the
+    # beginning will be treated as the directory for the entry.
+    # XXX: Since the auxiliary libraries are built as dynamically
+    # loaded modules on MacOS instead of shared libraries as it is
+    # done on Linux and BSD, another environment variable should
+    # be used to guide <ffi.load> while searching the extension.
+    if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+      AppendTestEnvVar(${test_title} DYLD_LIBRARY_PATH ${clib_dir}:)
+    else()
+      AppendTestEnvVar(${test_title} LD_LIBRARY_PATH ${clib_dir}:)
+    endif()
+  endforeach()
+endforeach()
+
+# XXX: Special workaround for several different loaded libraries
+# in the <gh-5813-resolving-of-c-symbols.test.lua>. Since the libs
+# can't be flatterned to one directory (see the comment in their
+# <CMakeLists.txt>), just set them manually here.
+set(CSYMBOLS_DIR
+  ${CMAKE_CURRENT_BINARY_DIR}/profilers/gh-5813-resolving-of-c-symbols
+)
+make_lua_path(CSYMBOLS_CPATHS
+  PATHS
+    ${CSYMBOLS_DIR}/both/?${CMAKE_SHARED_LIBRARY_SUFFIX}
+    ${CSYMBOLS_DIR}/gnuhash/?${CMAKE_SHARED_LIBRARY_SUFFIX}
+    ${CSYMBOLS_DIR}/hash/?${CMAKE_SHARED_LIBRARY_SUFFIX}
+    ${CSYMBOLS_DIR}/stripped/?${CMAKE_SHARED_LIBRARY_SUFFIX}
+)
+AppendTestEnvVar(
+  test/${TEST_SUITE_NAME}/profilers/gh-5813-resolving-of-c-symbols.test.lua
+  LUA_CPATH "${CSYMBOLS_CPATHS}"
+)
+
 # The part of the profilers toolchain is located in the <tools/>
 # directory, so LUA_PATH needs to be updated.
 file(GLOB_RECURSE profilers_tests
-- 
2.46.0


  parent reply	other threads:[~2024-09-23  7:21 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-23  7:18 [Tarantool-patches] [PATCH luajit 0/7] Shrink test env and fix flaky tests Sergey Kaplun via Tarantool-patches
2024-09-23  7:18 ` [Tarantool-patches] [PATCH luajit 1/7] test: move profilers tests to subdirectory Sergey Kaplun via Tarantool-patches
2024-09-23  7:40   ` Sergey Bronnikov via Tarantool-patches
2024-09-23  7:51     ` Sergey Kaplun via Tarantool-patches
2024-09-23  7:18 ` [Tarantool-patches] [PATCH luajit 2/7] test: rename <arm64-ccall-fp-convention.test.lua> Sergey Kaplun via Tarantool-patches
2024-09-23  7:45   ` Sergey Bronnikov via Tarantool-patches
2024-09-23  7:18 ` [Tarantool-patches] [PATCH luajit 3/7] cmake: introduce AppendTestEnvVar macro Sergey Kaplun via Tarantool-patches
2024-09-23  7:51   ` Sergey Bronnikov via Tarantool-patches
2024-09-23  8:18     ` Sergey Kaplun via Tarantool-patches
2024-09-23  7:18 ` [Tarantool-patches] [PATCH luajit 4/7] test: shrink LUA_PATH environment variable Sergey Kaplun via Tarantool-patches
2024-09-23  8:47   ` Sergey Bronnikov via Tarantool-patches
2024-09-23  7:18 ` Sergey Kaplun via Tarantool-patches [this message]
2024-09-23  7:18 ` [Tarantool-patches] [PATCH luajit 6/7] test: skip flaky tests with enabled table bump Sergey Kaplun via Tarantool-patches
2024-09-23  9:44   ` Sergey Bronnikov via Tarantool-patches
2024-09-23 11:08     ` Sergey Kaplun via Tarantool-patches
2024-09-23  7:18 ` [Tarantool-patches] [PATCH luajit 7/7] test: set LD_PRELOAD only when necessary Sergey Kaplun 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=ca4407f106d36cc7441a0709c4c243b2abacce4a.1727074292.git.skaplun@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 5/7] test: shrink LUA_CPATH and {DY}LD_LIBRARY_PATH' \
    /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