[Tarantool-patches] [PATCH luajit 1/2] test: set DYLD_LIBRARY_PATH environment variable

sergos sergos at tarantool.org
Thu Jun 2 11:51:46 MSK 2022


Hi!

Thanks for the patch, I can’t find any problems in it, although I couldn’t
apply it on the latest luajit.

Sergos.


> On 9 Dec 2021, at 13:24, Sergey Kaplun <skaplun at tarantool.org> wrote:
> 
> This patch allows to use tests with `ffi.load()` without usage of
> `utils.selfrun()` by setting the DYLD_LIBRARY_PATH variable for the
> process directly via additional env command. Also, this commit "reverts"
> part of the commit fae1681dd1c117a913f99cbeed0ca2b87cf581a1 ('test: fix
> dynamic modules loading on MacOS') since there is no need to tweak
> environment while running those tests.
> 
> Needed for tarantool/tarantool#6548
> ---
> test/tarantool-tests/CMakeLists.txt           | 19 +++++++++++--------
> .../gh-4427-ffi-sandwich.test.lua             |  4 ----
> .../lj-flush-on-trace.test.lua                |  4 ----
> test/tarantool-tests/utils.lua                | 17 -----------------
> 4 files changed, 11 insertions(+), 33 deletions(-)
> 
> diff --git a/test/tarantool-tests/CMakeLists.txt b/test/tarantool-tests/CMakeLists.txt
> index a872fa5e..992556d9 100644
> --- a/test/tarantool-tests/CMakeLists.txt
> +++ b/test/tarantool-tests/CMakeLists.txt
> @@ -94,22 +94,21 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
>   # 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
> -  # system programs (like /usr/bin/env used for preparing testing
> -  # environment). For more info, see the docs[2] below.
> +  # other programs (like /usr/bin/prove --exec using for launching
> +  # test suite). 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
> -  # prepend TEST_ prefix to its name to get around SIP magic
> -  # tricks. Finally, to set the variable required by FFI machinery
> -  # the introduced <utils.tweakenv> routine is used.
> +  # use env call in prove's --exec flag value 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 TEST_DYLD_LIBRARY_PATH="${LD_LIBRARY_PATH}")
> +  list(APPEND LUA_TEST_ENV_MORE DYLD_LIBRARY_PATH="${LD_LIBRARY_PATH}")
> else()
> -  list(APPEND LUA_TEST_ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}")
> +  list(APPEND LUA_TEST_ENV_MORE LD_LIBRARY_PATH="${LD_LIBRARY_PATH}")
> endif()
> 
> # LUA_CPATH and LD_LIBRARY_PATH variables and also TESTLIBS list
> @@ -120,10 +119,14 @@ add_custom_target(tarantool-tests
> add_custom_command(TARGET tarantool-tests
>   COMMENT "Running Tarantool tests"
>   COMMAND
> +  # XXX: We can't move everything to the "inner" env, since there
> +  # are some issues with escaping ';' for different shells. As
> +  # a result LUA_PATH/LUA_CPATH variables are set via the "outer"
> +  # env, since they are not stripped by SIP like LD_*/DYLD_* are.
>   env
>     ${LUA_TEST_ENV}
>     ${PROVE} ${CMAKE_CURRENT_SOURCE_DIR}
> -      --exec '${LUAJIT_TEST_COMMAND}'
> +      --exec 'env ${LUA_TEST_ENV_MORE} ${LUAJIT_TEST_COMMAND}'
>       --ext ${LUA_TEST_SUFFIX}
>       ${LUA_TEST_FLAGS}
>   WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
> diff --git a/test/tarantool-tests/gh-4427-ffi-sandwich.test.lua b/test/tarantool-tests/gh-4427-ffi-sandwich.test.lua
> index 3e6801a5..dd02130c 100644
> --- a/test/tarantool-tests/gh-4427-ffi-sandwich.test.lua
> +++ b/test/tarantool-tests/gh-4427-ffi-sandwich.test.lua
> @@ -3,10 +3,6 @@ local utils = require('utils')
> -- Disabled on *BSD due to #4819.
> utils.skipcond(jit.os == 'BSD', 'Disabled due to #4819')
> 
> --- XXX: Tweak the process environment to get around SIP.
> --- See the comment in suite CMakeLists.txt for more info.
> -utils.tweakenv(jit.os == 'OSX', 'DYLD_LIBRARY_PATH')
> -
> utils.selfrun(arg, {
>   {
>     arg = {
> diff --git a/test/tarantool-tests/lj-flush-on-trace.test.lua b/test/tarantool-tests/lj-flush-on-trace.test.lua
> index 81fd6e8f..c46b93f0 100644
> --- a/test/tarantool-tests/lj-flush-on-trace.test.lua
> +++ b/test/tarantool-tests/lj-flush-on-trace.test.lua
> @@ -3,10 +3,6 @@ local utils = require('utils')
> -- Disabled on *BSD due to #4819.
> utils.skipcond(jit.os == 'BSD', 'Disabled due to #4819')
> 
> --- XXX: Tweak the process environment to get around SIP.
> --- See the comment in suite CMakeLists.txt for more info.
> -utils.tweakenv(jit.os == 'OSX', 'DYLD_LIBRARY_PATH')
> -
> utils.selfrun(arg, {
>   {
>     arg = {
> diff --git a/test/tarantool-tests/utils.lua b/test/tarantool-tests/utils.lua
> index 5bd42b30..3b809515 100644
> --- a/test/tarantool-tests/utils.lua
> +++ b/test/tarantool-tests/utils.lua
> @@ -1,13 +1,8 @@
> local M = {}
> 
> -local ffi = require('ffi')
> local tap = require('tap')
> local bc = require('jit.bc')
> 
> -ffi.cdef([[
> -  int setenv(const char *name, const char *value, int overwrite);
> -]])
> -
> local function luacmd(args)
>   -- arg[-1] is guaranteed to be not nil.
>   local idx = -2
> @@ -78,18 +73,6 @@ function M.skipcond(condition, message)
>   os.exit(test:check() and 0 or 1)
> end
> 
> -function M.tweakenv(condition, variable)
> -  if not condition or os.getenv(variable) then return end
> -  local testvar = assert(os.getenv('TEST_' .. variable),
> -                         ('Neither %s nor auxiliary TEST_%s variables are set')
> -                         :format(variable, variable))
> -  -- XXX: The third argument of setenv(3) is set to zero to forbid
> -  -- overwriting the <variable>. Since there is the check above
> -  -- whether this <variable> is set in the process environment, it
> -  -- just makes this solution foolproof.
> -  ffi.C.setenv(variable, testvar, 0)
> -end
> -
> function M.hasbc(f, bytecode)
>   assert(type(f) == 'function', 'argument #1 should be a function')
>   assert(type(bytecode) == 'string', 'argument #2 should be a string')
> -- 
> 2.33.1
> 



More information about the Tarantool-patches mailing list