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()
Пример #2
0
    def run(self):
        Msg.dbg("MasterRun::run()")

        # Run single run applications here before anything else is done
        for app_cfg in self.m_app_info.mSingleRunApps:
            app_executor = app_cfg.createExecutor()
            app_executor.load(self.ctrl_item)
            if not app_executor.skip():
                # TODO: need to add some proper logging here (so we can find information in the output folder)
                Msg.info('Currently executing %s app' % app_cfg.name())
                app_executor.pre()
                app_executor.execute()
                app_executor.post()
                Msg.info('Finished executing %s app' % app_cfg.name())

        for my_ndx in range(self.num_runs):
            if self.terminated:
                break
            # my_usr_lbl = Msg.set_label( "user", "NUMRUNS" )
            Msg.info(Formats.exec_num_runs % (my_ndx + 1, self.num_runs))
            # Msg.set_label( "user", my_usr_lbl )
            Msg.blank()
            self.fctrl.process()

        # Wait until all the threads are done
        self.process_queue.fully_loaded = True
        workers_done_event.wait()
        summary_done_event.wait()

        if self.summary:
            Msg.dbg(Formats.summ_level % (self.sum_level))
            self.summary.process_summary(self.sum_level)

            # TODO: total_cycle_count and total_instruction_count are specific to RegressionSummary and
            # are used in the rtl application's reporter (PerformanceSummary does not contain either).
            # Do the rtl application and performance mode ever get run at the same time?

            # make cycle count and instruction count available in the shared object
            if isinstance(self.summary, RegressionSummary):
                self.m_app_info.mTagToReportInfo.update({
                    "master_run": {
                        "total_cycle_count": self.summary.total_cycle_count,
                        "total_instruction_count":
                        self.summary.total_instruction_count,
                        "initial_control_file": self.fctrl_name,
                        "output_dir": self.output_dir
                    }
                })

        if self.mode == "count":
            Msg.info("Total tasks counted in control file tree: " +
                     str(self.m_app_info.mNumTestsCount) + "\n")

        if self.terminated:
            Msg.info(
                "####\n#### Reached max fails limit before test was completed.\n####"
            )

        self.writeVersionInfo()
        self.modulesReport()
Пример #3
0
    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))
Пример #4
0
def main():
    signal.signal(signal.SIGINT, sig_interrupt_handler)
    my_pwd = None

    print(
        "\n=======================================\n\tInitializing ....\n=======================================\n"
    )
    try:
        my_module = MasterRun()

        # save current working directory
        my_pwd = PathUtils.current_dir()

        Msg.dbg("Original Directory: " + my_pwd)
        Msg.dbg("Processing Command Line and Loading Control File")
        my_module.load()

        if not PathUtils.chdir(my_module.output_dir, True):
            Msg.dbg("Unable to change into: " + my_module.output_dir +
                    ", using the current directory for output")

        Msg.info("\nConcurrent Operations: %s" %
                 (str(my_module.m_app_info.mProcessMax)))
        my_module.run()

        Msg.info("Test Completed ....\n")

    except FileNotFoundError as arg_ex:
        # Msg.error_trace("[ERROR] -  " + str(arg_ex) )
        Msg.err(str(arg_ex))
        Msg.blank()

    except LoadError as arg_ex:
        # Msg.error_trace("[ERROR] -  " + str(arg_ex) )
        Msg.err(str(arg_ex))
        Msg.blank()

    except Exception as arg_ex:

        from force_init import force_usage

        Msg.err("[ERROR] - An Unhandled Error has Occurred during run of " +
                str(sys.argv[0]))
        traceback.print_exc(file=sys.stdout)

    except:
        # traceback.print_exc( file=sys.stdout )
        # print( "An Unhandled Exception Occurred ..." )
        pass

    finally:
        # TODO
        # change back to original directory

        if my_pwd is not None:
            # Msg.dbg( "Restoring Original Directory: " + my_pwd )
            PathUtils.chdir(my_pwd)
