This commit is contained in:
adam-m 2012-07-23 17:30:08 -04:00
commit d2592e115e

View File

@ -11,19 +11,22 @@ import xml
from xml.dom.minidom import parse, parseString from xml.dom.minidom import parse, parseString
# Last modified 7/17/12 @5pm # Last modified 7/23/12 @3:00pm
# Usage: ./regression.py [-s FILE] OR [-l CONFIG] [OPTIONS] # Usage: ./regression.py [-f FILE] OR [-l CONFIG] [OPTIONS]
# Run the RegressionTest.java file, and compare the result with a gold standard # Run the RegressionTest.java file, and compare the result with a gold standard
# When the -i flag is set, this script only tests the image given by FILE. # When the -f flag is set, this script only tests the image given by FILE.
# An indexed NSRL database is expected at ./input/nsrl.txt-md5.idx, # An indexed NSRL database is expected at ./input/nsrl.txt-md5.idx,
# and an indexed notable hash database at ./input/notablehashes.txt-md5.idx # and an indexed notable hash database at ./input/notablehashes.txt-md5.idx
# In addition, any keywords to search for must be in ./input/notablekeywords.xml # In addition, any keywords to search for must be in ./input/notablekeywords.xml
# When the -l flag is set, the script looks for a config.xml file of the given name # When the -l flag is set, the script looks for a config.xml file of the given name
# where images are stored. For usage notes please see the example "config.xml" in # where images are stored. The above input files can be outsourced to different locations
# from the config.xml. For usage notes please see the example "config.xml" in
# the /script folder. # the /script folder.
# Options: # Options:
# -r, --rebuild Rebuild the gold standards from the test results for each image # -r, --rebuild Rebuild the gold standards from the test results for each image
# -i, --ignore Ignores unallocated space when ingesting. Faster, but less accurate results. # -i, --ignore Ignores the ./input directory when searching for files
# -u, --unallocated Ignores unallocated space when ingesting. Faster, but less accurate results.
# -d, --delete Disables the deletion of Solr indexing directory generated by Ingest. Uses more disk space..
hadErrors = False # If any of the tests failed hadErrors = False # If any of the tests failed
@ -119,8 +122,8 @@ def getImageSize(inFile, list):
filename = os.path.splitext(files)[0] filename = os.path.splitext(files)[0]
if filename == name: if filename == name:
filepath = os.path.join(path, files) filepath = os.path.join(path, files)
if not os.path.samefile(filepath, inFile): if not os.path.samefile(filepath, inFile):
size += os.path.getsize(filepath) size += os.path.getsize(filepath)
size += os.path.getsize(inFile) size += os.path.getsize(inFile)
return size return size
@ -235,6 +238,17 @@ def copyReportToGold(inFile, ignoreUnalloc, list):
else: else:
shutil.copy(testReport, goldReport) shutil.copy(testReport, goldReport)
def deleteKeywordFiles(inFile, ignoreUnalloc, list):
print "------------------------------------------------"
print "Deleting Keyword Search files"
inFile = imageName(inFile)
if ignoreUnalloc:
inFile += "-u"
if list:
inFile += "-l"
cwd = wgetcwd()
shutil.rmtree(os.path.join("./", outDir, inFile, "AutopsyTestCase", "KeywordSearch"))
def testCompareReports(inFile, ignoreUnalloc, list): def testCompareReports(inFile, ignoreUnalloc, list):
print "------------------------------------------------" print "------------------------------------------------"
print "Comparing report to golden report." print "Comparing report to golden report."
@ -342,6 +356,8 @@ def wabspath(inFile):
out,err = proc.communicate() out,err = proc.communicate()
return out.rstrip() return out.rstrip()
def copyLogs(inFile, ignoreUnalloc, list): def copyLogs(inFile, ignoreUnalloc, list):
name = imageName(inFile) name = imageName(inFile)
if ignoreUnalloc: if ignoreUnalloc:
@ -351,7 +367,7 @@ def copyLogs(inFile, ignoreUnalloc, list):
logDir = os.path.join("..","build","test","qa-functional","work","userdir0","var","log") logDir = os.path.join("..","build","test","qa-functional","work","userdir0","var","log")
shutil.copytree(logDir,os.path.join(outDir,name,"logs")) shutil.copytree(logDir,os.path.join(outDir,name,"logs"))
def testFile(image, rebuild, ignoreUnalloc, list): def testFile(image, rebuild, ignoreUnalloc, list, delete):
if imageType(image) != ImgType.UNKNOWN: if imageType(image) != ImgType.UNKNOWN:
testAddImageIngest(image, ignoreUnalloc, list) testAddImageIngest(image, ignoreUnalloc, list)
copyLogs(image, ignoreUnalloc, list) copyLogs(image, ignoreUnalloc, list)
@ -359,25 +375,31 @@ def testFile(image, rebuild, ignoreUnalloc, list):
clearGoldDir(image, ignoreUnalloc, list) clearGoldDir(image, ignoreUnalloc, list)
copyTestToGold(image, ignoreUnalloc, list) copyTestToGold(image, ignoreUnalloc, list)
copyReportToGold(image, ignoreUnalloc, list) copyReportToGold(image, ignoreUnalloc, list)
if delete:
deleteKeywordFiles(image, ignoreUnalloc, list)
else: else:
testCompareToGold(image, ignoreUnalloc, list) testCompareToGold(image, ignoreUnalloc, list)
testCompareReports(image, ignoreUnalloc, list) testCompareReports(image, ignoreUnalloc, list)
def usage(): def usage():
usage = "\ usage = "\
Usage: ./regression.py [-s FILE] [OPTIONS] \n\n\ Usage: ./regression.py [-f FILE] [OPTIONS] \n\n\
Run the RegressionTest.java file, and compare the result with a gold standard \n\n\ Run the RegressionTest.java file, and compare the result with a gold standard \n\n\
When the -i flag is set, this script only tests the image given by FILE.\n\ When the -f flag is set, this script only tests the image given by FILE.\n\
By default, it tests every image in ./input/\n\n\ By default, it tests every image in ./input/\n\n\
An indexed NSRL database is expected at ./input/nsrl.txt-md5.idx,\n\ An indexed NSRL database is expected at ./input/nsrl.txt-md5.idx,\n\
and an indexed notable hash database at ./input/notablehashes.txt-md5.idx\n\ and an indexed notable hash database at ./input/notablehashes.txt-md5.idx\n\
In addition, any keywords to search for must be in ./input/notablekeywords.xml\n\n\ In addition, any keywords to search for must be in ./input/notablekeywords.xml\n\n\
When the -l flag is set, the script looks for a config.xml file of the given name\n\ When the -l flag is set, the script looks for a config.xml file of the given name\n\
where images are stored. For usage notes please see the example config.xml in\n\ where images are stored. The above input files may be outsources to a different folder\n\
via the config file. For usage notes please see the example \"config.xml\" in\n\
the /script folder.\ the /script folder.\
Options:\n\n\ Options:\n\n\
-r, --rebuild\t\tRebuild the gold standards from the test results for each image\n\n\ -r, --rebuild\t\tRebuild the gold standards from the test results for each image.\n\n\
-u, --ignore\t\tIgnore unallocated space while ingesting" -i, --ignore\t\tIgnores the ./input directory when searching for files. ONLY use in combinatin with a config file.\n\n\
-u, --unallocated\t\tIgnores unallocated space when ingesting. Faster, but less accurate results.\n\n\
-d, --delete\t\tDisables the deletion of Solr indexing directory generated by Ingest. Uses more disk space."
return usage return usage
def main(): def main():
@ -387,21 +409,21 @@ def main():
ignoreUnalloc = False ignoreUnalloc = False
list = False list = False
test = True test = True
delete = True
argi = 1 argi = 1
Config = None #file pointed to by --list Config = None #file pointed to by --list
imgListB = [] #list of legal images from config imgListB = [] #list of legal images from config
cwd = wgetcwd() cwd = wgetcwd()
while argi < len(sys.argv): while argi < len(sys.argv):
arg = sys.argv[argi] arg = sys.argv[argi]
if arg == "-s" and argi+1 < len(sys.argv): #check for single if arg == "-f" and argi+1 < len(sys.argv): #check for single
single = True single = True
test = False test = False
argi+=1 argi+=1
image = sys.argv[argi] image = sys.argv[argi]
print "Running on single image: " + image print "Running on single image: " + image
if arg == "-l" or arg == "--list": #check for config file elif arg == "-l" or arg == "--list": #check for config file
list = True list = True
argi+=1 argi+=1
#check for file in ./ #check for file in ./
if(os.path.isfile(os.path.join("./", sys.argv[argi]))): if(os.path.isfile(os.path.join("./", sys.argv[argi]))):
@ -416,18 +438,21 @@ def main():
elif (arg == "--rebuild") or (arg == "-r"): #check for rebuild flag elif (arg == "--rebuild") or (arg == "-r"): #check for rebuild flag
rebuild = True rebuild = True
print "Running in REBUILD mode" print "Running in REBUILD mode"
elif (arg == "-u"): #check for ignore unallocated space flag elif (arg == "-u") or (arg == "--unallocated"): #check for ignore unallocated space flag
ignoreUnalloc = True ignoreUnalloc = True
print "Ignoring unallocated space" print "Ignoring unallocated space"
elif (arg == "--ignore") or (arg == "-i"): elif (arg == "--ignore") or (arg == "-i"):
ignoreInput = True ignoreInput = True
print "Ignoring /script/input directory" print "Ignoring /script/input directory"
elif (arg == "--delete") or (arg == "-d"):
delete = True
print "Will not delete keyword search Solr index"
else: else:
test = False test = False
print usage() print usage()
argi+=1 argi+=1
if single: if single:
testFile(image, rebuild, ignoreUnalloc, list) testFile(image, rebuild, ignoreUnalloc, list, delete)
if list: if list:
listImages = [] listImages = []
errors = 0 errors = 0
@ -446,14 +471,14 @@ def main():
errors+=1 errors+=1
print "Illegal files specified: " + str(errors) print "Illegal files specified: " + str(errors)
for image in listImages: for image in listImages:
testFile(image, rebuild, ignoreUnalloc, list) testFile(image, rebuild, ignoreUnalloc, list, delete)
if not ignoreInput: if not ignoreInput:
global inDir global inDir
inDir = os.path.join(cwd, "input") inDir = os.path.join(cwd, "input")
test = True test = True
if test: if test:
for inFile in os.listdir(inDir): for inFile in os.listdir(inDir):
testFile(os.path.join(inDir,inFile), rebuild, ignoreUnalloc, list) testFile(os.path.join(inDir,inFile), rebuild, ignoreUnalloc, list, delete)
if hadErrors == True: if hadErrors == True:
print "**********************************************" print "**********************************************"