コード例 #1
0
    def start_test(self):
        """ Setup the start of the test.  Stop shill and create test harness."""
        # Stop a system process on test duts for keeping connectivity up.
        ret = utils.stop_service('recover_duts', ignore_status=True)
        self.recover_duts_stopped = (ret == 0)

        self.stop_shill()

        # Deduce the root cryptohome directory name for our fake user.
        self.root_cryptohome_dir = utils.system_output(
            '%s system %s' % (self.cryptohome_path_command, self.fake_user))

        # Deduce the user cryptohome directory name for our fake user.
        self.user_cryptohome_dir = utils.system_output(
            '%s user %s' % (self.cryptohome_path_command, self.fake_user))

        # Deduce the directory for memory log storage.
        self.user_cryptohome_log_dir = ('%s/shill_logs' %
                                        self.root_cryptohome_dir)

        # The sanitized hash of the username is the basename of the cryptohome.
        self.fake_user_hash = os.path.basename(self.root_cryptohome_dir)

        # Just in case this hash actually exists, add these to the list of
        # saved directories.
        self.save_directories.append(self.root_cryptohome_dir)
        self.save_directories.append(self.user_cryptohome_dir)

        # Archive the system state we will be modifying, then remove them.
        utils.system('tar zcvf %s --directory / --ignore-failed-read %s'
                     ' 2>/dev/null' %
                     (self.saved_config, ' '.join(self.save_directories)))
        utils.system('rm -rf %s' % ' '.join(self.save_directories),
                     ignore_status=True)

        # Create the fake user's system cryptohome directory.
        os.mkdir(self.root_cryptohome_dir)
        self.new_shill_user_profile_dir = ('%s/shill' %
                                           self.root_cryptohome_dir)
        self.new_shill_user_profile = ('%s/shill.profile' %
                                       self.new_shill_user_profile_dir)

        # Create the fake user's user cryptohome directory.
        os.mkdir(self.user_cryptohome_dir)
        self.flimflam_user_profile_dir = ('%s/flimflam' %
                                          self.user_cryptohome_dir)
        self.flimflam_user_profile = ('%s/flimflam.profile' %
                                      self.flimflam_user_profile_dir)
        self.old_shill_user_profile_dir = ('%s/shill' %
                                           self.user_cryptohome_dir)
        self.old_shill_user_profile = ('%s/shill.profile' %
                                       self.old_shill_user_profile_dir)
        self.mock_flimflam = None
コード例 #2
0
    def run_once(self):
        url = 'http://azlaba29.mtv.corp.google.com:9380/auto/google3/java/'\
                'com/google/caribou/ui/pinto/modules/auto/tests/'\
                'latencytest_auto.html'
        js_expr = 'domAutomationController.send(!!window.G_testRunner'\
                '&& window.G_testRunner.isFinished())'

        # timeout is in ms, so allow a 5 minute timeout
        # as of jan-11 it normally takes about 2 minutes on x86-mario
        timeout = 5 * 60 * 1000

        os.chdir(self.bindir)

        # Select correct binary.
        cpuType = utils.get_cpu_arch()
        url_fetch_test = 'url_fetch_test'
        if cpuType == "arm":
            url_fetch_test += '.arm'

        # Stop chrome from restarting and kill login manager.
        try:
            orig_pid = utils.system_output('pgrep %s' %
                                           constants.SESSION_MANAGER)
            open(constants.DISABLE_BROWSER_RESTART_MAGIC_FILE, 'w').close()
        except IOError, e:
            logging.debug(e)
            raise error.TestError('Failed to disable browser restarting.')
コード例 #3
0
 def get_speed(self, name):
     try:
         out = utils.system_output('ethtool %s | grep Speed | \
             sed s/^.*:.// | sed s/M.*$//' % name)
     except error.CmdError, e:
         logging.info(e)
         raise error.TestFail('unable to determine negotiated link speed')
