def process_groups( self, arg_ofile ): my_total_count = 0 my_total_elapsed = 0 my_groups = self.groups.task_groups(); # Msg.trace("PerformanceSummaryItem::process_groups") for my_group, my_items in my_groups.items(): try: my_str = "\nBegin Group: %s\n" % ( my_group ) arg_ofile.write( my_str ) Msg.blank( "info" ) Msg.info( my_str ) my_grp_count, my_grp_elapsed = self.process_group_items( arg_ofile, my_items ) my_total_count += my_grp_count my_total_elapsed += my_grp_elapsed my_line = "\nGroup Instructions: %3d\n" % ( my_grp_count ) my_line += "Group Elapsed Time: %0.3f\n" % ( my_grp_elapsed ) my_line += "Group Instructions per Second: %0.3f\n" % ( SysUtils.ifthen( bool( my_grp_elapsed ), my_grp_count / my_grp_elapsed, 0 )) my_line += "End Group: %s\n" % ( my_group ) Msg.info( my_line ) arg_ofile.write( my_line ) except Exception as arg_ex: Msg.error_trace() Msg.err( "Unable to process, Group: %s, Reason: %s" % ( my_group, type( arg_ex ))) return my_total_count, my_total_elapsed
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 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 init_thread( self ): Msg.info( "HiEvent: Creating Test Thread ..." ) myThreadProcs = { "on-start" : self.thread_start # start thread sequence (outside thread space) , "on-execute" : self.thread_execute # thread termination handler (inside thread space) , "on-done" : self.thread_done # thread terminated handler (outside thread space) , "on-finished": self.thread_finished # thread before finished handler (inside thread space) } self.thread = ThreadFactory( "EventTestThread", True, myThreadProcs )
def process_errors(self, arg_ofile): if len(self.errors) > 0: arg_ofile.write("\n") Msg.blank() for my_eitem in self.errors: my_err_line = str(my_eitem.get_err_line()) Msg.info(my_err_line) arg_ofile.write("%s\n" % (my_err_line))
def exec_gen(self, arg_task_file): # Msg.dbg( "ExecuteController::exec_gen( %s )" % ( arg_task_file ) ) # NOTE: Do not change force_cmd may need to reuse!! # my_task_file = self.ctrl_item.file_path() # my_cmd = self.force_cmd % ( my_testfile, arg_testname.replace( ".py", ".gen.log" )) my_log = "gen.log" # arg_testname.replace( ".py", ".gen.log" ) my_elog = "gen.err" # arg_testname.replace( ".py", ".gen.log" ) my_cmd = self.force_cmd % (arg_task_file) # , my_log ) # Msg.dbg( "Generate Command Line: %s" % ( my_cmd )) # if self.ctrl_item.mode == "mock": # Msg.info( "Mock Generate: " + my_cmd ) # else: Msg.info( "ForceCommand = " + str({ "force-command": my_cmd, "force-log": my_log, "force-elog": my_elog, "max-instr": self.ctrl_item.max_instr, "min-instr": self.ctrl_item.min_instr }), True) Msg.flush() # if self.ctrl_item.summary is not None: # # update the current test with the generate cmd and the generate log file. # self.ctrl_item.summary.set_gen_info( arg_task_name, arg_ndx, my_cmd, my_log ) my_result = SysUtils.exec_process(my_cmd, my_log, my_elog, self.ctrl_item.timeout, True) # Msg.user( str( my_result[0] ) + ", type: " + str( type( my_result[0] ))) my_ret_code = int(my_result[0]) my_std_out = str(my_result[1]) my_std_err = str(my_result[2]) my_start = str(my_result[3]) my_end = str(my_result[4]) my_time_elapsed = SysUtils.ifthen(my_result[3] is not None, float(my_result[3]), 0.0) Msg.info("ForceResult = " + str({ "force-retcode": my_ret_code, "force-stdout": my_std_out, "force-stderr": my_std_err, "force-start": my_start, "force-end": my_end })) return SysUtils.success(my_result[0])
def run_test(self): Msg.info("HiThread(Loop): Start Unit Test ... ") myThreadProcs = { "on-start": self.thread_start # start thread sequence (outside thread space) , "on-execute": self. thread_execute # thread termination handler (inside thread space) , "on-finished": self. thread_finished # thread before finished handler (inside thread space) , "on-done": self. thread_done # thread terminated handler (outside thread space) } myThreadOpts = { "heartbeat-rate": 2, "sleep-period": 100, "daemon": False # run once threads should not be daemons , "active": False # do not start the thread until ready } Msg.info("UnitTest_LoopThread << Creating Thread With Loop... ") myThread = ThreadFactory("LoopThread", False, myThreadProcs, myThreadOpts) Msg.info("UnitTest_LoopThread << Initializing Thread ... ") myThread.start_thread() # wait for thread to terminate myThread.wait_for() Msg.info("UnitTest_LoopThread >> Thread Completed ... ")
def run_test(self): Msg.info("HiThread(NoLoop): Start Unit Test ... ") myThreadProcs = { "on-start": self.thread_start # start thread sequence (outside thread space) , "on-execute": self. thread_execute # thread termination handler (inside thread space) , "on-finished": self. thread_finished # thread before finished handler (inside thread space) , "on-done": self. thread_done # thread terminated handler (outside thread space) } Msg.info("UnitTest_NoLoopThread >> Creating NoLoop Thread ... ") myThread = ThreadFactory("NoLoopThread", True, myThreadProcs) Msg.info("UnitTest_NoLoopThread >> Initializing Thread ... ") myThread.start_thread() # wait for thread to terminate myThread.wait_for() Msg.info("UnitTest_NoLoopThread >> Thread Completed ... ")
def commit_generate( self ): self.force_result = SysUtils.ifthen( SysUtils.success( self.force_retcode ), "PASS", "FAIL" ) self.force_level = SummaryLevel.Any if SysUtils.failed( self.force_retcode ): self.force_level = SummaryLevel.Fail Msg.lout( self, "user" , "Performance Summary Item Commit Generate" ) if SysUtils.success( self.force_retcode ): self.instruction_counts( ) Msg.info( "Instructions: %d, Default: %d, Secondary: %d, Elapsed Time: %0.5f Seconds\n\n" % ( self.count, self.default, self.secondary, self.force_end - self.force_start )) return 1 return 0
def exec_iss(self, arg_task_name): # Msg.dbg( "ExecuteController::exec_iss( %s )" % ( arg_task_name ) ) # build rest of command for iss my_elf = "%s.Default.ELF" % (arg_task_name) # Msg.dbg( "Looking For: %s" % ( my_elf )) my_elf = SysUtils.ifthen(PathUtils.check_file(my_elf), " %s" % my_elf, "") # Msg.dbg( "Using ELF: %s" % ( my_elf )) my_elfns = "%s.Secondary.ELF" % (arg_task_name) # Msg.dbg( "Looking For: %s" % ( my_elfns )) my_elfns = SysUtils.ifthen(PathUtils.check_file(my_elfns), " %s" % my_elfns, "") my_cmd = self.sim_cmd % (my_elf, my_elfns) try: # execute the simulation Msg.info("ISSCommand = " + str({"iss-command": my_cmd})) my_log = self.sim_log my_elog = self.sim_log #my_ret_code = int( SysUtils.exec_cmd( my_cmd ) ) my_result = SysUtils.exec_process(my_cmd, my_log, my_elog, self.ctrl_item.timeout, True) my_ret_code = int(my_result[0]) my_std_out = str(my_result[1]) my_std_err = str(my_result[2]) my_start = str(my_result[3]) my_end = str(my_result[4]) Msg.info("ISSResult = " + str({ "iss-retcode": my_ret_code, "iss-log": self.sim_log, "iss-stdout": my_std_out, "iss-stderr": my_std_err, "iss-start": my_start, "iss-end": my_end })) except Exception as arg_ex: Msg.error_trace("ISS Execute Failure") Msg.err("ISS did not properly execute, Reason: %s" % (str(arg_ex))) return False return True
def execute(self): Msg.info("LoopThread::execute() => Enter ") for i in range(3): Msg.info("Thread Work: %d:%d" % (self.max_loops, i + 1)) self.check_finished() self.heartbeat() Msg.info("LoopThread::execute() => Leave")
def with_test( self ): # create a mutex my_mutex = HiMutex( "with_mutex" ) # Msg.info( "Before With: Mutex[%s] is %s" % ( my_mutex.name, SysUtils.ifthen( my_mutex.locked(), "Locked", "Unlocked" ))) Msg.info( "Before With: Mutex[%s]" % ( my_mutex.name )) with my_mutex : Msg.info( "In With: Mutex[%s]" % ( my_mutex.name )) # Msg.info( "In With: Mutex[%s] is %s" % ( my_mutex.name, SysUtils.ifthen( my_mutex.locked(), "Locked", "Unlocked" ))) Msg.info( "After With: Mutex[%s]" % ( my_mutex.name ))
def on_before_unsignal( self, arg_sender ): if type( arg_sender ) is not HiEvent: raise EIncompatableTypeError( "Event Notification Contained Incompatable Type" ) Msg.info( "Event[%s] is about to be unsignaled ... " % ( arg_sender.name ))
def process_result( self ): Msg.info( "HiEvent: Process Test Result ..." )
def process_result( self ): Msg.info( "HiThread(NoLoop): Process Test Results... " )
def run_test( self ): Msg.info( "HiEvent: Start Unit Test ..." ) my_wrapper = ThreadWrapper() my_wrapper.run_thread()
def thread_finished( self ): Msg.info( "UnitTest_NoLoopThread >> Exiting .... " ) if self.finished_event is not None: self.finished_event.Signaled() self.finished_event.Signal() self.finished_event.Signaled( True )
def process_result( self ): Msg.info( "HiSemaphore: Process Test Result ..." )
def execute(self): Msg.info("Begin: NoLoopThread::execute()") for i in range(5): Msg.info("Thread Work: %d" % (i)) Msg.info("End: NoLoopThread::execute()")
def run_thread( self ): Msg.info( "UnitTest_HiEvent >> Initializing Thread ... " ) self.thread.start_thread() # wait for thread to terminate self.thread.wait_for() Msg.info( "UnitTest_HiEvent >> Thread Completed ... " )
def process_result(self): Msg.info("HiQueue: Process Test Result ...")
def run_test(self): Msg.info("HiQueue: Start Unit Test ...")
if self.option_def(CmdLine.Switches[CmdLine.help], False, CmdLine.Help): # if self.get_option( ["-h","--" + CmdLine.Switches[CmdLine.help].replace("=", "" )], False ): 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)
def process_result(self): Msg.info("HiStack: Process Test Result ...")
def run_test(self): Msg.info("HiStack: Start Unit Test ...")
def on_after_unsignal( self, arg_sender ): if type( arg_sender ) is not HiEvent: raise EIncompatableTypeError( "Event Notification Contained Incompatable Type" ) Msg.info( "Event[%s] has been unsignaled ... " % ( arg_sender.name ))
def process_result( self ): Msg.info( "HiMutex: Process Test Result ..." )
def thread_start( self ): Msg.info( "UnitTest_NoLoopThread >> Started .... " ) if self.start_event is not None: self.start_event.Signaled() self.start_event.Signal() self.start_event.Signaled( True )
def thread_done ( self ): Msg.info( "UnitTest_NoLoopThread << Execute Done .... " ) if self.done_event is not None: self.done_event.Signaled() self.done_event.Signal() self.done_event.Signaled( True )
def run_test( self ): Msg.info( "HiSemaphore: Start Unit Test ..." )