Exemplo n.º 1
0
    def testVendorProcessOpenLibraries(self):
        """Checks if vendor processes load shared libraries on system."""
        asserts.skipIf(not vndk_utils.IsVndkRuntimeEnforced(self._dut),
                       "VNDK runtime is not enforced on the device.")
        vndk_lists = vndk_data.LoadVndkLibraryLists(
            self.data_file_path, self._dut.vndk_version, vndk_data.LL_NDK,
            vndk_data.LL_NDK_PRIVATE, vndk_data.VNDK, vndk_data.VNDK_PRIVATE,
            vndk_data.VNDK_SP, vndk_data.VNDK_SP_PRIVATE)
        asserts.assertTrue(vndk_lists, "Cannot load VNDK library lists.")
        allowed_libs = set()
        for vndk_list in vndk_lists:
            allowed_libs.update(vndk_list)
        logging.debug("Allowed system libraries: %s", allowed_libs)

        asserts.assertTrue(self._dut.isAdbRoot,
                           "Must be root to find all libraries in use.")
        cmds = self._ListProcessCommands(
            lambda x: (x.startswith("/odm/") or x.startswith("/vendor/")))
        deps = self._ListOpenFiles(
            cmds.keys(), lambda x: (x.startswith("/system/") and x.endswith(
                ".so") and x not in allowed_libs))
        if deps:
            error_lines = [
                "%s %s %s" % (pid, cmds[pid], libs)
                for pid, libs in deps.iteritems()
            ]
            logging.error("pid command libraries\n%s", "\n".join(error_lines))
            asserts.fail(
                "Number of vendor processes using system libraries: " +
                str(len(deps)))
    def filterOneTest(self, test_name):
        """Check test filters for a test name.

        The first layer of filter is user defined test filters:
        if a include filter is not empty, only tests in include filter will
        be executed regardless whether they are also in exclude filter. Else
        if include filter is empty, only tests not in exclude filter will be
        executed.

        The second layer of filter is checking abi bitness:
        if a test has a suffix indicating the intended architecture bitness,
        and the current abi bitness information is available, non matching tests
        will be skipped. By our convention, this function will look for bitness in suffix
        formated as "32bit", "32Bit", "32BIT", or 64 bit equivalents.

        This method assumes  const.SUFFIX_32BIT and const.SUFFIX_64BIT are in lower cases.

        Args:
            test_name: string, name of a test

        Raises:
            signals.TestSilent if a test should not be executed
        """
        super(VtsKernelLibcutilsTest, self).filterOneTest(test_name)
        asserts.skipIf(
            test_name.split('.')[0] not in self.include_test_suite,
            'Test case not selected.')
Exemplo n.º 3
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!")
 def testVndkCoreDirectory(self):
     """Verifies that VNDK-core directory doesn't contain extra files."""
     asserts.skipIf(not vndk_utils.IsVndkRuntimeEnforced(self._dut),
                    "VNDK runtime is not enforced on the device.")
     self._TestVndkDirectory(
         vndk_utils.GetVndkCoreDirectory(self.abi_bitness,
                                         self._vndk_version),
         vndk_data.VNDK, vndk_data.VNDK_PRIVATE)
Exemplo n.º 5
0
    def RunLtpOnce(self, test_case, n_bit):
        "Run one LTP test case"
        asserts.skipIf(test_case.is_filtered, test_case.note)
        asserts.skipIf(not self._requirement.Check(test_case), test_case.note)

        cmd = "export {envp} && {commands}".format(
            envp=self.GetEnvp(), commands=test_case.GetCommand())
        logging.info("Executing %s", cmd)
        self.CheckResult(self.shell.Execute(cmd))
    def VerifyTestResult(self, test_case, command_results):
        '''Parse Gtest xml result output.

        Sample
        <testsuites tests="1" failures="1" disabled="0" errors="0"
         timestamp="2017-05-24T18:32:10" time="0.012" name="AllTests">
          <testsuite name="ConsumerIrHidlTest"
           tests="1" failures="1" disabled="0" errors="0" time="0.01">
            <testcase name="TransmitTest" status="run" time="0.01"
             classname="ConsumerIrHidlTest">
              <failure message="hardware/interfaces..." type="">
                <![CDATA[hardware/interfaces...]]>
              </failure>
            </testcase>
          </testsuite>
        </testsuites>

        Args:
            test_case: GtestTestCase object, the test being run. This param
                       is not currently used in this method.
            command_results: dict of lists, shell command result
        '''
        asserts.assertTrue(command_results, 'Empty command response.')
        asserts.assertEqual(len(command_results), 3,
                            'Abnormal command response.')
        for item in command_results.values():
            asserts.assertEqual(
                len(item), 2,
                'Abnormal command result length: %s' % command_results)

        for stderr in command_results[const.STDERR]:
            if stderr and stderr.strip():
                for line in stderr.split('\n'):
                    logging.error(line)

        xml_str = command_results[const.STDOUT][1].strip()

        if self.batch_mode:
            self._ParseBatchResults(test_case, xml_str)
            return

        for stdout in command_results[const.STDOUT]:
            if stdout and stdout.strip():
                for line in stdout.split('\n'):
                    logging.info(line)

        asserts.assertFalse(
            command_results[const.EXIT_CODE][1],
            'Failed to show Gtest XML output: %s' % command_results)

        root = xml.etree.ElementTree.fromstring(xml_str)
        asserts.assertEqual(root.get('tests'), '1', 'No tests available')
        if root.get('errors') != '0' or root.get('failures') != '0':
            messages = [x.get('message') for x in root.findall('.//failure')]
            asserts.fail('\n'.join([x for x in messages if x]))
        asserts.skipIf(root.get('disabled') == '1', 'Gtest test case disabled')