コード例 #4
0
    def __TestAllLeafCommands(self):
        """Tests all "leaf" sub-commands return non-error.

        Commands that return ENOSYS or EINVAL are not counted as error.
        Return value are not check for correctness.

        Raises:
            error.TestFail Raised for commands that return non-zero exit code.
        """

        # Find all leaf commands by 'mosys -tv'.
        # Old mosys keeps track root:branch:node numbers; the output for one
        # command may look like, for example,
        #    [leaf 5:5] mosys platform variant
        # Latest mosys removes these numbers:
        #    [leaf] mosys platform variant
        cmd_re = re.compile('\[leaf[^\]]*\] (.+)')
        bad_cmd_list = []
        cmd_list = utils.system_output('mosys -tv')
        for line in cmd_list.splitlines():
            m = cmd_re.search(line)
            if m and not self.__TestOneCommand(m.group(1)):
                bad_cmd_list.append(m.group(1))

        if len(bad_cmd_list) == 1:
            raise error.TestFail('Command not properly implemented: ' +
                                 bad_cmd_list[0])
        elif len(bad_cmd_list) > 1:
            raise error.TestFail('Commands not properly implemented: ' +
                                 ','.join(bad_cmd_list))
コード例 #5
0
    def find_pid(self, process_name):
        """ Returns the process id of |process_name|.

        @param process_name string name of process to search for.

        """
        return utils.system_output('pgrep %s' % process_name,
                                   ignore_status=True).split('\n')[0]
コード例 #6
0
ファイル: net_utils.py プロジェクト: sconklin/autotest
 def get_ipaddr(self):
     ipaddr = "0.0.0.0"
     output = utils.system_output('ifconfig %s' % self._name)
     if output:
         match = re.search("inet addr:([\d\.]+)", output)
         if match:
             ipaddr = match.group(1)
     return ipaddr
コード例 #7
0
ファイル: net_utils.py プロジェクト: yochow/autotest
 def is_loopback_enabled(self):
     # Don't try ethtool -l on a bonded host
     if bond().is_enabled():
         return False
     output = utils.system_output('%s -l %s' % (self.ethtool, self._name))
     if output:
         return 'enabled' in output
     return False
コード例 #8
0
ファイル: net_utils.py プロジェクト: yochow/autotest
 def get_ipaddr(self):
     ipaddr = "0.0.0.0"
     output = utils.system_output('ifconfig %s' % self._name)
     if output:
         match = re.search("inet addr:([\d\.]+)", output)
         if match:
             ipaddr = match.group(1)
     return ipaddr
コード例 #9
0
ファイル: net_utils.py プロジェクト: sconklin/autotest
 def is_loopback_enabled(self):
     # Don't try ethtool -l on a bonded host
     if bond().is_enabled():
         return False
     output = utils.system_output('%s -l %s' % (self.ethtool, self._name))
     if output:
         return 'enabled' in output
     return False
コード例 #10
0
class desktopui_GmailLatency(test.test):
    version = 1

    def run_once(self):
        url = 'http://azlaba29.mtv.corp.google.com:9380/auto/google3/java/'\
                'com/google/caribou/ui/pinto/modules/auto/tests/'\
                'latencytest_auto.html'
        js_expr = 'domAutomationController.send(!!window.G_testRunner'\
                '&& window.G_testRunner.isFinished())'

        # timeout is in ms, so allow a 5 minute timeout
        # as of jan-11 it normally takes about 2 minutes on x86-mario
        timeout = 5 * 60 * 1000

        os.chdir(self.bindir)

        # Select correct binary.
        cpuType = utils.get_cpu_arch()
        url_fetch_test = 'url_fetch_test'
        if cpuType == "arm":
            url_fetch_test += '.arm'

        # Stop chrome from restarting and kill login manager.
        try:
            orig_pid = utils.system_output('pgrep %s' %
                                           constants.SESSION_MANAGER)
            open(constants.DISABLE_BROWSER_RESTART_MAGIC_FILE, 'w').close()
        except IOError, e:
            logging.debug(e)
            raise error.TestError('Failed to disable browser restarting.')

        # We could kill with signal 9 so that the session manager doesn't exit.
        # But this seems to leave the screen blank while the test is running.
        # So do it this way (which means clean_exit is always False)
        utils.nuke_process_by_name(name=constants.BROWSER)

        clean_exit = False
        try:
            time.sleep(1)
            new_pid = utils.system_output('pgrep %s' %
                                          constants.SESSION_MANAGER)
            if orig_pid != new_pid:
                # This is expected behaviour of the session manager.
                pass

            # Copy over chrome, chrome.pak, locales, chromeos needed for test.
            utils.system('cp -r %s/* .' % '/opt/google/chrome')

            # Setup parameters
            params = ('--url="%s" --wait_js_expr="%s" --wait_js_timeout=%d' %
                      (url, js_expr, timeout))
            graphics_utils.xsystem('./%s %s' % (url_fetch_test, params))

        except error.CmdError, e:
            logging.debug(e)
            raise error.TestFail('Gmail Latency test was unsuccessful in %s' %
                                 os.getcwd())
