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