def __init__(self, cros_path, password=''):
     self.logger = logging.getLogger(self.__class__.__name__)
     self.in_chroot = True if which('dut-control') else False
     ON_POSIX = 'posix' in sys.builtin_module_names
     if self.in_chroot:
         self.cros_sdk_session = Popen(['/bin/sh'], bufsize=1, stdin=PIPE, stdout=PIPE, stderr=PIPE,
                                       cwd=cros_path, close_fds=ON_POSIX, shell=True)
     else:
         cros_sdk_bin_path = which('cros_sdk')
         potential_path = os.path.join("cros_path", "chromium/tools/depot_tools/cros_sdk")
         if not cros_sdk_bin_path and os.path.isfile(potential_path):
             cros_sdk_bin_path = potential_path
         if not cros_sdk_bin_path:
             raise HostError("Failed to locate 'cros_sdk' make sure it is in your PATH")
         self.cros_sdk_session = Popen(['sudo -Sk {}'.format(cros_sdk_bin_path)], bufsize=1, stdin=PIPE,
                                       stdout=PIPE, stderr=PIPE, cwd=cros_path, close_fds=ON_POSIX, shell=True)
         self.cros_sdk_session.stdin.write(password)
         self.cros_sdk_session.stdin.write('\n')
     self.stdout_queue = Queue()
     self.stdout_thread = OutputPollingThread(self.cros_sdk_session.stdout, self.stdout_queue, 'stdout')
     self.stdout_thread.daemon = True
     self.stdout_thread.start()
     self.stderr_queue = Queue()
     self.stderr_thread = OutputPollingThread(self.cros_sdk_session.stderr, self.stderr_queue, 'stderr')
     self.stderr_thread.daemon = True
     self.stderr_thread.start()
Example #2
0
def _check_env():
    global ssh, scp, sshpass  # pylint: disable=global-statement
    if not ssh:
        ssh = which('ssh')
        scp = which('scp')
        sshpass = which('sshpass')
    if not (ssh and scp):
        raise HostError('OpenSSH must be installed on the host.')
def _check_env():
    global ssh, scp, sshpass  # pylint: disable=global-statement
    if not ssh:
        ssh = which('ssh')
        scp = which('scp')
        sshpass = which('sshpass')
    if not (ssh and scp):
        raise HostError('OpenSSH must be installed on the host.')
    def _start_servod(self):
        in_chroot = False if which('dut-control') is None else True
        password = ''
        if not in_chroot:
            msg = 'Instrument %s requires sudo access on this machine to start `servod`'
            self.logger.info(msg, self.name)
            self.logger.info('You need to be sudoer to use it.')
            password = getpass.getpass()
            check = subprocess.call('echo {} | sudo -S ls > /dev/null'.format(password), shell=True)
            if check:
                raise InstrumentError('Given password was either wrong or you are not a sudoer')
        self.server_session = CrosSdkSession(self.chroot_path, password=password)
        password = ''

        command = 'sudo servod -b {b} -c {b}.xml'
        if self.vid and self.pid:
            command += " -v " + self.vid
            command += " -p " + self.pid
        command += '&'
        self.server_session.send_command(command.format(b=self.board_name))
        for _ in xrange(self.servod_max_tries):
            server_lines = self.server_session.get_lines(timeout=1, from_stderr=True,
                                                         timeout_only_for_first_line=False)
            if server_lines:
                if 'Listening on' in server_lines[-1]:
                    self.port = int(server_lines[-1].split()[-1])
                    break
            time.sleep(self.servod_delay_between_tries)
        else:
            raise InstrumentError('Failed to start servod in cros_sdk environment')
