diff --git a/Testing/script/regression.py b/Testing/script/regression.py index 0a22c5754c..55de55d2a4 100644 --- a/Testing/script/regression.py +++ b/Testing/script/regression.py @@ -54,6 +54,8 @@ class Args: self.verbose = False self.exception = False self.exception_string = "" + self.output = False + self.output_dir = "" def parse(self): sys.argv.pop(0) @@ -99,11 +101,22 @@ class Args: try: arg = sys.argv.pop(0) 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_string = arg except: 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": printout(usage()) return False @@ -366,7 +379,7 @@ def run_test(image_file): # Set the case to work for this test case.image_file = 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.keyword_path = make_path(case.input_dir, "notablekeywords.xml") case.nsrl_path = make_path(case.input_dir, "nsrl.txt-md5.idx") @@ -387,7 +400,7 @@ def run_test(image_file): rebuild() # If NOT keeping Solr index (-k) 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): print_report([], "DELETE SOLR INDEX", "Solr index deleted.") elif args.keep: @@ -440,7 +453,7 @@ def run_ant(): case.ant.append("-Dkeyword_path=" + case.keyword_path) case.ant.append("-Dnsrl_path=" + case.nsrl_path) 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("-Dtest.timeout=" + str(case.timeout)) @@ -487,9 +500,9 @@ def rebuild(): clear_dir(gold_dir) # 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") - gold_to = make_local_path(case.gold, case.image_name, "standard.db") + gold_to = make_path(case.gold, case.image_name, "standard.db") try: copy_file(gold_from, gold_to) except FileNotFoundException as e: @@ -499,7 +512,7 @@ def rebuild(): errors.append(str(e) + "\n") # 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") try: 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 def compare_to_gold_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") try: 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 # from each log file generated by Autopsy def generate_common_log(): - #try: - logs_path = make_local_path(case.output_dir, case.image_name, "logs") + try: + logs_path = make_path(case.output_dir, case.image_name, "logs") common_log = open(case.common_log, "a") common_log.write("--------------------------------------------------\n") common_log.write(case.image_name + "\n") @@ -677,15 +690,15 @@ def generate_common_log(): log.close() common_log.write("\n\n") common_log.close() - #except Exception as e: - # printerror("Error: Unable to generate the common log.") - # printerror(str(e)) + except Exception as e: + printerror("Error: Unable to generate the common log.") + printerror(str(e)) # Fill in the global case's variables that require the log files def fill_case_data(): try: # 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) # 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 def get_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 = [] for file in os.listdir(logs_path): if "autopsy" in file: @@ -881,7 +894,7 @@ def report_all_errors(): # Searched all the known logs for the given regex # The function expects regex = re.compile(...) 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 = [] for file in os.listdir(logs_path): 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. # Returns a list of all lines with that 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 = [] for file in os.listdir(logs_path): 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 # Returns a list of all lines with that 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: results = [] log = open(logs_path, "r") @@ -938,7 +951,7 @@ def search_log(log, string): # Search through all the the logs of the given type # Types include autopsy, tika, and solr 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 = [] for file in os.listdir(logs_path): if type in file: @@ -1014,7 +1027,7 @@ def generate_html(): logs = "