Regression.py will now by default check ./input for images when being run with -l unless explicitly told otherwise

This commit is contained in:
0xNF 2012-07-20 16:26:34 -04:00
parent 35bc7b1cb6
commit 598eea4de9
2 changed files with 77 additions and 58 deletions

View File

@ -44,7 +44,7 @@ def testAddImageIngest(inFile, ignoreUnalloc, list):
#check for flags to append to folder name #check for flags to append to folder name
if ignoreUnalloc: if ignoreUnalloc:
testCaseName+="-i" testCaseName+="-u"
if list: if list:
testCaseName+="-l" testCaseName+="-l"
if os.path.exists(os.path.join(outDir,testCaseName)): if os.path.exists(os.path.join(outDir,testCaseName)):
@ -124,13 +124,13 @@ def getImageSize(inFile, list):
size += os.path.getsize(inFile) size += os.path.getsize(inFile)
return size return size
def testCompareToGold(inFile, ignore): def testCompareToGold(inFile, ignoreUnalloc, list):
print "-----------------------------------------------" print "-----------------------------------------------"
print "Comparing results for " + inFile + " with gold." print "Comparing results for " + inFile + " with gold."
name = imageName(inFile) name = imageName(inFile)
if ignore: if ignoreUnalloc:
name += ("-i") name += ("-u")
cwd = wgetcwd() cwd = wgetcwd()
goldFile = os.path.join("./",goldDir,name,"standard.db") goldFile = os.path.join("./",goldDir,name,"standard.db")
testFile = os.path.join("./",outDir,name,"AutopsyTestCase","autopsy.db") testFile = os.path.join("./",outDir,name,"AutopsyTestCase","autopsy.db")
@ -187,23 +187,23 @@ def testCompareToGold(inFile, ignore):
else: else:
print("Object counts match!") print("Object counts match!")
def clearGoldDir(inFile, ignore, list): def clearGoldDir(inFile, ignoreUnalloc, list):
cwd = wgetcwd() cwd = wgetcwd()
inFile = imageName(inFile) inFile = imageName(inFile)
if ignore: if ignoreUnalloc:
inFile += "-i" inFile += "-u"
if list: if list:
inFile += "-l" inFile += "-l"
if os.path.exists(os.path.join(cwd,goldDir,inFile)): if os.path.exists(os.path.join(cwd,goldDir,inFile)):
shutil.rmtree(os.path.join(cwd,goldDir,inFile)) shutil.rmtree(os.path.join(cwd,goldDir,inFile))
os.makedirs(os.path.join(cwd,goldDir,inFile)) os.makedirs(os.path.join(cwd,goldDir,inFile))
def copyTestToGold(inFile, ignore, list): def copyTestToGold(inFile, ignoreUnalloc, list):
print "------------------------------------------------" print "------------------------------------------------"
print "Recreating gold standard from results." print "Recreating gold standard from results."
inFile = imageName(inFile) inFile = imageName(inFile)
if ignore: if ignoreUnalloc:
inFile += "-i" inFile += "-u"
if list: if list:
inFile += "-l" inFile += "-l"
cwd = wgetcwd() cwd = wgetcwd()
@ -211,12 +211,12 @@ def copyTestToGold(inFile, ignore, list):
testFile = os.path.join("./",outDir,inFile,"AutopsyTestCase","autopsy.db") testFile = os.path.join("./",outDir,inFile,"AutopsyTestCase","autopsy.db")
shutil.copy(testFile, goldFile) shutil.copy(testFile, goldFile)
def copyReportToGold(inFile, ignore, list): def copyReportToGold(inFile, ignoreUnalloc, list):
print "------------------------------------------------" print "------------------------------------------------"
print "Recreating gold report from results." print "Recreating gold report from results."
inFile = imageName(inFile) inFile = imageName(inFile)
if ignore: if ignoreUnalloc:
inFile += "-i" inFile += "-u"
if list: if list:
inFile += "-l" inFile += "-l"
cwd = wgetcwd() cwd = wgetcwd()
@ -235,12 +235,12 @@ def copyReportToGold(inFile, ignore, list):
else: else:
shutil.copy(testReport, goldReport) shutil.copy(testReport, goldReport)
def testCompareReports(inFile, ignore, list): def testCompareReports(inFile, ignoreUnalloc, list):
print "------------------------------------------------" print "------------------------------------------------"
print "Comparing report to golden report." print "Comparing report to golden report."
name = imageName(inFile) name = imageName(inFile)
if ignore: if ignoreUnalloc:
name += "-i" name += "-u"
if list: if list:
name += "-l" name += "-l"
goldReport = os.path.join("./",goldDir,name,"report.html") goldReport = os.path.join("./",goldDir,name,"report.html")
@ -342,26 +342,26 @@ def wabspath(inFile):
out,err = proc.communicate() out,err = proc.communicate()
return out.rstrip() return out.rstrip()
def copyLogs(inFile, ignore, list): def copyLogs(inFile, ignoreUnalloc, list):
name = imageName(inFile) name = imageName(inFile)
if ignore: if ignoreUnalloc:
name +="-i" name +="-u"
if list: if list:
name+="-l" name+="-l"
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, ignore, list): def testFile(image, rebuild, ignoreUnalloc, list):
if imageType(image) != ImgType.UNKNOWN: if imageType(image) != ImgType.UNKNOWN:
testAddImageIngest(image, ignore, list) testAddImageIngest(image, ignoreUnalloc, list)
copyLogs(image, ignore, list) copyLogs(image, ignoreUnalloc, list)
if rebuild: if rebuild:
clearGoldDir(image, ignore, list) clearGoldDir(image, ignoreUnalloc, list)
copyTestToGold(image, ignore, list) copyTestToGold(image, ignoreUnalloc, list)
copyReportToGold(image, ignore, list) copyReportToGold(image, ignoreUnalloc, list)
else: else:
testCompareToGold(image, ignore, list) testCompareToGold(image, ignoreUnalloc, list)
testCompareReports(image, ignore, list) testCompareReports(image, ignoreUnalloc, list)
def usage(): def usage():
usage = "\ usage = "\
@ -383,7 +383,8 @@ def usage():
def main(): def main():
rebuild = False rebuild = False
single = False single = False
ignore = False ignoreInput = False
ignoreUnalloc = False
list = False list = False
test = True test = True
argi = 1 argi = 1
@ -394,11 +395,13 @@ def main():
arg = sys.argv[argi] arg = sys.argv[argi]
if arg == "-s" and argi+1 < len(sys.argv): #check for single if arg == "-s" and argi+1 < len(sys.argv): #check for single
single = True single = True
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 if 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]))):
@ -413,24 +416,27 @@ 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 == "--ignore") or (arg == "-i"): #check for ignore flag elif (arg == "-u"): #check for ignore unallocated space flag
ignore = True ignoreUnalloc = True
print "Ignoring unallocated space" print "Ignoring unallocated space"
elif (arg == "--ignore") or (arg == "-i"):
ignoreInput = True
print "Ignoring /script/input directory"
else: else:
test = False test = False
print usage() print usage()
argi+=1 argi+=1
if single: if single:
testFile(image, rebuild, ignore) testFile(image, rebuild, ignoreUnalloc, list)
if list: if list:
listImages = [] listImages = []
errors = 0 errors = 0
global inDir global inDir
out = Config.getElementsByTagName("indir")[0].getAttribute("value").encode() #there should only be one indir element in the config out = Config.getElementsByTagName("indir")[0].getAttribute("value").encode() #there should only be one indir element in the config
inDir = out inDir = out
for element in Config.getElementsByTagName("image"): for element in Config.getElementsByTagName("image"):
elem = element.getAttribute("value").encode() elem = element.getAttribute("value").encode()
proc2 = subprocess.Popen(("cygpath", "-i", elem), stdout=subprocess.PIPE) proc2 = subprocess.Popen(("cygpath", "-u", elem), stdout=subprocess.PIPE)
out2,err = proc2.communicate() out2,err = proc2.communicate()
out2 = out2.rstrip() out2 = out2.rstrip()
if(os.path.exists(out2) and os.path.isfile(out2)): if(os.path.exists(out2) and os.path.isfile(out2)):
@ -440,10 +446,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, ignore, list) testFile(image, rebuild, ignoreUnalloc, list)
elif test: if not ignoreInput:
global inDir
inDir = os.path.join(cwd, "input")
test = True
if test:
for inFile in os.listdir(inDir): for inFile in os.listdir(inDir):
testFile(os.path.join(inDir,inFile), rebuild, ignore, list) testFile(os.path.join(inDir,inFile), rebuild, ignoreUnalloc, list)
if hadErrors == True: if hadErrors == True:
print "**********************************************" print "**********************************************"

