Beispiel #1
0
    def run_once(self):
        # Get the start line of message belonging to this current boot.
        start_line = utils.run(
                'grep -ni "%s" "%s" | tail -n 1 | cut -d ":" -f 1' %
                (self.BOOT_START_LINE_MSG, self.MESSAGE_PATH),
                ignore_status=True).stdout.strip()
        logging.info('Start line: %s', start_line)
        if not start_line:
            raise error.TestFail('Start line of boot is not found.')

        def _grep_messages(pattern):
            return utils.run('tail -n +%s %s | grep "%s"' %
                             (start_line, self.MESSAGE_PATH, pattern),
                             ignore_status=True).stdout

        # Check hammerd is triggered on boot.
        if not _grep_messages(self.TRIGGER_ON_BOOT_MSG):
            raise error.TestFail('hammerd is not triggered on boot.')
        # Check hammerd is terminated normally.
        if _grep_messages(self.PROCESS_FAILED_MSG):
            hammerd_log = _grep_messages(self.PROCESS_NAME)
            logging.error('Hammerd log: %s', hammerd_log)
            raise error.TestFail('hammerd terminated with non-zero value')

        # Check that hammerd wrote to WRITE_SYSFS_PATH
        sysfspath = utils.read_one_line(self.WRITE_SYSFS_PATH)

        if not sysfspath:
            raise error.TestFail('%s is empty' % (self.WRITE_SYSFS_PATH))

        # Check that autosuspend is enabled
        power = utils.read_one_line(sysfspath + '/' +
                                    self.SYSFS_POWER_CONTROL_PATH)
        if power != 'auto':
            raise error.TestFail('Autosuspend not enabled on hammer port')
Beispiel #2
0
 def _online(self, ac_path):
     online_path = os.path.join(ac_path, 'online')
     if not os.path.exists(online_path):
         raise error.TestFail('online path does not exist: %s' %
                              online_path)
     online = utils.read_one_line(online_path)
     return online == '1'
Beispiel #3
0
 def run_once(self, test_which='Mains'):
     # This test doesn't apply to systems that run on AC only.
     cmd = "mosys psu type"
     if utils.system_output(cmd, ignore_status=True).strip() == "AC_only":
         return
     ac_paths = []
     bat_paths = []
     # Gather power supplies
     for path in glob.glob(power_ProbeDriver.power_supply_path):
         type_path = os.path.join(path, 'type')
         if not os.path.exists(type_path):
             continue
         # With the advent of USB Type-C, mains power might show up as
         # one of several variants of USB.
         psu_type = utils.read_one_line(type_path)
         if any([
                 psu_type == 'Mains', psu_type == 'USB',
                 psu_type == 'USB_DCP', psu_type == 'USB_CDP',
                 psu_type == 'USB_TYPE_C', psu_type == 'USB_PD',
                 psu_type == 'USB_PD_DRP'
         ]):
             ac_paths.append(path)
         elif psu_type == 'Battery':
             bat_paths.append(path)
     run_dict = {'Mains': self.run_ac, 'Battery': self.run_bat}
     run = run_dict.get(test_which)
     if run:
         run(ac_paths, bat_paths)
     else:
         raise error.TestNAError('Unknown test type: %s' % test_which)
Beispiel #4
0
def sysctl_kernel(key, value=None):
    """(Very) partial implementation of sysctl, for kernel params"""
    if value is not None:
        # write
        utils.write_one_line('/proc/sys/kernel/%s' % key, str(value))
    else:
        # read
        out = utils.read_one_line('/proc/sys/kernel/%s' % key)
        return int(re.search(r'\d+', out).group(0))
Beispiel #5
0
def sysctl_kernel(key, value=None):
    """(Very) partial implementation of sysctl, for kernel params"""
    if value:
        # write
        utils.write_one_line("/proc/sys/kernel/%s" % key, str(value))
    else:
        # read
        out = utils.read_one_line("/proc/sys/kernel/%s" % key)
        return int(re.search(r"\d+", out).group(0))
Beispiel #6
0
def sysctl(key, value=None):
    """Generic implementation of sysctl, to read and write.

    @param key: A location under /proc/sys
    @param value: If not None, a value to write into the sysctl.

    @return The single-line sysctl value as a string.
    """
    path = '/proc/sys/%s' % key
    if value is not None:
        utils.write_one_line(path, str(value))
    return utils.read_one_line(path)
