fixing tests for lua 5.2 os.execute call semantics

This commit is contained in:
Axel Kittenberger 2015-10-14 14:23:37 +02:00
parent 1f95925304
commit 2493476f64
7 changed files with 192 additions and 131 deletions

View File

@ -2,17 +2,17 @@
-- a heavy duty test. -- a heavy duty test.
-- makes thousends of random changes to the source tree -- makes thousends of random changes to the source tree
require('posix') require( 'posix' )
dofile('tests/testlib.lua') dofile( 'tests/testlib.lua' )
cwriteln('****************************************************************') cwriteln( '****************************************************************' )
cwriteln(' Testing default.direct with random data activity ') cwriteln( ' Testing default.direct with random data activity ' )
cwriteln('****************************************************************') cwriteln( '****************************************************************' )
local tdir, srcdir, trgdir = mktemps() local tdir, srcdir, trgdir = mktemps( )
-- makes some startup data -- makes some startup data
churn(srcdir, 10) churn( srcdir, 10 )
local logs = { } local logs = { }
--local logs = {'-log', 'Exec', '-log', 'Delay' } --local logs = {'-log', 'Exec', '-log', 'Delay' }
@ -20,24 +20,36 @@ local pid = spawn(
'./lsyncd', './lsyncd',
'-nodaemon', '-nodaemon',
'-direct', srcdir, trgdir, '-direct', srcdir, trgdir,
unpack(logs) unpack( logs )
) )
cwriteln('waiting for Lsyncd to startup') cwriteln( 'waiting for Lsyncd to startup' )
posix.sleep(1) posix.sleep( 1 )
churn(srcdir, 500) churn( srcdir, 500 )
cwriteln('waiting for Lsyncd to finish its jobs.') cwriteln( 'waiting for Lsyncd to finish its jobs.' )
posix.sleep(10) posix.sleep( 10 )
cwriteln('killing the Lsyncd daemon') cwriteln( 'killing the Lsyncd daemon' )
posix.kill(pid) posix.kill( pid )
local _, exitmsg, lexitcode = posix.wait(lpid)
cwriteln('Exitcode of Lsyncd = ',exitmsg,' ',lexitcode)
exitcode = os.execute('diff -r '..srcdir..' '..trgdir) local _, exitmsg, lexitcode = posix.wait( lpid )
cwriteln('Exitcode of diff = "', exitcode, '"') cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode )
if exitcode ~= 0 then os.exit(1) else os.exit(0) end _, result, code = os.execute( 'diff -r ' .. srcdir .. ' ' .. trgdir )
if result == 'exit'
then
cwriteln( 'Exitcode of diff = ', code )
else
cwriteln( 'Signal terminating diff = ', code )
end
if code ~= 0
then
os.exit( 1 )
else
os.exit( 0 )
end

View File

@ -39,10 +39,17 @@ posix.kill( pid )
local _, exitmsg, lexitcode = posix.wait( lpid ) local _, exitmsg, lexitcode = posix.wait( lpid )
cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode ) cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode )
exitcode = os.execute( 'diff -r '..srcdir..' '..trgdir ) _, result, code = os.execute( 'diff -r ' .. srcdir .. ' ' .. trgdir )
cwriteln( 'Exitcode of diff = "', exitcode, '"' )
if exitcode ~= 0 then if result == 'exit'
then
cwriteln( 'Exitcode of diff = ', code )
else
cwriteln( 'Signal terminating diff = ', code )
end
if exitcode ~= 0
then
os.exit( 1 ) os.exit( 1 )
else else
os.exit( 0 ) os.exit( 0 )

View File

@ -45,10 +45,17 @@ posix.kill(pid)
local _, exitmsg, lexitcode = posix.wait(lpid) local _, exitmsg, lexitcode = posix.wait(lpid)
cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode ) cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode )
exitcode = os.execute( 'diff -r ' .. srcdir .. ' ' .. trgdir ) _, result, code = os.execute( 'diff -r ' .. srcdir .. ' ' .. trgdir )
cwriteln( 'Exitcode of diff = "', exitcode, '"' )
if exitcode ~= 0 then if result == 'exit'
then
cwriteln( 'Exitcode of diff = ', code )
else
cwriteln( 'Signal terminating diff = ', code )
end
if exitcode ~= 0
then
os.exit( 1 ) os.exit( 1 )
else else
os.exit( 0 ) os.exit( 0 )

