Esempio n. 1
0
 def close_bgjob(self):
     """Close background job and log stdout and stderr."""
     utils.nuke_subprocess(self.bg_job.sp)
     utils.join_bg_jobs([self.bg_job], timeout=1)
     result = self.bg_job.result
     if result.stdout or result.stderr:
         logging.info('stdout of Chrome Driver:\n%s', result.stdout)
         logging.error('stderr of Chrome Driver:\n%s', result.stderr)
    def save_log_bg(self):
        """Save the log from client in background."""
        # Run a tail command in background that keeps all the log messages from
        # client.
        command = 'tail -n0 -f %s' % constants.MULTIMEDIA_XMLRPC_SERVER_LOG_FILE
        full_command = '%s "%s"' % (self._client.ssh_command(), command)

        if self._log_saving_job:
            # Kill and join the previous job, probably due to a DUT reboot.
            # In this case, a new job will be recreated.
            logging.info('Kill and join the previous log job.')
            utils.nuke_subprocess(self._log_saving_job.sp)
            utils.join_bg_jobs([self._log_saving_job])

        # Create the background job and pipe its stdout and stderr to the
        # Autotest logging.
        self._log_saving_job = utils.BgJob(full_command,
                                           stdout_tee=CLIENT_LOG_STREAM,
                                           stderr_tee=CLIENT_LOG_STREAM)
Esempio n. 3
0
    def run_gsctool_cmd_with_password(self, password, cmd, name, expect_error):
        """Run a gsctool command and input the password

        Args:
            password: The cr50 password string
            cmd: The gsctool command
            name: The name to give the job
            expect_error: True if the command should fail
        """
        set_pwd_cmd = utils.sh_escape(cmd)
        full_ssh_command = '%s "%s"' % (self.host.ssh_command(options='-tt'),
                                        set_pwd_cmd)
        stdout = StringIO.StringIO()
        # Start running the gsctool Command in the background.
        gsctool_job = utils.BgJob(full_ssh_command,
                                  nickname='%s_with_password' % name,
                                  stdout_tee=stdout,
                                  stderr_tee=utils.TEE_TO_LOGS,
                                  stdin=subprocess.PIPE)
        if gsctool_job == None:
            raise error.TestFail('could not start gsctool command %r', cmd)

        try:
            # Wait for enter prompt
            gsctool_job.process_output()
            logging.info(stdout.getvalue().strip())
            # Enter the password
            gsctool_job.sp.stdin.write(password + '\n')

            # Wait for re-enter prompt
            gsctool_job.process_output()
            logging.info(stdout.getvalue().strip())
            # Re-enter the password
            gsctool_job.sp.stdin.write(password + '\n')
            time.sleep(self.cr50.CONSERVATIVE_CCD_WAIT)
            gsctool_job.process_output()
        finally:
            exit_status = utils.nuke_subprocess(gsctool_job.sp)
            output = stdout.getvalue().strip()
            logging.info('%s stdout: %s', name, output)
            logging.info('%s exit status: %s', name, exit_status)
            if exit_status:
                message = ('gsctool %s failed using %r: %s %s' %
                           (name, password, exit_status, output))
                if expect_error:
                    logging.info(message)
                else:
                    raise error.TestFail(message)
            elif expect_error:
                raise error.TestFail('%s with %r did not fail when expected' %
                                     (name, password))
Esempio n. 4
0
 def _close_ccd_open_job(self):
     """Terminate the process and check the results."""
     exit_status = utils.nuke_subprocess(self._ccd_open_job.sp)
     stdout = self._ccd_open_stdout.getvalue().strip()
     delattr(self, '_ccd_open_job')
     if stdout:
         logging.info('stdout of ccd open:\n%s', stdout)
     if exit_status:
         logging.info('exit status: %d', exit_status)
     if 'Error' in stdout:
         raise error.TestFail('ccd open Error %s' %
                              stdout.split('Error')[-1])
     if self.cr50.OPEN != self.cr50.get_ccd_level():
         raise error.TestFail('unable to open cr50: %s' % stdout)
     else:
         logging.info('Opened Cr50')
Esempio n. 5
0
 def stop(self, test):
     if self.blktrace_job is not None:
         utils.nuke_subprocess(self.blktrace_job.sp)
     self.blktrace_job = None
 def stop(self, test):
     if self.blktrace_job is not None:
         utils.nuke_subprocess(self.blktrace_job.sp)
     self.blktrace_job = None