Beispiel #7
0
def sysctl(key, value=None):
    """Generic implementation of sysctl, to read and write.

    @param key: A location under /proc/sys
    @param value: If not None, a value to write into the sysctl.

    @return The single-line sysctl value as a string.
    """
    path = '/proc/sys/%s' % key
    if value is not None:
        utils.write_one_line(path, str(value))
    return utils.read_one_line(path)
Beispiel #8
0
    def _read_property(self, bat_path, field):
        """
        Reads the contents of a sysfs field for a battery sysfs.

        Fields:
        str     bat_path:           Battery sysfs path
        str     field:              Sysfs field to read.

        Return value:
        str     The contents of the sysfs field.
        """
        property_path = os.path.join(bat_path, field)
        if not self._has_property(bat_path, field):
            raise error.TestNAError('Path not found: %s' % property_path)
        return utils.read_one_line(property_path)
Beispiel #9
0
def get_gpu_family():
    """Returns the GPU family name."""
    global pciid_to_amd_architecture
    global pciid_to_intel_architecture

    socfamily = base_utils.get_cpu_soc_family()
    if socfamily == 'exynos5' or socfamily == 'rockchip' or has_mali():
        cmd = wflinfo_cmd()
        wflinfo = utils.system_output(cmd,
                                      retain_output=True,
                                      ignore_status=False)
        version = re.findall(r'OpenGL renderer string: '
                             r'Mali-T([0-9]+)', wflinfo)
        if version:
            return 'mali-t%s' % version[0]
        return 'mali-unrecognized'
    if socfamily == 'tegra':
        return 'tegra'
    if os.path.exists('/sys/kernel/debug/pvr'):
        return 'rogue'

    pci_vga_device = utils.run("lspci | grep VGA").stdout.rstrip('\n')
    bus_device_function = pci_vga_device.partition(' ')[0]
    pci_path = '/sys/bus/pci/devices/0000:' + bus_device_function + '/device'

    if not os.path.exists(pci_path):
        raise error.TestError('PCI device 0000:' + bus_device_function + ' not found')

    device_id = utils.read_one_line(pci_path).lower()

    if "Advanced Micro Devices" in pci_vga_device:
        if not pciid_to_amd_architecture:
            with open(_AMD_PCI_IDS_FILE_PATH, 'r') as in_f:
                pciid_to_amd_architecture = json.load(in_f)

        return pciid_to_amd_architecture[device_id]

    if "Intel Corporation" in pci_vga_device:
        # Only load Intel PCI ID file once and only if necessary.
        if not pciid_to_intel_architecture:
            with open(_INTEL_PCI_IDS_FILE_PATH, 'r') as in_f:
                pciid_to_intel_architecture = json.load(in_f)

        return pciid_to_intel_architecture[device_id]
 def test_preserves_leading_whitespace(self):
     self.create_test_file("   has leading whitespace")
     self.assertEqual("   has leading whitespace",
                      utils.read_one_line("filename"))
 def test_works_on_file_with_no_newlines(self):
     self.create_test_file("line but no newline")
     self.assertEqual("line but no newline",
                      utils.read_one_line("filename"))
     self.god.check_playback()
 def test_works_on_empty_file(self):
     self.create_test_file("")
     self.assertEqual("", utils.read_one_line("filename"))
     self.god.check_playback()
 def test_drops_extra_lines(self):
     self.create_test_file("line 1\nline 2\nline 3\n")
     self.assertEqual("line 1", utils.read_one_line("filename"))
     self.god.check_playback()
 def test_strips_read_lines(self):
     self.create_test_file("abc   \n")
     self.assertEqual("abc   ", utils.read_one_line("filename"))
     self.god.check_playback()
 def test_strips_read_lines(self):
     self.create_test_file("abc   \n")
     self.assertEqual("abc   ", utils.read_one_line("filename"))
     self.god.check_playback()
 def test_preserves_leading_whitespace(self):
     self.create_test_file("   has leading whitespace")
     self.assertEqual("   has leading whitespace",
                      utils.read_one_line("filename"))
 def test_works_on_file_with_no_newlines(self):
     self.create_test_file("line but no newline")
     self.assertEqual("line but no newline",
                      utils.read_one_line("filename"))
     self.god.check_playback()
 def test_works_on_empty_file(self):
     self.create_test_file("")
     self.assertEqual("", utils.read_one_line("filename"))
     self.god.check_playback()
 def test_drops_extra_lines(self):
     self.create_test_file("line 1\nline 2\nline 3\n")
     self.assertEqual("line 1", utils.read_one_line("filename"))
     self.god.check_playback()