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!")
def _IsElfObjectForAp(self, elf, target_path, abi_list): """Checks whether an ELF object is for application processor. Args: elf: The object of elf_parser.ElfParser. target_path: The path to the ELF file on target. abi_list: A list of strings, the ABIs of the application processor. Returns: A boolean, whether the ELF object is for application processor. """ if not any(elf.MatchCpuAbi(x) for x in abi_list): logging.debug("%s does not match the ABI", target_path) return False # b/115567177 Skip an ELF file if it meets the following 3 conditions: # The ELF type is executable. if not elf.IsExecutable(): return True # It requires special program interpreter. interp = elf.GetProgramInterpreter() if not interp or interp in self._DEFAULT_PROGRAM_INTERPRETERS: return True # It does not have execute permission in the file system. permissions = target_file_utils.GetPermission(target_path, self._dut.shell) if target_file_utils.IsExecutable(permissions): return True logging.debug("%s is not for application processor", target_path) return False
def GetPathPermission(self, path): '''Get the permission bits of a path, catching IOError.''' permission = '' try: permission = target_file_utils.GetPermission(path, self.shell) except IOError as e: logging.exception(e) asserts.fail('Path "%s" does not exist or has invalid ' 'permission bits' % path) return permission
def testHwbinderExistence(self): """Checks that hwbinder node exists. """ logging.info("Testing existence of %s", HWBINDER_PATH) asserts.assertTrue(target_file_utils.Exists(HWBINDER_PATH, self.shell), "%s: File does not exist." % HWBINDER_PATH) try: permissions = target_file_utils.GetPermission( HWBINDER_PATH, self.shell) asserts.assertTrue( target_file_utils.IsReadWrite(permissions), "%s: File has invalid permissions (%s)" % (HWBINDER_PATH, permissions)) except (ValueError, IOError) as e: asserts.fail("Failed to assert permissions: %s" % str(e))
def IsReadOnly(self, path): '''Check whether a given path is read only. Assertion will fail if given path does not exist or is not read only. ''' permission = '' try: permission = target_file_utils.GetPermission(path, self.shell) except IOError as e: logging.exception(e) asserts.fail('Path "%s" does not exist or has invalid ' 'permission bits' % path) try: asserts.assertTrue(target_file_utils.IsReadOnly(permission), 'path %s is not read only' % path) except IOError as e: logging.exception(e) asserts.fail('Got invalid permission bits "%s" for path "%s"' % (permission, path))