View File

@ -14,17 +14,17 @@ local log = {"-log", "all"}
writefile(cfgfile, [[ writefile(cfgfile, [[
settings = { settings = {
logfile = "]]..logfile..[[", logfile = "]]..logfile..[[",
nodaemon = true, nodaemon = true,
delay = 3, delay = 3,
} }
sync { sync {
default.rsync, default.rsync,
source = "]]..srcdir..[[", source = "]]..srcdir..[[",
target = "]]..trgdir..[[", target = "]]..trgdir..[[",
exclude = { exclude = {
"erf", "erf",
"/eaf", "/eaf",
"erd/", "erd/",
"/ead/", "/ead/",
@ -70,42 +70,51 @@ local function testfiles()
end end
cwriteln("testing startup excludes"); cwriteln( 'testing startup excludes' );
writefiles();
cwriteln("starting Lsyncd");
local pid = spawn("./lsyncd", cfgfile, '-log', 'all');
cwriteln("waiting for Lsyncd to start");
posix.sleep(3)
cwriteln("testing excludes after startup");
testfiles();
cwriteln("ok, removing sources");
if srcdir:sub(1,4) ~= "/tmp" then
-- just to make sure before rm -rf
cwriteln("exist before drama, srcdir is '", srcdir, "'");
os.exit(1);
end
os.execute("rm -rf "..srcdir.."/*");
cwriteln("waiting for Lsyncd to remove destination");
posix.sleep(5);
if os.execute("diff -urN "..srcdir.." "..trgdir) ~= 0 then
cwriteln("fail, target directory not empty!");
os.exit(1);
end
cwriteln( "writing files after startup" );
writefiles( ); writefiles( );
cwriteln( "waiting for Lsyncd to transmit changes" ); cwriteln( 'starting Lsyncd' );
local pid = spawn( './lsyncd', cfgfile, '-log', 'all');
cwriteln( 'waiting for Lsyncd to start' );
posix.sleep( 3 )
cwriteln( 'testing excludes after startup' );
testfiles( );
cwriteln( 'ok, removing sources' );
if srcdir:sub( 1,4 ) ~= '/tmp'
then
-- just to make sure before rm -rf
cwriteln( 'exit before drama, srcdir is "', srcdir, '"' );
os.exit( 1 );
end
os.execute( 'rm -rf '..srcdir..'/*' );
cwriteln( 'waiting for Lsyncd to remove destination' );
posix.sleep( 5 );
_, result, code = os.execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir )
if result ~= 'exit' or code ~= 0
then
cwriteln( 'fail, target directory not empty!' );
os.exit( 1 );
end
cwriteln( 'writing files after startup' );
writefiles( );
cwriteln( 'waiting for Lsyncd to transmit changes' );
posix.sleep( 5 ); posix.sleep( 5 );
testfiles( ); testfiles( );
cwriteln( "killing started Lsyncd" ); cwriteln( 'killing started Lsyncd' );
posix.kill( pid ); posix.kill( pid );
local _, exitmsg, lexitcode = posix.wait( lpid ); local _, exitmsg, lexitcode = posix.wait( lpid );
cwriteln( "Exitcode of Lsyncd = ", exitmsg, " ", lexitcode ); cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode );
if lexitcode == 143 then if lexitcode == 143
then
cwriteln( "OK" ); cwriteln( "OK" );
os.exit( 0 ); os.exit( 0 );
else else

View File

@ -1,15 +1,15 @@
#!/usr/bin/lua #!/usr/bin/lua
require('posix') require( 'posix' )
dofile('tests/testlib.lua') dofile( 'tests/testlib.lua' )
cwriteln('****************************************************************'); cwriteln( '****************************************************************' );
cwriteln(' Testing excludes'); cwriteln( ' Testing excludes' );
cwriteln('****************************************************************'); cwriteln( '****************************************************************' );
cwriteln(' (this test needs passwordless ssh localhost access '); cwriteln( ' (this test needs passwordless ssh localhost access ' );
cwriteln(' for current user)'); cwriteln( ' for current user)' );
local tdir, srcdir, trgdir = mktemps() local tdir, srcdir, trgdir = mktemps( )
local logfile = tdir .. 'log' local logfile = tdir .. 'log'
local cfgfile = tdir .. 'config.lua' local cfgfile = tdir .. 'config.lua'
local range = 5 local range = 5
@ -18,18 +18,18 @@ log = {'-log', 'all'}
writefile(cfgfile, [[ writefile(cfgfile, [[
settings = { settings = {
logfile = ']]..logfile..[[', logfile = ']]..logfile..[[',
nodaemon = true, nodaemon = true,
delay = 3, delay = 3,
} }
sync { sync {
default.rsyncssh, default.rsyncssh,
host = 'localhost', host = 'localhost',
source = ']]..srcdir..[[', source = ']]..srcdir..[[',
targetdir = ']]..trgdir..[[', targetdir = ']]..trgdir..[[',
exclude = { exclude = {
'erf', 'erf',
'/eaf', '/eaf',
'erd/', 'erd/',
'/ead/', '/ead/',
@ -64,14 +64,14 @@ end
-- test all files -- test all files
local function testfiles() local function testfiles()
testfile(trgdir .. 'erf', false); testfile( trgdir .. 'erf', false );
testfile(trgdir .. 'eaf', false); testfile( trgdir .. 'eaf', false );
testfile(trgdir .. 'erd', true); testfile( trgdir .. 'erd', true );
testfile(trgdir .. 'ead', true); testfile( trgdir .. 'ead', true );
testfile(trgdir .. 'd/erf', false); testfile( trgdir .. 'd/erf', false );
testfile(trgdir .. 'd/eaf', true); testfile( trgdir .. 'd/eaf', true );
testfile(trgdir .. 'd/erd', true); testfile( trgdir .. 'd/erd', true );
testfile(trgdir .. 'd/ead', true); testfile( trgdir .. 'd/ead', true );
end end
@ -89,27 +89,33 @@ if srcdir:sub(1,4) ~= '/tmp' then
cwriteln('exist before drama, srcdir is "', srcdir, '"'); cwriteln('exist before drama, srcdir is "', srcdir, '"');
os.exit(1); os.exit(1);
end end
os.execute('rm -rf '..srcdir..'/*');
cwriteln('waiting for Lsyncd to remove destination'); os.execute( 'rm -rf ' .. srcdir .. '/*' );
posix.sleep(5); cwriteln( 'waiting for Lsyncd to remove destination' );
if os.execute('diff -urN '..srcdir..' '..trgdir) ~= 0 then posix.sleep( 5 );
cwriteln('fail, target directory not empty!');
os.exit(1); _, result, code = os.execute('diff -urN '..srcdir..' '..trgdir) ~= 0
if result ~= 'exit' or code ~= 0
then
cwriteln( 'fail, target directory not empty!' );
os.exit( 1 );
end end
cwriteln('writing files after startup'); cwriteln( 'writing files after startup' );
writefiles(); writefiles( );
cwriteln('waiting for Lsyncd to transmit changes'); cwriteln( 'waiting for Lsyncd to transmit changes' );
posix.sleep(15); posix.sleep( 15 );
testfiles(); testfiles( );
cwriteln('killing started Lsyncd'); cwriteln( 'killing started Lsyncd' );
posix.kill(pid); posix.kill( pid );
local _, exitmsg, lexitcode = posix.wait(lpid); local _, exitmsg, lexitcode = posix.wait( lpid );
cwriteln('Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode); cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode );
posix.sleep(1); posix.sleep( 1 );
if lexitcode == 143 then if lexitcode == 143
then
cwriteln( 'OK' ); cwriteln( 'OK' );
os.exit( 0 ); os.exit( 0 );
else else

View File

@ -1,34 +1,46 @@
#!/usr/bin/lua #!/usr/bin/lua
require("posix") require( 'posix' )
dofile("tests/testlib.lua") dofile( 'tests/testlib.lua' )
cwriteln("****************************************************************") cwriteln( '****************************************************************' )
cwriteln(" Testing layer 4 default rsync with simulated data activity ") cwriteln( ' Testing layer 4 default rsync with simulated data activity ' )
cwriteln("****************************************************************") cwriteln( '****************************************************************' )
local tdir, srcdir, trgdir = mktemps() local tdir, srcdir, trgdir = mktemps()
local logfile = tdir .. "log" local logfile = tdir .. 'log'
local range = 5 local range = 5
local log = {"-log", "all"} local log = { '-log', 'all' }
posix.mkdir(srcdir .. "d") posix.mkdir( srcdir .. 'd' )
posix.mkdir(srcdir .. "d/e") posix.mkdir( srcdir .. 'd/e' )
if not writefile(srcdir .. "d/e/f1", 'test') then
os.exit(1) if not writefile( srcdir .. "d/e/f1", 'test' )
then
os.exit( 1 )
end end
cwriteln("starting Lsyncd") cwriteln( 'starting Lsyncd' )
logs = {} logs = { }
local pid = spawn("./lsyncd", "-logfile", logfile, "-nodaemon", "-delay", "5", local pid =
"-rsync", srcdir, trgdir, unpack(logs)) spawn(
cwriteln("waiting for lsyncd to start") './lsyncd',
posix.sleep(2) '-logfile', logfile,
'-nodaemon',
'-delay', '5',
"-rsync", srcdir, trgdir,
unpack( logs )
)
cwriteln("* making some data") cwriteln( 'waiting for lsyncd to start' )
cwriteln("* creating d[x]/e/f2") posix.sleep( 2 )
for i = 1, range do
cwriteln("[cp -r "..srcdir.."d "..srcdir.."d"..i.."]") cwriteln( '* making some data' )
os.execute("cp -r "..srcdir.."d "..srcdir.."d"..i) cwriteln( '* creating d[x]/e/f2' )
for i = 1, range
do
cwriteln( '[cp -r ' .. srcdir .. 'd ' .. srcdir .. 'd' .. i .. ']' )
os.execute( 'cp -r ' .. srcdir .. 'd ' .. srcdir .. 'd' .. i )
end end
-- mkdir -p "$S"/m/n -- mkdir -p "$S"/m/n
@ -38,23 +50,31 @@ end
-- echo 'test4' > "$S"/m${i}/n/another -- echo 'test4' > "$S"/m${i}/n/another
-- done -- done
cwriteln("* waiting for Lsyncd to do its job.") cwriteln( '* waiting for Lsyncd to do its job.' )
posix.sleep(10) posix.sleep( 10 )
cwriteln("* killing Lsyncd") cwriteln( '* killing Lsyncd' )
posix.kill(pid) posix.kill( pid )
local _, exitmsg, lexitcode = posix.wait(lpid) local _, exitmsg, lexitcode = posix.wait(lpid)
cwriteln("Exitcode of Lsyncd = ", exitmsg, " ", lexitcode) cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode)
posix.sleep(1) posix.sleep( 1 )
cwriteln("* differences:") cwriteln( '* differences:' )
exitcode = os.execute("diff -urN "..srcdir.." "..trgdir) _, result, code = os.execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir )
cwriteln("Exitcode of diff = '", exitcode, "'")
if exitcode ~= 0 then if result == 'exit'
os.exit(1) then
cwriteln( 'Exitcode of diff = "', code, '"')
else else
os.exit(0) cwriteln( 'Signal terminating diff = "', code, '"')
end
if result ~= 'exit' or exitcode ~= 0
then
os.exit( 1 )
else
os.exit( 0 )
end end
-- TODO remove temp -- TODO remove temp

View File

@ -1,5 +1,5 @@
-- common testing environment -- common testing environment
require('posix') posix = require('posix')
-- escape codes to colorize output on terminal -- escape codes to colorize output on terminal
local c1='\027[47;34m' local c1='\027[47;34m'