def test_flags_entries_multiple_flags_and_entries(self): # Not an error, generation step handles this, since # it that step has a more complete information # about all mappings. This can happen across multiple # mapping fragments. test_fragment = self.create_fragment_file(u""" [mapping:map] archive: libmain.a entries: obj1 (default); text->flash_text ALIGN(4) KEEP() SURROUND(sym1) SORT(name) obj1 (default); text->flash_text ALIGN(4) KEEP() SURROUND(sym1) SORT(name) """) fragment_file = FragmentFile(test_fragment, self.sdkconfig) fragment = fragment_file.fragments[0] expected = [('text', 'flash_text', [ Mapping.Align(4, True, False), Mapping.Keep(), Mapping.Surround('sym1'), Mapping.Sort('name') ]), ('text', 'flash_text', [ Mapping.Align(4, True, False), Mapping.Keep(), Mapping.Surround('sym1'), Mapping.Sort('name') ])] actual = fragment.flags[('obj1', None, 'default')] self.assertEqual(expected, actual)
def test_keep_flag(self): # Test parsing combinations and orders of flags test_fragment = self.create_fragment_file(u""" [mapping:map] archive: libmain.a entries: obj1 (default); text->flash_text KEEP(), rodata->flash_rodata KEEP() KEEP() """) fragment_file = FragmentFile(test_fragment, self.sdkconfig) fragment = fragment_file.fragments[0] expected = [('text', 'flash_text', [Mapping.Keep()]), ('rodata', 'flash_rodata', [Mapping.Keep(), Mapping.Keep()])] actual = fragment.flags[('obj1', None, 'default')] self.assertEqual(expected, actual)
def _detect_conflicts(self, rules): (archive, rules_list) = rules for specificity in range(0, PlacementRule.OBJECT_SPECIFICITY + 1): rules_with_specificity = filter(lambda r: r.specificity == specificity, rules_list) for rule_a, rule_b in itertools.combinations(rules_with_specificity, 2): intersections = rule_a.get_sections_intersection(rule_b) if intersections and rule_a.maps_same_entities_as(rule_b): rules_string = str([str(rule_a), str(rule_b)]) message = "Rules " + rules_string + " map sections " + str(list(intersections)) + " into multiple targets." mapping = self.mappings[Mapping.get_mapping_name_from_archive(archive)] raise GenerationException(message, mapping)
def test_surround_flag(self): # Test parsing combinations and orders of flags test_fragment = self.create_fragment_file(u""" [mapping:map] archive: libmain.a entries: obj1 (default); text->flash_text SURROUND(sym1) """) fragment_file = FragmentFile(test_fragment, self.sdkconfig) fragment = fragment_file.fragments[0] expected = [('text', 'flash_text', [Mapping.Surround('sym1')])] actual = fragment.flags[('obj1', None, 'default')] self.assertEqual(expected, actual)
def test_sort_flag(self): # Test parsing combinations and orders of flags test_fragment = self.create_fragment_file(u""" [mapping:map] archive: libmain.a entries: obj1 (default); text->flash_text SORT(name), rodata->flash_rodata SORT(alignment), data->dram0_data SORT(init_priority), bss->dram0_bss SORT(name, alignment), common->dram0_bss SORT(alignment, name), iram->iram0_text SORT(name, name), dram->dram0_data SORT(alignment, alignment) """) fragment_file = FragmentFile(test_fragment, self.sdkconfig) fragment = fragment_file.fragments[0] expected = [ ('text', 'flash_text', [Mapping.Sort('name')]), ('rodata', 'flash_rodata', [Mapping.Sort('alignment')]), ('data', 'dram0_data', [Mapping.Sort('init_priority')]), ('bss', 'dram0_bss', [Mapping.Sort('name', 'alignment')]), ('common', 'dram0_bss', [Mapping.Sort('alignment', 'name')]), ('iram', 'iram0_text', [Mapping.Sort('name', 'name')]), ('dram', 'dram0_data', [Mapping.Sort('alignment', 'alignment')]) ] actual = fragment.flags[('obj1', None, 'default')] self.assertEqual(expected, actual) test_fragment = self.create_fragment_file(u""" [mapping:map] archive: libmain.a entries: obj1 (default) text->iram0_text SORT(name) SORT(alignment) """)
def test_align_flag(self): # Test parsing combinations and orders of flags test_fragment = self.create_fragment_file(u""" [mapping:map] archive: libmain.a entries: obj1 (default); text->flash_text ALIGN(8), rodata->flash_rodata ALIGN(8, pre), data->dram0_data ALIGN(8, pre, post), bss->dram0_bss ALIGN(8, post), common->dram0_bss ALIGN(8, pre, post) ALIGN(8) """) fragment_file = FragmentFile(test_fragment, self.sdkconfig) fragment = fragment_file.fragments[0] expected = [ ('text', 'flash_text', [Mapping.Align(8, True, False)]), ('rodata', 'flash_rodata', [Mapping.Align(8, True, False)]), ('data', 'dram0_data', [Mapping.Align(8, True, True)]), ('bss', 'dram0_bss', [Mapping.Align(8, False, True)]), ('common', 'dram0_bss', [Mapping.Align(8, True, True), Mapping.Align(8, True, False)]) ] actual = fragment.flags[('obj1', None, 'default')] self.assertEqual(expected, actual) # Wrong post, pre order test_fragment = self.create_fragment_file(u""" [mapping:map] archive: libmain.a entries: obj1 (noflash) text->iram0_text ALIGN(8, post, pre) """) with self.assertRaises(ParseFatalException): FragmentFile(test_fragment, self.sdkconfig)
def test_flag_order(self): # Test that the order in which the flags are specified is retained test_fragment = self.create_fragment_file(u""" [mapping:map] archive: libmain.a entries: obj1 (default); text->flash_text ALIGN(4) KEEP() SURROUND(sym1) ALIGN(8) SORT(name), rodata->flash_rodata KEEP() ALIGN(4) KEEP() SURROUND(sym1) ALIGN(8) ALIGN(4) SORT(name) """) fragment_file = FragmentFile(test_fragment, self.sdkconfig) fragment = fragment_file.fragments[0] expected = [('text', 'flash_text', [ Mapping.Align(4, True, False), Mapping.Keep(), Mapping.Surround('sym1'), Mapping.Align(8, True, False), Mapping.Sort('name') ]), ('rodata', 'flash_rodata', [ Mapping.Keep(), Mapping.Align(4, True, False), Mapping.Keep(), Mapping.Surround('sym1'), Mapping.Align(8, True, False), Mapping.Align(4, True, False), Mapping.Sort('name') ])] actual = fragment.flags[('obj1', None, 'default')] self.assertEqual(expected, actual)
def _add_mapping(self, text): parser = Mapping.get_fragment_grammar() fragment = parser.parseString(text, parseAll=True) self.model.mappings[fragment[0].name] = fragment[0]