Example #5
0
 def initialize(self, context):
     # pylint: disable=access-member-before-definition
     self.in_chroot = False if which('dut-control') is None else True
     self.poller = None
     domains_string = '_mw '.join(self.power_domains + [''])
     password = ''
     if not self.in_chroot:
         self.logger.info('Instrument {} requires sudo acces on this machine'.format(self.name))
         self.logger.info('You need to be sudoer to use it.')
         password = getpass.getpass()
         check = subprocess.call('echo {} | sudo -S ls > /dev/null'.format(password), shell=True)
         if check:
             raise InstrumentError('Given password was either wrong or you are not a sudoer')
     self.server_session = CrosSdkSession(self.chroot_path, password=password)
     self.cros_session = CrosSdkSession(self.chroot_path, password=password)
     password = ''
     self.server_session.send_command('sudo servod -b {b} -c {b}.xml&'.format(b=self.board_name))
     checks = 0
     while True:
         if checks >= self.servod_max_tries:
             raise InstrumentError('Failed to start servod in cros_sdk environment')
         server_lines = self.server_session.get_lines(timeout=1, from_stderr=True,
                                                      timeout_only_for_first_line=False)
         if server_lines and 'Listening on' in server_lines[-1]:
             break
         time.sleep(self.servod_delay_between_tries)
         checks += 1
     self.port = int(server_lines[-1].split()[-1])
     self.command = 'dut-control {} -p {}'.format(domains_string, self.port)
     if not self.labels:
         self.labels = ["PORT_{}".format(channel) for channel, _ in enumerate(self.power_domains)]
     self.power_data = None
     self.stopped = True
Example #6
0
def _init_common(env):
    logger.debug('ANDROID_HOME: {}'.format(env.android_home))
    build_tools_directory = os.path.join(env.android_home, 'build-tools')
    if os.path.isdir(build_tools_directory):
        versions = os.listdir(build_tools_directory)
        for version in reversed(sorted(versions)):
            aapt_path = os.path.join(build_tools_directory, version, 'aapt')
            if os.path.isfile(aapt_path):
                logger.debug('Using aapt for version {}'.format(version))
                env.aapt = aapt_path
                break
        else:
            raise HostError(
                'aapt not found. Please make sure at least one Android platform is installed.'
            )
    else:
        # User may already installed 'aapt' from package provided by distro's
        # Try finding in $PATH
        aapt_path = which('aapt')
        if aapt_path:
            logger.debug('Using aapt from {}'.format(aapt_path))
            env.aapt = aapt_path
        else:
            msg = 'ANDROID_HOME ({}) does not appear to have valid Android SDK install (cannot find build-tools)'
            raise HostError(msg.format(env.android_home))
 def __init__(self, cros_path, password=''):
     self.logger = logging.getLogger(self.__class__.__name__)
     self.in_chroot = True if which('dut-control') else False
     ON_POSIX = 'posix' in sys.builtin_module_names
     if self.in_chroot:
         self.cros_sdk_session = Popen(['/bin/sh'],
                                       bufsize=1,
                                       stdin=PIPE,
                                       stdout=PIPE,
                                       stderr=PIPE,
                                       cwd=cros_path,
                                       close_fds=ON_POSIX,
                                       shell=True)
     else:
         cros_sdk_bin_path = which('cros_sdk')
         potential_path = os.path.join(
             "cros_path", "chromium/tools/depot_tools/cros_sdk")
         if not cros_sdk_bin_path and os.path.isfile(potential_path):
             cros_sdk_bin_path = potential_path
         if not cros_sdk_bin_path:
             raise HostError(
                 "Failed to locate 'cros_sdk' make sure it is in your PATH")
         self.cros_sdk_session = Popen(
             ['sudo -Sk {}'.format(cros_sdk_bin_path)],
             bufsize=1,
             stdin=PIPE,
             stdout=PIPE,
             stderr=PIPE,
             cwd=cros_path,
             close_fds=ON_POSIX,
             shell=True)
         self.cros_sdk_session.stdin.write(password)
         self.cros_sdk_session.stdin.write('\n')
     self.stdout_queue = Queue()
     self.stdout_thread = OutputPollingThread(self.cros_sdk_session.stdout,
                                              self.stdout_queue, 'stdout')
     self.stdout_thread.daemon = True
     self.stdout_thread.start()
     self.stderr_queue = Queue()
     self.stderr_thread = OutputPollingThread(self.cros_sdk_session.stderr,
                                              self.stderr_queue, 'stderr')
     self.stderr_thread.daemon = True
     self.stderr_thread.start()
