Ejemplo n.º 1
0
    def testUpdateSourceFileCounters(self):
        dev_package = self.dev_root_node.getElementsByTagName('package')[0]
        host_package = self.host_root_node.getElementsByTagName('package')[0]
        dev_source_node = dev_package.getElementsByTagName('sourcefile')[0]
        host_source_node = host_package.getElementsByTagName('sourcefile')[0]
        dev_counter_dict = generate_jacoco_report._CreateAttributeToObjectDict(
            dev_source_node.getElementsByTagName('counter'), 'type')
        self.assertEqual(
            dev_counter_dict['INSTRUCTION'].getAttribute('covered'), '1')
        self.assertEqual(
            dev_counter_dict['INSTRUCTION'].getAttribute('missed'), '15')
        self.assertEqual(dev_counter_dict['LINE'].getAttribute('covered'), '0')
        self.assertEqual(dev_counter_dict['LINE'].getAttribute('missed'), '3')

        total_dict = {'ci': 101, 'mi': 202, 'cb': 303, 'mb': 404}
        generate_jacoco_report._UpdateSourceFileCounters(
            dev_source_node, host_source_node, total_dict)
        self.assertEqual(
            dev_counter_dict['INSTRUCTION'].getAttribute('covered'), '101')
        self.assertEqual(
            dev_counter_dict['INSTRUCTION'].getAttribute('missed'), '202')
        self.assertEqual(dev_counter_dict['BRANCH'].getAttribute('covered'),
                         '303')
        self.assertEqual(dev_counter_dict['BRANCH'].getAttribute('missed'),
                         '404')
        self.assertEqual(dev_counter_dict['LINE'].getAttribute('covered'), '2')
        self.assertEqual(dev_counter_dict['LINE'].getAttribute('missed'), '1')
Ejemplo n.º 2
0
 def testCreateAttributeToObjectDict(self):
     device_packages = self.dev_root_node.getElementsByTagName('package')
     device_dict = generate_jacoco_report._CreateAttributeToObjectDict(
         device_packages, 'name')
     self.assertEqual(len(device_dict), 2)
     self.assertIn('package1', device_dict)
     self.assertIn('package3', device_dict)
Ejemplo n.º 3
0
    def testUpdatePackageSourceFiles(self):
        dev_package = self.dev_root_node.getElementsByTagName('package')[0]
        host_package = self.host_root_node.getElementsByTagName('package')[0]
        dev_source_node = dev_package.getElementsByTagName('sourcefile')[0]
        dev_line_dict = generate_jacoco_report._CreateAttributeToObjectDict(
            dev_source_node.getElementsByTagName('line'), 'nr')
        self.assertEqual(len(dev_line_dict), 3)
        self.assertIn('19', dev_line_dict)

        # The nr in host_package are now added to the dev_package.s
        generate_jacoco_report._UpdatePackageSourceFiles(
            dev_package, host_package)
        dev_line_dict = generate_jacoco_report._CreateAttributeToObjectDict(
            dev_source_node.getElementsByTagName('line'), 'nr')
        self.assertEqual(len(dev_line_dict), 5)
        for num in [15, 19, 20, 190, 200]:
            self.assertIn(str(num), dev_line_dict)
Ejemplo n.º 4
0
    def testAddMissingNodes(self):
        device_packages = self.dev_root_node.getElementsByTagName('package')
        host_packages = self.host_root_node.getElementsByTagName('package')
        device_dict = generate_jacoco_report._CreateAttributeToObjectDict(
            device_packages, 'name')
        host_dict = generate_jacoco_report._CreateAttributeToObjectDict(
            host_packages, 'name')

        self.assertEqual(len(device_dict), 2)
        self.assertEqual(len(host_dict), 3)
        self.assertNotIn('not_in_device_xml', device_dict)
        generate_jacoco_report._AddMissingNodes(device_dict, host_dict,
                                                self.dev_root_node, 'name')
        self.assertEqual(len(device_dict), 3)
        self.assertIn('not_in_device_xml', device_dict)
        self.assertEqual(
            len(self.dev_root_node.getElementsByTagName('package')), 3)
Ejemplo n.º 5
0
    def testCombineXmlFiles(self):
        with build_utils.TempDir() as temp_dir:
            temp_device_f = os.path.join(temp_dir, 'temp_device')
            temp_host_f = os.path.join(temp_dir, 'temp_host')
            temp_result_f = os.path.join(temp_dir, 'temp_result')
            with open(temp_device_f, 'w') as dev_f, open(temp_host_f,
                                                         'w') as host_f:
                dev_f.write(DEVICE_XML)
                host_f.write(HOST_XML)

            generate_jacoco_report._CombineXmlFiles(temp_result_f,
                                                    temp_device_f, temp_host_f)
            result_tree = minidom.parse(temp_result_f)
            result_root = result_tree.getElementsByTagName('report')[0]
            report_ans_dict = {
                'instruction': ('213', '327'),
                'branch': ('207', '207'),
                'method': ('205', '201'),
            }
            self.verify_counters(result_root, 6, report_ans_dict)

            self.assertEqual(len(result_root.getElementsByTagName('package')),
                             3)
            result_package = result_root.getElementsByTagName('package')[0]
            classes = result_package.getElementsByTagName('class')
            self.assertEqual(len(classes), 3)
            result_class_dict = generate_jacoco_report._CreateAttributeToObjectDict(
                classes, 'name')
            for key in result_class_dict:
                expected_classes = {'class1', 'class2', 'not_in_dev_package'}
                self.assertIn(key, expected_classes)

            class_ans_dict = {
                'instruction': ('2', '13'),
                'branch': ('2', '2'),
                'method': ('2', '0'),
            }
            self.verify_counters(result_class_dict['class1'], 6,
                                 class_ans_dict)

            methods = result_package.getElementsByTagName('method')
            self.assertEqual(len(methods), 3)
            result_method_dict = generate_jacoco_report._CreateAttributeToObjectDict(
                methods, 'name')
            for key in result_method_dict:
                expected_methods = {'method1', 'method2', 'method3'}
                self.assertIn(key, expected_methods)

            method_ans_dict = {
                'instruction': ('1', '6'),
                'branch': ('1', '1'),
                'line': ('1', '1'),
            }
            self.verify_counters(result_method_dict['method1'], 5,
                                 method_ans_dict)

            self.assertEqual(
                len(result_root.getElementsByTagName('sourcefile')), 3)
            source_file_node = result_root.getElementsByTagName(
                'sourcefile')[0]
            source_ans_dict = {
                'instruction': ('3', '19'),
                'branch': ('2', '4'),
                'line': ('2', '1'),
                'class': ('1', '0'),
            }
            self.verify_counters(source_file_node, 6, source_ans_dict)