Пример #5
0
    def run(self):
        Msg.dbg("MasterRun::run()")

        # Run single run applications here before anything else is done
        for app_cfg in self.m_app_info.mSingleRunApps:
            app_executor = app_cfg.createExecutor()
            app_executor.load(self.ctrl_item)
            if not app_executor.skip():
                Msg.info("Currently executing %s app" % app_cfg.name())
                app_executor.pre()
                app_executor.execute()
                app_executor.post()
                Msg.info("Finished executing %s app" % app_cfg.name())

        for my_ndx in range(self.num_runs):
            if self.terminated:
                break
            Msg.info(Formats.exec_num_runs % (my_ndx + 1, self.num_runs))
            Msg.blank()
            self.fctrl.process()

        # Wait until all the threads are done
        self.process_queue.fully_loaded = True
        workers_done_event.wait()
        summary_done_event.wait()

        if self.summary:
            Msg.dbg(Formats.summ_level % (self.sum_level))
            self.summary.process_summary(self.sum_level)

            # make cycle count and instruction count available in the shared
            # object
            if isinstance(self.summary, RegressionSummary):

                instruction_count = self.summary.total_instruction_count
                cycle_count = self.summary.total_cycle_count
                self.m_app_info.mTagToReportInfo.update({
                    "master_run": {
                        "total_cycle_count": cycle_count,
                        "total_instruction_count": instruction_count,
                        "initial_control_file": self.fctrl_name,
                        "output_dir": self.output_dir,
                    }
                })

        if self.mode == "count":
            Msg.info("Total tasks counted in control file tree: " +
                     str(self.m_app_info.mNumTestsCount) + "\n")

        if self.terminated:
            Msg.info(
                "####\n#### Reached max fails limit before test was completed.\n####"
            )

        self.writeVersionInfo()
        self.modulesReport()
Пример #6
0
    def process(self):

        for my_ndx in range(0, self.ctrl_item.iterations):

            # shutdown has been triggered do not do the next iteration
            if self.is_terminated():
                return

            try:
                self.process_task_list()

            except Exception as arg_ex:
                Msg.error_trace()
                Msg.err(str(arg_ex))
                Msg.blank()
Пример #7
0
    def process_task_list(self):
        for my_task_file in self.task_list:

            # shutdown has been triggered stop processing tasks
            if self.is_terminated():
                return

            my_curdir = PathUtils.current_dir()
            Msg.user("Task list current dir %s" % my_curdir)

            try:
                # self.process_task_file( my_task_file )
                self.process_task_file(my_task_file, my_curdir)
            except Exception as arg_ex:
                Msg.error_trace()
                Msg.err(str(arg_ex))
                Msg.blank()
Пример #8
0
    def process_summary_tasks( self, arg_ofile, arg_sum_level ):
        Msg.blank( "info" )
        my_instr_count = 0
        my_cycle_count = 0
        # get the outer task
        for my_key in self.tasks:
            try:
                arg_ofile.write( "\nTask: %s\n" % ( my_key ))
                task_instr_count, task_cycle_count = self.process_summary_task( arg_ofile, self.tasks[ my_key ], arg_sum_level )
                my_instr_count += task_instr_count
                my_cycle_count += task_cycle_count
            except:
                Msg.error_trace()
                Msg.err( "Processing Task %s, Skipping Item ...." % ( my_key ))

        self.total_instruction_count = my_instr_count
        self.total_cycle_count = my_cycle_count
        return my_instr_count, my_cycle_count
Пример #9
0
    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
Пример #10
0
    def process(self):
        # Msg.dbg( "TaskController::process()")

        for my_ndx in range(0, self.ctrl_item.iterations):

            # shutdown has been triggered do not do the next iteration
            if self.is_terminated():
                return

            try:
                self.process_task_list()

            except Exception as arg_ex:
                Msg.error_trace()
                Msg.err(str(arg_ex))
                Msg.blank()
                # self.do_fail()
            finally:
                pass