Example #8
0
 def validate(self):
     if not which('streamline'):
         raise InstrumentError('streamline not in PATH. Cannot enable Streamline tracing.')
     p = subprocess.Popen('streamline --version 2>&1', stdout=subprocess.PIPE, shell=True)
     out, _ = p.communicate()
     match = VERSION_REGEX.search(out)
     if not match:
         raise InstrumentError('Could not find streamline version.')
     version_tuple = tuple(map(int, match.group(1).split('.')))
     if version_tuple < (5, 17):
         raise InstrumentError('Need DS-5 v5.17 or greater; found v{}'.format(match.group(1)))
Example #9
0
 def setup(self, context):
     if self.device.platform != 'chromeos':
         raise WorkloadError('{} only supports ChromeOS devices'.format(self.name))
     self.test_that = which('test_that')
     if not self.test_that:
         message = ('Could not find "test_that"; {} must be running in a ChromeOS SDK chroot '
                    '(did you execute "cros_sdk"?)')
         raise WorkloadError(message.format(self.name))
     self.command = self._build_command()
     self.raw_output = None
     # make sure no other test is running
     self.device.execute('killall -9 autotest', check_exit_code=False)
Example #10
0
 def __init__(self, cros_path, password=''):
     self.in_chroot = True if which('dut-control') else False
     ON_POSIX = 'posix' in sys.builtin_module_names
     if self.in_chroot:
         self.cros_sdk_session = Popen(['/bin/sh'], bufsize=1, stdin=PIPE, stdout=PIPE, stderr=PIPE,
                                       cwd=cros_path, close_fds=ON_POSIX, shell=True)
     else:
         cros_sdk_bin_path = which('cros_sdk')
         if not cros_sdk_bin_path:
             raise HostError("Failed to locate 'cros_sdk' make sure it is in your PATH")
         self.cros_sdk_session = Popen(['sudo -Sk {}'.format(cros_sdk_bin_path)], bufsize=1, stdin=PIPE,
                                 stdout=PIPE, stderr=PIPE, cwd=cros_path, close_fds=ON_POSIX, shell=True)
         self.cros_sdk_session.stdin.write(password)
         self.cros_sdk_session.stdin.write('\n')
     self.stdout_queue = Queue()
     self.stdout_thread = OutputPollingThread(self.cros_sdk_session.stdout, self.stdout_queue, 'stdout')
     self.stdout_thread.daemon = True
     self.stdout_thread.start()
     self.stderr_queue = Queue()
     self.stderr_thread = OutputPollingThread(self.cros_sdk_session.stderr, self.stderr_queue, 'stderr')
     self.stderr_thread.daemon = True
     self.stderr_thread.start()
Example #11
0
 def validate(self):
     if not which('streamline'):
         raise InstrumentError(
             'streamline not in PATH. Cannot enable Streamline tracing.')
     p = subprocess.Popen('streamline --version 2>&1',
                          stdout=subprocess.PIPE,
                          shell=True)
     out, _ = p.communicate()
     match = VERSION_REGEX.search(out)
     if not match:
         raise InstrumentError('Could not find streamline version.')
     version_tuple = tuple(map(int, match.group(1).split('.')))
     if version_tuple < (5, 17):
         raise InstrumentError(
             'Need DS-5 v5.17 or greater; found v{}'.format(match.group(1)))
