コード例 #1
0
    def _flat_compare_key_ranges(self, key_id, source_key, target_key):
        mod = self._flat_compare_base_keys(
            key_id,
            source_key,
            target_key,
            extra_varnames=['ref', 'index_bits', 'first_index'])
        only_in_source = []
        only_in_target = []

        # Use hexadecimal format for index bits
        for entry in mod:
            if entry.value_id == 'index_bits':
                entry.source_value = self._num_to_str(entry.source_value)
                entry.target_value = self._num_to_str(entry.target_value)

        def get_subkeys_dict(key):
            subkeys = {}
            for sk in key.subkeys:
                subkeys[sk.int] = sk
            return subkeys

        src_subkeys = get_subkeys_dict(source_key)
        tgt_subkeys = get_subkeys_dict(target_key)

        # Find sub-keys only in source
        # ----------------------------
        for uid in src_subkeys.iterkeys():
            if uid not in tgt_subkeys:
                entry = plugin.FlatComparisonResultEntry(
                    sub_id="%s (sub-key %s)" % (key_id, self._num_to_str(uid)))
                only_in_source.append(entry)

        # Find sub-keys only in target
        # ----------------------------
        for uid in tgt_subkeys.iterkeys():
            if uid not in src_subkeys:
                entry = plugin.FlatComparisonResultEntry(
                    sub_id="%s (sub-key %s)" % (key_id, self._num_to_str(uid)))
                only_in_target.append(entry)

        # Find modified bits
        # ------------------
        for uid, src_subkey in src_subkeys.iteritems():
            if uid not in tgt_subkeys: continue
            tgt_subkey = tgt_subkeys[uid]

            mod.extend(
                self._flat_compare_object_attrs(
                    key_id="%s (sub-key %s)" % (key_id, self._num_to_str(uid)),
                    source_obj=src_subkey,
                    target_obj=tgt_subkey,
                    varnames=('ref', 'type', 'name')))

        return plugin.FlatComparisonResult(modified=mod,
                                           only_in_source=only_in_source,
                                           only_in_target=only_in_target)
 def test_compare(self):
     conf1 = self._open_config('comp_project_1')
     conf2 = self._open_config('comp_project_2')
     
     crml_file = None
     repo_uid = None
     
     def entry(**kwargs):
         kwargs['file']      = crml_file
         kwargs['impl_type'] = 'crml'
         kwargs['id']        = repo_uid
         return plugin.FlatComparisonResultEntry(**kwargs)
     
     comparison_result = None
     
     crml_file = 'Layer1/implml/00000001_simple_keys.crml'
     impl_filter = '00000001_simple_keys.crml$'
     repo_uid = '0x00000001'
     impls1 = plugin.get_impl_set(conf1, impl_filter)
     impls2 = plugin.get_impl_set(conf2, impl_filter)
     actual_result = impls1.flat_compare(impls2)
     
     expected_mods = [
         entry(sub_id='0x00000001', value_id='type',     source_value='int', target_value='real'),
         entry(sub_id='0x00000002', value_id='backup',   source_value=True,  target_value=False),
         
         entry(sub_id='0x00000003', value_id='read_only', source_value=True,     target_value=False),
         entry(sub_id='0x00000004', value_id='read_only', source_value=False,    target_value=True),
         # Changing read-only changes also cap_wr
         entry(sub_id='0x00000003', value_id='cap_wr',   source_value='AlwaysFail',    target_value=None),
         entry(sub_id='0x00000004', value_id='cap_wr',   source_value=None,            target_value='AlwaysFail'),
         
         entry(sub_id='0x00000005', value_id='type',     source_value='int',                 target_value='real'),
         entry(sub_id='0x00000006', value_id='name',     source_value='Setting 6',           target_value='Setting 6 (name changed)'),
         entry(sub_id='0x00000007', value_id='ref',      source_value='SimpleKeys.Setting7', target_value='SimpleKeys.Setting7RefChanged'),
         entry(sub_id='0x00000008', value_id='cap_rd',   source_value='ReadDeviceData',      target_value='ReadUserData'),
         entry(sub_id='0x00000008', value_id='cap_wr',   source_value='WriteDeviceData',     target_value='WriteUserData'),
         entry(sub_id='0x00000008', value_id='sid_rd',   source_value='0xAABBCCDD',          target_value='0x11223344'),
         entry(sub_id='0x00000008', value_id='sid_wr',   source_value='0xDDCCBBAA',          target_value='0x44332211'),
         entry(sub_id='0x00000009', value_id='cap_rd',   source_value='ReadDeviceData',      target_value=None),
         entry(sub_id='0x00000009', value_id='cap_wr',   source_value='WriteDeviceData',     target_value=None),
         entry(sub_id='0x00000009', value_id='sid_rd',   source_value='0xAABBCCDD',          target_value=None),
         entry(sub_id='0x00000009', value_id='sid_wr',   source_value='0xDDCCBBAA',          target_value=None),
     ]
     expected_removed = [
         entry(sub_id='0x10000001'),
         entry(sub_id='0x10000002'),
     ]
     expected_added = [
         entry(sub_id='0x20000001'),
         entry(sub_id='0x20000002'),
     ]
     expected_result = plugin.FlatComparisonResult(modified=expected_mods,
                                                   only_in_source=expected_removed,
                                                   only_in_target=expected_added)
     self.assertEquals(actual_result, expected_result)
