def testVerifyOverlay(self):
     """Verifies application of DT overlays."""
     overlay_idx_string = self.adb.shell(
         "cat /proc/cmdline | "
         "grep -o \"androidboot.dtbo_idx=[^ ]*\" |"
         "cut -d \"=\" -f 2")
     asserts.assertNotEqual(
         len(overlay_idx_string), 0,
         "Kernel command line missing androidboot.dtbo_idx")
     overlay_idx_list = overlay_idx_string.split(",")
     overlay_arg = []
     for idx in overlay_idx_list:
         overlay_file = "dumped_dtbo." + idx.rstrip()
         overlay_path = os.path.join(self.temp_dir, overlay_file)
         self.adb.push(overlay_path, self.device_path)
         overlay_arg.append(overlay_file)
     final_dt_path = path_utils.JoinTargetPath(self.device_path, "final_dt")
     self.shell.Execute("cp %s %s" % (FDT_PATH, final_dt_path))
     verification_test_path = path_utils.JoinTargetPath(
         self.device_path, "ufdt_verify_overlay")
     chmod_cmd = "chmod 755 %s" % verification_test_path
     results = self.shell.Execute(chmod_cmd)
     asserts.assertEqual(results[const.EXIT_CODE][0], 0, "Unable to chmod")
     cd_cmd = "cd %s" % (self.device_path)
     verify_cmd = "./ufdt_verify_overlay final_dt %s" % (
         " ".join(overlay_arg))
     cmd = str("%s && %s" % (cd_cmd, verify_cmd))
     logging.info(cmd)
     results = self.shell.Execute(cmd)
     asserts.assertEqual(results[const.EXIT_CODE][0], 0,
                         "Incorrect Overlay Application")
    def RunTestcase(self, testcase):
        """Runs the given testcase and asserts the result.

        Args:
            testcase: a LinuxKselftestTestcase object, specifies which
                test case to run.
        """
        if not testcase:
            asserts.skip("Test is not supported on this abi.")

        chmod_cmd = "chmod -R 755 %s" % path_utils.JoinTargetPath(
            config.KSFT_DIR, testcase.testsuite)
        cd_cmd = "cd %s" % path_utils.JoinTargetPath(
            config.KSFT_DIR, testcase.testsuite)

        cmd = [
            chmod_cmd,
            "%s && %s" % (cd_cmd, testcase.test_cmd)
        ]
        logging.info("Executing: %s", cmd)

        result = self._shell.Execute(cmd)
        logging.info("EXIT_CODE: %s:", result[const.EXIT_CODE])

        asserts.assertFalse(
            any(result[const.EXIT_CODE]),
            "%s failed." % testcase.testname)
Example #3
0
    def CreateCorpus(self, fuzzer, fuzzer_config):
        """Creates a corpus directory on target.

        Args:
            fuzzer: string, name of the fuzzer executable.
            fuzzer_config: dict, contains configuration for the fuzzer.

        Returns:
            string, path to corpus directory on the target.
        """
        corpus = fuzzer_config.get("corpus", [])
        corpus_dir = path_utils.JoinTargetPath(config.FUZZER_TEST_DIR,
                                               "%s_corpus" % fuzzer)

        self._dut.adb.shell("mkdir %s -p" % corpus_dir)
        for idx, corpus_entry in enumerate(corpus):
            corpus_entry = corpus_entry.replace("x", "\\x")
            corpus_entry_file = path_utils.JoinTargetPath(
                corpus_dir, "input%s" % idx)
            cmd = "echo -ne '%s' > %s" % (str(corpus_entry), corpus_entry_file)
            # Vts shell drive doesn't play nicely with escape characters,
            # so we use adb shell.
            self._dut.adb.shell("\"%s\"" % cmd)

        return corpus_dir
