Skip to content

Commit abb6d26

Browse files
committed
Adding memap tests and adding to travis ci
1 parent e8b0687 commit abb6d26

File tree

3 files changed

+210
-38
lines changed

3 files changed

+210
-38
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ script:
55
- PYTHONPATH=. python tools/test/config_test/config_test.py
66
- python tools/test/pylint.py
77
- py.test tools/test/toolchains/api.py
8+
- python tools/test/memap/memap_test.py
89
- python tools/build_travis.py
910
before_install:
1011
- sudo add-apt-repository -y ppa:terry.guo/gcc-arm-embedded

tools/memap.py

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,44 @@ def generate_table(self, file_desc):
518518

519519
toolchains = ["ARM", "ARM_STD", "ARM_MICRO", "GCC_ARM", "IAR"]
520520

521+
def compute_report(self):
522+
for k in self.sections:
523+
self.subtotal[k] = 0
524+
525+
for i in sorted(self.modules):
526+
for k in self.sections:
527+
self.subtotal[k] += self.modules[i][k]
528+
529+
# Calculate misc flash sections
530+
self.misc_flash_mem = 0
531+
for i in self.modules:
532+
for k in self.misc_flash_sections:
533+
if self.modules[i][k]:
534+
self.misc_flash_mem += self.modules[i][k]
535+
536+
self.mem_summary = {
537+
'static_ram': (self.subtotal['.data'] + self.subtotal['.bss']),
538+
'heap': (self.subtotal['.heap']),
539+
'stack': (self.subtotal['.stack']),
540+
'total_ram': (self.subtotal['.data'] + self.subtotal['.bss'] +
541+
self.subtotal['.heap']+self.subtotal['.stack']),
542+
'total_flash': (self.subtotal['.text'] + self.subtotal['.data'] +
543+
self.misc_flash_mem),
544+
}
545+
546+
self.mem_report = []
547+
for i in sorted(self.modules):
548+
self.mem_report.append({
549+
"module":i,
550+
"size":{
551+
k:self.modules[i][k] for k in self.print_sections
552+
}
553+
})
554+
555+
self.mem_report.append({
556+
'summary': self.mem_summary
557+
})
558+
521559
def parse(self, mapfile, toolchain):
522560
""" Parse and decode map file depending on the toolchain
523561
@@ -540,44 +578,9 @@ def parse(self, mapfile, toolchain):
540578
self.parse_map_file_iar(file_input)
541579
else:
542580
result = False
543-
544-
for k in self.sections:
545-
self.subtotal[k] = 0
546-
547-
for i in sorted(self.modules):
548-
for k in self.sections:
549-
self.subtotal[k] += self.modules[i][k]
550-
551-
# Calculate misc flash sections
552-
self.misc_flash_mem = 0
553-
for i in self.modules:
554-
for k in self.misc_flash_sections:
555-
if self.modules[i][k]:
556-
self.misc_flash_mem += self.modules[i][k]
557-
558-
self.mem_summary = {
559-
'static_ram': (self.subtotal['.data'] + self.subtotal['.bss']),
560-
'heap': (self.subtotal['.heap']),
561-
'stack': (self.subtotal['.stack']),
562-
'total_ram': (self.subtotal['.data'] + self.subtotal['.bss'] +
563-
self.subtotal['.heap']+self.subtotal['.stack']),
564-
'total_flash': (self.subtotal['.text'] + self.subtotal['.data'] +
565-
self.misc_flash_mem),
566-
}
567-
568-
self.mem_report = []
569-
for i in sorted(self.modules):
570-
self.mem_report.append({
571-
"module":i,
572-
"size":{
573-
k:self.modules[i][k] for k in self.print_sections
574-
}
575-
})
576-
577-
self.mem_report.append({
578-
'summary': self.mem_summary
579-
})
580-
581+
582+
self.compute_report()
583+
581584
except IOError as error:
582585
print "I/O error({0}): {1}".format(error.errno, error.strerror)
583586
result = False

tools/test/memap/memap_test.py

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
"""
2+
mbed SDK
3+
Copyright (c) 2016 ARM Limited
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
"""
17+
import sys
18+
import os
19+
20+
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", ".."))
21+
sys.path.insert(0, ROOT)
22+
23+
import unittest
24+
from tools.memap import MemapParser
25+
from copy import deepcopy
26+
27+
"""
28+
Tests for test_api.py
29+
"""
30+
31+
class MemapParserTests(unittest.TestCase):
32+
"""
33+
Test cases for Test Api
34+
"""
35+
36+
def setUp(self):
37+
"""
38+
Called before each test case
39+
40+
:return:
41+
"""
42+
self.memap_parser = MemapParser()
43+
44+
self.memap_parser.modules = {
45+
"Misc": {
46+
"unknown": 0,
47+
".ARM": 8,
48+
".ARM.extab": 0,
49+
".init": 12,
50+
"OUTPUT": 0,
51+
".stack": 0,
52+
".eh_frame": 0,
53+
".fini_array": 4,
54+
".heap": 0,
55+
".stabstr": 0,
56+
".interrupts_ram": 0,
57+
".init_array": 0,
58+
".stab": 0,
59+
".ARM.attributes": 7347,
60+
".bss": 8517,
61+
".flash_config": 16,
62+
".interrupts": 1024,
63+
".data": 2325,
64+
".ARM.exidx": 0,
65+
".text": 59906,
66+
".jcr": 0
67+
},
68+
"Fill": {
69+
"unknown": 12,
70+
".ARM": 0,
71+
".ARM.extab": 0,
72+
".init": 0,
73+
"OUTPUT": 0,
74+
".stack": 0,
75+
".eh_frame": 0,
76+
".fini_array": 0,
77+
".heap": 65536,
78+
".stabstr": 0,
79+
".interrupts_ram": 1024,
80+
".init_array": 0,
81+
".stab": 0,
82+
".ARM.attributes": 0,
83+
".bss": 2235,
84+
".flash_config": 0,
85+
".interrupts": 0,
86+
".data": 3,
87+
".ARM.exidx": 0,
88+
".text": 136,
89+
".jcr": 0
90+
}
91+
}
92+
93+
self.memap_parser.compute_report()
94+
95+
def tearDown(self):
96+
"""
97+
Called after each test case
98+
99+
:return:
100+
"""
101+
pass
102+
103+
def generate_test_helper(self, output_type, file_output=None):
104+
"""
105+
Helper that ensures that the member variables "modules", "mem_report",
106+
and "mem_summary" are unchanged after calling "generate_output"
107+
108+
:param output_type: type string that is passed to "generate_output"
109+
:param file_output: path to output file that is passed to "generate_output"
110+
:return:
111+
"""
112+
113+
old_modules = deepcopy(self.memap_parser.modules)
114+
old_report = deepcopy(self.memap_parser.mem_report)
115+
old_summary = deepcopy(self.memap_parser.mem_summary)
116+
self.memap_parser.generate_output(output_type, file_output)
117+
self.assertEqual(self.memap_parser.modules, old_modules,
118+
"generate_output modified the 'modules' property")
119+
self.assertEqual(self.memap_parser.mem_report, old_report,
120+
"generate_output modified the 'mem_report' property")
121+
self.assertEqual(self.memap_parser.mem_summary, old_summary,
122+
"generate_output modified the 'mem_summary' property")
123+
124+
def test_report_computed(self):
125+
"""
126+
Test ensures the report and summary are computed
127+
128+
:return:
129+
"""
130+
self.assertTrue(self.memap_parser.mem_report)
131+
self.assertTrue(self.memap_parser.mem_summary)
132+
self.assertEqual(self.memap_parser.mem_report[-1]['summary'],
133+
self.memap_parser.mem_summary,
134+
"mem_report did not contain a correct copy of mem_summary")
135+
136+
def test_generate_output_table(self):
137+
"""
138+
Test ensures that an output of type "table" can be generated correctly
139+
140+
:return:
141+
"""
142+
self.generate_test_helper('table')
143+
144+
def test_generate_output_json(self):
145+
"""
146+
Test ensures that an output of type "json" can be generated correctly
147+
148+
:return:
149+
"""
150+
file_name = '.json_test_output.json'
151+
self.generate_test_helper('json', file_output=file_name)
152+
self.assertTrue(os.path.exists(file_name), "Failed to create json file")
153+
os.remove(file_name)
154+
155+
def test_generate_output_csv_ci(self):
156+
"""
157+
Test ensures that an output of type "csv-ci" can be generated correctly
158+
159+
:return:
160+
"""
161+
file_name = '.csv_ci_test_output.csv'
162+
self.generate_test_helper('csv-ci', file_output=file_name)
163+
self.assertTrue(os.path.exists(file_name), "Failed to create csv-ci file")
164+
os.remove(file_name)
165+
166+
167+
if __name__ == '__main__':
168+
unittest.main()

0 commit comments

Comments
 (0)