コード例 #3
0
    def _flat_compare_bitmask_keys(self, key_id, source_key, target_key):
        mod = self._flat_compare_base_keys(key_id,
                                           source_key,
                                           target_key,
                                           extra_varnames=['type'])
        only_in_source = []
        only_in_target = []

        def get_bits_dict(key):
            bits = {}
            for bit in key.bits:
                bits[bit.index] = bit
            return bits

        src_bits = get_bits_dict(source_key)
        tgt_bits = get_bits_dict(target_key)

        # Find bits only in source
        # ------------------------
        for index in src_bits.iterkeys():
            if index not in tgt_bits:
                entry = plugin.FlatComparisonResultEntry(sub_id="%s (bit %s)" %
                                                         (key_id, index))
                only_in_source.append(entry)

        # Find bits only in target
        # ------------------------
        for index in tgt_bits.iterkeys():
            if index not in src_bits:
                entry = plugin.FlatComparisonResultEntry(sub_id="%s (bit %s)" %
                                                         (key_id, index))
                only_in_target.append(entry)

        # Find modified bits
        # ------------------
        for index, src_bit in src_bits.iteritems():
            if index not in tgt_bits: continue
            tgt_bit = tgt_bits[index]

            mod.extend(
                self._flat_compare_object_attrs(key_id="%s (bit %s)" %
                                                (key_id, index),
                                                source_obj=src_bit,
                                                target_obj=tgt_bit,
                                                varnames=('ref', 'invert')))

        return plugin.FlatComparisonResult(modified=mod,
                                           only_in_source=only_in_source,
                                           only_in_target=only_in_target)
    def assert_comparison_result_after_change_equals(
            self,
            modification_code,
            added=[],
            removed=[],
            modified=[],
            check_keys_in_entry_data=True,
            target_resource_ref='test.crml'):
        # Make a copy of the test repo and modify it using the given code
        repo = self.repo.copy()
        exec(modification_code)

        expected_result = plugin.FlatComparisonResult(only_in_source=removed,
                                                      only_in_target=added,
                                                      modified=modified)

        comparator = CrmlComparator('test.crml', self.repo)
        actual_result = comparator.flat_compare(target_resource_ref, repo)
        self.assertEquals(expected_result, actual_result)

        # Assert that all comparison result entries have references to the
        # repository objects
        for entry in actual_result.only_in_source:
            self.assertTrue(isinstance(entry.data['repo'], CrmlRepository))
        for entry in actual_result.only_in_target:
            self.assertTrue(isinstance(entry.data['repo'], CrmlRepository))
        for entry in actual_result.modified:
            self.assertTrue(
                isinstance(entry.data['source_repo'], CrmlRepository))
            self.assertTrue(
                isinstance(entry.data['target_repo'], CrmlRepository))

        # Check also references to CRML key objects if specified
        if check_keys_in_entry_data:
            for entry in actual_result.only_in_source:
                self.assertTrue(isinstance(entry.data['key'], CrmlKeyBase))
            for entry in actual_result.only_in_target:
                self.assertTrue(isinstance(entry.data['key'], CrmlKeyBase))
            for entry in actual_result.modified:
                self.assertTrue(
                    isinstance(entry.data['source_key'], CrmlKeyBase))
                self.assertTrue(
                    isinstance(entry.data['target_key'], CrmlKeyBase))