Example #4
0
    def CreateTestCases(self):
        """Create a list of HalHidlReplayTestCase objects."""
        required_params = [
            keys.ConfigKeys.IKEY_HAL_HIDL_REPLAY_TEST_TRACE_PATHS,
            keys.ConfigKeys.IKEY_ABI_BITNESS
        ]
        opt_params = [keys.ConfigKeys.IKEY_BINARY_TEST_DISABLE_FRAMEWORK]
        self.getUserParams(req_param_names=required_params,
                           opt_param_names=opt_params)
        self.abi_bitness = str(self.abi_bitness)
        self.trace_paths = map(str, self.hal_hidl_replay_test_trace_paths)

        self.replayer_binary_path = path_utils.JoinTargetPath(
            self.DEVICE_TMP_DIR, self.abi_bitness,
            "vts_hal_replayer%s" % self.abi_bitness)
        self.custom_ld_library_path = path_utils.JoinTargetPath(
            self.DEVICE_TMP_DIR, self.abi_bitness)

        for trace_path in self.trace_paths:
            trace_file_name = str(os.path.basename(trace_path))
            target_trace_path = path_utils.JoinTargetPath(
                self.DEVICE_VTS_TRACE_FILE_PATH, trace_file_name)
            self._dut.adb.push(
                path_utils.JoinTargetPath(self.data_file_path,
                                          "hal-hidl-trace", trace_path),
                target_trace_path)
            service_instance_combinations = self._GetServiceInstanceCombinations(
                target_trace_path)

            appendix_list = []
            if service_instance_combinations:
                for instance_combination in service_instance_combinations:
                    test_case = self.CreateReplayTestCase(
                        trace_file_name, target_trace_path)
                    service_name_list = []
                    for instance in instance_combination:
                        test_case.args += " --hal_service_instance=" + instance
                        service_name_list.append(instance[instance.find('/') +
                                                          1:])
                    name_appendix = "({0})".format(",".join(service_name_list))
                    test_case.name_appendix = name_appendix
                    self.testcases.append(test_case)
                    appendix_list.append(name_appendix)
                self.test_filter.ExpandAppendix(appendix_list,
                                                _HAL_TEST_NAME_PATTERN)
            else:
                test_case = self.CreateReplayTestCase(trace_file_name,
                                                      target_trace_path)
                self.testcases.append(test_case)
    def CreateTestCases(self):
        """Create a list of HalHidlReplayTestCase objects."""
        required_params = [
            keys.ConfigKeys.IKEY_HAL_HIDL_REPLAY_TEST_TRACE_PATHS,
            keys.ConfigKeys.IKEY_HAL_HIDL_PACKAGE_NAME,
            keys.ConfigKeys.IKEY_ABI_BITNESS
        ]
        opt_params = [keys.ConfigKeys.IKEY_BINARY_TEST_DISABLE_FRAMEWORK]
        self.getUserParams(
            req_param_names=required_params, opt_param_names=opt_params)
        self.hal_hidl_package_name = str(self.hal_hidl_package_name)
        self.abi_bitness = str(self.abi_bitness)
        self.trace_paths = map(str, self.hal_hidl_replay_test_trace_paths)

        target_package, target_version = self.hal_hidl_package_name.split("@")
        custom_ld_library_path = path_utils.JoinTargetPath(self.DEVICE_TMP_DIR,
                                                           self.abi_bitness)
        driver_binary_path = path_utils.JoinTargetPath(
            self.DEVICE_TMP_DIR, self.abi_bitness,
            "fuzzer%s" % self.abi_bitness)
        target_vts_driver_file_path = path_utils.JoinTargetPath(
            self.DEVICE_TMP_DIR, self.abi_bitness,
            "%s@%s-vts.driver.so" % (target_package, target_version))

        if not self._skip_all_testcases:
            service_names = self.getServiceName()
        else:
            service_names = [""]

        test_suite = ''
        for trace_path in self.trace_paths:
            logging.info("trace_path: %s", trace_path)
            trace_file_name = str(os.path.basename(trace_path))
            trace_path = path_utils.JoinTargetPath(
                self.DEVICE_TMP_DIR, "vts_replay_trace", trace_file_name)
            for service_name in service_names:
                test_name = "replay_test_" + trace_file_name
                if service_name:
                    test_name += "_" + service_name
                test_case = hal_hidl_replay_test_case.HalHidlReplayTestCase(
                    trace_path,
                    target_vts_driver_file_path,
                    service_name,
                    test_suite,
                    test_name,
                    driver_binary_path,
                    ld_library_path=custom_ld_library_path)
                self.testcases.append(test_case)
    def setUpClass(self):
        """Prepares class and initializes a target device."""
        super(HalHidlReplayTest, self).setUpClass()

        if self._skip_all_testcases:
            return

        # TODO(zhuoyao): consider to push trace just before each test case.
        for trace_path in self.trace_paths:
            trace_path = str(trace_path)
            trace_file_name = str(os.path.basename(trace_path))
            self._dut.adb.push(
                path_utils.JoinTargetPath(self.data_file_path,
                                          "hal-hidl-trace", trace_path),
                path_utils.JoinTargetPath(self.DEVICE_TMP_DIR,
                                          "vts_replay_trace", trace_file_name))