コード例 #11
0
ファイル: net_utils.py プロジェクト: sconklin/autotest
    def parse_ethtool(self, field, match, option='', next_field=''):
        output = utils.system_output('%s %s %s' % (self.ethtool,
                                                   option, self._name))
        if output:
            match = re.search('\n\s*%s:\s*(%s)%s' %
                              (field, match, next_field), output, re.S)
            if match:
                return match.group(1)

        return ''
コード例 #12
0
ファイル: net_utils.py プロジェクト: yochow/autotest
    def parse_ethtool(self, field, match, option='', next_field=''):
        output = utils.system_output('%s %s %s' % (self.ethtool,
                                                   option, self._name))
        if output:
            match = re.search('\n\s*%s:\s*(%s)%s' %
                              (field, match, next_field), output, re.S)
            if match:
                return match.group(1)

        return ''
コード例 #13
0
def actual_disk_device(ldevice):
    # get actual ide or sata device for some logical disk device
    tuner = '/usr/local/sbin/tunedisknames'
    if not os.path.exists(tuner):
        return ldevice
    disk_map = utils.system_output(tuner + ' printmap')
    for line in disk_map.splitlines():
        parts = line.split()
        if parts[1] == ldevice:
            return parts[0]
    raise ValueError("Could not find mapping for %s" % ldevice)
コード例 #14
0
def actual_disk_device(ldevice):
    # get actual ide or sata device for some logical disk device
    tuner = '/usr/local/sbin/tunedisknames'
    if not os.path.exists(tuner):
        return ldevice
    disk_map = utils.system_output(tuner + ' printmap')
    for line in disk_map.splitlines():
        parts = line.split()
        if parts[1] == ldevice:
            return parts[0]
    raise ValueError("Could not find mapping for %s" % ldevice)
コード例 #15
0
def fio_generate_graph():
    """
    Scan for fio log file in output directory and send data to generate each
    graph to fio_graph_generator class.
    """
    log_types = ['bw', 'iops', 'lat', 'clat', 'slat']

    # move fio log to result dir
    for log_type in log_types:
        logging.info('log_type %s', log_type)
        logs = utils.system_output('ls *_%s.*log' % log_type,
                                   ignore_status=True)
        if not logs:
            continue

        pattern = r"""(?P<jobname>.*)_                    # jobname
                      ((?P<runpass>p\d+)_|)               # pass
                      (?P<type>bw|iops|lat|clat|slat)     # type
                      (.(?P<thread>\d+)|)                 # thread id for newer fio.
                      .log
                   """
        matcher = re.compile(pattern, re.X)

        pass_list = []
        current_job = ''

        for log in logs.split():
            match = matcher.match(log)
            if not match:
                logging.warn('Unknown log file %s', log)
                continue

            jobname = match.group('jobname')
            runpass = match.group('runpass') or '1'
            if match.group('thread'):
                runpass += '_' + match.group('thread')

            # All files for particular job name are group together for create
            # graph that can compare performance between result from each pass.
            if jobname != current_job:
                if pass_list:
                    fio_graph_generator(current_job, log_type, pass_list).run()
                current_job = jobname
                pass_list = []
            pass_list.append((runpass, log))

        if pass_list:
            fio_graph_generator(current_job, log_type, pass_list).run()

        cmd = 'mv *_%s.*log results' % log_type
        utils.run(cmd, ignore_status=True)
        utils.run('mv *.html results', ignore_status=True)
コード例 #16
0
    def is_muted(self):
        """
        Returns mute status of system.

        @returns: True if system muted, False if not.

        """
        MUTE_STATUS = 'Muted'
        CTC_GREP_FOR_MUTED = 'cras_test_client --dump_server_info | grep muted'

        output = utils.system_output(CTC_GREP_FOR_MUTED)
        muted = output.split(':')[-1].strip()
        return muted == MUTE_STATUS