Exemplo n.º 7
0
 def setUp(self):
     """Checks if the the preconditions to run the test are met."""
     if "x86" in self.dut.cpu_abi:
         global block_dev_path
         block_dev_path = "/dev/block"
         acpio_idx_string = self.adb.shell(
             "cat /proc/cmdline | "
             "grep -o \"androidboot.acpio_idx=[^ ]*\" |"
             "cut -d \"=\" -f 2 ").replace('\n', '')
         asserts.skipIf((len(acpio_idx_string) == 0),
                        "Skipping test for x86 NON-ACPI ABI")
    def filterOneTest(self, test_name):
        """Check test filters for a test name.

        The first layer of filter is user defined test filters:
        if a include filter is not empty, only tests in include filter will
        be executed regardless whether they are also in exclude filter. Else
        if include filter is empty, only tests not in exclude filter will be
        executed.

        The second layer of filter is checking _skip_all_testcases flag:
        the subclass may set _skip_all_testcases to True in its implementation
        of setUpClass. If the flag is set, this method raises signals.TestSkip.

        The third layer of filter is checking abi bitness:
        if a test has a suffix indicating the intended architecture bitness,
        and the current abi bitness information is available, non matching tests
        will be skipped. By our convention, this function will look for bitness in suffix
        formated as "32bit", "32Bit", "32BIT", or 64 bit equivalents.

        This method assumes const.SUFFIX_32BIT and const.SUFFIX_64BIT are in lower cases.

        Args:
            test_name: string, name of a test

        Raises:
            signals.TestSilent if a test should not be executed
            signals.TestSkip if a test should be logged but not be executed
        """
        if self.include_filter:
            if test_name not in self.include_filter:
                msg = "Test case '%s' not in include filter %s." % (
                    test_name, self.include_filter)
                logging.info(msg)
                raise signals.TestSilent(msg)
        elif test_name in self.exclude_filter:
            msg = "Test case '%s' in exclude filter %s." % (
                test_name, self.exclude_filter)
            logging.info(msg)
            raise signals.TestSilent(msg)

        if self._skip_all_testcases:
            raise signals.TestSkip("All test cases skipped.")

        asserts.skipIf(
            self.abi_bitness and
            ((self.skip_on_32bit_abi is True) and self.abi_bitness == "32")
            or ((self.skip_on_64bit_abi is True) and self.abi_bitness == "64")
            or (test_name.lower().endswith(const.SUFFIX_32BIT)
                and self.abi_bitness != "32") or
            (test_name.lower().endswith(const.SUFFIX_64BIT)
             and self.abi_bitness != "64" and not self.run_32bit_on_64bit_abi),
            "Test case '{}' excluded as ABI bitness is {}.".format(
                test_name, self.abi_bitness))
 def setUp(self):
     """Checks if the the preconditions to run the test are met."""
     global acpio_idx_string
     asserts.skipIf("x86" not in self.dut.cpu_abi,
                    "Skipping test for NON-x86 ABI")
     acpio_idx_string = self.adb.shell(
         "cat /proc/cmdline | "
         "grep -o \"androidboot.acpio_idx=[^ ]*\" |"
         "cut -d \"=\" -f 2 ")
     acpio_idx_string = acpio_idx_string.replace('\n', '')
     asserts.assertTrue(acpio_idx_string,
                        "Skipping test for x86 NON-ACPI ABI")
    def RunTestCase(self, test_case):
        """Runs the test case corresponding to binder bitness.

        Args:
            test_case: GtestTestCase object
        """
        asserts.skipIf(
            (self._TAG_IPC32 in test_case.tag and self._is_32 == False),
            "Skip tests for 32-bit binder interface.")
        asserts.skipIf(self._TAG_IPC64 in test_case.tag and self._is_32,
                       "Skip tests for 64-bit binder interface.")
        super(VtsKernelBinderTest, self).RunTestCase(test_case)
 def testRecoveryImageHeader(self):
     """Validates recovery image header."""
     asserts.skipIf(self.slot_suffix,
                    "A/B devices do not have a separate recovery partition")
     recovery_path = target_file_utils.FindFiles(self.shell, BLOCK_DEV_PATH,
                                                 "recovery", "-type l")
     logging.info("recovery path %s", recovery_path)
     if not recovery_path:
         asserts.fail("Unable to find path to recovery image on device.")
     host_recovery_path = os.path.join(self.temp_dir, "recovery.img")
     self.adb.pull("%s %s" % (recovery_path[0], host_recovery_path))
     self.CheckImageHeader(host_recovery_path, True)