Example #7
0
        def _SerializeVTSFuzzerParams(params):
            """Creates VTS command line flags for fuzzer executable.

            Args:
                params: dict, contains flags and their values.

            Returns:
                string, of form "--<flag0>=<val0> --<flag1>=<val1> ... "
            """
            VTS_SPEC_FILES = "vts_spec_files"
            VTS_EXEC_SIZE = "vts_exec_size"
            DELIMITER = ":"

            # vts_spec_files is a string list, will be serialized like this:
            # [a, b, c] -> "a:b:c"
            vts_spec_files = params.get(VTS_SPEC_FILES, {})
            target_vts_spec_files = DELIMITER.join(
                map(
                    lambda x: path_utils.JoinTargetPath(
                        config.FUZZER_SPEC_DIR, x), vts_spec_files))
            flags = "--%s=\"%s\" " % (VTS_SPEC_FILES, target_vts_spec_files)

            vts_exec_size = params.get(VTS_EXEC_SIZE, {})
            flags += "--%s=%s" % (VTS_EXEC_SIZE, vts_exec_size)
            return flags
Example #8
0
    def _loadElfObjects(self, host_dir, target_dir, elf_error_handler):
        """Scans a host directory recursively and loads all ELF files in it.

        Args:
            host_dir: The host directory to scan.
            target_dir: The path from which host_dir is copied.
            elf_error_handler: A function that takes 2 arguments
                               (target_path, exception). It is called when
                               the parser fails to read an ELF file.

        Returns:
            List of ElfObject.
        """
        objs = []
        for root_dir, file_name in utils.iterate_files(host_dir):
            full_path = os.path.join(root_dir, file_name)
            rel_path = os.path.relpath(full_path, host_dir)
            target_path = path_utils.JoinTargetPath(
                target_dir, *rel_path.split(os.path.sep))
            try:
                elf = elf_parser.ElfParser(full_path)
            except elf_parser.ElfError:
                logging.debug("%s is not an ELF file", target_path)
                continue
            try:
                deps = elf.ListDependencies()
            except elf_parser.ElfError as e:
                elf_error_handler(target_path, e)
                continue
            finally:
                elf.Close()

            logging.info("%s depends on: %s", target_path, ", ".join(deps))
            objs.append(self.ElfObject(target_path, elf.bitness, deps))
        return objs
