mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-06 21:00:22 +00:00
Added screenshots and an output directory argument to the tester.
This commit is contained in:
parent
a7eb7b49ee
commit
3919f77ea8
@ -54,6 +54,8 @@ class Args:
|
|||||||
self.verbose = False
|
self.verbose = False
|
||||||
self.exception = False
|
self.exception = False
|
||||||
self.exception_string = ""
|
self.exception_string = ""
|
||||||
|
self.output = False
|
||||||
|
self.output_dir = ""
|
||||||
|
|
||||||
def parse(self):
|
def parse(self):
|
||||||
sys.argv.pop(0)
|
sys.argv.pop(0)
|
||||||
@ -99,11 +101,22 @@ class Args:
|
|||||||
try:
|
try:
|
||||||
arg = sys.argv.pop(0)
|
arg = sys.argv.pop(0)
|
||||||
printout("Running in exception mode: ")
|
printout("Running in exception mode: ")
|
||||||
printout("Printing all exceptions with the string '" + arg + "'\n")
|
printout("Printing all exceptions with the string '" + arg + "'.\n")
|
||||||
self.exception = True
|
self.exception = True
|
||||||
self.exception_string = arg
|
self.exception_string = arg
|
||||||
except:
|
except:
|
||||||
printerror("Error: No exception string given.")
|
printerror("Error: No exception string given.")
|
||||||
|
elif(arg == "-o" or arg == "--output"):
|
||||||
|
try:
|
||||||
|
arg = sys.argv.pop(0)
|
||||||
|
if dir_exists(arg):
|
||||||
|
printout("Running with output directory set to " + arg + ".\n")
|
||||||
|
self.output = True
|
||||||
|
self.output_dir = arg
|
||||||
|
else:
|
||||||
|
printerror("Error: Given output directory for -o doesn't exist.")
|
||||||
|
except:
|
||||||
|
printerror("Error: No output directory given.\n")
|
||||||
elif arg == "-h" or arg == "--help":
|
elif arg == "-h" or arg == "--help":
|
||||||
printout(usage())
|
printout(usage())
|
||||||
return False
|
return False
|
||||||
@ -366,7 +379,7 @@ def run_test(image_file):
|
|||||||
# Set the case to work for this test
|
# Set the case to work for this test
|
||||||
case.image_file = image_file
|
case.image_file = image_file
|
||||||
case.image_name = case.get_image_name(image_file)
|
case.image_name = case.get_image_name(image_file)
|
||||||
case.antlog_dir = make_local_path(case.output_dir, case.image_name, "antlog.txt")
|
case.antlog_dir = make_path(case.output_dir, case.image_name, "antlog.txt")
|
||||||
case.known_bad_path = make_path(case.input_dir, "notablehashes.txt-md5.idx")
|
case.known_bad_path = make_path(case.input_dir, "notablehashes.txt-md5.idx")
|
||||||
case.keyword_path = make_path(case.input_dir, "notablekeywords.xml")
|
case.keyword_path = make_path(case.input_dir, "notablekeywords.xml")
|
||||||
case.nsrl_path = make_path(case.input_dir, "nsrl.txt-md5.idx")
|
case.nsrl_path = make_path(case.input_dir, "nsrl.txt-md5.idx")
|
||||||
@ -387,7 +400,7 @@ def run_test(image_file):
|
|||||||
rebuild()
|
rebuild()
|
||||||
# If NOT keeping Solr index (-k)
|
# If NOT keeping Solr index (-k)
|
||||||
if not args.keep:
|
if not args.keep:
|
||||||
solr_index = make_local_path(case.output_dir, case.image_name, "AutopsyTestCase", "KeywordSearch")
|
solr_index = make_path(case.output_dir, case.image_name, "AutopsyTestCase", "KeywordSearch")
|
||||||
if clear_dir(solr_index):
|
if clear_dir(solr_index):
|
||||||
print_report([], "DELETE SOLR INDEX", "Solr index deleted.")
|
print_report([], "DELETE SOLR INDEX", "Solr index deleted.")
|
||||||
elif args.keep:
|
elif args.keep:
|
||||||
@ -440,7 +453,7 @@ def run_ant():
|
|||||||
case.ant.append("-Dkeyword_path=" + case.keyword_path)
|
case.ant.append("-Dkeyword_path=" + case.keyword_path)
|
||||||
case.ant.append("-Dnsrl_path=" + case.nsrl_path)
|
case.ant.append("-Dnsrl_path=" + case.nsrl_path)
|
||||||
case.ant.append("-Dgold_path=" + make_local_path(case.gold))
|
case.ant.append("-Dgold_path=" + make_local_path(case.gold))
|
||||||
case.ant.append("-Dout_path=" + make_local_path(case.output_dir, case.image_name))
|
case.ant.append("-Dout_path=" + make_path(case.output_dir, case.image_name))
|
||||||
case.ant.append("-Dignore_unalloc=" + "%s" % args.unallocated)
|
case.ant.append("-Dignore_unalloc=" + "%s" % args.unallocated)
|
||||||
case.ant.append("-Dtest.timeout=" + str(case.timeout))
|
case.ant.append("-Dtest.timeout=" + str(case.timeout))
|
||||||
|
|
||||||
@ -487,9 +500,9 @@ def rebuild():
|
|||||||
clear_dir(gold_dir)
|
clear_dir(gold_dir)
|
||||||
|
|
||||||
# Rebuild the database
|
# Rebuild the database
|
||||||
gold_from = make_local_path(case.output_dir, case.image_name,
|
gold_from = make_path(case.output_dir, case.image_name,
|
||||||
"AutopsyTestCase", "autopsy.db")
|
"AutopsyTestCase", "autopsy.db")
|
||||||
gold_to = make_local_path(case.gold, case.image_name, "standard.db")
|
gold_to = make_path(case.gold, case.image_name, "standard.db")
|
||||||
try:
|
try:
|
||||||
copy_file(gold_from, gold_to)
|
copy_file(gold_from, gold_to)
|
||||||
except FileNotFoundException as e:
|
except FileNotFoundException as e:
|
||||||
@ -499,7 +512,7 @@ def rebuild():
|
|||||||
errors.append(str(e) + "\n")
|
errors.append(str(e) + "\n")
|
||||||
|
|
||||||
# Rebuild the HTML report
|
# Rebuild the HTML report
|
||||||
html_path = make_local_path(case.output_dir, case.image_name,
|
html_path = make_path(case.output_dir, case.image_name,
|
||||||
"AutopsyTestCase", "Reports")
|
"AutopsyTestCase", "Reports")
|
||||||
try:
|
try:
|
||||||
html_from = get_file_in_dir(html_path, ".html")
|
html_from = get_file_in_dir(html_path, ".html")
|
||||||
@ -576,7 +589,7 @@ def compare_to_gold_db():
|
|||||||
# the regression test against the gold standard html report
|
# the regression test against the gold standard html report
|
||||||
def compare_to_gold_html():
|
def compare_to_gold_html():
|
||||||
gold_html_file = make_local_path(case.gold, case.image_name, "standard.html")
|
gold_html_file = make_local_path(case.gold, case.image_name, "standard.html")
|
||||||
autopsy_html_path = make_local_path(case.output_dir, case.image_name,
|
autopsy_html_path = make_path(case.output_dir, case.image_name,
|
||||||
"AutopsyTestCase", "Reports")
|
"AutopsyTestCase", "Reports")
|
||||||
try:
|
try:
|
||||||
autopsy_html_file = get_file_in_dir(autopsy_html_path, ".html")
|
autopsy_html_file = get_file_in_dir(autopsy_html_path, ".html")
|
||||||
@ -658,8 +671,8 @@ def compare_tsk_objects():
|
|||||||
# Generate the "common log": a log of all exceptions and warnings
|
# Generate the "common log": a log of all exceptions and warnings
|
||||||
# from each log file generated by Autopsy
|
# from each log file generated by Autopsy
|
||||||
def generate_common_log():
|
def generate_common_log():
|
||||||
#try:
|
try:
|
||||||
logs_path = make_local_path(case.output_dir, case.image_name, "logs")
|
logs_path = make_path(case.output_dir, case.image_name, "logs")
|
||||||
common_log = open(case.common_log, "a")
|
common_log = open(case.common_log, "a")
|
||||||
common_log.write("--------------------------------------------------\n")
|
common_log.write("--------------------------------------------------\n")
|
||||||
common_log.write(case.image_name + "\n")
|
common_log.write(case.image_name + "\n")
|
||||||
@ -677,15 +690,15 @@ def generate_common_log():
|
|||||||
log.close()
|
log.close()
|
||||||
common_log.write("\n\n")
|
common_log.write("\n\n")
|
||||||
common_log.close()
|
common_log.close()
|
||||||
#except Exception as e:
|
except Exception as e:
|
||||||
# printerror("Error: Unable to generate the common log.")
|
printerror("Error: Unable to generate the common log.")
|
||||||
# printerror(str(e))
|
printerror(str(e))
|
||||||
|
|
||||||
# Fill in the global case's variables that require the log files
|
# Fill in the global case's variables that require the log files
|
||||||
def fill_case_data():
|
def fill_case_data():
|
||||||
try:
|
try:
|
||||||
# Open autopsy.log.0
|
# Open autopsy.log.0
|
||||||
log_path = make_local_path(case.output_dir, case.image_name, "logs", "autopsy.log.0")
|
log_path = make_path(case.output_dir, case.image_name, "logs", "autopsy.log.0")
|
||||||
log = open(log_path)
|
log = open(log_path)
|
||||||
|
|
||||||
# Set the case starting time based off the first line of autopsy.log.0
|
# Set the case starting time based off the first line of autopsy.log.0
|
||||||
@ -845,7 +858,7 @@ def csv_header(csv_path):
|
|||||||
# Returns a list of all the exceptions listed in all the autopsy logs
|
# Returns a list of all the exceptions listed in all the autopsy logs
|
||||||
def get_exceptions():
|
def get_exceptions():
|
||||||
exceptions = []
|
exceptions = []
|
||||||
logs_path = make_local_path(case.output_dir, case.image_name, "logs")
|
logs_path = make_path(case.output_dir, case.image_name, "logs")
|
||||||
results = []
|
results = []
|
||||||
for file in os.listdir(logs_path):
|
for file in os.listdir(logs_path):
|
||||||
if "autopsy" in file:
|
if "autopsy" in file:
|
||||||
@ -881,7 +894,7 @@ def report_all_errors():
|
|||||||
# Searched all the known logs for the given regex
|
# Searched all the known logs for the given regex
|
||||||
# The function expects regex = re.compile(...)
|
# The function expects regex = re.compile(...)
|
||||||
def regex_search_logs(regex):
|
def regex_search_logs(regex):
|
||||||
logs_path = make_local_path(case.output_dir, case.image_name, "logs")
|
logs_path = make_path(case.output_dir, case.image_name, "logs")
|
||||||
results = []
|
results = []
|
||||||
for file in os.listdir(logs_path):
|
for file in os.listdir(logs_path):
|
||||||
log = open(make_path(logs_path, file), "r")
|
log = open(make_path(logs_path, file), "r")
|
||||||
@ -896,7 +909,7 @@ def regex_search_logs(regex):
|
|||||||
# Search through all the known log files for a specific string.
|
# Search through all the known log files for a specific string.
|
||||||
# Returns a list of all lines with that string
|
# Returns a list of all lines with that string
|
||||||
def search_logs(string):
|
def search_logs(string):
|
||||||
logs_path = make_local_path(case.output_dir, case.image_name, "logs")
|
logs_path = make_path(case.output_dir, case.image_name, "logs")
|
||||||
results = []
|
results = []
|
||||||
for file in os.listdir(logs_path):
|
for file in os.listdir(logs_path):
|
||||||
log = open(make_path(logs_path, file), "r")
|
log = open(make_path(logs_path, file), "r")
|
||||||
@ -921,7 +934,7 @@ def search_common_log(string):
|
|||||||
# Searches the given log for the given string
|
# Searches the given log for the given string
|
||||||
# Returns a list of all lines with that string
|
# Returns a list of all lines with that string
|
||||||
def search_log(log, string):
|
def search_log(log, string):
|
||||||
logs_path = make_local_path(case.output_dir, case.image_name, "logs", log)
|
logs_path = make_path(case.output_dir, case.image_name, "logs", log)
|
||||||
try:
|
try:
|
||||||
results = []
|
results = []
|
||||||
log = open(logs_path, "r")
|
log = open(logs_path, "r")
|
||||||
@ -938,7 +951,7 @@ def search_log(log, string):
|
|||||||
# Search through all the the logs of the given type
|
# Search through all the the logs of the given type
|
||||||
# Types include autopsy, tika, and solr
|
# Types include autopsy, tika, and solr
|
||||||
def search_log_set(type, string):
|
def search_log_set(type, string):
|
||||||
logs_path = make_local_path(case.output_dir, case.image_name, "logs")
|
logs_path = make_path(case.output_dir, case.image_name, "logs")
|
||||||
results = []
|
results = []
|
||||||
for file in os.listdir(logs_path):
|
for file in os.listdir(logs_path):
|
||||||
if type in file:
|
if type in file:
|
||||||
@ -1014,7 +1027,7 @@ def generate_html():
|
|||||||
logs = "<div id='logs'>\
|
logs = "<div id='logs'>\
|
||||||
<h2><a name='" + case.image_name + "-logs'>Logs</a></h2>\
|
<h2><a name='" + case.image_name + "-logs'>Logs</a></h2>\
|
||||||
<hr color='#00a00f'>"
|
<hr color='#00a00f'>"
|
||||||
logs_path = make_local_path(case.output_dir, case.image_name, "logs")
|
logs_path = make_path(case.output_dir, case.image_name, "logs")
|
||||||
for file in os.listdir(logs_path):
|
for file in os.listdir(logs_path):
|
||||||
logs += "<p><a href='file:\\" + make_path(logs_path, file) + "' target='_blank'>" + file + "</a></p>"
|
logs += "<p><a href='file:\\" + make_path(logs_path, file) + "' target='_blank'>" + file + "</a></p>"
|
||||||
logs += "</div>"
|
logs += "</div>"
|
||||||
@ -1195,7 +1208,7 @@ def wgetcwd():
|
|||||||
def copy_logs():
|
def copy_logs():
|
||||||
try:
|
try:
|
||||||
log_dir = os.path.join("..","build","test","qa-functional","work","userdir0","var","log")
|
log_dir = os.path.join("..","build","test","qa-functional","work","userdir0","var","log")
|
||||||
shutil.copytree(log_dir, make_local_path(case.output_dir, case.image_name, "logs"))
|
shutil.copytree(log_dir, make_path(case.output_dir, case.image_name, "logs"))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
printerror("Error: Failed to copy the logs.")
|
printerror("Error: Failed to copy the logs.")
|
||||||
printerror(str(e) + "\n")
|
printerror(str(e) + "\n")
|
||||||
@ -1302,6 +1315,7 @@ Options:
|
|||||||
-v Verbose mode; prints all errors to the screen.
|
-v Verbose mode; prints all errors to the screen.
|
||||||
-e ex Prints out all errors containing ex.
|
-e ex Prints out all errors containing ex.
|
||||||
-l cfg Runs from configuration file cfg.
|
-l cfg Runs from configuration file cfg.
|
||||||
|
-o dir Uses dir as the output directory. Must be a full path.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
@ -1364,11 +1378,14 @@ def main():
|
|||||||
pass
|
pass
|
||||||
# Otherwise test away!
|
# Otherwise test away!
|
||||||
else:
|
else:
|
||||||
case.output_dir = make_path("output", time.strftime("%Y.%m.%d-%H.%M.%S"))
|
if not args.output:
|
||||||
|
case.output_dir = make_local_path("output", time.strftime("%Y.%m.%d-%H.%M.%S"))
|
||||||
|
else:
|
||||||
|
case.output_dir = make_path(args.output_dir, time.strftime("%Y.%m.%d-%H.%M.%S"))
|
||||||
os.makedirs(case.output_dir)
|
os.makedirs(case.output_dir)
|
||||||
case.common_log = make_local_path(case.output_dir, "AutopsyErrors.txt")
|
case.common_log = make_path(case.output_dir, "AutopsyErrors.txt")
|
||||||
case.csv = make_local_path(case.output_dir, "CSV.txt")
|
case.csv = make_path(case.output_dir, "CSV.txt")
|
||||||
case.html_log = make_local_path(case.output_dir, "AutopsyTestCase.html")
|
case.html_log = make_path(case.output_dir, "AutopsyTestCase.html")
|
||||||
|
|
||||||
# If user wants to do a single file and a list (contradictory?)
|
# If user wants to do a single file and a list (contradictory?)
|
||||||
if args.single and args.list:
|
if args.single and args.list:
|
||||||
|
@ -18,10 +18,18 @@
|
|||||||
*/
|
*/
|
||||||
package org.sleuthkit.autopsy.testing;
|
package org.sleuthkit.autopsy.testing;
|
||||||
|
|
||||||
|
import java.awt.AWTException;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.Robot;
|
||||||
|
import java.awt.Toolkit;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
import javax.swing.JDialog;
|
import javax.swing.JDialog;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
@ -77,7 +85,7 @@ public class RegressionTest extends TestCase{
|
|||||||
"testConfigureIngest2a",
|
"testConfigureIngest2a",
|
||||||
"testIngest",
|
"testIngest",
|
||||||
"testGenerateReportToolbar",
|
"testGenerateReportToolbar",
|
||||||
"testGenerateReportButton"
|
"testGenerateReportButton"
|
||||||
);
|
);
|
||||||
return NbModuleSuite.create(conf);
|
return NbModuleSuite.create(conf);
|
||||||
|
|
||||||
@ -226,6 +234,7 @@ public class RegressionTest extends TestCase{
|
|||||||
// consistently, making it seem like default behavior
|
// consistently, making it seem like default behavior
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
new Timeout("pausing", 10000 + (rand.nextInt(15000) + 5000)).sleep();
|
new Timeout("pausing", 10000 + (rand.nextInt(15000) + 5000)).sleep();
|
||||||
|
screenshot("Finished Ingest");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,12 +263,29 @@ public class RegressionTest extends TestCase{
|
|||||||
JButtonOperator jbo0 = new JButtonOperator(reportDialogOperator, "Generate Report");
|
JButtonOperator jbo0 = new JButtonOperator(reportDialogOperator, "Generate Report");
|
||||||
jbo0.pushNoBlock();
|
jbo0.pushNoBlock();
|
||||||
new Timeout("pausing", 3000).sleep(); // Give it a few seconds to generate
|
new Timeout("pausing", 3000).sleep(); // Give it a few seconds to generate
|
||||||
|
screenshot("Finished Report");
|
||||||
|
|
||||||
JDialog previewDialog = JDialogOperator.waitJDialog("Report Preview", false, false);
|
JDialog previewDialog = JDialogOperator.waitJDialog("Report Preview", false, false);
|
||||||
JDialogOperator previewDialogOperator = new JDialogOperator(previewDialog);
|
JDialogOperator previewDialogOperator = new JDialogOperator(previewDialog);
|
||||||
JButtonOperator jbo1 = new JButtonOperator(previewDialogOperator, "Close");
|
JButtonOperator jbo1 = new JButtonOperator(previewDialogOperator, "Close");
|
||||||
jbo1.pushNoBlock();
|
jbo1.pushNoBlock();
|
||||||
new Timeout("pausing", 3000).sleep(); // Give the program a second to idle to be safe
|
new Timeout("pausing", 3000).sleep(); // Give the program a second to idle to be safe
|
||||||
|
screenshot("Done Testing");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void screenshot(String name) {
|
||||||
|
logger.info("Taking screenshot.");
|
||||||
|
try {
|
||||||
|
Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
|
||||||
|
BufferedImage capture = new Robot().createScreenCapture(screenRect);
|
||||||
|
String outPath = System.getProperty("out_path");
|
||||||
|
ImageIO.write(capture, "png", new File(outPath + "\\" + name + ".png"));
|
||||||
|
new Timeout("pausing", 1000).sleep(); // give it a second to save
|
||||||
|
} catch (IOException ex) {
|
||||||
|
logger.info("IOException taking screenshot.");
|
||||||
|
} catch (AWTException ex) {
|
||||||
|
logger.info("AWTException taking screenshot.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user