diff --git a/tests/rand.lua b/tests/rand.lua deleted file mode 100755 index a4def70..0000000 --- a/tests/rand.lua +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/lua --- a heavy duty test. --- makes thousends of random changes to the source tree --- checks every X changes if lsyncd managed to keep target tree in sync. - -require("posix") - --- always makes the same "random", so failures can be debugged. -math.randomseed(1) - --- escape codes to colorize output on terminal -local c1="\027[47;34m" -local c0="\027[0m" - ---- --- writes colorized --- -function cwriteln(...) - io.write(c1) - io.write(...) - io.write(c0, "\n") -end - -cwriteln("******************************************************************") -cwriteln("* heavy duty tests duing randoms *") -cwriteln("******************************************************************") - -local lpid = posix.fork() -if lpid < 0 then - cwriteln("ERROR: failed fork!") - os.exit(-1); -end -if lpid == 0 then - posix.exec("./lsyncd", "-nodaemon", "-log", "all", "-rsync", "src", "trg") - -- should not return - cwriteln("ERROR: failed to spawn lysncd!") - os.exit(-1); -end - --- cleans the targets -os.execute("rm -rf src/*") -os.execute("rm -rf trg/*") -posix.sleep(1) - - -while true do - -- throw a die what to do - local acn = math.random(2) - if acn == 1 then - -- creates a directory - print(string.char(96)) - end - if acn == 2 then - -- creates a files - end - -end - --- kills the lsyncd daemon -posix.kill(lpid) -local _, exitmsg, exitcode = posix.wait(lpid) -cwriteln("Exitcode of Lsyncd = ", exitmsg, " ", exitcode) -os.exit(lexitcode) - diff --git a/tests/randomrsync.lua b/tests/randomrsync.lua new file mode 100755 index 0000000..3015f24 --- /dev/null +++ b/tests/randomrsync.lua @@ -0,0 +1,54 @@ +#!/usr/bin/lua +-- a heavy duty test. +-- makes thousends of random changes to the source tree +-- checks every X changes if lsyncd managed to keep target tree in sync. +require("posix") +dofile("tests/testlib.lua") + +-- always makes the same "random", so failures can be debugged. +math.randomseed(1) + +local tdir = mktempd() +cwriteln("using ", tdir, " as test root") + +local srcdir = tdir.."src/" +local trgdir = tdir.."trg/" + +posix.mkdir(srcdir) +posix.mkdir(trgdir) +spawn("./lsyncd","-nodaemon","-log","all","-rsync",srcdir,trgdir) + +-- lets Lsyncd startup +posix.sleep(1) + +-- all dirs created, indexed by integer and path +adiri = {""} +adirp = {[""]=true} + +for ai=1,100 do + -- throw a die what to do + local acn = math.random(1) + + -- 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 np = rp..string.char(96 + math.random(26)).."/" + if not adirp[np] then + -- does not yet exist. + posix.mkdir(np) + table.insert(adiri, np) + adirp[np]=true + end + end +end + + + +-- kills the lsyncd daemon +-- posix.kill(lpid) +-- local _, exitmsg, exitcode = posix.wait(lpid) +-- cwriteln("Exitcode of Lsyncd = ", exitmsg, " ", exitcode) +-- os.exit(lexitcode) + diff --git a/tests/testlib.lua b/tests/testlib.lua index a38b03a..1405ae4 100755 --- a/tests/testlib.lua +++ b/tests/testlib.lua @@ -1,7 +1,7 @@ -- common testing environment - require("posix") + -- escape codes to colorize output on terminal local c1="\027[47;34m" local c0="\027[0m" @@ -28,6 +28,8 @@ end ----- -- spawns a subprocess. -- +-- @returns the processes pid +-- function spawn(...) local pid = posix.fork() if pid < 0 then @@ -43,5 +45,3 @@ function spawn(...) return pid end -print(mktempd()) -