Example #9
0
    def output_file_path(self, output_file_path):
        """Set output_file_path.

        Lengths of both file name and path will be checked. If longer than
        maximum allowance, file name will be set to a random name, and
        directory will be set to relative directory.

        Args:
            output_file_path: string, intended path of output xml file
        """
        output_file_path = path_utils.TargetNormPath(output_file_path.strip())
        output_base_name = path_utils.TargetBaseName(output_file_path)
        output_dir_name = path_utils.TargetDirName(output_file_path)

        if len(output_base_name) > utils.MAX_FILENAME_LEN:
            logging.warn(
                'File name of output file "{}" is longer than {}.'.format(
                    output_file_path, utils.MAX_FILENAME_LEN))
            output_base_name = '{}.xml'.format(uuid.uuid4())
            output_file_path = path_utils.JoinTargetPath(
                output_dir_name, output_base_name)
            logging.debug('Output file path is set as "%s".', output_file_path)

        if len(output_file_path) > utils.MAX_PATH_LEN:
            logging.warn(
                'File path of output file "{}" is longer than {}.'.format(
                    output_file_path, utils.MAX_PATH_LEN))
            output_file_path = output_base_name
            logging.debug('Output file path is set as "%s".', output_file_path)

        self._output_file_path = output_file_path
    def ParseTestSource(self, source):
        '''Convert host side binary path to device side path.

        Args:
            source: string, binary test source string

        Returns:
            A tuple of (string, string, string), representing (host side
            absolute path, device side absolute path, tag). Returned tag
            will be None if the test source is for pushing file to working
            directory only. If source file is specified for adb push but does not
            exist on host, None will be returned.
        '''
        tag = ''
        path = source
        if self.TAG_DELIMITER in source:
            tag, path = source.split(self.TAG_DELIMITER)

        src = path
        dst = None
        if self.PUSH_DELIMITER in path:
            src, dst = path.split(self.PUSH_DELIMITER)

        if src:
            src = os.path.join(self.data_file_path, src)
            if not os.path.exists(src):
                logging.warning(
                    'binary source file is specified '
                    'but does not exist on host: %s', src)
                return None

        push_only = dst is not None and dst == ''

        if not dst:
            if tag in self.working_directory:
                dst = path_utils.JoinTargetPath(self.working_directory[tag],
                                                os.path.basename(src))
            else:
                dst = path_utils.JoinTargetPath(
                    self.DEVICE_TMP_DIR,
                    'binary_test_temp_%s' % self.__class__.__name__, tag,
                    os.path.basename(src))

        if push_only:
            tag = None

        return str(src), str(dst), tag
    def CheckAllTestCaseExecutables(self, test_cases):
        """Run a batch job to check executable exists and set permissions.

        The result will be stored in self._executable_available for use in
        TestBinaryExists method.

        Args:
            test_case: list of TestCase objects.
        """
        executables_generators = (
            test_case.GetRequiredExecutablePaths(self.ltp_bin_host_path)
            for test_case in test_cases)
        executables = list(
            set(itertools.chain.from_iterable(executables_generators)))

        # Set all executables executable permission using chmod.
        logging.info("Setting permissions on device")
        permission_command = "chmod 775 %s" % path_utils.JoinTargetPath(
            ltp_configs.LTPBINPATH, '*')
        permission_result = self.shell.Execute(permission_command)
        if permission_result[const.EXIT_CODE][0]:
            logging.error("Permission command '%s' failed.",
                          permission_command)

        # Check existence of all executables used in test definition.
        # Some executables needed by test cases but not listed in test
        # definition will not be checked here
        logging.info("Checking binary existence on host")

        executable_exists_results = map(os.path.exists, executables)

        self._executable_available = dict(
            zip(executables, executable_exists_results))

        not_exists = [
            exe for exe, exists in self._executable_available.iteritems()
            if not exists
        ]
        if not_exists:
            logging.info("The following binaries does not exist: %s",
                         not_exists)

        logging.info("Finished checking binary existence on host.")

        # Check whether all the internal binaries in path needed exist
        bin_path_exist_commands = [
            "which %s" % bin for bin in ltp_configs.INTERNAL_BINS
        ]
        bin_path_results = map(
            operator.not_,
            self.shell.Execute(bin_path_exist_commands)[const.EXIT_CODE])

        bin_path_results = map(
            operator.not_,
            self.shell.Execute(bin_path_exist_commands)[const.EXIT_CODE])

        self._executable_available.update(
            dict(zip(ltp_configs.INTERNAL_BINS, bin_path_results)))
 def setUpClass(self):
     """Initializes the DUT and creates temporary directories."""
     self.dut = self.android_devices[0]
     self.shell = self.dut.shell
     self.adb = self.dut.adb
     self.temp_dir = tempfile.mkdtemp()
     logging.info("Create %s", self.temp_dir)
     self.device_path = str(
         path_utils.JoinTargetPath(DEVICE_TEMP_DIR, self.abi_bitness))
     self.shell.Execute("mkdir %s -p" % self.device_path)