Exemplo n.º 12
0
    def SkipIfThermalThrottling(self, retry_delay_secs=0):
        """Skips the current test case if a target device is under thermal throttling.

        Args:
            retry_delay_secs: integer, if not 0, retry after the specified seconds.
        """
        throttling = self.IsUnderThermalThrottling()
        if throttling and retry_delay_secs > 0:
            logging.info("Wait for %s seconds for the target to cool down.",
                         retry_delay_secs)
            time.sleep(retry_delay_secs)
            throttling = self.IsUnderThermalThrottling()
        asserts.skipIf(throttling, "Thermal throttling")
Exemplo n.º 13
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)
Exemplo n.º 14
0
    def _filterOneTestThroughAbiBitness(self, test_name):
        """Check test filter for the given test name.

        Args:
            test_name: string, name of a test

        Raises:
            signals.TestSilent if a test should not be executed
        """
        asserts.skipIf(
            self.abi_bitness and
            ((self.skip_on_32bit_abi is True) and self.abi_bitness == "32")
            or ((self.skip_on_64bit_abi is True) and self.abi_bitness == "64")
            or (test_name.lower().endswith(const.SUFFIX_32BIT)
                and self.abi_bitness != "32") or
            (test_name.lower().endswith(const.SUFFIX_64BIT)
             and self.abi_bitness != "64" and not self.run_32bit_on_64bit_abi),
            "Test case '{}' excluded as ABI bitness is {}.".format(
                test_name, self.abi_bitness))
Exemplo n.º 15
0
    def RunTestcase(self, testcase):
        """Runs the given testcase and asserts the result.

        Args:
            testcase: string, format testsuite/testname, specifies which
                test case to run.
        """
        host_input = self.CreateHostInput(testcase)
        asserts.skipIf(
            not host_input,
            "%s not configured to run against this target model." % testcase)

        items = testcase.split("/", 1)
        testsuite = items[0]

        chmod_cmd = "chmod -R 755 %s" % path_utils.JoinTargetPath(
            config.POC_TEST_DIR, testsuite)
        logging.info("Executing: %s", chmod_cmd)
        self._dut.adb.shell(chmod_cmd)

        test_flags = self.CreateTestFlags(host_input)
        test_cmd = "%s %s" % (path_utils.JoinTargetPath(
            config.POC_TEST_DIR, testcase), test_flags)
        logging.info("Executing: %s", test_cmd)

        try:
            stdout = self._dut.adb.shell(test_cmd)
            result = {
                const.STDOUT: stdout,
                const.STDERR: "",
                const.EXIT_CODE: 0
            }
        except adb.AdbError as e:
            result = {
                const.STDOUT: e.stdout,
                const.STDERR: e.stderr,
                const.EXIT_CODE: e.ret_code
            }
        logging.info("Test results:\n%s", result)

        self.AssertTestResult(result)
