Beispiel #1
0
 def test_launch_fsmtest_regression_3(self):
     print "Starting test_launch_fsmtest_regression_3"
     cmd = ["../../bin/fsmt", "../data/scxml/launchtests_seq5.scxml"]
     sub_process = subprocess.Popen(cmd)
     t0 = time.time()
     pid = sub_process.pid
     rc = ResourceCentre(int(pid))
     rc_spawn = eventlet.spawn(rc.resource_counter, "reg3")
     sub_proc_ret_code = sub_process.wait()
     rc.stop()
     t1 = time.time()
     duration = t1 - t0
     self.assertEqual("reg3", rc.caller)
     self.assertEqual(sub_proc_ret_code, 0)
     self.assertNotEqual(sub_proc_ret_code, 1)
     self.assertNotEqual(sub_proc_ret_code, -9)
     self.assertNotEqual(sub_proc_ret_code, -15)
     self.assertNotEqual(sub_proc_ret_code, -2)
     self.assertLess(duration, 12)
     self.assertGreater(duration, 6)
     self.current_cpu_avg = rc.get_average_cpu()
     # This is much more because the internal logger does
     # not take the startup phase into account, however.
     # We need to check this for regression testing
     self.assertLess(self.current_cpu_avg, 20)
     rc_spawn.kill()
Beispiel #2
0
    def run(self):
        """
        Runner method. Sets-up the state machine properly and starts the SCXML Engine.
        """
        # global websocket_connection

        if self.is_setup:
            self.log.debug("Creating FSMT instance using your config: %s", self.path_to_scxml_file[:])
            state_machine_wrapper = StateMachineWrapper()
            state_machine_wrapper.create_state_machine(self.path_to_scxml_file)

            state_machine_wrapper.log_setup(
                self.log, self.log_folder, self.log_folder_fsm,
                self.log_folder_images, self.log_folder_plots,
                self.log_folder_videos, self.log_folder_data,
                self.log_folder_logs, float(self.kill_timeout))

            state_machine_wrapper.xunit_xml_builder = XunitXmlBuilder("FSMT run on %s" % self.path_to_scxml_file[:],
                                                                      self.state_xunit_xml_path)

            process_communicator = ProcessCommunicator()
            process_communicator.setup(state_machine_wrapper, None, self.log)
            state_machine_wrapper.process_communicator = process_communicator

            #####################################
            ###   Start of actual SM script   ###
            #####################################

            # Web Sockets
            # ws_connection = WebSocketConnection()
            # websocket_connection = ws_connection
            # state_machine_wrapper.wsconn = None

            # This signal handler enables us to trap the CTRL+C command and
            # send a exit_grace aka statemachine.send(unsatisfied_criteria)
            # to the SM interpreter. All procs should be killed then.
            def signal_handler(signal, frame):
                self.log.warning("\n\nYou pressed CTRL+C! Trying to gracefully terminate all running processes\n\n")
                state_machine_wrapper.exit_grace = True

            signal.signal(signal.SIGINT, signal_handler)

            # Watch for exit_grace = True, this needs to be a eventlet
            # thread! Otherwise you cannot switch context
            state_machine_wrapper.exit_watcher = ExitWatcher(state_machine_wrapper)

            # Exit watcher is closed in the clean_up block
            eventlet.spawn(state_machine_wrapper.exit_watcher.do_watch)

            init_time = time.time()
            state_machine_wrapper.init_time = init_time
            fsm_pid = os.getpid()
            resource_centre = ResourceCentre(fsm_pid)
            eventlet.spawn(resource_centre.resource_counter)
            state_machine_wrapper.unsatisfied = False
            state_machine_wrapper.start()

            # Build the component based xunit XML
            state_machine_wrapper.xunit_xml_builder.write_xml()

            # Zipping it all up
            source = self.log_folder
            destination = (self.log_folder + ".zip")
            # self.log.info("Writing log archive to %s", destination)
            make_zipfile(source, destination)

            # 'Softlink' latest ZIP Archive and xUnit XML file
            up_dir = self.log_base
            current_file_name = os.path.basename(self.path_to_scxml_file[:])
            current_run = up_dir + current_file_name + "-latest.run"
            current_zip = up_dir + current_file_name + "-latest.zip"
            current_xunit = up_dir + current_file_name + "-latest-xunit.xml"
            # Cleanup old softlink before creating new one
            if os.path.isfile(current_run):
                subprocess.call(["rm", "-f", current_run])
            subprocess.call(["ln", "-sfn", self.log_folder, current_run])
            subprocess.call(["ln", "-sf", str(self.state_xunit_xml_path), current_xunit])
            subprocess.call(["ln", "-sf", str(destination), current_zip])
            self.log.info("Softlink latest RUN %s", str(current_run))
            self.log.info("Softlink latest XUnit %s", str(current_xunit))
            self.log.info("Softlink latest ZIP archive %s", str(current_zip))

            self.log.info("Absolute runtime : %s seconds" % round((time.time() - init_time), 3))

            resource_centre.stop()

            self.log.info("Maximum CPU usage: %s %%", round(resource_centre.max_cpu, 3))
            self.log.info("Average CPU usage: %s %%", round(resource_centre.get_average_cpu(), 3))
            self.log.info("Maximum MEM usage: %s %%", round(resource_centre.max_mem, 3))

            # Cores does not make sense here since fsmt itself will not use more than one core.
            # self.log.info("Maximum CORES    : %s", resource_centre.max_thr)

            if state_machine_wrapper.exit_grace or state_machine_wrapper.unsatisfied:
                result = ""
                if state_machine_wrapper.exit_grace:
                    result += "CTRL+C DETECTED...FSMT RUN ABORTED"
                    state_machine_wrapper.log.warning(result)
                self.log.error(">> FSMT RUN ABORTED OR FAILED <<")
                sys.exit(1)
            else:
                self.log.info(">> FSMT RUN WAS SUCCESSFUL <<")
        else:
            self.log.error("You need to call setup() before calling the run() method!")
            sys.exit(1)