コード例 #5
0
    def _get_flat_key_comparison_result(self, key_id, source_key, target_key):
        """
        Return a flat comparison result for a source and target CRML key pair.
        
        @param key_id: The ID of the key, e.g. '0x00000001' for a simple key or
            '0x00001000-0x00001FFF' for a key range.
        @param source_key: The source key object.
        @param target_key: The target key object.
        @return: A plugin.FlatComparisonResult object.
        """
        result = plugin.FlatComparisonResult()

        if type(source_key) == type(target_key):
            comp_funcs = {
                CrmlSimpleKey: self._flat_compare_simple_keys,
                CrmlBitmaskKey: self._flat_compare_bitmask_keys,
                CrmlKeyRange: self._flat_compare_key_ranges
            }
            func = comp_funcs[type(source_key)]
            result.extend(func(key_id, source_key, target_key))
        else:
            # Perform base key comparison
            result.modified.extend(
                self._flat_compare_base_keys(key_id, source_key, target_key))

            # Add an entry for key type change
            type_ids = {
                CrmlSimpleKey: 'simple_key',
                CrmlBitmaskKey: 'bitmask_key',
                CrmlKeyRange: 'key_range'
            }
            entry = plugin.FlatComparisonResultEntry(
                sub_id=key_id,
                value_id='key_type',
                source_value=type_ids[type(source_key)],
                target_value=type_ids[type(target_key)])
            result.modified.append(entry)

        return result
 def test_compare_all(self):
     conf1 = self._open_config('comp_project_1')
     conf2 = self._open_config('comp_project_2')
     impls1 = plugin.get_impl_set(conf1)
     impls2 = plugin.get_impl_set(conf2)
     actual_result = impls1.flat_compare(impls2)
     
     expected_result = plugin.FlatComparisonResult(
         only_in_source = [
         FlatComparisonResultEntry(file='Layer1/implml/00000001_simple_keys.crml', impl_type='crml', id='0x00000001', sub_id='0x10000001'),
         FlatComparisonResultEntry(file='Layer1/implml/00000001_simple_keys.crml', impl_type='crml', id='0x00000001', sub_id='0x10000002'),
         FlatComparisonResultEntry(file='Layer1/implml/00000002_bitmask_keys.crml', impl_type='crml', id='0x00000002', sub_id='0x00000001 (bit 4)'),
         FlatComparisonResultEntry(file='Layer1/implml/00000002_bitmask_keys.crml', impl_type='crml', id='0x00000002', sub_id='0x00000003 (bit 4)'),
         FlatComparisonResultEntry(file='Layer1/implml/00000002_bitmask_keys.crml', impl_type='crml', id='0x00000002', sub_id='0x10000001'),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00001001-0x00001FFF (sub-key 0x00000004)'),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00003001-0x00003FFF (sub-key 0x00000004)'),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x10001001-0x10001FFF'),
         FlatComparisonResultEntry(file='Layer1/implml/10000001_removed_repo.crml', impl_type='crml', id='0x10000001'),
         ],
         only_in_target = [
         FlatComparisonResultEntry(file='Layer1/implml/00000001_simple_keys.crml', impl_type='crml', id='0x00000001', sub_id='0x20000001'),
         FlatComparisonResultEntry(file='Layer1/implml/00000001_simple_keys.crml', impl_type='crml', id='0x00000001', sub_id='0x20000002'),
         FlatComparisonResultEntry(file='Layer1/implml/00000002_bitmask_keys.crml', impl_type='crml', id='0x00000002', sub_id='0x00000001 (bit 5)'),
         FlatComparisonResultEntry(file='Layer1/implml/00000002_bitmask_keys.crml', impl_type='crml', id='0x00000002', sub_id='0x00000003 (bit 5)'),
         FlatComparisonResultEntry(file='Layer1/implml/00000002_bitmask_keys.crml', impl_type='crml', id='0x00000002', sub_id='0x20000001'),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00001001-0x00001FFF (sub-key 0x00000005)'),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00003001-0x00003FFF (sub-key 0x00000005)'),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x20001001-0x20001FFF'),
         FlatComparisonResultEntry(file='Layer1/implml/20000001_added_repo.crml', impl_type='crml', id='0x20000001'),
         ],
         modified = [
         FlatComparisonResultEntry(file='Layer1/implml/00000001_simple_keys.crml', impl_type='crml', id='0x00000001', sub_id='0x00000001', value_id='type', source_value='int', target_value='real'),
         FlatComparisonResultEntry(file='Layer1/implml/00000001_simple_keys.crml', impl_type='crml', id='0x00000001', sub_id='0x00000002', value_id='backup', source_value=True, target_value=False),
         FlatComparisonResultEntry(file='Layer1/implml/00000001_simple_keys.crml', impl_type='crml', id='0x00000001', sub_id='0x00000003', value_id='cap_wr', source_value='AlwaysFail', target_value=None),
         FlatComparisonResultEntry(file='Layer1/implml/00000001_simple_keys.crml', impl_type='crml', id='0x00000001', sub_id='0x00000003', value_id='read_only', source_value=True, target_value=False),
         FlatComparisonResultEntry(file='Layer1/implml/00000001_simple_keys.crml', impl_type='crml', id='0x00000001', sub_id='0x00000004', value_id='cap_wr', source_value=None, target_value='AlwaysFail'),
         FlatComparisonResultEntry(file='Layer1/implml/00000001_simple_keys.crml', impl_type='crml', id='0x00000001', sub_id='0x00000004', value_id='read_only', source_value=False, target_value=True),
         FlatComparisonResultEntry(file='Layer1/implml/00000001_simple_keys.crml', impl_type='crml', id='0x00000001', sub_id='0x00000005', value_id='type', source_value='int', target_value='real'),
         FlatComparisonResultEntry(file='Layer1/implml/00000001_simple_keys.crml', impl_type='crml', id='0x00000001', sub_id='0x00000006', value_id='name', source_value='Setting 6', target_value='Setting 6 (name changed)'),
         FlatComparisonResultEntry(file='Layer1/implml/00000001_simple_keys.crml', impl_type='crml', id='0x00000001', sub_id='0x00000007', value_id='ref', source_value='SimpleKeys.Setting7', target_value='SimpleKeys.Setting7RefChanged'),
         FlatComparisonResultEntry(file='Layer1/implml/00000001_simple_keys.crml', impl_type='crml', id='0x00000001', sub_id='0x00000008', value_id='cap_rd', source_value='ReadDeviceData', target_value='ReadUserData'),
         FlatComparisonResultEntry(file='Layer1/implml/00000001_simple_keys.crml', impl_type='crml', id='0x00000001', sub_id='0x00000008', value_id='cap_wr', source_value='WriteDeviceData', target_value='WriteUserData'),
         FlatComparisonResultEntry(file='Layer1/implml/00000001_simple_keys.crml', impl_type='crml', id='0x00000001', sub_id='0x00000008', value_id='sid_rd', source_value='0xAABBCCDD', target_value='0x11223344'),
         FlatComparisonResultEntry(file='Layer1/implml/00000001_simple_keys.crml', impl_type='crml', id='0x00000001', sub_id='0x00000008', value_id='sid_wr', source_value='0xDDCCBBAA', target_value='0x44332211'),
         FlatComparisonResultEntry(file='Layer1/implml/00000001_simple_keys.crml', impl_type='crml', id='0x00000001', sub_id='0x00000009', value_id='cap_rd', source_value='ReadDeviceData', target_value=None),
         FlatComparisonResultEntry(file='Layer1/implml/00000001_simple_keys.crml', impl_type='crml', id='0x00000001', sub_id='0x00000009', value_id='cap_wr', source_value='WriteDeviceData', target_value=None),
         FlatComparisonResultEntry(file='Layer1/implml/00000001_simple_keys.crml', impl_type='crml', id='0x00000001', sub_id='0x00000009', value_id='sid_rd', source_value='0xAABBCCDD', target_value=None),
         FlatComparisonResultEntry(file='Layer1/implml/00000001_simple_keys.crml', impl_type='crml', id='0x00000001', sub_id='0x00000009', value_id='sid_wr', source_value='0xDDCCBBAA', target_value=None),
         FlatComparisonResultEntry(file='Layer1/implml/00000002_bitmask_keys.crml', impl_type='crml', id='0x00000002', sub_id='0x00000001', value_id='cap_rd', source_value='ReadDeviceData', target_value='ReadUserData'),
         FlatComparisonResultEntry(file='Layer1/implml/00000002_bitmask_keys.crml', impl_type='crml', id='0x00000002', sub_id='0x00000001', value_id='cap_wr', source_value='WriteDeviceData', target_value='WriteUserData'),
         FlatComparisonResultEntry(file='Layer1/implml/00000002_bitmask_keys.crml', impl_type='crml', id='0x00000002', sub_id='0x00000001', value_id='name', source_value='Bitmask 1', target_value='Bitmask 1 (name changed)'),
         FlatComparisonResultEntry(file='Layer1/implml/00000002_bitmask_keys.crml', impl_type='crml', id='0x00000002', sub_id='0x00000001', value_id='sid_rd', source_value='0xAABBCCDD', target_value='0x11223344'),
         FlatComparisonResultEntry(file='Layer1/implml/00000002_bitmask_keys.crml', impl_type='crml', id='0x00000002', sub_id='0x00000001', value_id='sid_wr', source_value='0xDDCCBBAA', target_value='0x44332211'),
         FlatComparisonResultEntry(file='Layer1/implml/00000002_bitmask_keys.crml', impl_type='crml', id='0x00000002', sub_id='0x00000001', value_id='type', source_value='int', target_value='binary'),
         FlatComparisonResultEntry(file='Layer1/implml/00000002_bitmask_keys.crml', impl_type='crml', id='0x00000002', sub_id='0x00000001 (bit 2)', value_id='ref', source_value='BitmaskKeys.Bit2', target_value='BitmaskKeys.Bit2RefChanged'),
         FlatComparisonResultEntry(file='Layer1/implml/00000002_bitmask_keys.crml', impl_type='crml', id='0x00000002', sub_id='0x00000001 (bit 3)', value_id='invert', source_value=False, target_value=True),
         FlatComparisonResultEntry(file='Layer1/implml/00000002_bitmask_keys.crml', impl_type='crml', id='0x00000002', sub_id='0x00000003', value_id='name', source_value='Modified read-only bitmask', target_value='Modified read-only bitmask (name changed)'),
         FlatComparisonResultEntry(file='Layer1/implml/00000002_bitmask_keys.crml', impl_type='crml', id='0x00000002', sub_id='0x00000003', value_id='type', source_value='int', target_value='binary'),
         FlatComparisonResultEntry(file='Layer1/implml/00000002_bitmask_keys.crml', impl_type='crml', id='0x00000002', sub_id='0x00000003 (bit 2)', value_id='ref', source_value='BitmaskKeys.Bit2', target_value='BitmaskKeys.Bit2RefChanged'),
         FlatComparisonResultEntry(file='Layer1/implml/00000002_bitmask_keys.crml', impl_type='crml', id='0x00000002', sub_id='0x00000003 (bit 3)', value_id='invert', source_value=False, target_value=True),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00001001-0x00001FFF', value_id='backup', source_value=True, target_value=False),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00001001-0x00001FFF', value_id='cap_rd', source_value='ReadDeviceData', target_value='ReadUserData'),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00001001-0x00001FFF', value_id='cap_wr', source_value='WriteDeviceData', target_value='WriteUserData'),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00001001-0x00001FFF', value_id='first_index', source_value=1L, target_value=2L),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00001001-0x00001FFF', value_id='index_bits', source_value='0x00000FF0', target_value='0x00001FE0'),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00001001-0x00001FFF', value_id='name', source_value='Sequence 1', target_value='Sequence 1 (name changed)'),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00001001-0x00001FFF', value_id='ref', source_value='KeyRanges.Seq1', target_value='KeyRanges.Seq1RefChanged'),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00001001-0x00001FFF', value_id='sid_rd', source_value='0x11223344', target_value='0xAABBCCDD'),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00001001-0x00001FFF', value_id='sid_wr', source_value='0x44332211', target_value='0xDDCCBBAA'),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00001001-0x00001FFF (sub-key 0x00000002)', value_id='name', source_value='Sub-setting 2', target_value='Sub-setting 2 (name changed)'),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00001001-0x00001FFF (sub-key 0x00000002)', value_id='ref', source_value='SubSetting2', target_value='SubSetting2RefChanged'),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00001001-0x00001FFF (sub-key 0x00000002)', value_id='type', source_value='int', target_value='real'),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00002000-0x00002FFF', value_id='backup', source_value=True, target_value=False),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00002000-0x00002FFF', value_id='read_only', source_value=True, target_value=False),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00003000-0x00003FFF', value_id='read_only', source_value=False, target_value=True),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00003001-0x00003FFF', value_id='cap_rd', source_value='ReadDeviceData', target_value='ReadUserData'),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00003001-0x00003FFF', value_id='cap_wr', source_value='WriteDeviceData', target_value='WriteUserData'),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00003001-0x00003FFF', value_id='first_index', source_value=1, target_value=2),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00003001-0x00003FFF', value_id='index_bits', source_value='0x00000FF0', target_value='0x00001FE0'),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00003001-0x00003FFF', value_id='name', source_value='Read-only sequence', target_value='Read-only sequence (name changed)'),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00003001-0x00003FFF', value_id='ref', source_value='KeyRanges.ReadOnlySeq', target_value='KeyRanges.ReadOnlySeqRefChanged'),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00003001-0x00003FFF', value_id='sid_rd', source_value='0x11223344', target_value='0xAABBCCDD'),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00003001-0x00003FFF', value_id='sid_wr', source_value='0x44332211', target_value='0xDDCCBBAA'),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00003001-0x00003FFF (sub-key 0x00000002)', value_id='name', source_value='Sub-setting 2', target_value='Sub-setting 2 (name changed)'),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00003001-0x00003FFF (sub-key 0x00000002)', value_id='ref', source_value='SubSetting2', target_value='SubSetting2RefChanged'),
         FlatComparisonResultEntry(file='Layer1/implml/00000003_key_ranges.crml', impl_type='crml', id='0x00000003', sub_id='0x00003001-0x00003FFF (sub-key 0x00000002)', value_id='type', source_value='int', target_value='real'),
         FlatComparisonResultEntry(file='Layer1/implml/00000004_key_type_changed.crml', impl_type='crml', id='0x00000004', sub_id='0x00000001', value_id='key_type', source_value='simple_key', target_value='bitmask_key'),
         FlatComparisonResultEntry(file='Layer1/implml/00000004_key_type_changed.crml', impl_type='crml', id='0x00000004', sub_id='0x00000002', value_id='key_type', source_value='bitmask_key', target_value='simple_key'),
         FlatComparisonResultEntry(file='Layer1/implml/00000004_key_type_changed.crml', impl_type='crml', id='0x00000004', sub_id='0x00000003', value_id='backup', source_value=True, target_value=False),
         FlatComparisonResultEntry(file='Layer1/implml/00000004_key_type_changed.crml', impl_type='crml', id='0x00000004', sub_id='0x00000003', value_id='cap_rd', source_value='ReadDeviceData', target_value='ReadUserData'),
         FlatComparisonResultEntry(file='Layer1/implml/00000004_key_type_changed.crml', impl_type='crml', id='0x00000004', sub_id='0x00000003', value_id='cap_wr', source_value='AlwaysFail', target_value='WriteUserData'),
         FlatComparisonResultEntry(file='Layer1/implml/00000004_key_type_changed.crml', impl_type='crml', id='0x00000004', sub_id='0x00000003', value_id='name', source_value='Bitmask key to simple key (other attrs changed also)', target_value='Bitmask key to simple key (other attrs changed also [xyz])'),
         FlatComparisonResultEntry(file='Layer1/implml/00000004_key_type_changed.crml', impl_type='crml', id='0x00000004', sub_id='0x00000003', value_id='read_only', source_value=True, target_value=False),
         FlatComparisonResultEntry(file='Layer1/implml/00000004_key_type_changed.crml', impl_type='crml', id='0x00000004', sub_id='0x00000003', value_id='sid_rd', source_value='0xAABBCCDD', target_value='0x11223344'),
         FlatComparisonResultEntry(file='Layer1/implml/00000004_key_type_changed.crml', impl_type='crml', id='0x00000004', sub_id='0x00000003', value_id='sid_wr', source_value=None, target_value='0x44332211'),
         FlatComparisonResultEntry(file='Layer1/implml/00000004_key_type_changed.crml', impl_type='crml', id='0x00000004', sub_id='0x00000003', value_id='type', source_value='int', target_value='binary'),
         FlatComparisonResultEntry(file='Layer1/implml/00000005_repo_attrs_changed.crml', impl_type='crml', id='0x00000005', sub_id=None, value_id='backup', source_value=True, target_value=False),
         FlatComparisonResultEntry(file='Layer1/implml/00000005_repo_attrs_changed.crml', impl_type='crml', id='0x00000005', sub_id=None, value_id='cap_rd', source_value='ReadDeviceData', target_value='ReadUserData'),
         FlatComparisonResultEntry(file='Layer1/implml/00000005_repo_attrs_changed.crml', impl_type='crml', id='0x00000005', sub_id=None, value_id='cap_wr', source_value='WriteDeviceData', target_value='WriteUserData'),
         FlatComparisonResultEntry(file='Layer1/implml/00000005_repo_attrs_changed.crml', impl_type='crml', id='0x00000005', sub_id=None, value_id='rfs', source_value=True, target_value=False),
         FlatComparisonResultEntry(file='Layer1/implml/00000005_repo_attrs_changed.crml', impl_type='crml', id='0x00000005', sub_id=None, value_id='sid_rd', source_value='0x11223344', target_value='0xAABBCCDD'),
         FlatComparisonResultEntry(file='Layer1/implml/00000005_repo_attrs_changed.crml', impl_type='crml', id='0x00000005', sub_id=None, value_id='sid_wr', source_value='0x44332211', target_value='0xDDCCBBAA'),
         FlatComparisonResultEntry(file='Layer1/implml/00000005_repo_attrs_changed.crml', impl_type='crml', id='0x00000005', sub_id=None, value_id='uid_name', source_value='RepoAttrsChanged', target_value='RepoAttrsChangedXyz'),
         FlatComparisonResultEntry(file='Layer1/implml/00000006_renamed_repo_xyz.crml', impl_type='crml', id='0x00000006', sub_id=None, value_id='file', source_value='Layer1/implml/00000006_renamed_repo.crml', target_value='Layer1/implml/00000006_renamed_repo_xyz.crml'),
         ],
         duplicate = [
         DuplicateImplementationEntry(impl_type='crml', id='0x30000000', files_in_source=['Layer1/implml/30000000_duplicate_repo1_proj1.crml', 'Layer1/implml/30000000_duplicate_repo2_proj1.crml'], files_in_target=['Layer1/implml/30000000_duplicate_repo2_proj2.crml', 'Layer1/implml/30000000_duplicate_repo1_proj2.crml'])
         ])
     self.assertEquals(actual_result, expected_result)