Пример #11
0
    def process_summary_totals( self, arg_ofile, arg_instr_count, arg_cycle_count ):
        Msg.blank("info")

        # generator totals
        my_gfails =  self.gen_total - self.gen_passed
        my_lines =  "\nGenerate    : %3d\n" % ( self.gen_total )
        my_lines += "Generate Fails: %3d\n" % ( my_gfails )
        my_lines += "Generate Success Rate : %5.2f%%\n" % ( SysUtils.percent( self.gen_passed, self.gen_total ))
        my_lines += "\n"

        my_sfails = 0
        if self.iss_total >0:
            # ISS sim totals
            my_sfails =  self.iss_total - self.iss_passed
            my_lines += "ISS Sim   : %3d\n" % ( self.iss_total )
            my_lines += "ISS Sim Fails: %3d\n" % ( my_sfails )
            my_lines += "ISS Sim Success Rate : %5.2f%%\n" % ( SysUtils.percent( self.iss_passed, self.iss_total ))
            my_lines += "\n"

            my_lines += "Total Instructions Emulated: %3d\n" % ( arg_instr_count )
            my_lines += "\n"

        my_rfails = 0
        if self.rtl_total >0:
            # RTL sim totals
            my_rfails =  self.rtl_total - self.rtl_passed
            my_lines += "RTL Sim   : %3d\n" % ( self.rtl_total )
            my_lines += "RTL Sim Fails: %3d\n" % ( my_rfails )
            my_lines += "RTL Sim Success Rate : %5.2f%%\n" % ( SysUtils.percent( self.rtl_passed, self.rtl_total ))
            my_lines += "\n"

            my_lines += "Total Cycle Count: %3d\n" % ( arg_cycle_count )
            my_lines += "\n"

        my_cfails = 0
        if self.trace_cmp_total > 0:
            # simulation totals
            my_cfails = self.trace_cmp_total - self.trace_cmp_passed
            my_lines += "Compared     : %3d\n" % ( self.trace_cmp_total )
            my_lines += "Compare Fails: %3d\n" % ( my_cfails )
            my_lines += "Compare Success Rate : %5.2f%%\n" % ( SysUtils.percent( self.trace_cmp_passed, self.trace_cmp_total ))
            my_lines += "\n"


        # task totals
        my_task_total = ( self.task_total)
        my_total_fails =  my_gfails + my_sfails + my_cfails + my_rfails
        my_lines += "Total Tasks     : %3d\n" % ( my_task_total )
        my_lines += "Task Fails      : %3d\n"   % ( my_total_fails )
        my_lines += "Task Success Rate: %5.2f%%\n" % ( SysUtils.percent( my_task_total - my_total_fails, ( my_task_total )))
        my_lines += "\n"
        my_lines += "Total Run Time: %0.5f Seconds" % ( DateTime.Time() - self.start_time )

        Msg.blank("info")
        Msg.info( my_lines )
        Msg.blank("info")

        arg_ofile.write( my_lines )
Пример #12
0
 def __exit__(self, exc_type, exc_val, exc_tb):
     self.process_result()
     Msg.blank()
Пример #13
0
    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.GenCmd == SummaryDetail.GenCmd:
                my_msg += "GenCmd, "
            if self.detail_flags & SummaryDetail.GenResult == SummaryDetail.GenResult:
                my_msg += "GenResult, "
            if self.detail_flags & SummaryDetail.IssCmd == SummaryDetail.IssCmd:
                my_msg += "IssCommand, "
            if self.detail_flags & SummaryDetail.IssResult == SummaryDetail.IssResult:
                my_msg += "IssResult, "
            if self.detail_flags & SummaryDetail.TraceCmpCmd == SummaryDetail.TraceCmpCmd:
                my_msg += "TraceCmpCommand, "
            if self.detail_flags & SummaryDetail.TraceCmpResult == SummaryDetail.TraceCmpResult:
                my_msg += "TraceCmpResult, "

            # remove the trailing comma
            my_msg = my_msg[:-2]

        Msg.user(my_msg, "SUM-RPT")
        Msg.user("Force Return Code: %s" % (str(self.force_retcode)),
                 "SUM-RPT")
        # Msg.trace()

        # Msg.info( "Originating Control File: %s"  % ( self.parent_fctrl ))
        # Msg.info( "Control File Item: %s"  % ( str(  self.fctrl_item )))  2
        # Msg.info( "F-Run Control File: %s" % ( self.frun_path ))
        Msg.dbg("Force Ret Code: %s" % (str(self.force_retcode)))

        if SysUtils.success(self.force_retcode):
            Msg.info("[SUCCESS] Generate Command: %s" % (str(self.force_cmd)))
            Msg.info("Instructions Generated - "
                     "Default: %d, Secondary: %d, Total: %d" %
                     (self.default, self.secondary, self.total))
        elif self.signal_id is not None:
            Msg.info("[INCOMPLETE] Generate Command: %s" %
                     (str(self.force_cmd)))
            Msg.info("No Instructions Generated")
        else:
            Msg.info("[FAILED] Generate Command: %s" % (str(self.force_cmd)))
            Msg.info("No Instructions Generated")

        if self.iss_cmd is not None:
            if self.iss_success():
                Msg.info("[SUCCESS] ISS Command: %s" % (str(self.iss_cmd)))
            elif self.signal_id is not None:
                Msg.info("[INCOMPLETE] ISS Command: %s" % (str(self.iss_cmd)))
            else:
                Msg.info("[FAILED] ISS Command: %s" % (str(self.iss_cmd)))
            # Msg.fout( self.iss_log, "user" )

        if self.rtl_cmd is not None:
            if SysUtils.success(self.rtl_retcode):
                Msg.info("[SUCCESS] RTL Command: %s" % (str(self.rtl_cmd)))
                Msg.info("Cycle count : %d" % (self.cycle_count))
            elif self.signal_id is not None:
                Msg.info("[INCOMPLETE] RTL Command: %s" % (str(self.rtl_cmd)))
            else:
                Msg.info("[FAILED] RTL Command: %s" % (str(self.rtl_cmd)))

        if self.detail_flags & SummaryDetail.TraceCmpCmd == SummaryDetail.TraceCmpCmd:
            Msg.info("Comparing Simulation output .... ")
            if SysUtils.success(self.trace_cmp_retcode):
                Msg.info("[SUCCESS] Trace Compare Command: %s" %
                         (str(self.trace_cmp_cmd)))
            elif self.signal_id is not None:
                Msg.info("[INCOMPLETE] Trace Compare Command: %s" %
                         (str(self.trace_cmp_cmd)))
            else:
                Msg.info("[FAILED] Trace Compare Command: %s" %
                         (str(self.trace_cmp_cmd)))

        Msg.blank()