コード例 #17
0
    def test_body(self):
        # Make sure that shill is started with
        # --accept-hostname-from=pseudoethernet0.
        required_flag = '--accept-hostname-from=pseudoethernet0'
        pid = utils.system_output('pgrep shill')
        process_info = utils.system_output('ps %s' % pid)
        if required_flag not in process_info:
            raise error.TestNAError('Invalid Test. '
                                    'Expected shill to be started with %s' %
                                    required_flag)

        # Keep track of the original hostname.
        original_hostname = utils.system_output('hostname')
        if original_hostname != DEFAULT_HOSTNAME:
            logging.warning('Unexpected starting hostname %s (expected %s)',
                            original_hostname, DEFAULT_HOSTNAME)
            # Set the hostname to something we know.
            utils.system('hostname %s' % DEFAULT_HOSTNAME)

        subnet_mask = self.ethernet_pair.interface_subnet_mask
        intended_ip = dhcp_test_base.DhcpTestBase.rewrite_ip_suffix(
                subnet_mask,
                self.server_ip,
                INTENDED_IP_SUFFIX)
        # Two real name servers, and a bogus one to be unpredictable.
        dns_servers = ['8.8.8.8', '8.8.4.4', '192.168.87.88']
        domain_name = 'corp.google.com'
        dns_search_list = [
                'corgie.google.com',
                'lies.google.com',
                'that.is.a.tasty.burger.google.com',
                ]
        # This is the pool of information the server will give out to the client
        # upon request.
        dhcp_options = {
                dhcp_packet.OPTION_SERVER_ID : self.server_ip,
                dhcp_packet.OPTION_SUBNET_MASK : subnet_mask,
                dhcp_packet.OPTION_IP_LEASE_TIME : LEASE_TIME_SECONDS,
                dhcp_packet.OPTION_REQUESTED_IP : intended_ip,
                dhcp_packet.OPTION_DNS_SERVERS : dns_servers,
                dhcp_packet.OPTION_DOMAIN_NAME : domain_name,
                dhcp_packet.OPTION_HOST_NAME : TEST_HOSTNAME,
                dhcp_packet.OPTION_DNS_DOMAIN_SEARCH_LIST : dns_search_list,
                }

        try:
            self.negotiate_and_check_lease(dhcp_options)
            system_hostname = utils.system_output('hostname')
        finally:
            # Set the hostname back to the original to avoid side effects.
            utils.system_output('hostname %s' % original_hostname)

        # Test that shill updated the system hostname correctly.
        if system_hostname != TEST_HOSTNAME:
            raise error.TestFail('Expected system host name to be set to '
                                 '%s, but got %s instead.' %
                                 (TEST_HOSTNAME, system_hostname))
コード例 #18
0
    def _gather_vboot_times(self, results):
        """Read and report firmware internal timestamps.

        The firmware for all Chrome platforms except Mario records
        the ticks since power on at selected times during startup.
        These timestamps can be extracted from the `crossystem`
        command.

        If the timestamps are available, convert the tick times to
        seconds and record the following keyvals in `results`:
          * seconds_power_on_to_lf_start
          * seconds_power_on_to_lf_end
          * seconds_power_on_to_lk_start
          * seconds_power_on_to_lk_end

        The frequency of the recorded tick timestamps is determined
        by reading `_CPU_FREQ_FILE` and is recorded in the keyval
        mhz_primary_cpu.

        @param results  Keyvals dictionary.

        """
        try:
            khz = int(utils.read_one_line(self._CPU_FREQ_FILE))
        except IOError:
            logging.info(
                'Test is unable to read "%s", not calculating the '
                'vboot times.', self._CPU_FREQ_FILE)
            return
        hertz = khz * 1000.0
        results['mhz_primary_cpu'] = khz / 1000.0
        try:
            out = utils.system_output('crossystem')
        except error.CmdError:
            logging.info('Unable to run crossystem, not calculating the vboot '
                         'times.')
            return
        # Parse the crossystem output, we are looking for vdat_timers
        items = out.splitlines()
        for item in items:
            times_re = re.compile(r'LF=(\d+),(\d+) LK=(\d+),(\d+)')
            match = re.findall(times_re, item)
            if match:
                times = map(lambda s: round(float(s) / hertz, 2), match[0])
                results['seconds_power_on_to_lf_start'] = times[0]
                results['seconds_power_on_to_lf_end'] = times[1]
                results['seconds_power_on_to_lk_start'] = times[2]
                results['seconds_power_on_to_lk_end'] = times[3]
コード例 #19
0
    def run_once(self):

        cpuType = utils.get_cpu_arch()
        logging.debug("cpu type is %s" % cpuType)

        # test return values
        result = utils.system("rootdev -s")
        logging.debug("Rootdev test res: %d", result)
        if (result != 0):
            raise error.TestFail("Rootdev failed")
        result = utils.system("rootdev -s -d")
        logging.debug("Rootdev test -d switch res: %d", result)
        if (result != 0):
            raise error.TestFail("Rootdev failed -s -d")

        # test with -d Results should be without the partition device number
        text = utils.system_output("rootdev -s -d 2>&1")
        text = text.strip()
        logging.debug("Rootdev -s -d txt is *%s*", text)
        self.test_no_partition(text, cpuType)
