示例#1
0
  def _Run(self, url):
    """Run the latency test.

    Handles the actual latency measurement, which is identical across
    different platforms, as well as result storing.
    """
    # Motopho scripts use relative paths, so switch to the Motopho directory.
    os.chdir(self._args.motopho_path)

    # Set up the thread that runs the Motopho script.
    motopho_thread = mt.MotophoThread(self._num_samples)
    motopho_thread.start()

    # Run multiple times so we can get an average and standard deviation.
    for _ in xrange(self._num_samples):
      self.robot_arm.ResetPosition()
      # Start the Motopho script.
      motopho_thread.StartIteration()
      # Let the Motopho be stationary so the script can calculate the bias.
      time.sleep(3)
      motopho_thread.BlockNextIteration()
      # Move so we can measure latency.
      self.robot_arm.StartMotophoMovement()
      if not motopho_thread.WaitForIterationEnd(MOTOPHO_THREAD_TIMEOUT):
        # TODO(bsheedy): Look into ways to prevent Motopho from not sending any
        # data until unplugged and replugged into the machine after a reboot.
        logging.error('Motopho thread timeout, '
                      'Motopho may need to be replugged.')
      self.robot_arm.StopAllMovement()
      time.sleep(1)
    self._StoreResults(motopho_thread.latencies, motopho_thread.correlations,
                       url)
示例#2
0
    def _Run(self, url):
        """Run the latency test.

    Handles the actual latency measurement, which is identical across
    different platforms, as well as result storing.
    """
        # Motopho scripts use relative paths, so switch to the Motopho directory.
        os.chdir(self._args.motopho_path)

        # Set up the thread that runs the Motopho script.
        motopho_thread = mt.MotophoThread()
        motopho_thread.start()

        # Run multiple times so we can get an average and standard deviation.
        num_retries = 0
        samples_obtained = 0
        while samples_obtained < self._num_samples:
            self.robot_arm.ResetPosition()
            # Start the Motopho script.
            motopho_thread.StartIteration()
            # Let the Motopho be stationary so the script can calculate the bias.
            time.sleep(3)
            motopho_thread.BlockNextIteration()
            # Move so we can measure latency.
            self.robot_arm.StartMotophoMovement()
            if not motopho_thread.WaitForIterationEnd(MOTOPHO_THREAD_TIMEOUT):
                # TODO(bsheedy): Look into ways to prevent Motopho from not sending any
                # data until unplugged and replugged into the machine after a reboot.
                logging.error('Motopho thread timeout, '
                              'Motopho may need to be replugged.')

            self.robot_arm.StopAllMovement()

            if motopho_thread.failed_iteration:
                num_retries += 1
                if num_retries > MOTOPHO_THREAD_RETRIES:
                    self._ReportSummaryResult(False, url)
                    # Raising an exception with another thread still alive causes the
                    # test to hang until the swarming timeout is hit, so kill the thread
                    # before raising.
                    motopho_thread.Terminate()
                    motopho_thread.join(MOTOPHO_THREAD_TERMINATION_TIMEOUT)
                    raise RuntimeError(
                        'Motopho thread failed more than %d times, aborting' %
                        (MOTOPHO_THREAD_RETRIES))
                logging.warning('Motopho thread failed, retrying iteration')
            else:
                samples_obtained += 1
            time.sleep(1)
        self._ReportSummaryResult(True, url)
        self._StoreResults(motopho_thread.latencies,
                           motopho_thread.correlations, url)
        # Leaving old threads around shouldn't cause issues, but clean up just in
        # case
        motopho_thread.Terminate()
        motopho_thread.join(MOTOPHO_THREAD_TERMINATION_TIMEOUT)
        if motopho_thread.isAlive():
            logging.warning('Motopho thread failed to terminate.')