예제 #1
0
    def runProcFileTest(self, test_object):
        """Reads from the file and checks that it parses and the content is valid.

        Args:
            test_object: inherits KernelProcFileTestBase, contains the test functions
        """
        asserts.skipIf(test_object in TEST_OBJECTS_64 and not self.dut.is64Bit,
                       "Skip test for 64-bit kernel.")
        filepath = test_object.get_path()
        target_file_utils.assertPermissionsAndExistence(
            self.shell, filepath, test_object.get_permission_checker())

        logging.info("Testing format of %s", filepath)

        asserts.assertTrue(
            test_object.prepare_test(self.shell), "Setup failed!")

        if not test_object.test_format():
            return

        file_content = self.ReadFileContent(filepath)
        try:
            parse_result = test_object.parse_contents(file_content)
        except (SyntaxError, ValueError, IndexError) as e:
            asserts.fail("Failed to parse! " + str(e))
        asserts.assertTrue(
            test_object.result_correct(parse_result), "Results not valid!")
예제 #2
0
    def testVendorPropertyNamespace(self):
        """Ensures vendor properties have proper namespace.

        Vendor or ODM properties must have their own prefix.
        """
        logging.info("Checking existence of %s",
                     self._VENDOR_PROPERTY_CONTEXTS_FILE_PATH)
        target_file_utils.assertPermissionsAndExistence(
                self.shell, self._VENDOR_PROPERTY_CONTEXTS_FILE_PATH,
                target_file_utils.IsReadable)

        # Pull vendor property contexts file from device.
        self.dut.adb.pull("%s %s" % (self._VENDOR_PROPERTY_CONTEXTS_FILE_PATH,
                                     self._temp_dir))
        logging.info("Adb pull %s to %s",
                     self._VENDOR_PROPERTY_CONTEXTS_FILE_PATH,
                     self._temp_dir)

        with open(os.path.join(self._temp_dir, "vendor_property_contexts"),
                  "r") as property_contexts_file:
            property_dict = self._ParsePropertyDictFromPropertyContextsFile(
                    property_contexts_file)
        logging.info("Found %d property names in vendor property contexts",
                     len(property_dict))
        for name in property_dict:
            has_proper_namesapce = False
            for prefix in self._VENDOR_OR_ODM_NAMEPACES:
                if name.startswith(prefix):
                    has_proper_namesapce = True
                    break
            asserts.assertTrue(
                    has_proper_namesapce,
                    "Vendor property (%s) has wrong namespace" % name)
예제 #3
0
    def testProcPerUidTimes(self):
        # TODO: make these files mandatory once they're in AOSP
        try:
            filepaths = self.dut.adb.shell("find /proc/uid -name time_in_state")
        except:
            asserts.skip("/proc/uid/ directory does not exist and is optional")

        asserts.skipIf(not filepaths,
                       "per-UID time_in_state files do not exist and are optional")

        filepaths = filepaths.splitlines()
        for filepath in filepaths:
            target_file_utils.assertPermissionsAndExistence(
                self.shell, filepath, target_file_utils.IsReadOnly
            )
            file_content = self.ReadFileContent(filepath)
    def testExportedPlatformPropertyIntegrity(self):
        """Ensures public property contexts isn't modified at all.

        Public property contexts must not be modified.
        """
        logging.info("Checking existence of %s",
                     self._SYSTEM_PROPERTY_CONTEXTS_FILE_PATH)
        target_file_utils.assertPermissionsAndExistence(
            self.shell, self._SYSTEM_PROPERTY_CONTEXTS_FILE_PATH,
            target_file_utils.IsReadable)

        # Pull system property contexts file from device.
        self.dut.adb.pull(
            "%s %s" %
            (self._SYSTEM_PROPERTY_CONTEXTS_FILE_PATH, self._temp_dir))
        logging.info("Adb pull %s to %s",
                     self._SYSTEM_PROPERTY_CONTEXTS_FILE_PATH, self._temp_dir)

        with open(os.path.join(self._temp_dir, "plat_property_contexts"),
                  "r") as property_contexts_file:
            sys_property_dict = self._ParsePropertyDictFromPropertyContextsFile(
                property_contexts_file, True)
        logging.info(
            "Found %d exact-matching properties "
            "in system property contexts", len(sys_property_dict))

        pub_property_contexts_file_path = os.path.join(
            self.data_file_path, self._PUBLIC_PROPERTY_CONTEXTS_FILE_PATH)
        with open(pub_property_contexts_file_path,
                  "r") as property_contexts_file:
            pub_property_dict = self._ParsePropertyDictFromPropertyContextsFile(
                property_contexts_file, True)

        for name in pub_property_dict:
            public_tokens = pub_property_dict[name]
            asserts.assertTrue(name in sys_property_dict,
                               "Exported property (%s) doesn't exist" % name)
            if name in self._MODIFIABLE_PROPERTIES:
                continue
            system_tokens = sys_property_dict[name]
            asserts.assertEqual(public_tokens, system_tokens,
                                "Exported property (%s) is modified" % name)
