Ejemplo n.º 1
0
 def testPerCpuCpufreq(self):
     '''Check each cpu's scaling_cur_freq, scaling_min_freq, scaling_max_freq,
     scaling_available_frequencies, and time_in_state files.
     '''
     f = '/sys/devices/system/cpu/online'
     self.IsReadOnly(f)
     online_cpus = target_file_utils.ReadFileContent(f, self.shell)
     cpu_ranges = online_cpus.split(',')
     cpu_list = []
     for r in cpu_ranges:
         m = re.match(r'(\d+)(-\d+)?', r)
         asserts.assertTrue(m is not None,
                 'malformatted range in /sys/devices/system/cpu/online')
         start_cpu = int(m.group(1))
         if m.group(2) is None:
             end_cpu = start_cpu
         else:
             end_cpu = int(m.group(2))
         cpu_list += range(start_cpu, end_cpu+1)
     for cpu in cpu_list:
         f = '/sys/devices/system/cpu/cpu%s/cpufreq/scaling_cur_freq' % cpu
         self.IsReadOnly(f)
         content = target_file_utils.ReadFileContent(f, self.shell)
         self.ConvertToInteger(content)
         f = '/sys/devices/system/cpu/cpu%s/cpufreq/scaling_min_freq' % cpu
         self.IsReadWrite(f)
         content = target.file_utils.ReadFileContent(f, self.shell)
         self.ConvertToInteger(content)
         f = '/sys/devices/system/cpu/cpu%s/cpufreq/scaling_max_freq' % cpu
         self.IsReadWrite(f)
         content = target.file_utils.ReadFileContent(f, self.shell)
         self.ConvertToInteger(content)
         f = '/sys/devices/system/cpu/cpu%s/cpufreq/scaling_available_frequencies' % cpu
         self.IsReadOnly(f)
         content = target.file_utils.ReadFileContent(f, self.shell)
         avail_freqs = content.split(' ')
         for x in avail_freqs:
             self.ConvertToInteger(x)
         f = '/sys/devices/system/cpu/cpu%s/cpufreq/stats/time_in_state' % cpu
         self.IsReadOnly(f)
         content = target.file_utils.ReadFileContent(f, shelf.shell)
         for line in content:
             values = line.split()
             for v in values:
                 try:
                     unused = int(v)
                 except ValueError as e:
                     asserts.fail("Malformatted time_in_state file at %s" % f)
    def runSelinuxFileTest(self, test_object):
        """Reads the file and checks that its content and permissions are valid.

        Args:
            test_object: inherits KernelSelinuxFileTestBase, contains the test functions
        """
        logging.info("Testing existence of %s" % (test_object.get_path()))

        asserts.assertTrue(
            target_file_utils.Exists(test_object.get_path(), self.shell),
            "%s: File does not exist." % test_object.get_path())

        logging.info("Testing permissions of %s" % (test_object.get_path()))
        try:
            permissions = target_file_utils.GetPermission(
                test_object.get_path(), self.shell)
            asserts.assertTrue(
                test_object.get_permission_checker()(permissions),
                "%s: File has invalid permissions (%s)" %
                (test_object.get_path(), permissions))
        except (ValueError, IOError) as e:
            asserts.fail("Failed to assert permissions: %s" % str(e))

        logging.info("Testing format of %s" % (test_object.get_path()))
        file_content = target_file_utils.ReadFileContent(
            test_object.get_path(), self.shell)
        asserts.assertTrue(test_object.result_correct(file_content),
                           "Results not valid!")
Ejemplo n.º 3
0
 def testSysPowerState(self):
     '''/sys/power/state controls the system sleep states.'''
     filepath = '/sys/power/state'
     self.IsReadWrite(filepath)
     content = target_file_utils.ReadFileContent(filepath, self.shell)
     allowed_states = ['freeze', 'mem', 'disk', 'standby']
     for state in content.split():
         if state not in allowed_states:
             asserts.fail("Invalid system power state: %s" % state)
Ejemplo n.º 4
0
 def testNetMTU(self):
     '''Check for /sys/class/net/*/mtu.'''
     dirlist = target_file_utils.FindFiles(self.shell, '/sys/class/net',
                                           '*', '-maxdepth 1 -type l')
     for entry in dirlist:
         mtufile = entry + "/mtu"
         self.IsReadWrite(mtufile)
         content = target_file_utils.ReadFileContent(mtufile, self.shell)
         self.ConvertToInteger(content)
Ejemplo n.º 5
0
 def testAndroidUSB(self):
     '''Check for the existence of required files in /sys/class/android_usb.
     '''
     state = '/sys/class/android_usb/android0/state'
     self.IsReadOnly(state)
     contents = target_file_utils.ReadFileContent(state, self.shell).strip()
     asserts.assertTrue(
         contents in ['DISCONNECTED', 'CONNECTED', 'CONFIGURED'],
         '%s does not contain an expected string' % state)
Ejemplo n.º 6
0
 def testIpv4(self):
     '''Check /sys/kernel/ipv4/*.'''
     files = ['tcp_rmem_def', 'tcp_rmem_max', 'tcp_rmem_min',
              'tcp_wmem_def', 'tcp_wmem_max', 'tcp_wmem_min',]
     for f in files:
         path = '/sys/kernel/ipv4/' + f
         self.IsReadWrite(path)
         content = target_file_utils.ReadFileContent(path, self.shell)
         self.ConvertToInteger(content)
Ejemplo n.º 7
0
    def tryReadFileContent(self, f, shell):
        '''Attempt to read a file.

        If the file does not exist None will be returned.
        '''
        try:
            content = target_file_utils.ReadFileContent(f, self.shell)
        except IOError as e:
            return None
        return content
Ejemplo n.º 8
0
 def testRtcHctosys(self):
     '''Check that at least one rtc exists with hctosys = 1.'''
     rtclist = target_file_utils.FindFiles(self.shell, '/sys/class/rtc',
                                           'rtc*', '-maxdepth 1 -type l')
     for entry in rtclist:
         content = target_file_utils.ReadFileContent(
             entry + "/hctosys", self.shell)
         try:
             hctosys = int(content)
         except ValueError as e:
             continue
         if hctosys == 1:
             return
     asserts.fail("No RTC with hctosys=1 present")
Ejemplo n.º 9
0
    def testCpuOnlineFormat(self):
        '''Check the format of cpu online file.

        Confirm /sys/devices/system/cpu/online exists and is read-only.
        Parse contents to ensure it is a comma-separated series of ranges
        (%d-%d) and/or integers.
        '''
        filepath = '/sys/devices/system/cpu/online'
        self.IsReadOnly(filepath)
        content = target_file_utils.ReadFileContent(filepath, self.shell)
        regex = '(\d+(-\d+)?)(,\d+(-\d+)?)*'
        if content.endswith('\n'):
            content = content[:-1]
        self.MatchRegex(regex, content)
Ejemplo n.º 10
0
 def testKernelMax(self):
     '''Check the value of /sys/devices/system/cpu/kernel_max.'''
     filepath = '/sys/devices/system/cpu/kernel_max'
     self.IsReadOnly(filepath)
     content = target_file_utils.ReadFileContent(filepath, self.shell)
     self.ConvertToInteger(content)