Example #1
0
    def _ExecuteOneAdbShellCommand(self, dut, serial, cmd):
        """Helper method to execute a shell command and return results.

        Args:
            dut: the device under test.
            cmd: string, command to execute.
        Returns:
            stdout result of the command, None if command fails.
        """
        if dut is None:
            results = cmd_utils.ExecuteShellCommand("adb -s %s shell %s" %
                                                    (serial, cmd))
            if (results[cmd_utils.EXIT_CODE][0]):
                logging.error("Fail to execute command: %s. error: %s" %
                              (cmd, str(results[cmd_utils.STDERR][0])))
                return None
            else:
                return results[cmd_utils.STDOUT][0]
        else:
            try:
                return dut.adb.shell(cmd)
            except AdbError as e:
                logging.warn("Fail to execute command: %s. error: %s" %
                             (cmd, str(e)))
                return None
Example #2
0
    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
        executable_exists_commands = [
            "ls %s" % executable for executable in executables
            if executable not in ltp_configs.INTERNAL_BINS
        ]
        logging.info("Checking binary existence on host: %s",
                     executable_exists_commands)

        cmd_results = cmd_utils.ExecuteShellCommand(executable_exists_commands)
        executable_exists_results = map(operator.not_,
                                        cmd_results[cmd_utils.EXIT_CODE])
        logging.info("Finished checking binary existence on host: %s",
                     cmd_results)

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

        # 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)))
Example #3
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
    def testHostBinary(self):
        """Tests host-side binaries."""
        android_build_top = os.getenv("ANDROID_BUILD_TOP", "")
        asserts.assertTrue(
            android_build_top,
            "$ANDROID_BUILD_TOP is not set. Please run lunch <build target>")

        for binary_test_source in self.binary_test_source:
            binary_test_source = str(binary_test_source)
            binary_path = os.path.join(android_build_top, binary_test_source)

            cmd_result = cmd_utils.ExecuteShellCommand(binary_path)
            asserts.assertFalse(
                any(results[cmd_utils.EXIT_CODE]),
                "Test failed with the following results:\n "
                "command result: %s" % results)
Example #5
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 #6
0
    def _ParseTraceData(self, trace_file):
        """Parses the data stored in trace_file, calculates the avg/max/min
        latency for each API.

        Args:
            trace_file: file that stores the trace data.

        Returns:
            VTSProfilingData which contain the list of API names and the avg/max/min
            latency for each API.
        """
        profiling_data = VTSProfilingData()
        api_timestamps = {}
        api_latencies = {}

        data_file_path = getattr(self, keys.ConfigKeys.IKEY_DATA_FILE_PATH)
        trace_processor_binary = os.path.join(data_file_path, "host", "bin",
                                              "trace_processor")
        trace_processor_lib = os.path.join(data_file_path, "host", "lib64")
        trace_processor_cmd = [
            "chmod a+x %s" % trace_processor_binary,
            "LD_LIBRARY_PATH=%s %s -m profiling_trace %s" %
            (trace_processor_lib, trace_processor_binary, trace_file)
        ]

        results = cmd_utils.ExecuteShellCommand(trace_processor_cmd)
        if any(results[cmd_utils.EXIT_CODE]):
            logging.error("Fail to execute command: %s" % trace_processor_cmd)
            return profiling_data

        stdout_lines = results[const.STDOUT][1].split("\n")
        first_line = True
        for line in stdout_lines:
            if not line:
                continue
            if first_line:
                _, mode = line.split(":")
                profiling_data.options.add("hidl_hal_mode=%s" % mode)
                first_line = False
            else:
                api, latency = line.split(":")
                if profiling_data.values.get(api):
                    profiling_data.values[api].append(long(latency))
                else:
                    profiling_data.values[api] = [long(latency)]

        return profiling_data
Example #7
0
    def ConnectInstanceToAdb(self, ip=None):
        '''Connect an Acloud instance to adb

        Args:
            ip: string, ip address
        '''
        if not ip:
            ip = self.GetInstanceIP()

        cmds = [('ssh -i ~/.ssh/acloud_rsa -o UserKnownHostsFile=/dev/null '
                 '-o StrictHostKeyChecking=no -L 40000:127.0.0.1:6444 -L '
                 '30000:127.0.0.1:5555 -N -f -l root %s') % ip,
                'adb connect 127.0.0.1:30000']

        for cmd in cmds:
            print cmd
            results = cmd_utils.ExecuteShellCommand(cmd)
            if any(results[cmd_utils.EXIT_CODE]):
                logging.error("Fail to execute command: %s\nResult:%s" %
                              (cmd, results))
                return
            print 'Acloud instance created and connected to local port 127.0.0.1:30000'
Example #8
0
    def _ParseTraceData(self, trace_file, measure_api_coverage):
        """Parses the data stored in trace_file, calculates the avg/max/min
        latency for each API.

        Args:
            trace_file: file that stores the trace data.
            measure_api_coverage: whether to measure the api coverage data.

        Returns:
            VTSProfilingData which contain the list of API names and the avg/max/min
            latency for each API.
        """
        profiling_data = VTSProfilingData()
        api_timestamps = {}
        api_latencies = {}

        trace_processor_binary = os.path.join(self.data_file_path, "host",
                                              "bin", "trace_processor")
        trace_processor_lib = os.path.join(self.data_file_path, "host",
                                           "lib64")
        trace_processor_cmd = [
            "chmod a+x %s" % trace_processor_binary,
            "LD_LIBRARY_PATH=%s %s -m profiling_trace %s" %
            (trace_processor_lib, trace_processor_binary, trace_file)
        ]

        results = cmd_utils.ExecuteShellCommand(trace_processor_cmd)
        if any(results[cmd_utils.EXIT_CODE]):
            logging.error("Fail to execute command: %s" % trace_processor_cmd)
            logging.error("stdout: %s" % results[const.STDOUT])
            logging.error("stderr: %s" % results[const.STDERR])
            return profiling_data

        stdout_lines = results[const.STDOUT][1].split("\n")
        first_line = True
        for line in stdout_lines:
            if not line:
                continue
            if first_line:
                _, mode = line.split(":")
                profiling_data.options.add("hidl_hal_mode=%s" % mode)
                first_line = False
            else:
                full_api, latency = line.rsplit(":", 1)
                full_interface, api_name = full_api.rsplit("::", 1)
                if profiling_data.values.get(api_name):
                    profiling_data.values[api_name].append(long(latency))
                else:
                    profiling_data.values[api_name] = [long(latency)]

                if measure_api_coverage:
                    package, interface_name = full_interface.split("::")
                    package_name, version = package.split("@")

                    if full_interface in self.api_coverage_data:
                        self.api_coverage_data[
                            full_interface].covered_apis.add(api_name)
                    else:
                        total_apis = self._GetTotalApis(
                            package_name, version, interface_name)
                        if total_apis:
                            vts_api_coverage = VTSApiCoverageData(
                                package_name, version, interface_name)
                            vts_api_coverage.total_apis = total_apis
                            if api_name in total_apis:
                                vts_api_coverage.covered_apis.add(api_name)
                            else:
                                logging.warning("API %s is not supported by %s",
                                                api_name, full_interface)
                            self.api_coverage_data[
                                full_interface] = vts_api_coverage

        return profiling_data