Allow and default to relative paths for binaries executed

This commit is contained in:
Daniel Poelzleithner 2021-12-02 17:01:37 +01:00
parent 9b2b3ad6e6
commit 564d54be76
8 changed files with 113 additions and 26 deletions

View File

@ -86,20 +86,26 @@ add_custom_target( manpage
DEPENDS doc/manpage/lsyncd.1.txt
)
# create_symlink( ${CMAKE_SOURCE_DIR}/tests tests)
ADD_CUSTOM_TARGET(add_tests ALL
COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_SOURCE_DIR}/tests tests)
add_custom_target( tests
COMMAND echo "Running the tests"
COMMAND echo "Note you are expected to:"
COMMAND echo " * have lua-posix installed"
COMMAND echo " * have a passwordless ssh access to localhost"
COMMAND ${LUA_EXECUTABLE} tests/schedule.lua
COMMAND ${LUA_EXECUTABLE} tests/l4rsyncdata.lua
COMMAND ${LUA_EXECUTABLE} tests/filter-rsync.lua
COMMAND ${LUA_EXECUTABLE} tests/exclude-rsync.lua
COMMAND ${LUA_EXECUTABLE} tests/exclude-rsyncssh.lua
COMMAND ${LUA_EXECUTABLE} tests/churn-rsync.lua
COMMAND ${LUA_EXECUTABLE} tests/churn-rsyncssh.lua
COMMAND ${LUA_EXECUTABLE} tests/churn-direct.lua
COMMAND ${LUA_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/setup.lua
COMMAND ${LUA_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/schedule.lua
COMMAND ${LUA_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/l4rsyncdata.lua
COMMAND ${LUA_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/filter-rsync.lua
COMMAND ${LUA_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/exclude-rsync.lua
COMMAND ${LUA_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/exclude-rsyncssh.lua
COMMAND ${LUA_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/churn-rsync.lua
COMMAND ${LUA_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/churn-rsyncssh.lua
COMMAND ${LUA_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/churn-direct.lua
COMMAND ${LUA_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/teardown.lua
COMMAND echo "Finished all successfull!"
DEPENDS add_tests
)
# compiling and linking it all together

View File

@ -682,7 +682,7 @@ rsync.exitcodes = default.rsyncExitCodes
rsync.rsync =
{
-- The rsync binary to be called.
binary = '/usr/bin/rsync',
binary = 'rsync',
links = true,
times = true,
protect_args = true

View File

@ -608,7 +608,7 @@ rsyncssh.ssh = {
--
-- the binary called
--
binary = '/usr/bin/ssh',
binary = 'ssh',
--
-- if set adds this key to ssh

View File

@ -13,39 +13,43 @@
gcc
cmake
glib
rsync
openssh
];
version = builtins.elemAt
(builtins.match ''.*set\(.LSYNCD_VERSION ([0-9\.]*).*''
(builtins.substring 0 500
(builtins.readFile ./CMakeLists.txt))) 0;
# buildTypes = {
# lua5_2 = pkgs.lua5_2;
# lua5_3 = pkgs.lua5_3;
# };
buildTypes = {
lua5_1 = [pkgs.lua5_1 pkgs.lua51Packages.luaposix pkgs.lua51Packages.penlight];
lua5_2 = [pkgs.lua5_2 pkgs.lua52Packages.luaposix pkgs.lua52Packages.penlight];
lua5_3 = [pkgs.lua5_3 pkgs.lua53Packages.luaposix pkgs.lua53Packages.penlight];
lua5_4 = [pkgs.lua5_4 pkgs.lua54Packages.luaposix pkgs.lua54Packages.penlight];
};
in
let
mkLsync = luaPackage: pkgs.stdenv.mkDerivation ({
mkLsync = luaPackages: pkgs.stdenv.mkDerivation ({
inherit version;
name = "lsyncd";
src = ./.;
# nativeBuildInputs = [ pkgs.qt5.wrapQtAppsHook ];
buildInputs = defaultDeps ++ [luaPackage];
buildInputs = defaultDeps ++ luaPackages;
});
in
{
packages = {
lsyncd = mkLsync pkgs.lua5_3;
lsyncd_lua5_1 = mkLsync pkgs.lua5_1;
lsyncd_lua5_2 = mkLsync pkgs.lua5_2;
lsyncd_lua5_3 = mkLsync pkgs.lua5_3;
lsyncd_lua5_4 = mkLsync pkgs.lua5_4;
lsyncd = mkLsync buildTypes.lua5_3;
lsyncd_lua5_1 = mkLsync buildTypes.lua5_1;
lsyncd_lua5_2 = mkLsync buildTypes.lua5_2;
lsyncd_lua5_3 = mkLsync buildTypes.lua5_3;
lsyncd_lua5_4 = mkLsync buildTypes.lua5_4;
};
defaultPackage = self.packages.${system}.lsyncd;
devShell = pkgs.mkShell {
buildInputs = defaultDeps;
buildInputs = defaultDeps ++ buildTypes.lua5_3;
};
}
);

View File

@ -1278,7 +1278,7 @@ l_exec( lua_State *L )
}
}
execv( binary, ( char ** ) argv );
execvp( binary, ( char ** ) argv );
// in a sane world execv does not return!
printlogf(

9
tests/setup.lua Normal file
View File

@ -0,0 +1,9 @@
-- a heavy duty test.
-- makes thousends of random changes to the source tree
require( 'posix' )
dofile( 'tests/testlib.lua' )
cwriteln( ' Start Testsuite ' )
startSshd()

8
tests/teardown.lua Normal file
View File

@ -0,0 +1,8 @@
-- a heavy duty test.
-- makes thousends of random changes to the source tree
require( 'posix' )
dofile( 'tests/testlib.lua' )
stopSshd()

View File

@ -1,5 +1,8 @@
-- common testing environment
posix = require( 'posix' )
string = require( 'string' )
path = require( 'pl.path' )
stringx = require( 'pl.stringx' )
-- escape codes to colorize output on terminal
local c1='\027[47;34m'
@ -90,13 +93,70 @@ function writefile
return true
end
function script_path()
-- local str = debug.getinfo(2, "S").source:sub(2)
-- return str:match("(.*/)")
return path.dirname(path.abspath(debug.getinfo(1).short_src))
end
--
-- Starts test ssh server
--
function startSshd()
-- local f = io.open(script_path() .. "ssh/sshd.pid", 'r')
-- if f
-- then
-- return false
-- end
cwriteln(arg[0])
cwriteln(script_path() .. "ssh/sshd_config")
local sshdPath = script_path() .. "/ssh/"
local f = io.open( sshdPath .. "sshd_config", 'w')
f:write([[
Port 2468
HostKey ]] .. sshdPath .. [[ssh_host_rsa_key
HostKey ]] .. sshdPath .. [[ssh_host_dsa_key
AuthorizedKeysFile ]] .. sshdPath .. [[authorized_keys
ChallengeResponseAuthentication no
UsePAM no
#Subsystem sftp /usr/lib/ssh/sftp-server
PidFile ]] .. sshdPath .. [[sshd.pid
]])
f:close( )
local which = io.popen("which sshd")
local path = which:read("a")
local exePath = string.sub(path, 0, #path - 1 )
-- local sshPath = which:read("a*")
local pid = spawn(exePath, "-f", sshdPath .. "sshd_config")
cwriteln( 'spawned sshd server: ' .. pid)
return true
end
--
-- Stop test ssh server
--
function stopSshd()
local f = io.open(script_path() .. "/ssh/sshd.pid", 'r')
if not f
then
return false
end
pid = stringx.strip(f:read("*a"))
posix.kill(tonumber(pid))
end
--
-- Spawns a subprocess.
--
-- Returns the processes pid.
--
function spawn
(...)
function spawn(...)
args = { ... }
cwriteln( 'spawning: ', table.concat( args, ' ' ) )