Example #12
0
def _init_common(env):
    logger.debug('ANDROID_HOME: {}'.format(env.android_home))
    build_tools_directory = os.path.join(env.android_home, 'build-tools')
    if os.path.isdir(build_tools_directory):
        versions = os.listdir(build_tools_directory)
        for version in reversed(sorted(versions)):
            aapt_path = os.path.join(build_tools_directory, version, 'aapt')
            if os.path.isfile(aapt_path):
                logger.debug('Using aapt for version {}'.format(version))
                env.aapt = aapt_path
                break
        else:
            raise HostError('aapt not found. Please make sure at least one Android platform is installed.')
    else:
        # User may already installed 'aapt' from package provided by distro's
        # Try finding in $PATH
        aapt_path = which('aapt')
        if aapt_path:
            logger.debug('Using aapt from {}'.format(aapt_path))
            env.aapt = aapt_path
        else:
            msg = 'ANDROID_HOME ({}) does not appear to have valid Android SDK install (cannot find build-tools)'
            raise HostError(msg.format(env.android_home))
Example #13
0
class AcmeCapeInstrument(Instrument):

    name = 'acmecape'
    description = """
    Instrumetnation for the BayLibre ACME cape for power/energy measurment.
    """

    parameters = [
        Parameter('iio-capture',
                  default=which('iio-capture'),
                  description="""
                  Path to the iio-capture binary will be taken from the
                  environment, if not specfied.
                  """),
        Parameter('host',
                  default='baylibre-acme.local',
                  description="""
                  Host name (or IP address) of the ACME cape board.
                  """),
        Parameter('iio-device',
                  default='iio:device0',
                  description="""
                  """),
        Parameter('buffer-size',
                  kind=int,
                  default=256,
                  description="""
                  Size of the capture buffer (in KB).
                  """),
    ]

    def initialize(self, context):
        if self.iio_capture is None:
            raise HostError('Missing iio-capture binary')
        self.command = None
        self.subprocess = None

    def setup(self, context):
        self.outfile = os.path.join(context.output_directory,
                                    'acme-capture.csv')
        params = dict(
            iio_capture=self.iio_capture,
            host=self.host,
            buffer_size=self.buffer_size,
            iio_device=self.iio_device,
            outfile=self.outfile,
        )
        self.command = IIOCAP_CMD_TEMPLATE.substitute(**params)
        self.logger.debug('ACME cape command: {}'.format(self.command))

    def very_fast_start(self, context):  # pylint: disable=unused-argument
        self.subprocess = Popen(self.command.split(),
                                stdout=PIPE,
                                stderr=STDOUT)

    def very_fast_stop(self, context):  # pylint: disable=unused-argument
        self.subprocess.terminate()

    def update_result(self, context):
        timeout_secs = 10
        for _ in xrange(timeout_secs):
            if self.subprocess.poll() is not None:
                break
            time.sleep(1)
        else:
            output = _read_nonblock(self.subprocess.stdout)
            self.subprocess.kill()
            self.logger.error('iio-capture did not terminate gracefully')
            if self.subprocess.poll() is None:
                msg = 'Could not terminate iio-capture:\n{}'
                raise HostError(msg.format(output))
        if not os.path.isfile(self.outfile):
            raise HostError('Output CSV not generated.')

        context.add_iteration_artifact('iio-capture', self.outfile, 'data')
        if os.stat(self.outfile).st_size == 0:
            self.logger.warning('"{}" appears to be empty'.format(
                self.outfile))
            return
        self._compute_stats(context)

    def _compute_stats(self, context):
        with open(self.outfile, 'rb') as fh:
            reader = csv.reader(fh, skipinitialspace=True)
            header = reader.next()
            power_index = header.index('power mW')
            ts_index = header.index('timestamp ms')

            last_ts = 0.0
            energy_uj = 0
            ave_power_mw = 0.0

            for i, row in enumerate(reader):
                row_power_mw = float(row[power_index])
                row_ts = float(row[ts_index])

                if i == 0:
                    ave_power_mw = row_power_mw
                else:
                    ave_power_mw = ave_power_mw + (row_power_mw -
                                                   ave_power_mw) / i
                    energy_uj += row_power_mw * (row_ts - last_ts)
                last_ts = row_ts

            context.add_metric('power', ave_power_mw, 'milliwatts')
            context.add_metric('energy', energy_uj / 1000000, 'joules')