diff --git a/testing/istate/base/persistence-read/vars.log b/testing/istate/base/persistence-read/vars.log index 9a7d2c771e..129c730768 100644 --- a/testing/istate/base/persistence-read/vars.log +++ b/testing/istate/base/persistence-read/vars.log @@ -20,9 +20,9 @@ file "test" of string 2 } { -[3, GHI] = 103, [2, DEF] = 102, -[1, ABC] = 101 +[1, ABC] = 101, +[3, GHI] = 103 } { [12345] = /^?(12345)$?/, diff --git a/testing/istate/base/persistence-write/vars.log b/testing/istate/base/persistence-write/vars.log index 9a7d2c771e..129c730768 100644 --- a/testing/istate/base/persistence-write/vars.log +++ b/testing/istate/base/persistence-write/vars.log @@ -20,9 +20,9 @@ file "test" of string 2 } { -[3, GHI] = 103, [2, DEF] = 102, -[1, ABC] = 101 +[1, ABC] = 101, +[3, GHI] = 103 } { [12345] = /^?(12345)$?/, diff --git a/testing/istate/base/sync-rcv/remote.log b/testing/istate/base/sync-rcv/remote.log index 4feea4ccc3..01c0aa34cc 100644 --- a/testing/istate/base/sync-rcv/remote.log +++ b/testing/istate/base/sync-rcv/remote.log @@ -1,4 +1,4 @@ -xxxxxxxxxx.xxxxxx [info] [parent] pipe's socket buffer size is 8192, setting to 1048576 +xxxxxxxxxx.xxxxxx [info] [parent] raised pipe's socket buffer size from 126K to 1024K xxxxxxxxxx.xxxxxx [info] [parent] communication started, parent xxxxxxxxxx.xxxxxx [info] [parent] [#1/127.0.0.1:47757] added peer xxxxxxxxxx.xxxxxx [info] [child] [#1/127.0.0.1:47757] connected diff --git a/testing/istate/base/sync-rcv/vars.log b/testing/istate/base/sync-rcv/vars.log index 428ac7929d..a86d2a82da 100644 --- a/testing/istate/base/sync-rcv/vars.log +++ b/testing/istate/base/sync-rcv/vars.log @@ -20,9 +20,9 @@ file "test2" of string 2 } { -[3, GHI] = 103, [4, JKL] = 104, -[2, DEF] = 103 +[2, DEF] = 103, +[3, GHI] = 103 } { [12345] = /^?(12345)$?/, diff --git a/testing/istate/base/sync-send/vars.log b/testing/istate/base/sync-send/vars.log index 428ac7929d..a86d2a82da 100644 --- a/testing/istate/base/sync-send/vars.log +++ b/testing/istate/base/sync-send/vars.log @@ -20,9 +20,9 @@ file "test2" of string 2 } { -[3, GHI] = 103, [4, JKL] = 104, -[2, DEF] = 103 +[2, DEF] = 103, +[3, GHI] = 103 } { [12345] = /^?(12345)$?/, diff --git a/testing/istate/istate.py b/testing/istate/istate.py index 8c7b28fe4a..72b3eb4288 100755 --- a/testing/istate/istate.py +++ b/testing/istate/istate.py @@ -1,5 +1,5 @@ #! /usr/bin/env python -# +# # Tests persistence. # # $Id: istate.py,v 1.1.2.4 2005/10/11 22:31:42 sommer Exp $ @@ -14,82 +14,82 @@ import subprocess import tests optparser = optparse.OptionParser( usage = "%prog [options]", version = "0.1" ) -optparser.add_option( "-s", "--show-diff", action = "store_true", dest = "showdiff", +optparser.add_option( "-s", "--show-diff", action = "store_true", dest = "showdiff", default = False, help = "show diffs of mismatches" ) -optparser.add_option( "-b", "--new-base", action = "store_true", dest = "newbase", +optparser.add_option( "-b", "--new-base", action = "store_true", dest = "newbase", default = False, help = "create new baseline" ) -optparser.add_option( "-d", "--debug", action = "store_true", dest = "debug", +optparser.add_option( "-d", "--debug", action = "store_true", dest = "debug", default = False, help = "enable debug output" ) -optparser.add_option( "-t", "--set", action = "store", type = "string", dest = "set", +optparser.add_option( "-t", "--set", action = "store", type = "string", dest = "set", default = None, help = "only do given test set" ) - + ( tests.Options, args ) = optparser.parse_args() if len(args) != 0: optparser.error( "Wrong number of arguments" ) -########################################## +########################################## # Write persistent data and read it back. ########################################## if tests.testSet("persistence"): - tests.spawnBro("persistence-write", - ["-r", os.path.join(tests.Traces, "empty.trace"), + tests.spawnBro("persistence-write", + ["-r", os.path.join(tests.Traces, "empty.trace"), os.path.join(tests.Scripts, "vars-init.bro"), os.path.join(tests.Scripts, "vars-print.bro")]) tests.waitProc("persistence-write") tests.finishTest("persistence-write", ["stdout.log", "stderr.log", "vars.log"]) - tests.spawnBro("persistence-read", + tests.spawnBro("persistence-read", [os.path.join(tests.Scripts, "vars-declare.bro"), - os.path.join(tests.Scripts, "vars-print.bro")], + os.path.join(tests.Scripts, "vars-print.bro")], copy=[os.path.join(tests.workDir("persistence-write"), ".state")]) tests.waitProc("persistence-read") tests.finishTest("persistence-read", ["stdout.log", "stderr.log", "vars.log"]) tests.compareFiles("persistence-write", "persistence-read", ["vars.log"]) -########################################## +########################################## # Exchange events (clear-text). # -# The used trace contains two connections separated by a silence of a -# couple of seconds. We start the processes so that the events for the +# The used trace contains two connections separated by a silence of a +# couple of seconds. We start the processes so that the events for the # *second* one (which is a full HTTP connection) are exchanged. -########################################## +########################################## if tests.testSet("events"): - tests.spawnBro("events-send", - ["-r", os.path.join(tests.Scripts, os.path.join(tests.Traces, "web.trace")), - "--pseudo-realtime", + tests.spawnBro("events-send", + ["-r", os.path.join(tests.Scripts, os.path.join(tests.Traces, "web.trace")), + "--pseudo-realtime", "-C", os.path.join(tests.Scripts, "events-send.bro")]) time.sleep(2) - tests.spawnBro("events-rcv", + tests.spawnBro("events-rcv", [os.path.join(tests.Scripts, "events-rcv.bro")]) tests.waitProc("events-send") tests.killProc("events-rcv") tests.finishTest("events-send", ["stdout.log", "stderr.log", "http.log", "conn.log"], ignoreTime=True) tests.finishTest("events-rcv", ["stdout.log", "stderr.log", "http.log", "conn.log"], ignoreTime=True) - tests.spawnBro("events-display", + tests.spawnBro("events-display", ["-x", os.path.join(tests.workDir("events-rcv"), "events.bst")]) tests.waitProc("events-display") tests.finishTest("events-display", ["stdout.log"], ignoreTime=True, sort=True, delete=['127.0.0.1:[0-9]*',"Event.*remote_.*"]) tests.compareFiles("events-send", "events-rcv", ["http.log"], ignoreTime=True, ignoreSessionID=True) -########################################## +########################################## # Exchange synchronized state -########################################## +########################################## if tests.testSet("sync"): - tests.spawnBro("sync-send", + tests.spawnBro("sync-send", [os.path.join(tests.Scripts, "vars-sync-send.bro")]) - tests.spawnBro("sync-rcv", + tests.spawnBro("sync-rcv", [os.path.join(tests.Scripts, "vars-sync-rcv.bro")]) tests.waitProc("sync-send") time.sleep(1) @@ -99,10 +99,10 @@ if tests.testSet("sync"): tests.compareFiles("sync-send", "sync-rcv", ["vars.log"], ignoreTime=True) -# Old version -# tests.spawnBro("sync-send", -# ["-r", os.path.join(tests.Scripts, os.path.join(tests.Traces, "web.trace")), -# "--pseudo-realtime", +# Old version +# tests.spawnBro("sync-send", +# ["-r", os.path.join(tests.Scripts, os.path.join(tests.Traces, "web.trace")), +# "--pseudo-realtime", # "-C", # os.path.join(tests.Scripts, "vars-sync-send.bro")]) @@ -113,22 +113,22 @@ if tests.testSet("sync"): if tests.testSet("broccoli"): - broctest = os.path.join(tests.Bro, "aux/broccoli/test") - broclib = os.path.join(tests.Bro, "aux/broccoli/src/.libs") - broping = os.path.join(broctest, "broping") + broctest = os.path.join(tests.BroBase, "aux/broccoli/test") + broclib = os.path.join(tests.BroBase, "build/aux/broccoli/src/") + broping = os.path.join(tests.BroBase, "build/aux/broccoli/test/broping") - brocpy = os.path.join(tests.Bro, "aux/broccoli/bindings/python") + brocpy = os.path.join(tests.BroBase, "build/aux/broccoli/bindings/broccoli-python") broccoli = True - + # Test if Broccoli was compiled. if not os.path.exists(broping): print " Broccoli was not compiled, skipping tests." broccoli = False - - # Test if this is a IPv6 Bro. + + # Test if this is a IPv6 Bro. if broccoli: - v6 = subprocess.call(["grep", "-q", "#define BROv6", os.path.join(tests.Bro, "config.h")]) + v6 = subprocess.call(["grep", "-q", "#define BROv6", os.path.join(tests.BroBase, "build/config.h")]) if v6 == 0: print " Bro built with IPv6 support not compatible with Broccoli, skipping tests." broccoli = False @@ -136,21 +136,21 @@ if tests.testSet("broccoli"): if broccoli: tests.spawnBro("bro-ping", [os.path.join(broctest, "broping-record.bro")]) time.sleep(1) - tests.spawnProc("broccoli-ping", - [broping, - "-r", - "-c", "5", + tests.spawnProc("broccoli-ping", + [broping, + "-r", + "-c", "5", "127.0.0.1"]) tests.waitProc("broccoli-ping") tests.killProc("bro-ping") - - tests.finishTest("bro-ping", ["stdout.log", "stderr.log", "remote.log"], - ignoreTime=True, delete=["127.0.0.1:[0-9]*", "pid.*pid.*", - ".*Resource temporarily unavailable.*", ".*connection closed.*", + + tests.finishTest("bro-ping", ["stdout.log", "stderr.log", "remote.log"], + ignoreTime=True, delete=["127.0.0.1:[0-9]*", "pid.*pid.*", + ".*Resource temporarily unavailable.*", ".*connection closed.*", ".*peer disconnected.*"]) tests.finishTest("broccoli-ping", ["stdout.log", "stderr.log"], delete=["time=.* s$"]) - + # Test if Python binding are installed. sopath = subprocess.Popen(["find", brocpy, "-name", "_broccoli_intern.so"], stdout=subprocess.PIPE).communicate()[0] if sopath != "": @@ -158,7 +158,7 @@ if tests.testSet("broccoli"): os.environ["LD_LIBRARY_PATH"] = broclib os.environ["DYLD_LIBRARY_PATH"] = broclib os.environ["PYTHONPATH"] = os.path.dirname(sopath) - + tests.spawnBro("python-bro", [os.path.join(brocpy, "tests/test.bro")]) time.sleep(1) tests.spawnProc("python-script", [os.path.join(brocpy, "tests/test.py")]) @@ -169,6 +169,6 @@ if tests.testSet("broccoli"): else: print " Python bindings not built, skipping test." print " (To build: cd %s && python setup.py build)" % brocpy - - + + diff --git a/testing/istate/tests.py b/testing/istate/tests.py index a8bbb5172a..0673108563 100644 --- a/testing/istate/tests.py +++ b/testing/istate/tests.py @@ -13,11 +13,11 @@ import subprocess Testing = os.path.abspath(".") # Path to top-level Bro directory. -if os.path.exists("../../src/bro"): - Bro = os.path.abspath("../..") +if os.path.exists("../../build/src/bro"): + BroBase = os.path.abspath("../..") else: - Bro = os.path.abspath("../../bro") - + error("cannot find build directory") + # Path where tmp files are created. Tmp = os.path.join(Testing, "tmp") @@ -32,7 +32,7 @@ Traces = os.path.join(Testing, "traces") # Where the base files to compare against are stored. Base = os.path.join(os.getcwd(), "./base") - + # Process ID of all processes we've spawned, indexed by textual tag *and* pid. Running = {} @@ -46,40 +46,40 @@ def error(str): print >>sys.stderr, "Error:", str sys.exit(1) -def debug(str): +def debug(str): if Options.debug: print >>sys.stderr, "Debug:", str -def log(str): +def log(str): print >>sys.stderr, str # Returns full path of given process' working directory. -def workDir(tag): +def workDir(tag): return os.path.join(Tmp, tag) # Intializes work dir for given process. def initWorkDir(tag): - + try: os.mkdir(Tmp) except OSError, e: if e.errno != errno.EEXIST: raise - + os.system("rm -rf " + workDir(tag)) os.mkdir(workDir(tag)) # Spawns process identified by the given tag. Enters process into RunningBro. -def spawnProc(tag, cmdline, copy=[]): +def spawnProc(tag, cmdline, copy=[]): initWorkDir(tag) os.chdir(workDir(tag)) for i in copy: debug("Copying %s into workdir of %s" % (i, tag)) os.system("cp -r %s %s" % (i, workDir(tag))) - + debug("Spawning '%s' as %s" % (" ".join(cmdline), tag)) - + saved_stdin = os.dup(0) saved_stdout = os.dup(1) saved_stderr = os.dup(2) @@ -93,31 +93,34 @@ def spawnProc(tag, cmdline, copy=[]): os.dup2(saved_stdin, 0) os.dup2(saved_stdout, 1) os.dup2(saved_stderr, 2) - + Running[tag] = pid Running[pid] = tag -# Spaws a Bro process. +# Spaws a Bro process. def spawnBro(tag, args, copy=[]): - os.putenv("BROPATH", os.path.join(Bro, "policy") + ":" + Scripts) + bropath = os.path.join(BroBase, "policy") + bropath += ":" + os.path.join(BroBase, "build/src") + + os.putenv("BROPATH", bropath + ":" + Scripts) os.unsetenv("BRO_LOG_SUFFIX") args += ["--load-seeds", BroSeed, "-B", "state,comm"] - spawnProc(tag, [os.path.join(Bro, "src/bro")] + args, copy=copy) - -# Examines a process' exit code. -def parseExitCode(tag, result): + spawnProc(tag, [os.path.join(BroBase, "build/src/bro")] + args, copy=copy) + +# Examines a process' exit code. +def parseExitCode(tag, result): if os.WCOREDUMP(result): error("process %s core dumped." % tag) if os.WIFSIGNALED(result): error("process %s got signal %d." % (tag, os.WTERMSIG(result))) - + if not os.WIFEXITED(result): error("process %s exited abnormally (%d)." % (tag, result)) result = os.WEXITSTATUS(result) - debug("process %s exited with %d" % (tag, result)) - + debug("process %s exited with %d" % (tag, result)) + return result # Waits for process to finish. @@ -126,7 +129,7 @@ def waitProc(tag): result = parseExitCode(tag, result) if result != 0: error("Execution of %s failed." % tag) - + del Running[pid] del Running[tag] @@ -147,43 +150,43 @@ def killProc(tag): parseExitCode(tag, result) del Running[pid] del Running[tag] - + # Cleans up temporary stuff def cleanup(): os.system("rm -rf " + Tmp) # Canonicalizes file content for diffing. def canonicalizeFile(file, ignoreTime, ignoreSessionID, sort, delete): - + cmd = [] - + if delete: for i in delete: cmd += ["sed 's/%s//g' | grep -v '^$'" % i] - + if ignoreTime: cmd += ["sed 's/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\.[0-9][0-9]\{0,6\}/xxxxxxxxxx.xxxxxx/g'"] if ignoreSessionID: # A session is either "%1" or "%my-peer-description-1" cmd += ["sed 's/%\([^ ]*-\)\{0,1\}[0-9][0-9]*/%XXX/g'"] - + if sort: cmd += ["LC_ALL=c sort"] - + if not cmd: return - + tmp = file + ".tmp" - cmd = "cat %s | %s >%s" % (file, " | ".join(cmd), tmp) + cmd = "cat %s | %s >%s" % (file, " | ".join(cmd), tmp) debug("Canonicalizing '%s'" % cmd) os.system(cmd) os.system("mv %s %s" % (tmp, file)) -# Diffs the two files, If mismatch, prints "FAILED" and returns true. +# Diffs the two files, If mismatch, prints "FAILED" and returns true. def diff(file1, file2): - + quiet = ">/dev/null" if Options.showdiff: quiet = "" @@ -192,37 +195,37 @@ def diff(file1, file2): if not os.path.exists(f): print "FAILED (%s does not exist)" % f return False - + diff = "diff -u %s %s %s" % (file1, file2, quiet) - + debug("Executing '%s'" % diff) result = os.system(diff) - + if os.WEXITSTATUS(result) != 0: print "FAILED" return False - + return True - + # Compares files of process against base version. Returns false if mismatch found. def checkFiles(tag, files, ignoreTime, sort, delete): base = os.path.join(Base, tag) work = workDir(tag) - + print " Checking %s..." % tag, - + failed = False - + for file in files: oldfile = os.path.join(base, file) newfile = os.path.join(work, file) canonicalizeFile(newfile, ignoreTime, False, sort, delete) - + if not diff(oldfile, newfile): failed = True break - + if not failed: print "ok" else: @@ -234,25 +237,25 @@ def compareFiles(tag1, tag2, files, ignoreTime=False, ignoreSessionID=False, sor work2 = workDir(tag2) print " Comparing %s with %s..." % (tag1, tag2), - + failed = False - + for file in files: file1 = os.path.join(work1, file) file2 = os.path.join(work2, file) canonicalizeFile(file1, ignoreTime, ignoreSessionID, sort, delete) canonicalizeFile(file2, ignoreTime, ignoreSessionID, sort, delete) - + if not diff(file1, file2): failed = True break - + if not failed: print "ok" else: Failed = failed - + # Make the result of process new baseline. def makeNewBase(tag, files, ignoreTime, sort, delete): @@ -261,21 +264,21 @@ def makeNewBase(tag, files, ignoreTime, sort, delete): except OSError, e: if e.errno != errno.EEXIST: raise - + base = os.path.join(Base, tag) work = workDir(tag) print " Copying files for %s..." % tag - + try: os.mkdir(base) except OSError, e: if e.errno != errno.EEXIST: raise - + # Delete all files but those belonging to CVS. os.system("find %s -type f -not -path '*/CVS/*' -not -path '*/.svn/*' -exec rm '{}' ';'" % base) - + for file in files: oldfile = os.path.join(work, file) newfile = os.path.join(base, file) @@ -285,13 +288,13 @@ def makeNewBase(tag, files, ignoreTime, sort, delete): def testSet(set): if Options.set and set != Options.set: return False - + print "Running set '%s' ..." % set return True - + # Either check given files or make it new baseline, depending on options. def finishTest(tag, files, ignoreTime=False, sort=False, delete=None): if Options.newbase: makeNewBase(tag, files, ignoreTime, sort, delete) else: - checkFiles(tag, files, ignoreTime, sort, delete) + checkFiles(tag, files, ignoreTime, sort, delete)