예제 #5
0
    def testProcSysAbiSwpInstruction(self):
        """Tests /proc/sys/abi/swp.

        /proc/sys/abi/swp sets the execution behaviour for the obsoleted ARM instruction
        SWP. As per the setting in /proc/sys/abi/swp, the usage of SWP{B}
        can either generate an undefined instruction abort or use software emulation
        or hardware execution.
        """

        asserts.skipIf(not ("arm" in self.dut.cpu_abi and self.dut.is64Bit),
                       "file not present on non-ARM64 device")
        target_file_utils.assertPermissionsAndExistence(
            self.shell, self._PROC_SYS_ABI_SWP_FILE_PATH, target_file_utils.IsReadWrite)
        file_content = self.ReadFileContent(self._PROC_SYS_ABI_SWP_FILE_PATH)
        try:
            swp_state = int(file_content)
        except ValueError as e:
            asserts.fail("Failed to parse %s" % self._PROC_SYS_ABI_SWP_FILE_PATH)
        asserts.assertTrue(swp_state >= 0 and swp_state <= 2,
                           "%s contains incorrect value: %d" % (self._PROC_SYS_ABI_SWP_FILE_PATH,
                                                                swp_state))
    def testKernelConfigs(self):
        """Ensures all kernel configs conform to Android requirements.

        Detects kernel version of device and validates against appropriate
        Common Android Kernel android-base.cfg and Android Treble
        requirements.
        """
        logging.info("Testing existence of %s" % self.PROC_FILE_PATH)
        target_file_utils.assertPermissionsAndExistence(
            self.shell, self.PROC_FILE_PATH, target_file_utils.IsReadOnly)

        logging.info("Validating kernel version of device.")
        kernel_version = self.checkKernelVersion()

        # Pull configs from the universal config file.
        configs = dict()
        config_file_path = os.path.join(self.data_file_path,
                                        self.KERNEL_CONFIG_FILE_PATH,
                                        "android-" + kernel_version,
                                        "android-base.cfg")
        with open(config_file_path, 'r') as config_file:
            configs = self.parseConfigFileToDict(config_file, configs)

        # Pull configs from device.
        device_configs = dict()
        self.dut.adb.pull("%s %s" % (self.PROC_FILE_PATH, self._temp_dir))
        logging.info("Adb pull %s to %s", self.PROC_FILE_PATH, self._temp_dir)

        localpath = os.path.join(self._temp_dir, "config.gz")
        with gzip.open(localpath, "rb") as device_config_file:
            device_configs = self.parseConfigFileToDict(
                device_config_file, device_configs)

        # Check device architecture and pull arch-specific configs.
        kernelArch = self.checkKernelArch(device_configs)
        if kernelArch is not "":
            config_file_path = os.path.join(self.data_file_path,
                                            self.KERNEL_CONFIG_FILE_PATH,
                                            "android-" + kernel_version,
                                            "android-base-%s.cfg" % kernelArch)
            if os.path.isfile(config_file_path):
                with open(config_file_path, 'r') as config_file:
                    configs = self.parseConfigFileToDict(config_file, configs)

        # Determine any deviations from the required configs.
        should_be_enabled = []
        should_not_be_set = []
        incorrect_config_state = []
        for config_name, config_state in configs.iteritems():
            if (config_state == "y"
                    and (config_name not in device_configs
                         or device_configs[config_name] not in ("y", "m"))):
                should_be_enabled.append(config_name)
            elif (config_state == "n" and (config_name in device_configs)
                  and device_configs[config_name] != "n"):
                should_not_be_set.append(config_name + "=" +
                                         device_configs[config_name])
            elif (config_name in device_configs
                  and device_configs[config_name] != config_state):
                incorrect_config_state.append(config_name + "=" +
                                              device_configs[config_name])

        if ("CONFIG_OF" not in device_configs
                and "CONFIG_ACPI" not in device_configs):
            should_be_enabled.append("CONFIG_OF | CONFIG_ACPI")

        asserts.assertTrue(
            len(should_be_enabled) == 0 and len(should_not_be_set) == 0
            and len(incorrect_config_state) == 0,
            ("The following kernel configs should be enabled: [%s]\n"
             "The following kernel configs should not be set: [%s]\n"
             "THe following kernel configs have incorrect state: [%s]") %
            (", ".join(should_be_enabled), ", ".join(should_not_be_set),
             ", ".join(incorrect_config_state)))