コード例 #20
0
ファイル: net_utils.py プロジェクト: yochow/autotest
 def is_down(self):
     output = utils.system_output('ifconfig %s' % self._name)
     if output:
         return 'UP' not in output
     return False
コード例 #21
0
 def iface_up(self, name):
     try:
         out = utils.system_output('ifconfig %s' % name)
     except error.CmdError, e:
         logging.info(e)
         raise error.TestFail('test interface not found')
コード例 #22
0
 def _subprocess_pid(pattern):
     pid = utils.system_output('ps -U chronos -o pid,args | grep %s'
                               % pattern, ignore_status=True)
     return pid.lstrip().split(' ')[0] if pid else 0
コード例 #23
0
    def run_once(self):
        with chrome.Chrome() as cr:
            test_processes = []
            test_processes.append(
                    _TestProcess('while :; do :; done ; # tst00','bash.*tst00'))
            # Create a test command that ignores SIGTERM.
            test_processes.append(
                    _TestProcess('trap 15; while :; do :; done ; # tst01',
                                 'bash.*tst01'))

            for test in test_processes:
                if not test.run_me_as_chronos():
                    raise error.TestFail(
                            'Did not start: bash %s' % test.command)

            session_manager = self.__get_session_manager_pid()
            if not session_manager:
                raise error.TestError('Could not find session manager pid')

            if not self.__has_chronos_processes(session_manager):
                raise error.TestFail(
                        'Expected to find processes owned by chronos that were '
                        'not started by the session manager while logged in.')

            cpids = self.__get_chronos_pids()

            # Sanity checks: make sure test jobs are in the list and still
            # running.
            for test in test_processes:
                if cpids.count(test.pid_bash) != 1:
                    raise error.TestFail('Job missing (%s - %s)' %
                                         (test.pid_bash, test.command))
                if self.__is_process_dead(test.pid_bash):
                    raise error.TestFail('Job prematurely dead (%s - %s)' %
                                         (test.pid_bash, test.command))

        logging.info('Logged out, searching for processes that should be dead.')

        # Wait until we have a new session manager.  At that point, all
        # old processes should be dead.
        old_session_manager = session_manager
        utils.poll_for_condition(
                lambda: old_session_manager != self.__get_session_manager_pid())
        session_manager = self.__get_session_manager_pid()

        # Make sure all pre-logout chronos processes are now dead.
        old_pid_count = 0
        for p in cpids:
            if not self.__is_process_dead(p):
                old_pid_count += 1
                proc_args = utils.system_output('ps -p %s -o args=' % p,
                                                ignore_status=True)
                logging.info('Found pre-logout chronos process pid=%s (%s) '
                             'still alive.', p, proc_args)
                # If p is something we started, kill it.
                for test in test_processes:
                    if (p == test.pid_su or p == test.pid_bash):
                        utils.signal_pid(p, signal.SIGKILL)

        if old_pid_count > 0:
            raise error.TestFail('Found %s chronos processes that survived '
                                 'logout.' % old_pid_count)
コード例 #24
0
 def __get_session_manager_pid(self):
     """Get the PID of the session manager."""
     return utils.system_output('pgrep "^session_manager$"',
                                ignore_status=True)
コード例 #25
0
 def __get_chronos_pids(self):
     """Get a list of all PIDs that are owned by chronos."""
     return utils.system_output('pgrep -U chronos',
                                ignore_status=True).splitlines()
コード例 #26
0
 def is_iface_up(self, name):
     try:
         out = utils.system_output('ifconfig %s' % name)
     except error.CmdError, e:
         logging.info(e)
         raise error.TestNAError('test interface not found')
コード例 #27
0
 def _get_unmount_all_paths(self):
     """Returns a set representing all the paths that would be unmounted by
     imageloader.
     """
     return utils.system_output(
         '/usr/sbin/imageloader --dry_run --unmount_all').splitlines()
コード例 #28
0
ファイル: net_utils.py プロジェクト: sconklin/autotest
 def is_down(self):
     output = utils.system_output('ifconfig %s' % self._name)
     if output:
         return 'UP' not in output
     return False