Example #13
0
    def setUpClass(self):
        """Prepares class and initializes a target device."""
        super(HalHidlReplayTest, self).setUpClass()

        if self._skip_all_testcases:
            return

        # TODO(zhuoyao): consider to push trace just before each test case.
        for trace_path in self.trace_paths:
            trace_path = str(trace_path)
            trace_file_name = str(os.path.basename(trace_path))
            self._dut.adb.push(
                path_utils.JoinTargetPath(self.data_file_path,
                                          "hal-hidl-trace", trace_path),
                path_utils.JoinTargetPath(self.DEVICE_TMP_DIR,
                                          "vts_replay_trace", trace_file_name))
        if self.coverage.enabled:
            # enable passthrough mode to measure code coverage.
            self.shell.Execute('setprop vts.hidl.get_stub true')
Example #14
0
    def _GetGcdaDict(self, dut, serial):
        """Retrieves GCDA files from device and creates a dictionary of files.

        Find all GCDA files on the target device, copy them to the host using
        adb, then return a dictionary mapping from the gcda basename to the
        temp location on the host.

        Args:
            dut: the device under test.

        Returns:
            A dictionary with gcda basenames as keys and contents as the values.
        """
        logging.debug("Creating gcda dictionary")
        gcda_dict = {}
        logging.debug("Storing gcda tmp files to: %s",
                      self.local_coverage_path)

        self._ExecuteOneAdbShellCommand(dut, serial, _FLUSH_COMMAND)

        gcda_files = set()
        if self._hal_names:
            pids = self._GetHalPids(dut, self._hal_names)
            pids.add(_SP_COVERAGE_PATH)
            for pid in pids:
                path = path_utils.JoinTargetPath(TARGET_COVERAGE_PATH, pid)
                try:
                    files = dut.adb.shell("find %s -name \"*.gcda\"" % path)
                    gcda_files.update(files.split("\n"))
                except AdbError as e:
                    logging.info("No gcda files found in path: \"%s\"", path)
        else:
            cmd = ("find %s -name \"*.gcda\"" % TARGET_COVERAGE_PATH)
            result = self._ExecuteOneAdbShellCommand(dut, serial, cmd)
            if result:
                gcda_files.update(result.split("\n"))

        for gcda in gcda_files:
            if gcda:
                basename = os.path.basename(gcda.strip())
                file_name = os.path.join(self.local_coverage_path, basename)
                if dut is None:
                    results = cmd_utils.ExecuteShellCommand(
                        "adb -s %s pull %s %s " % (serial, gcda, file_name))
                    if (results[cmd_utils.EXIT_CODE][0]):
                        logging.error(
                            "Fail to execute command: %s. error: %s" %
                            (cmd, str(results[cmd_utils.STDERR][0])))
                else:
                    dut.adb.pull("%s %s" % (gcda, file_name))
                gcda_content = open(file_name, "rb").read()
                gcda_dict[gcda.strip()] = gcda_content
        self._ClearTargetGcov(dut, serial)
        return gcda_dict