コード例 #7
0
    def flat_compare(self, target_resource_ref, target_repo):
        """
        Compare two CRML repository models.
        @return: A plugin.FlatComparisonResult object.
        """
        source_repo = self.repo

        result = plugin.FlatComparisonResult()

        source_repo_uid = self._num_to_str(source_repo.uid_value)
        target_repo_uid = self._num_to_str(target_repo.uid_value)

        if source_repo_uid != target_repo_uid:
            raise RuntimeError(
                "Comparing CRML implementations instances that don't have the same repository UID (%r vs. %r)"
                % (source_repo_uid, target_repo_uid))

        # Default field contents for new entries
        default_field_content = {'data': {}}

        Entry = plugin.FlatComparisonResultEntry

        if self.resource_ref != target_resource_ref:
            result.modified.append(
                Entry(value_id='file',
                      source_value=self.resource_ref,
                      target_value=target_resource_ref,
                      data={
                          'source_repo': source_repo,
                          'target_repo': target_repo
                      }))

        # Compare repository attributes
        # -----------------------------
        repo_mods = self._flat_compare_object_attrs(
            key_id=None,
            source_obj=source_repo,
            target_obj=target_repo,
            varnames=('uid_name', 'owner', 'backup', 'rfs', 'access'))
        content = default_field_content.copy()
        content['data'] = {
            'source_repo': source_repo,
            'target_repo': target_repo
        }
        self._fill_in_entry_fields(repo_mods, content)
        result.modified.extend(repo_mods)

        source_data = self._get_flat_comparison_data(source_repo)
        target_data = self._get_flat_comparison_data(target_repo)

        # Find entries only in source
        # ---------------------------
        for id, crml_key in source_data.iteritems():
            if id not in target_data:
                data = {'repo': source_repo, 'key': crml_key}
                result.only_in_source.append(Entry(sub_id=id, data=data))

        # Find entries only in target
        # ---------------------------
        for id, crml_key in target_data.iteritems():
            if id not in source_data:
                data = {'repo': source_repo, 'key': crml_key}
                result.only_in_target.append(Entry(sub_id=id, data=data))

        # Find differing entries
        # ----------------------
        for id, source_key in source_data.iteritems():
            if id not in target_data: continue
            target_key = target_data[id]
            if source_key == target_key: continue

            # Get the comparison result for the key
            comp_result = self._get_flat_key_comparison_result(
                id, source_key, target_key)

            # Fill in the missing fields of the result entries
            content = default_field_content.copy()
            content['data'] = {'repo': source_repo, 'key': source_key}
            self._fill_in_entry_fields(comp_result.only_in_source, content)

            content = default_field_content.copy()
            content['data'] = {'repo': target_repo, 'key': target_key}
            self._fill_in_entry_fields(comp_result.only_in_target, content)

            content = default_field_content.copy()
            content['data'] = {
                'source_repo': source_repo,
                'target_repo': target_repo,
                'source_key': source_key,
                'target_key': target_key
            }
            self._fill_in_entry_fields(comp_result.modified, content)

            result.extend(comp_result)

        return result
コード例 #8
0
 def _flat_compare_simple_keys(self, key_id, source_key, target_key):
     mod = self._flat_compare_base_keys(key_id,
                                        source_key,
                                        target_key,
                                        extra_varnames=['ref', 'type'])
     return plugin.FlatComparisonResult(modified=mod)