예제 #1
0
    def _ParseBatchResults(self, test_case_original, xml_str):
        '''Parse batch mode gtest results

        Args:
            test_case_original: GtestTestCase object, original batch test case object
            xml_str: string, result xml output content
        '''
        root = self._ParseResultXmlString(xml_str)

        for test_suite in root:
            logging.debug('Test tag: %s, attribute: %s',
                          test_suite.tag,
                          test_suite.attrib)
            for test_case in test_suite:
                result = gtest_test_case.GtestTestCase(
                    test_suite.get('name'),
                    test_case.get('name'), '', test_case_original.tag,
                    self.PutTag, name_appendix=test_case_original.name_appendix)

                failure_message = None
                for sub in test_case:
                    if sub.tag == 'failure':
                        failure_message = sub.get('message')

                test_case_filtered = filter(
                    lambda sub: sub.tag not in _GTEST_RESULT_ATTRIBUTE_WHITE_LIST, test_case)
                if len(test_case_filtered) and not failure_message:
                    failure_message = 'Error: %s\n' % test_case.attrib
                    for sub in test_case_filtered:
                        failure_message += '%s: %s\n' % (sub.tag, sub.attrib)

                result.failure_message = failure_message

                self._gtest_results.append(result)
    def _ParseBatchResults(self, test_case_original, xml_str):
        '''Parse batch mode gtest results

        Args:
            test_case_original: GtestTestCase object, original batch test case object
            xml_str: string, result xml output content
        '''
        root = xml.etree.ElementTree.fromstring(xml_str)

        for test_suite in root:
            print test_suite.tag, test_suite.attrib
            for test_case in test_suite:
                result = gtest_test_case.GtestTestCase(test_suite.get('name'),
                                                       test_case.get('name'),
                                                       '',
                                                       test_case_original.tag,
                                                       self.PutTag)

                failure_message = None
                for sub in test_case:
                    if sub.tag == 'failure':
                        failure_message = sub.get('message')

                if len(test_case) and not failure_message:
                    failure_message = 'Error: %s\n' % test_case.attrib
                    for sub in test_case:
                        failure_message += '%s: %s\n' % (sub.tag, sub.attrib)

                result.failure_message = failure_message

                self._gtest_results.append(result)
    def CreateTestCase(self, path, tag=''):
        '''Create a list of GtestTestCase objects from a binary path.

        Args:
            path: string, absolute path of a gtest binary on device
            tag: string, a tag that will be appended to the end of test name

        Returns:
            A list of GtestTestCase objects
        '''
        working_directory = self.working_directory[
            tag] if tag in self.working_directory else None
        envp = self.envp[tag] if tag in self.envp else ''
        args = self.args[tag] if tag in self.args else ''
        ld_library_path = self.ld_library_path[
            tag] if tag in self.ld_library_path else None
        profiling_library_path = self.profiling_library_path[
            tag] if tag in self.ld_library_path else None

        args += " --gtest_list_tests"
        list_test_case = binary_test_case.BinaryTestCase(
            'gtest_list_tests',
            path,
            path,
            tag,
            self.PutTag,
            working_directory,
            ld_library_path,
            profiling_library_path,
            envp=envp,
            args=args)
        cmd = ['chmod 755 %s' % path, list_test_case.GetRunCommand()]
        cmd_results = self.shell.Execute(cmd)
        if any(cmd_results[const.EXIT_CODE]
               ):  # gtest binary doesn't exist or is corrupted
            logging.error('Failed to list test cases from binary %s' % path)

        test_cases = []

        test_suite = ''
        for line in cmd_results[const.STDOUT][1].split('\n'):
            line = str(line)
            if not len(line.strip()):
                continue
            elif line.startswith(' '):  # Test case name
                test_name = line.split('#')[0].strip()
                test_case = gtest_test_case.GtestTestCase(
                    test_suite, test_name, path, tag, self.PutTag,
                    working_directory, ld_library_path, profiling_library_path)
                logging.info('Gtest test case: %s' % test_case)
                test_cases.append(test_case)
            else:  # Test suite name
                test_suite = line.strip()
                if test_suite.endswith('.'):
                    test_suite = test_suite[:-1]

        return test_cases