Example #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)
Example #16
0
    def _ClearTargetGcov(self, dut, serial, path_suffix=None):
        """Removes gcov data from the device.

        Finds and removes all gcda files relative to TARGET_COVERAGE_PATH.
        Args:
            dut: the device under test.
            path_suffix: optional string path suffix.
        """
        path = TARGET_COVERAGE_PATH
        if path_suffix:
            path = path_utils.JoinTargetPath(path, path_suffix)
        self._ExecuteOneAdbShellCommand(dut, serial, _CLEAN_TRACE_COMMAND)
    def InternalAddLtpPathToCommand(self, command):
        """Internal function to change binary in commands to their full path"""
        tokens = command.strip().split()

        # If not ltp executables:
        if (tokens[0] in ltp_configs.INTERNAL_BINS
                or tokens[0] in ltp_configs.INTERNAL_SHELL_COMMANDS
                or tokens[0].find('=') > 0):
            return command
        else:  # Is Ltp executable
            tokens[0] = path_utils.JoinTargetPath(ltp_configs.LTPBINPATH,
                                                  tokens[0])
            return ' '.join(tokens)
    def tearDownClass(self):
        """Performs clean-up tasks."""
        # Delete the pushed file.
        if not self._skip_all_testcases:
            for trace_path in self.trace_paths:
                trace_file_name = str(os.path.basename(trace_path))
                target_trace_path = path_utils.JoinTargetPath(
                    self.DEVICE_TMP_DIR, "vts_replay_trace", trace_file_name)
                cmd_results = self.shell.Execute("rm -f %s" % target_trace_path)
                if not cmd_results or any(cmd_results[const.EXIT_CODE]):
                    logging.warning("Failed to remove: %s", cmd_results)

        super(HalHidlReplayTest, self).tearDownClass()
Example #19
0
    def GetRequiredExecutablePaths(self, ltp_bin_path=ltp_configs.LTPBINPATH):
        """Get required executables' paths.

        Returns:
            A list of all executables' paths that will be needed
            by its command. For LTP's executables, absolute path will be
            returned. For binaries in system's PATH, only the name will be
            returned.
        """
        return [
            path_utils.JoinTargetPath(ltp_bin_path, executable)
            if executable not in ltp_configs.INTERNAL_BINS else executable
            for executable in self.InternalGetExecutableNames()
            if executable not in ltp_configs.INTERNAL_SHELL_COMMANDS
        ]
Example #20
0
    def GetTraceFiles(self,
                      dut,
                      host_profiling_trace_path=None,
                      trace_file_tool=None):
        """Pulls the trace file and save it under the profiling trace path.

        Args:
            dut: the testing device.
            host_profiling_trace_path: directory that stores trace files on host.
            trace_file_tool: tools that used to store the trace file.

        Returns:
            Name list of trace files that stored on host.
        """
        if not os.path.exists(LOCAL_PROFILING_TRACE_PATH):
            os.makedirs(LOCAL_PROFILING_TRACE_PATH)

        if not host_profiling_trace_path:
            host_profiling_trace_path = LOCAL_PROFILING_TRACE_PATH

        dut.shell.InvokeTerminal("profiling_shell")
        target_trace_file = path_utils.JoinTargetPath(
            TARGET_PROFILING_TRACE_PATH, "*.vts.trace")
        results = dut.shell.profiling_shell.Execute("ls " + target_trace_file)
        asserts.assertTrue(results, "failed to find trace file")
        stdout_lines = results[const.STDOUT][0].split("\n")
        logging.info("stdout: %s", stdout_lines)
        trace_files = []
        for line in stdout_lines:
            if line:
                temp_file_name = os.path.join(LOCAL_PROFILING_TRACE_PATH,
                                              os.path.basename(line.strip()))
                dut.adb.pull("%s %s" % (line, temp_file_name))
                trace_file_name = os.path.join(host_profiling_trace_path,
                                               os.path.basename(line.strip()))
                logging.info("Saving profiling traces: %s" % trace_file_name)
                if temp_file_name != trace_file_name:
                    file_cmd = ""
                    if trace_file_tool:
                        file_cmd += trace_file_tool
                    file_cmd += " cp " + temp_file_name + " " + trace_file_name
                    results = cmd_utils.ExecuteShellCommand(file_cmd)
                    if results[const.EXIT_CODE][0] != 0:
                        logging.error(results[const.STDERR][0])
                        logging.error("Fail to execute command: %s" % file_cmd)
                trace_files.append(temp_file_name)
        return trace_files
