Skip to content

Commit 371212a

Browse files
theotherjimmyadbridge
authored andcommitted
Test the module_add function
1 parent 01475cf commit 371212a

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

tools/memap.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
RE_OBJECT_LIBRARY_IAR = re.compile(r'^\s+(.+\.o)\s.*')
2828

2929
RE_OBJECT_FILE_GCC = re.compile(r'^(.+\/.+\.o)$')
30-
RE_LIBRARY_OBJECT_GCC = re.compile(r'^.+\/(lib.+\.a)\((.+\.o)\)$')
30+
RE_LIBRARY_OBJECT_GCC = re.compile(r'^.+\/lib(.+\.a)\((.+\.o)\)$')
3131
RE_STD_SECTION_GCC = re.compile(r'^\s+.*0x(\w{8,16})\s+0x(\w+)\s(.+)$')
3232
RE_FILL_SECTION_GCC = re.compile(r'^\s*\*fill\*\s+0x(\w{8,16})\s+0x(\w+).*$')
3333

@@ -219,14 +219,25 @@ def parse_map_file_gcc(self, file_desc):
219219
next_section = self.check_new_section_gcc(line)
220220

221221
if next_section == "OUTPUT":
222-
return
222+
break
223223
elif next_section:
224224
current_section = next_section
225225

226226
object_name, object_size = self.parse_section_gcc(line, prefixes)
227227

228228
self.module_add(object_name, object_size, current_section)
229229

230+
common_prefix = os.path.dirname(os.path.commonprefix([
231+
o for o in self.modules.keys() if (o.endswith(".o") and not o.startswith("[lib]"))]))
232+
new_modules = {}
233+
for name, stats in self.modules.items():
234+
if name.startswith("[lib]"):
235+
new_modules[name] = stats
236+
elif name.endswith(".o"):
237+
new_modules[os.path.relpath(name, common_prefix)] = stats
238+
else:
239+
new_modules[name] = stats
240+
self.modules = new_modules
230241

231242
def parse_object_name_armcc(self, line):
232243
""" Parse object file

tools/test/memap/parse_test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,23 @@ def test_parse_gcc():
3939
memap = MemapParser()
4040
memap.parse_map_file_gcc(open(join(dirname(__file__), "gcc.map")))
4141
assert memap.modules == PARSED_IAR_GCC_DATA
42+
43+
44+
def test_add_empty_module():
45+
memap = MemapParser()
46+
old_modules = deepcopy(memap.modules)
47+
memap.module_add("", 8, ".data")
48+
assert(old_modules == memap.modules)
49+
memap.module_add("main.o", 0, ".text")
50+
assert(old_modules == memap.modules)
51+
memap.module_add("main.o", 8, "")
52+
assert(old_modules == memap.modules)
53+
54+
def test_add_full_module():
55+
memap = MemapParser()
56+
old_modules = deepcopy(memap.modules)
57+
memap.module_add("main.o", 8, ".data")
58+
assert(old_modules != memap.modules)
59+
assert("main.o" in memap.modules)
60+
assert(".data" in memap.modules["main.o"])
61+
assert(memap.modules["main.o"][".data"] == 8)

0 commit comments

Comments
 (0)