예제 #1
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
예제 #2
0
    def tearDownClass(self):
        '''Perform clean-up tasks'''
        # Retrieve coverage if applicable
        if self.coverage.enabled and self.coverage.global_coverage:
            if not self.isSkipAllTests():
                self.coverage.SetCoverageData(dut=self._dut, isGlobal=True)

        # Clean up the pushed binaries
        logging.info('Start class cleaning up jobs.')
        # Delete pushed files

        sources = [
            self.ParseTestSource(src) for src in self.binary_test_source
        ]
        sources = set(filter(bool, sources))
        paths = [dst for src, dst, tag in sources if src and dst]
        cmd = ['rm -rf %s' % dst for dst in paths]
        cmd_results = self.shell.Execute(cmd, no_except=True)
        if not cmd_results or any(cmd_results[const.EXIT_CODE]):
            logging.warning('Failed to clean up test class: %s', cmd_results)

        # Delete empty directories in working directories
        dir_set = set(path_utils.TargetDirName(dst) for dst in paths)
        dir_set.add(self.ParseTestSource('')[1])
        dirs = list(dir_set)
        dirs.sort(lambda x, y: cmp(len(y), len(x)))
        cmd = ['rmdir %s' % d for d in dirs]
        cmd_results = self.shell.Execute(cmd, no_except=True)
        if not cmd_results or any(cmd_results[const.EXIT_CODE]):
            logging.warning('Failed to remove: %s', cmd_results)

        if not self.isSkipAllTests() and self.profiling.enabled:
            self.profiling.ProcessAndUploadTraceData()

        logging.info('Finished class cleaning up jobs.')
예제 #3
0
 def output_file_path(self):
     """Get output_file_path"""
     if not hasattr(self,
                    '_output_file_path') or self._output_file_path is None:
         self.output_file_path = '{directory}/gtest_output_{name}.xml'.format(
             directory=path_utils.TargetDirName(self.path),
             name=re.sub(r'\W+', '_', str(self)))
     return self._output_file_path
예제 #4
0
    def testKernelNetworking(self):
        """Android kernel unit test."""
        # Push the test binary to target device.
        self.shell('mkdir -p %s' %
                   path_utils.TargetDirName(self.target_bin_path))
        self.dut.adb.push('%s %s' % (self.host_bin_path, self.target_bin_path))
        self.shell('chmod 777 %s' % self.target_bin_path)

        # Execute the test binary.
        result = self.shell(self.target_bin_path, no_except=True)

        logging.info('stdout: %s', result[const.STDOUT])
        logging.error('stderr: %s', result[const.STDERR])
        logging.info('exit code: %s', result[const.EXIT_CODE])
        asserts.assertFalse(
            result[const.EXIT_CODE],
            'kernel_net_tests binary returned non-zero exit code.')
예제 #5
0
    def tearDownClass(self):
        '''Perform clean-up tasks'''
        if getattr(self, keys.ConfigKeys.IKEY_BINARY_TEST_STOP_NATIVE_SERVERS,
                   False):
            logging.debug("Restarts all properly configured native servers.")
            results = self._dut.setProp(self.SYSPROP_VTS_NATIVE_SERVER, "0")

        # Restart Android runtime.
        if getattr(self, keys.ConfigKeys.IKEY_BINARY_TEST_DISABLE_FRAMEWORK,
                   False):
            logging.debug("Starts the Android framework.")
            self._dut.start()

        # Retrieve coverage if applicable
        if self.coverage.enabled and self.coverage.global_coverage:
            self.coverage.SetCoverageData(dut=self._dut, isGlobal=True)

        # Clean up the pushed binaries
        logging.info('Start class cleaning up jobs.')
        # Delete pushed files

        sources = [
            self.ParseTestSource(src) for src in self.binary_test_source
        ]
        sources = set(filter(bool, sources))
        paths = [dst for src, dst, tag in sources if src and dst]
        cmd = ['rm -rf %s' % dst for dst in paths]
        cmd_results = self.shell.Execute(cmd, no_except=True)
        if not cmd_results or any(cmd_results[const.EXIT_CODE]):
            logging.warning('Failed to clean up test class: %s', cmd_results)

        # Delete empty directories in working directories
        dir_set = set(path_utils.TargetDirName(dst) for dst in paths)
        dir_set.add(self.ParseTestSource('')[1])
        dirs = list(dir_set)
        dirs.sort(lambda x, y: cmp(len(y), len(x)))
        cmd = ['rmdir %s' % d for d in dirs]
        cmd_results = self.shell.Execute(cmd, no_except=True)
        if not cmd_results or any(cmd_results[const.EXIT_CODE]):
            logging.warning('Failed to remove: %s', cmd_results)

        if self.profiling.enabled:
            self.profiling.ProcessAndUploadTraceData()

        logging.info('Finished class cleaning up jobs.')
예제 #6
0
    def testElfDependency(self):
        """Scans library/executable dependency on vendor partition."""
        read_errors = []
        objs = self._loadElfObjects(
            self._temp_dir, path_utils.TargetDirName(self._TARGET_VENDOR_DIR),
            lambda p, e: read_errors.append((p, str(e))))

        dep_errors = self._testSpHalDependency(32, objs)
        if self._dut.is64Bit:
            dep_errors.extend(self._testSpHalDependency(64, objs))
        # TODO(hsinyichen): check other vendor libraries

        if read_errors:
            logging.error("%d read errors:", len(read_errors))
            for x in read_errors:
                logging.error("%s: %s", x[0], x[1])
        if dep_errors:
            logging.error("%d disallowed dependencies:", len(dep_errors))
            for x in dep_errors:
                logging.error("%s: %s", x[0], ", ".join(x[1]))
        error_count = len(read_errors) + len(dep_errors)
        asserts.assertEqual(error_count, 0,
                            "Total number of errors: " + str(error_count))
예제 #7
0
 def __init__(self, target_path, bitness, deps):
     self.target_path = target_path
     self.name = path_utils.TargetBaseName(target_path)
     self.target_dir = path_utils.TargetDirName(target_path)
     self.bitness = bitness
     self.deps = deps
예제 #8
0
 def tearDownClass(self):
     self.shell('rm -rf %s' %
                path_utils.TargetDirName(self.target_bin_path))