def process_summary( self, sum_level = SummaryLevel.Fail ): my_file_name = "%sperformance_summary.log" % ( PathUtils().include_trailing_path_delimiter( self.summary_dir )) Msg.dbg( "Master Log File: %s" % ( my_file_name )) my_utcdt = DateTime.UTCNow() my_ofile = None try: # First try to open file with open( my_file_name, "w" ) as my_ofile: my_ofile.write( "Date: %s\n" % ( DateTime.DateAsStr( my_utcdt ))) my_ofile.write( "Time: %s\n" % ( DateTime.TimeAsStr( my_utcdt ))) self.process_errors( my_ofile ) my_total_count, my_total_elapsed = self.process_groups( my_ofile ) Msg.blank( "info" ) my_line = "Total Instructions Generated: %3d\n" % ( my_total_count ) my_line += "Total Elapsed Time: %0.3f\n" % ( my_total_elapsed ) my_line += "Overall Instructions per Second: %0.3f\n" % ( SysUtils.ifthen( bool( my_total_elapsed ), my_total_count / my_total_elapsed, 0 )) Msg.info( my_line ) my_ofile.write( my_line ) except Exception as arg_ex: Msg.error_trace() Msg.err( "Error Processing Summary, " + str( arg_ex ) ) finally: my_ofile.close()
def set_current_test(self, arg_test_id, arg_test_log, arg_sim_cmd): Msg.dbg("RegressionSummary:: set_current_test( %s, %s, %s " % (str(arg_test_id), str(arg_test_log), str(arg_sim_cmd))) self.curr_test_id = arg_test_id self.curr_test_log = arg_test_log self.sim_cmd = arg_sim_cmd
def check_parent_dir(self, arg_fctrl_dir): Msg.dbg("Checking for control file in parent directory") Msg.user( "Test Root[%s], Work Dir[%s]" % (str(self.parent_data.test_root), str(self.parent_data.work_dir)), "CHECK-PARENT-DIR") if arg_fctrl_dir.startswith(".."): my_search_dir = arg_fctrl_dir my_work_dir = PathUtils.append_path(self.parent_data.test_root, self.parent_data.work_dir) my_test_root = self.parent_data.test_root Msg.user( "Updated Test Root[%s], Full Work Dir[%s], Search Dir[%s]" % (my_test_root, my_work_dir, my_search_dir), "CHECK-PARENT-DIR") while my_search_dir.startswith(".."): # First get the parent directory # The search [updated] directory started with [..] split path for both the work directory and the search directory # this fact that the [updated] search directory still begins with a [..], means that the work directory my_test_root, my_dumy = PathUtils.split_dir(my_test_root) my_work_dir, my_dumy = PathUtils.split_dir(my_work_dir) my_search_dir = my_search_dir[3:] Msg.user( "Updated Test Root[%s], Full Work Dir[%s], Search Dir[%s]" % (my_test_root, my_work_dir, my_search_dir), "CHECK-PARENT-DIR") my_filepath = str( PathUtils.append_path( my_work_dir, PathUtils.append_path(my_search_dir, self.fctrl_name))) Msg.user("File Path[%s] ... " % (my_filepath), "CHECK-PARENT-DIR") if PathUtils.check_found(my_filepath): self.fctrl_dir = PathUtils.append_path( my_work_dir, my_search_dir) return True my_filepath = str( PathUtils.append_path( my_test_root, PathUtils.append_path(my_search_dir, self.fctrl_name))) Msg.user("File Path[%s] ... " % (my_filepath), "CHECK-PARENT-DIR") if PathUtils.check_found(my_filepath): self.fctrl_dir = PathUtils.append_path( my_test_root, my_search_dir) return True raise Exception( "Control Item File[%s] Not Found in Parent Directory: [%s]" % (self.fctrl_name, arg_fctrl_dir)) return False
def report( self ): if self.default is None: self.default = 0 if self.secondary is None: self.secondary = 0 if self.total is None: self.total = 0 Msg.info( "Task Id: %s, Task Index: %d" % ( self.task_id, self.task_index )) my_msg = "Process Log Contains " if self.detail_flags & SummaryDetail.AnyDetail == SummaryDetail.Nothing : my_msg = "Process No Found or is Empty" else: if self.detail_flags & SummaryDetail.ForceCmd == SummaryDetail.ForceCmd : my_msg += "ForceCommand, " if self.detail_flags & SummaryDetail.ForceResult == SummaryDetail.ForceResult: my_msg += "ForceResult, " if self.detail_flags & SummaryDetail.IssCmd == SummaryDetail.IssCmd : my_msg += "IssCommand, " if self.detail_flags & SummaryDetail.IssResult == SummaryDetail.IssResult : my_msg += "IssResult, " my_msg = my_msg[:-2] # Msg.user( my_msg ) # Msg.info( "Originating Control File: %s" % ( self.parent_fctrl )) # Msg.info( "Control File Item: %s" % ( str( self.fctrl_item ))) # Msg.info( "F-Run Control File: %s" % ( self.frun_path )) Msg.dbg( "Force Ret Code: %s" % ( str( self.force_retcode ))) Msg.info( "[%s], Generate Command: %s" % ( SysUtils.ifthen( SysUtils.success( self.force_retcode ), "SUCCESS", "FAILED" ), str( self.force_cmd ))) Msg.info( "Instructions Generated - Default: %d, Secondary: %d, Total: %d" % ( self.default, self.secondary, self.total )) if self.iss_cmd is not None: if self.iss_success(): Msg.info( "[SUCCESS], ISS Command: %s" % ( str( self.iss_cmd ))) else: Msg.info( "[FAILED], ISS Command: %s" % ( str( self.iss_cmd ))) #Msg.fout( self.iss_log, "user" ) Msg.blank()
def run(self): Msg.dbg("ThreadTestRun::run()") with UnitTest_HiThread(): pass with UnitTest_HiEvent(): pass with UnitTest_HiMutex(): pass
def load_process_log(self): self.force_cmd = None self.force_elog = None self.force_log = None self.force_retcode = None self.force_stderr = None self.force_stdout = None self.force_level = SummaryLevel.Any self.force_start = 0.00 self.force_end = 0.00 self.iss_cmd = None self.iss_log = None self.iss_retcode = None self.max_instr = None self.min_instr = None # Msg.fout( self.process_log, "dbg" ) with open(self.process_log, "r") as my_flog: try: for my_line in my_flog: Msg.dbg("Load: %s" % my_line) self.load_process_line(my_line) except Exception as arg_ex: Msg.error_trace(arg_ex) Msg.err(str(arg_ex)) finally: my_flog.close() # here is the lowdown, if a generate line exists in the process log then a Result line must also exists, if (self.detail_flags & SummaryDetail.ForceCmd ) and not (self.detail_flags & SummaryDetail.ForceResult): self.load_gen_result({ "force-retcode": self.process_result[0], "force-stdout": self.process_result[2], "force-stderr": self.process_result[2], "force_start": self.process_result[3], "force_end": self.process_result[4] }) elif (self.detail_flags & SummaryDetail.IssCmd ) and not (self.detail_flags & SummaryDetail.IssResult): self.load_iss_result({ "iss-retcode": self.process_result[0], "iss-log": None })
def check_full_path(self, arg_fctrl_dir): # handle fully qualified path if found Msg.dbg("Checking for control file with real path[%s][%s]" % (str(arg_fctrl_dir), str(self.fctrl_name))) if arg_fctrl_dir.startswith("/"): # there is only one scenario where the control directory starts with the path delimiter and that is the path # is a real path from the root directory of the system, the control file must exist at that location if PathUtils.check_found( PathUtils.append_path(arg_fctrl_dir, self.fctrl_name)): self.fctrl_dir = arg_fctrl_dir return True raise Exception( "Control Item File: [%s] count not be located Not Found at [%s]" % (self.fctrl_name, arg_fctrl_dir)) return False
def load_process_info(self, arg_process_info): # update the user label and send iteration message to the screen if user is active # my_usr_lbl = Msg.set_label( "user", "PROCESS-RESULT" ) # Msg.user( "Executing Iteration #%d of Test File: %s" % ( my_ndx + 1, arg_task_file )) Msg.dbg("self.process_result: (%s)" % (str(arg_process_info.get("process-result", None)))) # Msg.set_label( "user", my_usr_lbl ) self.process_cmd = arg_process_info.get("process-cmd", None) self.process_log = arg_process_info.get("process-log", None) self.process_result = arg_process_info.get("process-result", None) self.frun_path = arg_process_info.get("frun-path", None) self.parent_fctrl = arg_process_info.get("parent-fctrl", None) self.fctrl_item = arg_process_info.get("fctrl-item", None) self.item_group = arg_process_info.get("item-group", None) self.fctrl_content = arg_process_info.get("content", None) self.detail_flags = SummaryDetail.Nothing
def instruction_counts( self ): my_lines = None my_glog = "%s%s" % ( PathUtils.include_trailing_path_delimiter( self.work_dir ), self.force_log ) Msg.user("Path: %s" % my_glog) with open( my_glog, "r" ) as my_log: my_lines = my_log.readlines() Msg.dbg( "Line %d: %s" % ( len( my_lines ), my_lines[-1])) my_log.close() try: my_results = [ my_tmp for my_tmp in my_lines if re.search( ' Instructions Generated', my_tmp )] Msg.lout( my_results, "dbg" ) if not my_results: raise Exception( "Instruction Count Not Found in \"gen.log\"" ) # ok there are instruction counts located for my_line in my_results: my_line = my_line.strip() # find the instruction type (Total, Default, Secondary) my_lpos = my_line.find(']') my_rpos = my_line.find( "Instr" ) my_type = PerformanceInstructionType.instruction_type(( my_line[my_lpos + 1 : my_rpos - 1 ]).strip()) # get the count for this instruction type my_lpos = my_line.find( ':' ) my_count = int( my_line[my_lpos+2:].strip()) if my_type == PerformanceInstructionType.Total: self.count = my_count elif my_type == PerformanceInstructionType.Secondary: self.secondary = my_count elif my_type == PerformanceInstructionType.Default: self.default = my_count except ValueError: Msg.error_trace() Msg.err( "Unable to extract instruction count from %s" % ( int( my_lines[-1] ))) return 0
def check_work_dir(self, arg_fctrl_dir): # check the work directory Msg.dbg( "Checking for control file using implict path[%s] of current control file" % (str(arg_fctrl_dir))) if not self.parent_data.work_dir is None: my_tmp_dir = PathUtils.append_path(self.parent_data.work_dir, arg_fctrl_dir) if not SysUtils.found(my_tmp_dir.find(self.parent_data.test_root)): # Prepend the test_root on the work directory my_tmp_dir = PathUtils.append_path(self.parent_data.test_root, my_tmp_dir) if PathUtils.check_found( PathUtils.append_path(my_tmp_dir, self.fctrl_name)): self.fctrl_dir = my_tmp_dir # Msg.dbg( "Using Control File Directory: %s" % ( self.fctrl_dir )) return True return False
def extract_results(self, arg_result, arg_cmd, arg_log, arg_process_item, arg_start_time, arg_end_time): Msg.dbg("Return Code %s, Command Line: |%s|, Log File: %s" % (str(arg_result), arg_cmd, arg_log)) #Msg.fout( arg_log, "info" ) my_summary_item = SummaryQueueItem({ "process-cmd": arg_cmd, "process-log": arg_log, "process-result": arg_result, "frun-path": arg_process_item.frun_path, "parent-fctrl": arg_process_item.parent_fctrl, "fctrl-item": arg_process_item.fctrl_item, "item-group": arg_process_item.item_group, "content": arg_process_item.content, "start-time": arg_start_time, "end-time": arg_end_time }) while (self.summary.queue.enqueue(my_summary_item) == False): self.HeartBeat() pass
def extract_iss_data(self, arg_item_dict): # first get the iss dictionary # Msg.lout( arg_item_dict, "user", "RAW Item Dictionary ..." ) my_iss_data = arg_item_dict.get(CtrlItmKeys.iss, CtrlItmDefs.iss) my_iss_path = my_iss_data.get(CtrlItmKeys.iss_path, None) if my_iss_path is not None: # if the iss path was not specified then the iss path currently in the parent data instance is the correct one Msg.dbg("Iss Path: %s, Test Root: %s" % (my_iss_path, self.parent_data.test_root)) # check to see if path is absolute path if not SysUtils.found(my_iss_path.find( self.parent_data.test_root)): Msg.dbg("Test Root Not Found ...") # if not then prepend the test root my_iss_path = PathUtils.include_trailing_path_delimiter( self.parent_data.test_root ) + PathUtils.exclude_leading_path_delimiter(my_iss_path) self.parent_data.update_iss_path(my_iss_path) Msg.dbg("Final Iss Path: %s" % (self.parent_data.iss_path))
def load_force_log(self, arg_seed_only=False): self.default = None self.secondary = None self.total = None self.seed = None self.task_path = PathUtils.include_trailing_path_delimiter( self.work_dir) my_glog = "%s%s" % (self.task_path, self.force_log) Msg.dbg("Path: %s" % my_glog) # Msg.user( "Opening Generator Log File: %s" % ( my_glog )) with open(my_glog, "r") as my_flog: try: for my_line in my_flog: if SysUtils.found( my_line.find("Secondary Instructions Generated")): # my_secondary = my_line.replace( "[notice]Secondary Instructions Generated:", "" ).strip() # self.secondary = int( my_secondary ) my_lpos = my_line.find(':') my_count = int(my_line[my_lpos + 2:].strip()) # Msg.user( "Secondary Instructions: %d" % ( my_count )) self.secondary = my_count elif SysUtils.found( my_line.find("Default Instructions Generated")): # my_pos = my_line.find( ":" ) + 2 # my_default = my_line[ my_pos: ].strip() # get the count for this instruction type my_lpos = my_line.find(':') my_count = int(my_line[my_lpos + 2:].strip()) # Msg.user( "Default Instructions: %d" % ( my_count )) self.default = my_count # my_default = my_line.replace( "[notice]Default Instructions Generated:", "" ).strip() # self.default = int( my_default ) if SysUtils.found( my_line.find("Total Instructions Generated")): self.total = int( my_line.replace( "[notice]Total Instructions Generated: ", "").strip()) my_lpos = my_line.find(':') my_count = int(my_line[my_lpos + 2:].strip()) # Msg.user( "Total Instructions: %d" % ( my_count )) self.total = my_count if SysUtils.found(my_line.find("Initial seed")): self.seed = my_line.replace("[notice]", "").replace( "Initial seed = ", "").strip() # Msg.dbg( "Seed: %s" % ( self.seed )) # for simulation only the seed is needed if arg_seed_only: break if not (self.seed is None or self.total is None or self.secondary is None or self.default is None): break except Exception as arg_ex: # NOTE: Determine the possible errors and handle accordingly, for now just keep processing Msg.error_trace() Msg.err(str(arg_ex)) finally: my_flog.close()
def add_result(self, arg_ret_code): my_tup = None self.total_count += 1 Msg.dbg("Adding Simulation results, \"%s\"" % (str(self.sim_cmd))) if arg_ret_code != 0: # only need to create a tuple with the return code Msg.dbg("Simulation Failed, return code: " + str(arg_ret_code)) self.failed_count += 1 #my_tup = ( 1, arg_ret_code, self.curr_test_log, None, "FAIL", SysUtils.ifthen( self.out_dir is None, self.summary_dir, self.out_dir )) my_tup = (1, arg_ret_code, self.curr_test_log, None, "FAIL") else: my_lines = None try: Msg.dbg("Attempting to Open: " + self.curr_test_log) with open(self.curr_test_log, "r") as my_log: Msg.dbg("File Open: " + self.curr_test_log) my_lines = my_log.readlines() Msg.dbg("Line %d: %s" % (len(my_lines), my_lines[-1])) my_lastline = my_lines[-1] my_segs = my_lastline.split() my_num_instr = int(my_segs[0]) if my_num_instr < self.num_instr: # Simulation worked return code = 0 and the instruction limit was not reached Msg.dbg( "Simulation Success, return code = 0 and the instruction limit was not reached" ) # my_tup = ( 0, arg_ret_code, self.curr_test_log, None, "PASS", SysUtils.ifthen( self.out_dir is None, self.summary_dir, self.out_dir ) ) my_tup = (0, arg_ret_code, self.curr_test_log, None, "PASS") else: # Msg.dbg("Simulation Failed, Instruction Limit Reached ") self.failed_count += 1 #my_tup = ( 2, arg_ret_code, self.curr_test_log, "Instruction Limit Reached: Failed at " + str( self.num_instr ) + " Instructions ", "FAIL", SysUtils.ifthen( self.out_dir is None, self.summary_dir, self.out_dir ) ) my_tup = (2, arg_ret_code, self.curr_test_log, "Instruction Limit Reached: Failed at " + str(self.num_instr) + " Instructions ", "FAIL") except: if Msg._debug(): traceback.print_exc(file=sys.stdout) my_tup = (arg_ret_code, "Unsupported", "Unable to Extract Test Failure Information", "FAIL", " ") finally: my_log.close() self.results[self.curr_test_id] = my_tup Msg.dbg("Results Tuple: " + str(my_tup)) self.curr_test_id = None self.curr_test_log = None
def __init__( self): Msg.dbg( "Controller::__init__()" ) self.ctrl_item = None
from force_init import force_usage force_usage(UsageStr) if __name__ == "__main__": # save current working directory my_pwd = PathUtils.current_dir() try: my_module = UnitTestRun(the_force_root) Msg.info("\nForce Path: %s" % (str(the_force_root))) Msg.info("Original Directory: " + my_pwd) Msg.dbg("Processing Command Line and Loading Control File") my_module.load() Msg.dbg("Directory set to %s" % (PathUtils.current_dir())) if not PathUtils.chdir(the_force_root, False): Msg.dbg( "Directory Unchanged, using the current directory for output") my_module.run() Msg.dbg("Test Completed ....\n") Msg.blank() sys.exit(40) except getopt.GetoptError as arg_ex: from force_init import force_usage
def load(self): Msg.dbg("ForrestRun::load()") self.check_usage() self.process_cmdline()