Exemplo n.º 16
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))
Exemplo n.º 17
0
    def AssertTestResult(self, result):
        """Asserts that testcase finished as expected.

        Checks that device is in responsive state. If not, waits for boot
        then reports test as failure. If it is, asserts that all test commands
        returned exit code 0.

        Args:
            result: dict(str, str, int), stdout, stderr and return code
                from test run.
        """
        if self._dut.hasBooted():
            exit_code = result[const.EXIT_CODE]
            asserts.skipIf(exit_code == config.ExitCode.POC_TEST_SKIP,
                           "Test case was skipped.")
            asserts.assertFalse(exit_code == config.ExitCode.POC_TEST_FAIL,
                                "Test case failed.")
        else:
            self._dut.waitForBootCompletion()
            self._dut.rootAdb()
            self.PushFiles()
            asserts.fail("Test case left the device in unresponsive state.")
    def CheckResult(self, cmd_results, result=None, note=None):
        """Check a test result and emit exceptions if test failed or skipped.

        If the shell command result is not yet interpreted, self.Verify will
        be called to interpret the results.

        Args:
            cmd_results: dict([str],[str],[int]), command results from shell.
            result: int, which is one of the values of _PASS, _SKIP, and _FAIL
            note: string, reason why a test failed or get skipped
        """
        asserts.assertTrue(cmd_results, "No response received. Socket timeout")

        logging.info("stdout: %s", cmd_results[const.STDOUT])
        logging.info("stderr: %s", cmd_results[const.STDERR])
        logging.info("exit_code: %s", cmd_results[const.EXIT_CODE])

        if result is None:
            result, note = self.Verify(cmd_results)
        logging.info("verify result: %s", result)
        logging.info("note: %s", note)

        asserts.skipIf(result == self._SKIP, note)
        asserts.assertEqual(result, self._PASS, note)
Exemplo n.º 19
0
    def filterOneTest(self, test_name):
        """Check test filters for a test name.

        The first layer of filter is user defined test filters:
        if a include filter is not empty, only tests in include filter will
        be executed regardless whether they are also in exclude filter. Else
        if include filter is empty, only tests not in exclude filter will be
        executed.

        The second layer of filter is checking _skip_all_testcases flag:
        the subclass may set _skip_all_testcases to True in its implementation
        of setUpClass. If the flag is set, this method raises signals.TestSkip.

        The third layer of filter is checking abi bitness:
        if a test has a suffix indicating the intended architecture bitness,
        and the current abi bitness information is available, non matching tests
        will be skipped. By our convention, this function will look for bitness in suffix
        formated as "32bit", "32Bit", "32BIT", or 64 bit equivalents.

        This method assumes const.SUFFIX_32BIT and const.SUFFIX_64BIT are in lower cases.

        Args:
            test_name: string, name of a test

        Raises:
            signals.TestSilent if a test should not be executed
            signals.TestSkip if a test should be logged but not be executed
        """
        if (hasattr(self, keys.ConfigKeys.KEY_INCLUDE_FILTER) and
                getattr(self, keys.ConfigKeys.KEY_INCLUDE_FILTER)):
            if test_name not in getattr(self,
                                        keys.ConfigKeys.KEY_INCLUDE_FILTER):
                logging.info("Test case '%s' not in include filter." %
                             test_name)
                raise signals.TestSilent(
                    "Test case '%s' not in include filter." % test_name)
        elif (hasattr(self, keys.ConfigKeys.KEY_EXCLUDE_FILTER) and
              test_name in getattr(self, keys.ConfigKeys.KEY_EXCLUDE_FILTER)):
            logging.info("Test case '%s' in exclude filter." % test_name)
            raise signals.TestSilent("Test case '%s' in exclude filter." %
                                     test_name)

        if self._skip_all_testcases:
            raise signals.TestSkip("All test cases skipped.")

        if hasattr(self, keys.ConfigKeys.IKEY_ABI_BITNESS):
            bitness = getattr(self, keys.ConfigKeys.IKEY_ABI_BITNESS)
            run_32bit_on_64bit_abi = getattr(
                self, keys.ConfigKeys.IKEY_RUN_32BIT_ON_64BIT_ABI, False)

            skip_on_32bit_abi = getattr(
                self, keys.ConfigKeys.IKEY_SKIP_ON_32BIT_ABI, False)
            skip_on_64bit_abi = getattr(
                self, keys.ConfigKeys.IKEY_SKIP_ON_64BIT_ABI, False)

            asserts.skipIf(
                ((skip_on_32bit_abi is True) and bitness == "32") or (
                    (skip_on_64bit_abi is True) and bitness == "64") or
                (test_name.lower().endswith(const.SUFFIX_32BIT) and
                 bitness != "32") or (
                     test_name.lower().endswith(const.SUFFIX_64BIT) and
                     bitness != "64" and not run_32bit_on_64bit_abi),
                "Test case '{}' excluded as ABI bitness is {}.".format(
                    test_name, bitness))
Exemplo n.º 20
0
 def setUp(self):
     """Checks if the the preconditions to run the test are met."""
     asserts.skipIf("x86" in self.dut.cpu_abi, "Skipping test for x86 ABI")