Example #21
0
    def setUpClass(self):
        required_params = [
            keys.ConfigKeys.IKEY_DATA_FILE_PATH,
        ]
        self.getUserParams(required_params)
        logging.info('%s: %s', keys.ConfigKeys.IKEY_DATA_FILE_PATH,
                     self.data_file_path)

        self.dut = self.android_devices[0]
        self.shell = self.dut.adb.shell

        # 32-bit version of the test should only run against 32-bit kernel;
        # same for 64 bit.
        bin_path = ('nativetest64' if self.dut.is64Bit else 'nativetest',
                    'kernel_net_tests', 'kernel_net_tests')

        self.host_bin_path = os.path.join(self.data_file_path, 'DATA',
                                          *bin_path)
        self.target_bin_path = path_utils.JoinTargetPath('data', *bin_path)
Example #22
0
    def RunTestcase(self, fuzzer):
        """Runs the given testcase and asserts the result.

        Args:
            fuzzer: string, name of fuzzer executable.
        """
        self.PushFiles(fuzzer)

        fuzzer_config = self.fuzzer_configs.get(fuzzer, {})
        test_flags = self.CreateFuzzerFlags(fuzzer_config)
        corpus_dir = self.CreateCorpus(fuzzer, fuzzer_config)

        chmod_cmd = "chmod -R 755 %s" % path_utils.JoinTargetPath(
            config.FUZZER_TEST_DIR, fuzzer)
        self._dut.adb.shell(chmod_cmd)

        cd_cmd = "cd %s" % config.FUZZER_TEST_DIR
        ld_path = "LD_LIBRARY_PATH=/data/local/tmp/64:/data/local/tmp/32:$LD_LIBRARY_PATH"
        test_cmd = "./%s" % fuzzer

        fuzz_cmd = "%s && %s %s %s %s > /dev/null" % (cd_cmd, ld_path,
                                                      test_cmd, corpus_dir,
                                                      test_flags)
        logging.debug("Executing: %s", fuzz_cmd)
        # TODO(trong): vts shell doesn't handle timeouts properly, change this after it does.
        try:
            stdout = self._dut.adb.shell("'%s'" % fuzz_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
            }
        self.AssertTestResult(fuzzer, result)
Example #23
0
import os

from vts.utils.python.os import path_utils

from vts.testcases.kernel.ltp import ltp_enums

VTS_LTP_OUTPUT = os.path.join('DATA', 'nativetest', 'ltp')
LTP_RUNTEST_DIR = os.path.join(VTS_LTP_OUTPUT, 'runtest')
LTP_DISABLED_BUILD_TESTS_CONFIG_PATH = os.path.join(VTS_LTP_OUTPUT,
                                                    'disabled_tests.txt')

# Environment paths for ltp test cases
# string, ltp build root directory on target
LTPDIR = '/data/local/tmp/ltp'
# Directory for environment variable 'TMP' needed by some test cases
TMP = path_utils.JoinTargetPath(LTPDIR, 'tmp')
# Directory for environment variable 'TMPBASE' needed by some test cases
TMPBASE = path_utils.JoinTargetPath(TMP, 'tmpbase')
# Directory for environment variable 'LTPTMP' needed by some test cases
LTPTMP = path_utils.JoinTargetPath(TMP, 'ltptemp')
# Directory for environment variable 'TMPDIR' needed by some test cases
TMPDIR = path_utils.JoinTargetPath(TMP, 'tmpdir')
# Path where ltp test binary exists
LTPBINPATH = path_utils.JoinTargetPath(LTPDIR, 'testcases', 'bin')
# Add LTP's binary path to PATH
PATH = '/system/bin:%s' % LTPBINPATH

# Default number of threads to run LTP tests. Zero means matching to number
# of CPU threads
DEFAULT_NUMBER_OF_THREADS = 0
Example #24
0
 def GetCorpusName(self):
     """Returns corpus directory name on target."""
     corpus_dir = path_utils.JoinTargetPath(config.FUZZER_TEST_DIR,
                                            '%s_corpus' % self._test_name)
     return corpus_dir