This commit is contained in:
Axel Kittenberger 2010-11-18 16:59:50 +00:00
parent 0c7bc18595
commit b5870c31de
2 changed files with 20 additions and 12 deletions

View File

@ -8,7 +8,7 @@ dofile("tests/testlib.lua")
-- always makes the same "random", so failures can be debugged. -- always makes the same "random", so failures can be debugged.
math.randomseed(1) math.randomseed(1)
local tdir = mktempd() local tdir = mktempd().."/"
cwriteln("using ", tdir, " as test root") cwriteln("using ", tdir, " as test root")
local srcdir = tdir.."src/" local srcdir = tdir.."src/"
@ -16,15 +16,16 @@ local trgdir = tdir.."trg/"
posix.mkdir(srcdir) posix.mkdir(srcdir)
posix.mkdir(trgdir) posix.mkdir(trgdir)
spawn("./lsyncd","-nodaemon","-log","all","-rsync",srcdir,trgdir) local pid = spawn("./lsyncd","-nodaemon","-rsync",srcdir,trgdir)
-- lets Lsyncd startup cwriteln("waiting for Lsyncd to startup")
posix.sleep(1) posix.sleep(1)
-- all dirs created, indexed by integer and path -- all dirs created, indexed by integer and path
adiri = {""} adiri = {""}
adirp = {[""]=true} adirp = {[""]=true}
cwriteln("making random data")
for ai=1,100 do for ai=1,100 do
-- throw a die what to do -- throw a die what to do
local acn = math.random(1) local acn = math.random(1)
@ -32,23 +33,28 @@ for ai=1,100 do
-- 1 .. creates a directory -- 1 .. creates a directory
if acn == 1 then if acn == 1 then
-- chooses a random directory to create it into -- chooses a random directory to create it into
local ri = math.random(adirs.size()) local ri = math.random(#adiri)
local rp = adiri[dn] local rp = adiri[ri]
local np = rp..string.char(96 + math.random(26)).."/" local np = rp..string.char(96 + math.random(26)).."/"
if not adirp[np] then if not adirp[np] then
-- does not yet exist. -- does not yet exist.
posix.mkdir(np) cwriteln("mkdir "..srcdir..np)
posix.mkdir(srcdir..np)
table.insert(adiri, np) table.insert(adiri, np)
adirp[np]=true adirp[np]=true
end end
end end
end end
cwriteln("waiting for Lsyncd to finish its jobs.")
posix.sleep(20)
cwriteln("killing the Lsyncd daemon")
posix.kill(pid)
local _, exitmsg, exitcode = posix.wait(lpid)
cwriteln("Exitcode of Lsyncd = ", exitmsg, " ", exitcode)
-- kills the lsyncd daemon exitcode = os.execute("diff -r "..srcdir.." "..trgdir)
-- posix.kill(lpid) cwriteln("Exitcode of diff = ", exitcode)
-- local _, exitmsg, exitcode = posix.wait(lpid) os.exit(exitcode)
-- cwriteln("Exitcode of Lsyncd = ", exitmsg, " ", exitcode)
-- os.exit(lexitcode)

View File

@ -31,12 +31,14 @@ end
-- @returns the processes pid -- @returns the processes pid
-- --
function spawn(...) function spawn(...)
args = {...}
cwriteln("spawning: ", table.concat(args, " "))
local pid = posix.fork() local pid = posix.fork()
if pid < 0 then if pid < 0 then
cwriteln("Error, failed fork!") cwriteln("Error, failed fork!")
os.exit(-1) os.exit(-1)
end end
if lpid == 0 then if pid == 0 then
posix.exec(...) posix.exec(...)
-- should not return -- should not return
cwriteln("Error, failed to spawn: ", ...) cwriteln("Error, failed to spawn: ", ...)