diff --git a/tests/randomrsync.lua b/tests/randomrsync.lua index 3015f24..bf478e1 100755 --- a/tests/randomrsync.lua +++ b/tests/randomrsync.lua @@ -8,7 +8,7 @@ dofile("tests/testlib.lua") -- always makes the same "random", so failures can be debugged. math.randomseed(1) -local tdir = mktempd() +local tdir = mktempd().."/" cwriteln("using ", tdir, " as test root") local srcdir = tdir.."src/" @@ -16,15 +16,16 @@ local trgdir = tdir.."trg/" posix.mkdir(srcdir) 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) -- all dirs created, indexed by integer and path adiri = {""} adirp = {[""]=true} +cwriteln("making random data") for ai=1,100 do -- throw a die what to do local acn = math.random(1) @@ -32,23 +33,28 @@ for ai=1,100 do -- 1 .. creates a directory if acn == 1 then -- chooses a random directory to create it into - local ri = math.random(adirs.size()) - local rp = adiri[dn] + local ri = math.random(#adiri) + local rp = adiri[ri] local np = rp..string.char(96 + math.random(26)).."/" if not adirp[np] then -- does not yet exist. - posix.mkdir(np) + cwriteln("mkdir "..srcdir..np) + posix.mkdir(srcdir..np) table.insert(adiri, np) adirp[np]=true 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 --- posix.kill(lpid) --- local _, exitmsg, exitcode = posix.wait(lpid) --- cwriteln("Exitcode of Lsyncd = ", exitmsg, " ", exitcode) --- os.exit(lexitcode) +exitcode = os.execute("diff -r "..srcdir.." "..trgdir) +cwriteln("Exitcode of diff = ", exitcode) +os.exit(exitcode) diff --git a/tests/testlib.lua b/tests/testlib.lua index 1405ae4..6301aac 100755 --- a/tests/testlib.lua +++ b/tests/testlib.lua @@ -31,12 +31,14 @@ end -- @returns the processes pid -- function spawn(...) + args = {...} + cwriteln("spawning: ", table.concat(args, " ")) local pid = posix.fork() if pid < 0 then cwriteln("Error, failed fork!") os.exit(-1) end - if lpid == 0 then + if pid == 0 then posix.exec(...) -- should not return cwriteln("Error, failed to spawn: ", ...)