예제 #4
0
    def CreateTestCase(self, path, tag=''):
        '''Create a list of GtestTestCase objects from a binary path.

        Args:
            path: string, absolute path of a gtest binary on device
            tag: string, a tag that will be appended to the end of test name

        Returns:
            A list of GtestTestCase objects on success; an empty list otherwise.
            In non-batch mode, each object respresents a test case in the
            gtest binary located at the provided path. Usually there are more
            than one object returned.
            In batch mode, each object represents a gtest binary located at
            the provided path; the returned list will always be a one object
            list in batch mode. Test case names are stored in full_name
            property in the object, delimited by ':' according to gtest
            documentation, after being filtered and processed according to
            host configuration.
        '''
        working_directory = self.working_directory[
            tag] if tag in self.working_directory else None
        envp = self.envp[tag] if tag in self.envp else ''
        args = self.args[tag] if tag in self.args else ''
        ld_library_path = self.ld_library_path[
            tag] if tag in self.ld_library_path else None
        profiling_library_path = self.profiling_library_path[
            tag] if tag in self.profiling_library_path else None

        gtest_list_args = args + " --gtest_list_tests"
        list_test_case = binary_test_case.BinaryTestCase(
            'gtest_list_tests',
            path,
            path,
            tag,
            self.PutTag,
            working_directory,
            ld_library_path,
            profiling_library_path,
            envp=envp,
            args=gtest_list_args)
        cmd = ['chmod 755 %s' % path, list_test_case.GetRunCommand()]
        cmd_results = self.shell.Execute(cmd)
        test_cases = []
        asserts.assertFalse(any(cmd_results[const.EXIT_CODE]),
                'Failed to list test cases from %s. Command: %s, Result: %s.' %
                (path, cmd, cmd_results))

        test_suite = ''
        for line in cmd_results[const.STDOUT][1].split('\n'):
            line = str(line)
            if not len(line.strip()):
                continue
            elif line.startswith(' '):  # Test case name
                test_name = line.split('#')[0].strip()
                test_case = gtest_test_case.GtestTestCase(
                    test_suite, test_name, path, tag, self.PutTag,
                    working_directory, ld_library_path, profiling_library_path,
                    envp=envp, args=args)
                logging.debug('Gtest test case: %s' % test_case)
                test_cases.append(test_case)
            else:  # Test suite name
                test_suite = line.strip()
                if test_suite.endswith('.'):
                    test_suite = test_suite[:-1]

        #if not self.batch_mode:
        # Avoid batch mode as it creates overly large filters
        return test_cases
    def CreateTestCase(self, path, tag=''):
        '''Create a list of GtestTestCase objects from a binary path.

        Args:
            path: string, absolute path of a gtest binary on device
            tag: string, a tag that will be appended to the end of test name

        Returns:
            A list of GtestTestCase objects.
            In non-batch mode, each object respresents a test case in the
            gtest binary located at the provided path. Usually there are more
            than one object returned.
            In batch mode, each object represents a gtest binary located at
            the provided path; the returned list will always be a one object
            list in batch mode. Test case names are stored in full_name
            property in the object, delimited by ':' according to gtest
            documentation, after being filtered and processed according to
            host configuration.
        '''
        working_directory = self.working_directory[
            tag] if tag in self.working_directory else None
        envp = self.envp[tag] if tag in self.envp else ''
        args = self.args[tag] if tag in self.args else ''
        ld_library_path = self.ld_library_path[
            tag] if tag in self.ld_library_path else None
        profiling_library_path = self.profiling_library_path[
            tag] if tag in self.ld_library_path else None

        args += " --gtest_list_tests"
        list_test_case = binary_test_case.BinaryTestCase(
            'gtest_list_tests',
            path,
            path,
            tag,
            self.PutTag,
            working_directory,
            ld_library_path,
            profiling_library_path,
            envp=envp,
            args=args)
        cmd = ['chmod 755 %s' % path, list_test_case.GetRunCommand()]
        cmd_results = self.shell.Execute(cmd)
        if any(cmd_results[const.EXIT_CODE]
               ):  # gtest binary doesn't exist or is corrupted
            logging.error('Failed to list test cases from binary %s' % path)

        test_cases = []

        test_suite = ''
        for line in cmd_results[const.STDOUT][1].split('\n'):
            line = str(line)
            if not len(line.strip()):
                continue
            elif line.startswith(' '):  # Test case name
                test_name = line.split('#')[0].strip()
                test_case = gtest_test_case.GtestTestCase(
                    test_suite, test_name, path, tag, self.PutTag,
                    working_directory, ld_library_path, profiling_library_path)
                logging.info('Gtest test case: %s' % test_case)
                test_cases.append(test_case)
            else:  # Test suite name
                test_suite = line.strip()
                if test_suite.endswith('.'):
                    test_suite = test_suite[:-1]

        if not self.batch_mode:
            return test_cases

        # Gtest batch mode
        test_names = map(lambda test: test.full_name, test_cases)

        gtest_batch = gtest_test_case.GtestTestCase(path, '', path, tag,
                                                    self.PutTag,
                                                    working_directory,
                                                    ld_library_path,
                                                    profiling_library_path)
        gtest_batch.full_name = ':'.join(test_names)
        return [gtest_batch]