Пример #14
0
 def thread_done(self):
     Msg.info("UnitTest_LoopThread << Execute Done .... ")
     Msg.blank()
Пример #15
0
        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

        Msg.error_trace("[ERROR] - " + str(arg_ex))
        force_usage(UsageStr)
        sys.exit(41)

    except Exception as arg_ex:

        from force_init import force_usage

        Msg.err(
    def load(self, arg_ctrl_item):
        super().load(arg_ctrl_item)
        # Msg.user( "FileController::load(1)" )

        self.parent_fctrl = self.ctrl_item.file_path()
        # Msg.user( "FileController::load(2)" )
        Msg.user("File Path: %s" % (self.parent_fctrl), "FCTRL-LOADER")

        try:
            my_content = open(self.parent_fctrl).read()

            # Msg.user( "FileController::load(3)" )
        except Exception as arg_ex:
            # Msg.user( "FileController::load(4)" )
            Msg.err("Message: %s, Control File Path: %s" %
                    (str(arg_ex), self.parent_fctrl))
            my_err_queue_item = SummaryErrorQueueItem({
                "error":
                arg_ex,
                "message":
                "Control File Not Found ...",
                "path":
                self.ctrl_item.file_path(),
                "type":
                str(type(arg_ex))
            })

            ## Msg.user( "FileController::load(5)" )
            if self.mProcessQueue.summary is not None:
                self.mProcessQueue.summary.queue.enqueue(my_err_queue_item)
            return False
        finally:
            # Msg.user( "FileController::load(6)" )
            pass

        try:
            # Msg.user( "FileController::load(7)" )
            my_glb, my_loc = SysUtils.exec_content(my_content, False,
                                                   self.mControlFileLocals)
            # Msg.user( "FileController::load(8)" )

        except Exception as arg_ex:
            # Msg.user( "FileController::load(9)" )
            my_exc_type, my_exc_val, my_exc_tb = sys.exc_info()
            my_ex = arg_ex

            Msg.err("Message: %s, Control File Path: %s" %
                    (str(arg_ex), self.parent_fctrl))
            Msg.blank()

            ## Msg.user( "FileController::load(10)" )
            my_err_queue_item = SummaryErrorQueueItem({
                "error":
                arg_ex,
                "message":
                "Control File not processed...",
                "path":
                self.ctrl_item.file_path(),
                "type":
                str(my_exc_type)
            })

            if self.mProcessQueue.summary is not None:
                self.mProcessQueue.summary.queue.enqueue(my_err_queue_item)
            return False

        finally:
            # Msg.user( "FileController::load(12)" )
            pass

        self.fcontrol = my_loc["control_items"]

        #propagate local variables
        for key in my_loc.keys():
            self.mControlFileLocals.update({key: my_loc[key]})

        # Msg.user( "FileController::load(13)" )
        return True
    def process(self):

        # Msg.dbg( "FileController::process()" )
        # Msg.dbg( "FileController Contents: \n\"" + str( self.fcontrol ) + "\n" )

        try:
            # Msg.lout( my_options["work-dir"], MsgLevel.dbg, "Work Director Stack" )
            # a control file may iterate through to completion according to the amount set in num_runs
            for my_ndx in range(self.ctrl_item.iterations):

                # Msg.user( "Executing %d of %d Iterations, Control File: %s" % ( my_ndx + 1, self.ctrl_item.iterations, self.ctrl_item.file_path()) , "FILE-ITERATION")
                if self.is_terminated():
                    break

                try:
                    my_item_ndx = 0
                    # each item in the control set exists as a dictionary
                    for my_item_dict in self.fcontrol:
                        try:
                            if self.is_terminated():
                                break

                            my_item_ndx += 1
                            # Msg.user( "Processing Line: %s" % (str( my_item_dict )), "CTRL-FILE"  )  )

                            my_ctrl_item = ControlItem()
                            my_ctrl_item.parent_fctrl = self.parent_fctrl
                            my_ctrl_item.fctrl_item = str(my_item_dict)

                            try:
                                my_ctrl_item.load(self.mAppsInfo, my_item_dict,
                                                  self.ctrl_item)
                            except:
                                raise

                            my_item_type = my_ctrl_item.item_type()
                            my_controller = None

                            if my_item_type == ControlItemType.TaskItem:
                                # Msg.dbg( "\nControl Item is a Control Task ..." )
                                my_controller = TaskController(
                                    self.mProcessQueue, self.mAppsInfo)

                            elif my_item_type == ControlItemType.FileItem:
                                # Msg.dbg( "\nControl Item is a Control File ..." )
                                my_controller = FileController(
                                    self.mProcessQueue, self.mAppsInfo,
                                    self.mControlFileLocals)

                            else:
                                raise Exception(
                                    "\"" + my_fctrl_name +
                                    "\": Unknown Item Type ...\nUnable to Process ... "
                                )

                            if my_controller.load(my_ctrl_item):
                                my_controller.set_on_fail_proc(
                                    self.on_fail_proc)
                                my_controller.set_is_term_proc(
                                    self.is_term_proc)
                                my_controller.process()
                            # Msg.dbg( "%s: Controller Creation Complete" % ( my_ctrl_item.fctrl_name ))

                        except TypeError as arg_ex:

                            Msg.err(str(arg_ex))
                            my_err_queue_item = SummaryErrorQueueItem({
                                "error":
                                "Item #%s Contains an Invalid Type" %
                                (str(my_item_ndx)),
                                "message":
                                arg_ex,
                                "path":
                                self.ctrl_item.file_path(),
                                "type":
                                str(type(arg_ex))
                            })

                            if self.mProcessQueue.summary is not None:
                                self.mProcessQueue.summary.queue.enqueue(
                                    my_err_queue_item)
                            Msg.blank()

                        except FileNotFoundError as arg_ex:

                            Msg.err(str(arg_ex))
                            my_err_queue_item = SummaryErrorQueueItem({
                                "error":
                                arg_ex,
                                "message":
                                "Control File Not Found ...",
                                "path":
                                self.ctrl_item.file_path(),
                                "type":
                                str(type(arg_ex))
                            })

                            if self.mProcessQueue.summary is not None:
                                self.mProcessQueue.summary.queue.enqueue(
                                    my_err_queue_item)
                            Msg.blank()

                        except Exception as arg_ex:
                            Msg.error_trace(str(arg_ex))
                            Msg.err(str(arg_ex))
                            Msg.blank()

                        finally:
                            my_controller = None
                            my_item_dict = None

                except Exception as arg_ex:
                    Msg.error_trace("[ERROR] - " + str(arg_ex))
                    Msg.err(str(arg_ex))
                finally:
                    pass

        finally:
            pass
            # Msg.dbg()

        return True
Пример #18
0
def main():
    # set up signal handlers,
    signal.signal(signal.SIGINT, handle_signal)
    signal.signal(signal.SIGTERM, handle_signal)

    # initialize variables
    my_hlog = None
    my_org_stdout = None

    # global the_output_path =

    # Step 1: Save the originating directory
    my_pwd = PathUtils.current_dir()

    # Step 3: Extract Pid Group
    os.setpgid(os.getpid(), os.getpid())

    my_module = ForrestRun()

    try:
        my_module.force_path = the_force_root

        my_logfile = my_module.m_app_info.mCmdLineOpts.option_def(
            CmdLine.Switches[CmdLine.logfile], None)

        if my_logfile is not None:
            # print( "Redirecting STDOUT to my_logfile" )
            my_org_stdout = sys.stdout
            my_hlog = open(my_logfile, "w")
            sys.stdout = my_hlog
            Msg.user("Log File: %s" % (str(my_logfile)), "STDLOG")

        Msg.dbg("\nForce Path: %s" % (str(the_force_root)))
        Msg.dbg("Original Directory: " + my_pwd)

        # save current working directory

        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(my_module.frun_dir, False):
            Msg.dbg(
                "Directory Unchanged, using the current directory for output")

        my_module.run()
        Msg.dbg("Test Completed ....\n")
        Msg.blank()
        # sys.exit( 0 )

    except Exception as ex:
        from force_init import force_usage

        Msg.err("An Unhandled Error has Occurred during run of " +
                str(sys.argv[0]))
        traceback.print_exc(file=sys.stdout)
        Msg.error_trace(str(ex))
        my_module.m_app_info.mCmdLineOpts.print_help()
        sys.exit(41)

    except BaseException:
        print("[ERROR] - An Unhandled Error has Occurred during run of " +
              str(sys.argv[0]))
        traceback.print_exc(file=sys.stdout)
        sys.exit(42)

    finally:
        if my_logfile is not None:
            my_hlog.close()
            sys.stdout = my_org_stdout
            with open(my_logfile, "r") as my_hlog:
                print(my_hlog.read())

        if my_pwd is not None:
            PathUtils.chdir(my_pwd)
            Msg.dbg("Returned To: %s" % (PathUtils.current_dir()))
Пример #19
0
    def process(self):

        for my_ndx in range(self.ctrl_item.iterations):

            if self.is_terminated():
                break

            try:
                my_item_ndx = 0
                for my_item_dict in self.fcontrol:
                    try:
                        if self.is_terminated():
                            break

                        my_item_ndx += 1

                        my_ctrl_item = ControlItem()
                        my_ctrl_item.parent_fctrl = self.parent_fctrl
                        my_ctrl_item.fctrl_item = str(my_item_dict)

                        try:
                            my_ctrl_item.load(
                                self.mAppsInfo,
                                my_item_dict,
                                self.ctrl_item,
                            )
                        except BaseException:
                            raise

                        my_item_type = my_ctrl_item.item_type()
                        my_controller = None

                        if my_item_type == ControlItemType.TaskItem:
                            my_controller = TaskController(
                                self.mProcessQueue, self.mAppsInfo)

                        elif my_item_type == ControlItemType.FileItem:
                            my_controller = FileController(
                                self.mProcessQueue,
                                self.mAppsInfo,
                                self.mControlFileLocals,
                            )

                        else:
                            raise Exception('"' + my_fctrl_name +
                                            '": Unknown Item Type ...\n'
                                            "Unable to Process ... ")

                        if my_controller.load(my_ctrl_item):
                            my_controller.set_on_fail_proc(self.on_fail_proc)
                            my_controller.set_is_term_proc(self.is_term_proc)
                            my_controller.process()

                    except TypeError as arg_ex:

                        Msg.err(str(arg_ex))
                        my_err_queue_item = SummaryErrorQueueItem({
                            "error":
                            "Item #%s Contains an Invalid "
                            "Type" % (str(my_item_ndx)),
                            "message":
                            arg_ex,
                            "path":
                            self.ctrl_item.file_path(),
                            "type":
                            str(type(arg_ex)),
                        })

                        if self.mProcessQueue.summary is not None:
                            self.mProcessQueue.summary.queue.enqueue(
                                my_err_queue_item)
                        Msg.blank()

                    except FileNotFoundError as arg_ex:

                        Msg.err(str(arg_ex))
                        my_err_queue_item = SummaryErrorQueueItem({
                            "error":
                            arg_ex,
                            "message":
                            "Control File Not Found ...",
                            "path":
                            self.ctrl_item.file_path(),
                            "type":
                            str(type(arg_ex)),
                        })

                        if self.mProcessQueue.summary is not None:
                            self.mProcessQueue.summary.queue.enqueue(
                                my_err_queue_item)
                        Msg.blank()

                    except Exception as arg_ex:
                        Msg.error_trace(str(arg_ex))
                        Msg.err(str(arg_ex))
                        Msg.blank()

                    finally:
                        my_controller = None
                        my_item_dict = None

            except Exception as arg_ex:
                Msg.error_trace("[ERROR] - " + str(arg_ex))
                Msg.err(str(arg_ex))

        return True