View File

@ -28,29 +28,28 @@ https://github.com/sleuthkit/autopsy/blob/master/BUILDING.txt
1) Install Cygwin 1) Install Cygwin
1a) Download and run the Cygwin setup, available at Download and run the Cygwin setup, available at
http://www.cygwin.com/setup.exe http://www.cygwin.com/setup.exe
From the list of packages to install, select both Database and Python.
1b) From the list of packages to install, select both Database and Python.
2) Setting up Regression.py 2) Setting up Regression.py
2a) Place all images that you wish to regression test under Place all images that you wish to regression test under
autopsy/Testing/script/input autopsy/Testing/script/input
2b) Ensure that the following files are also under /input Ensure that the following files are also under /input
notablehashes.txt-md5.idx notablehashes.txt-md5.idx
nsrl.txt-md5.idx nsrl.txt-md5.idx
notablekeywords.xml notablekeywords.xml
2c) place the gold standard database files ("standards.db") for each image under place the gold standard database files ("standards.db") for each image under
autopsy/Testing/script/gold/{name of image} autopsy/Testing/script/gold/{name of image}
@ -60,39 +59,49 @@ https://github.com/sleuthkit/autopsy/blob/master/BUILDING.txt
3) Run regression tests 3) Run regression tests
3a) From the Cygwin terminal, navigate to the /script folder and run "./regression.py". The script will automatically begin Autopsy and run ingestion and analysis on all the images from the ./input directory, and will close when finished. The Cygwin terminal will print out whether or not errors were encountered at the end of each image's test. From the Cygwin terminal, navigate to the /script folder and run "./regression.py".
The script will automatically begin Autopsy and run ingestion and analysis on all the images from the ./input directory, and will close when finished.
The Cygwin terminal will print out whether or not errors were encountered at the end of each image's test.
3b) It is possible to run testing on images that do not reside within ./input. To accomplish this, a configuration file is specified as a flag when run. Please see 4 below. It is possible to run testing on images that do not reside within ./input.
To accomplish this, a configuration file is specified as a flag when run. Please see 4 below.
\section regression_test_update Options Options:
Currently, the script supports four argument parameters: Currently, the script supports four argument parameters:
-s {imgname} : runs the test with a single image as specified by {imgname}. Must include the path, it does not read from input. -s {imgname} : runs the test with a single image as specified by {imgname}. Must include the path, it does not read from input.
-r or --rebuild : runs in REBUILD mode, see 5 below -r or --rebuild : runs in REBUILD mode, see 5 below
-l {config} or --list {config} : runs with the specified {config} file. If you do not specify a path to the file, it searches for it under ./. It will attempt to search for the file by the specified path name if surrounded in quotes. -l {config} or --list {config} : runs with the specified {config} file. If you do not specify a path to the file, it searches for it under ./. It will attempt to search for the file by the specified path name if surrounded in quotes. By default will also search ./input for images in addition.
-u or --ignore : runs ignoring unallocated space. Useful for determining framework is operational. Appends "-u" to the output and gold folders for distinguishing them from others. Will automatically compare the right reports. -u : runs ignoring unallocated space. Useful for determining framework is operational. Appends "-u" to the output and gold folders for distinguishing them from others. Will automatically compare the right reports.
-i or --ignore : Will ignore the ./input directory. Use only in combination with -l
These can be run in any combination. These can be run in any combination.
\section regression_test_config Running regression tests with a config file \section regression_test_config Running regression tests with a config file
4) Running with a configuration file 4) Running with a configuration file
The config file is any user defined XML file that has the following properties: 1 element with the tag "indir" to specify where the hash databases are, and any number of elements with the tag "image", where the program will look for external images. These images do not have to be held locally. They may be on network shares, or other attached drives. We have included a sample "config.xml" in the script folder as a guide. Note that the config file may be named anything. The config file is any user defined XML file that has the following properties: 1 element with the tag "indir" to specify where the hash databases are, and any number of elements with the tag "image",
where the program will look for external images. These images do not have to be held locally. They may be on network shares, or other attached drives. We have included a sample "config.xml" in the script folder as a guide.
Note that the config file may be named anything.
5) OPTIONAL: Update the standards databases /section optional_standards_update OPTIONAL: Update the standards databases
5a) From the Cygwin terminal, navigate to From the Cygwin terminal, navigate to
autopsy/Testing/script autopsy/Testing/script
5b) run "./regression.py -r", The script will automatically delete pre-existing standards.db files and generate the updated ones in the proper locations (/script/gold/{name of image}). run:
./regression.py -r
The script will automatically delete pre-existing standards.db files and generate the updated ones in the proper locations (/script/gold/{name of image}).
Running in -r will also generate a golden report file built from the image. Normal runs of regression.py compare their generated report against the golden one, and report any differences in the file, ignoring the timestamp. Running in -r will also generate a golden report file built from the image. Normal runs of regression.py compare their generated report against the golden one, and report any differences in the file, ignoring the timestamp.