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