BA
/
BaBoRo_test2
Backup 1
mbed-os/tools/test/memap/memap_test.py@0:02dd72d1d465, 2018-04-24 (annotated)
- Committer:
- borlanic
- Date:
- Tue Apr 24 11:45:18 2018 +0000
- Revision:
- 0:02dd72d1d465
BaBoRo_test2 - backup 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
borlanic | 0:02dd72d1d465 | 1 | """ |
borlanic | 0:02dd72d1d465 | 2 | mbed SDK |
borlanic | 0:02dd72d1d465 | 3 | Copyright (c) 2017 ARM Limited |
borlanic | 0:02dd72d1d465 | 4 | |
borlanic | 0:02dd72d1d465 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
borlanic | 0:02dd72d1d465 | 6 | you may not use this file except in compliance with the License. |
borlanic | 0:02dd72d1d465 | 7 | You may obtain a copy of the License at |
borlanic | 0:02dd72d1d465 | 8 | |
borlanic | 0:02dd72d1d465 | 9 | http://www.apache.org/licenses/LICENSE-2.0 |
borlanic | 0:02dd72d1d465 | 10 | |
borlanic | 0:02dd72d1d465 | 11 | Unless required by applicable law or agreed to in writing, software |
borlanic | 0:02dd72d1d465 | 12 | distributed under the License is distributed on an "AS IS" BASIS, |
borlanic | 0:02dd72d1d465 | 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
borlanic | 0:02dd72d1d465 | 14 | See the License for the specific language governing permissions and |
borlanic | 0:02dd72d1d465 | 15 | limitations under the License. |
borlanic | 0:02dd72d1d465 | 16 | """ |
borlanic | 0:02dd72d1d465 | 17 | import sys |
borlanic | 0:02dd72d1d465 | 18 | from os.path import isfile, join |
borlanic | 0:02dd72d1d465 | 19 | import json |
borlanic | 0:02dd72d1d465 | 20 | |
borlanic | 0:02dd72d1d465 | 21 | import pytest |
borlanic | 0:02dd72d1d465 | 22 | |
borlanic | 0:02dd72d1d465 | 23 | import tools.memap |
borlanic | 0:02dd72d1d465 | 24 | from tools.memap import MemapParser |
borlanic | 0:02dd72d1d465 | 25 | from copy import deepcopy |
borlanic | 0:02dd72d1d465 | 26 | |
borlanic | 0:02dd72d1d465 | 27 | """ |
borlanic | 0:02dd72d1d465 | 28 | Tests for test_api.py |
borlanic | 0:02dd72d1d465 | 29 | """ |
borlanic | 0:02dd72d1d465 | 30 | |
borlanic | 0:02dd72d1d465 | 31 | @pytest.fixture |
borlanic | 0:02dd72d1d465 | 32 | def memap_parser(): |
borlanic | 0:02dd72d1d465 | 33 | """ |
borlanic | 0:02dd72d1d465 | 34 | Called before each test case |
borlanic | 0:02dd72d1d465 | 35 | |
borlanic | 0:02dd72d1d465 | 36 | :return: |
borlanic | 0:02dd72d1d465 | 37 | """ |
borlanic | 0:02dd72d1d465 | 38 | memap_parser = MemapParser() |
borlanic | 0:02dd72d1d465 | 39 | |
borlanic | 0:02dd72d1d465 | 40 | memap_parser.modules = { |
borlanic | 0:02dd72d1d465 | 41 | "mbed-os/targets/TARGET/TARGET_MCUS/api/pinmap.o": { |
borlanic | 0:02dd72d1d465 | 42 | ".text": 1, |
borlanic | 0:02dd72d1d465 | 43 | ".data": 2, |
borlanic | 0:02dd72d1d465 | 44 | ".bss": 3, |
borlanic | 0:02dd72d1d465 | 45 | ".heap": 0, |
borlanic | 0:02dd72d1d465 | 46 | ".stack": 0, |
borlanic | 0:02dd72d1d465 | 47 | ".interrupts_ram":0, |
borlanic | 0:02dd72d1d465 | 48 | ".init":0, |
borlanic | 0:02dd72d1d465 | 49 | ".ARM.extab":0, |
borlanic | 0:02dd72d1d465 | 50 | ".ARM.exidx":0, |
borlanic | 0:02dd72d1d465 | 51 | ".ARM.attributes":0, |
borlanic | 0:02dd72d1d465 | 52 | ".eh_frame":0, |
borlanic | 0:02dd72d1d465 | 53 | ".init_array":0, |
borlanic | 0:02dd72d1d465 | 54 | ".fini_array":0, |
borlanic | 0:02dd72d1d465 | 55 | ".jcr":0, |
borlanic | 0:02dd72d1d465 | 56 | ".stab":0, |
borlanic | 0:02dd72d1d465 | 57 | ".stabstr":0, |
borlanic | 0:02dd72d1d465 | 58 | ".ARM.exidx":0, |
borlanic | 0:02dd72d1d465 | 59 | ".ARM":0, |
borlanic | 0:02dd72d1d465 | 60 | ".interrupts":0, |
borlanic | 0:02dd72d1d465 | 61 | ".flash_config":0, |
borlanic | 0:02dd72d1d465 | 62 | "unknown":0, |
borlanic | 0:02dd72d1d465 | 63 | "OUTPUT":0, |
borlanic | 0:02dd72d1d465 | 64 | }, |
borlanic | 0:02dd72d1d465 | 65 | "[lib]/libc.a/lib_a-printf.o": { |
borlanic | 0:02dd72d1d465 | 66 | ".text": 4, |
borlanic | 0:02dd72d1d465 | 67 | ".data": 5, |
borlanic | 0:02dd72d1d465 | 68 | ".bss": 6, |
borlanic | 0:02dd72d1d465 | 69 | ".heap": 0, |
borlanic | 0:02dd72d1d465 | 70 | ".stack": 0, |
borlanic | 0:02dd72d1d465 | 71 | ".interrupts_ram":0, |
borlanic | 0:02dd72d1d465 | 72 | ".init":0, |
borlanic | 0:02dd72d1d465 | 73 | ".ARM.extab":0, |
borlanic | 0:02dd72d1d465 | 74 | ".ARM.exidx":0, |
borlanic | 0:02dd72d1d465 | 75 | ".ARM.attributes":0, |
borlanic | 0:02dd72d1d465 | 76 | ".eh_frame":0, |
borlanic | 0:02dd72d1d465 | 77 | ".init_array":0, |
borlanic | 0:02dd72d1d465 | 78 | ".fini_array":0, |
borlanic | 0:02dd72d1d465 | 79 | ".jcr":0, |
borlanic | 0:02dd72d1d465 | 80 | ".stab":0, |
borlanic | 0:02dd72d1d465 | 81 | ".stabstr":0, |
borlanic | 0:02dd72d1d465 | 82 | ".ARM.exidx":0, |
borlanic | 0:02dd72d1d465 | 83 | ".ARM":0, |
borlanic | 0:02dd72d1d465 | 84 | ".interrupts":0, |
borlanic | 0:02dd72d1d465 | 85 | ".flash_config":0, |
borlanic | 0:02dd72d1d465 | 86 | "unknown":0, |
borlanic | 0:02dd72d1d465 | 87 | "OUTPUT":0, |
borlanic | 0:02dd72d1d465 | 88 | }, |
borlanic | 0:02dd72d1d465 | 89 | "main.o": { |
borlanic | 0:02dd72d1d465 | 90 | ".text": 7, |
borlanic | 0:02dd72d1d465 | 91 | ".data": 8, |
borlanic | 0:02dd72d1d465 | 92 | ".bss": 0, |
borlanic | 0:02dd72d1d465 | 93 | ".heap": 0, |
borlanic | 0:02dd72d1d465 | 94 | ".stack": 0, |
borlanic | 0:02dd72d1d465 | 95 | ".interrupts_ram":0, |
borlanic | 0:02dd72d1d465 | 96 | ".init":0, |
borlanic | 0:02dd72d1d465 | 97 | ".ARM.extab":0, |
borlanic | 0:02dd72d1d465 | 98 | ".ARM.exidx":0, |
borlanic | 0:02dd72d1d465 | 99 | ".ARM.attributes":0, |
borlanic | 0:02dd72d1d465 | 100 | ".eh_frame":0, |
borlanic | 0:02dd72d1d465 | 101 | ".init_array":0, |
borlanic | 0:02dd72d1d465 | 102 | ".fini_array":0, |
borlanic | 0:02dd72d1d465 | 103 | ".jcr":0, |
borlanic | 0:02dd72d1d465 | 104 | ".stab":0, |
borlanic | 0:02dd72d1d465 | 105 | ".stabstr":0, |
borlanic | 0:02dd72d1d465 | 106 | ".ARM.exidx":0, |
borlanic | 0:02dd72d1d465 | 107 | ".ARM":0, |
borlanic | 0:02dd72d1d465 | 108 | ".interrupts":0, |
borlanic | 0:02dd72d1d465 | 109 | ".flash_config":0, |
borlanic | 0:02dd72d1d465 | 110 | "unknown":0, |
borlanic | 0:02dd72d1d465 | 111 | "OUTPUT":0, |
borlanic | 0:02dd72d1d465 | 112 | }, |
borlanic | 0:02dd72d1d465 | 113 | "test.o": { |
borlanic | 0:02dd72d1d465 | 114 | ".text": 0, |
borlanic | 0:02dd72d1d465 | 115 | ".data": 0, |
borlanic | 0:02dd72d1d465 | 116 | ".bss": 0, |
borlanic | 0:02dd72d1d465 | 117 | ".heap": 0, |
borlanic | 0:02dd72d1d465 | 118 | ".stack": 0, |
borlanic | 0:02dd72d1d465 | 119 | ".interrupts_ram":0, |
borlanic | 0:02dd72d1d465 | 120 | ".init":0, |
borlanic | 0:02dd72d1d465 | 121 | ".ARM.extab":0, |
borlanic | 0:02dd72d1d465 | 122 | ".ARM.exidx":0, |
borlanic | 0:02dd72d1d465 | 123 | ".ARM.attributes":0, |
borlanic | 0:02dd72d1d465 | 124 | ".eh_frame":0, |
borlanic | 0:02dd72d1d465 | 125 | ".init_array":0, |
borlanic | 0:02dd72d1d465 | 126 | ".fini_array":0, |
borlanic | 0:02dd72d1d465 | 127 | ".jcr":0, |
borlanic | 0:02dd72d1d465 | 128 | ".stab":0, |
borlanic | 0:02dd72d1d465 | 129 | ".stabstr":0, |
borlanic | 0:02dd72d1d465 | 130 | ".ARM.exidx":0, |
borlanic | 0:02dd72d1d465 | 131 | ".ARM":0, |
borlanic | 0:02dd72d1d465 | 132 | ".interrupts":0, |
borlanic | 0:02dd72d1d465 | 133 | ".flash_config":0, |
borlanic | 0:02dd72d1d465 | 134 | "unknown":0, |
borlanic | 0:02dd72d1d465 | 135 | "OUTPUT":0, |
borlanic | 0:02dd72d1d465 | 136 | }, |
borlanic | 0:02dd72d1d465 | 137 | } |
borlanic | 0:02dd72d1d465 | 138 | return memap_parser |
borlanic | 0:02dd72d1d465 | 139 | |
borlanic | 0:02dd72d1d465 | 140 | |
borlanic | 0:02dd72d1d465 | 141 | def generate_test_helper(memap_parser, format, depth, sep, file_output=None): |
borlanic | 0:02dd72d1d465 | 142 | """ |
borlanic | 0:02dd72d1d465 | 143 | Helper that tests that the member variables "modules" is |
borlanic | 0:02dd72d1d465 | 144 | unchanged after calling "generate_output" |
borlanic | 0:02dd72d1d465 | 145 | |
borlanic | 0:02dd72d1d465 | 146 | :param memap_parser: the parser object |
borlanic | 0:02dd72d1d465 | 147 | :param depth: how much detail to put in the report |
borlanic | 0:02dd72d1d465 | 148 | :param format: the file type to output |
borlanic | 0:02dd72d1d465 | 149 | :param file_output: the file to output to |
borlanic | 0:02dd72d1d465 | 150 | """ |
borlanic | 0:02dd72d1d465 | 151 | old_modules = deepcopy(memap_parser.modules) |
borlanic | 0:02dd72d1d465 | 152 | |
borlanic | 0:02dd72d1d465 | 153 | tools.memap.sep = sep |
borlanic | 0:02dd72d1d465 | 154 | memap_parser.generate_output(format, depth, file_output=file_output) |
borlanic | 0:02dd72d1d465 | 155 | |
borlanic | 0:02dd72d1d465 | 156 | assert memap_parser.modules == old_modules,\ |
borlanic | 0:02dd72d1d465 | 157 | "generate_output modified the 'modules' property" |
borlanic | 0:02dd72d1d465 | 158 | |
borlanic | 0:02dd72d1d465 | 159 | for file_name in memap_parser.short_modules: |
borlanic | 0:02dd72d1d465 | 160 | assert(len(file_name.split(tools.memap.sep)) <= depth) |
borlanic | 0:02dd72d1d465 | 161 | |
borlanic | 0:02dd72d1d465 | 162 | |
borlanic | 0:02dd72d1d465 | 163 | @pytest.mark.parametrize("depth", [1, 2, 20]) |
borlanic | 0:02dd72d1d465 | 164 | @pytest.mark.parametrize("sep", ["\\", "/"]) |
borlanic | 0:02dd72d1d465 | 165 | def test_report_computed(memap_parser, depth, sep): |
borlanic | 0:02dd72d1d465 | 166 | """ |
borlanic | 0:02dd72d1d465 | 167 | Test that a report and summary are computed |
borlanic | 0:02dd72d1d465 | 168 | |
borlanic | 0:02dd72d1d465 | 169 | :param memap_parser: Mocked parser |
borlanic | 0:02dd72d1d465 | 170 | :param depth: the detail of the output |
borlanic | 0:02dd72d1d465 | 171 | """ |
borlanic | 0:02dd72d1d465 | 172 | |
borlanic | 0:02dd72d1d465 | 173 | memap_parser.generate_output('table', depth, sep) |
borlanic | 0:02dd72d1d465 | 174 | |
borlanic | 0:02dd72d1d465 | 175 | # Report is created after generating output |
borlanic | 0:02dd72d1d465 | 176 | assert memap_parser.mem_summary |
borlanic | 0:02dd72d1d465 | 177 | assert memap_parser.mem_report |
borlanic | 0:02dd72d1d465 | 178 | |
borlanic | 0:02dd72d1d465 | 179 | |
borlanic | 0:02dd72d1d465 | 180 | @pytest.mark.parametrize("depth", [1, 2, 20]) |
borlanic | 0:02dd72d1d465 | 181 | @pytest.mark.parametrize("sep", ["\\", "/"]) |
borlanic | 0:02dd72d1d465 | 182 | def test_generate_output_table(memap_parser, depth, sep): |
borlanic | 0:02dd72d1d465 | 183 | """ |
borlanic | 0:02dd72d1d465 | 184 | Test that an output of type "table" can be generated correctly |
borlanic | 0:02dd72d1d465 | 185 | :param memap_parser: Mocked parser |
borlanic | 0:02dd72d1d465 | 186 | :param depth: the detail of the output |
borlanic | 0:02dd72d1d465 | 187 | """ |
borlanic | 0:02dd72d1d465 | 188 | generate_test_helper(memap_parser, 'table', depth, sep) |
borlanic | 0:02dd72d1d465 | 189 | |
borlanic | 0:02dd72d1d465 | 190 | |
borlanic | 0:02dd72d1d465 | 191 | @pytest.mark.parametrize("depth", [1, 2, 20]) |
borlanic | 0:02dd72d1d465 | 192 | @pytest.mark.parametrize("sep", ["\\", "/"]) |
borlanic | 0:02dd72d1d465 | 193 | def test_generate_output_json(memap_parser, tmpdir, depth, sep): |
borlanic | 0:02dd72d1d465 | 194 | """ |
borlanic | 0:02dd72d1d465 | 195 | Test that an output of type "json" can be generated correctly |
borlanic | 0:02dd72d1d465 | 196 | :param memap_parser: Mocked parser |
borlanic | 0:02dd72d1d465 | 197 | :param tmpdir: a unique location to place an output file |
borlanic | 0:02dd72d1d465 | 198 | :param depth: the detail of the output |
borlanic | 0:02dd72d1d465 | 199 | """ |
borlanic | 0:02dd72d1d465 | 200 | file_name = str(tmpdir.join('output.json').realpath()) |
borlanic | 0:02dd72d1d465 | 201 | generate_test_helper(memap_parser, 'json', depth, sep, file_name) |
borlanic | 0:02dd72d1d465 | 202 | assert isfile(file_name), "Failed to create json file" |
borlanic | 0:02dd72d1d465 | 203 | json.load(open(file_name)) |
borlanic | 0:02dd72d1d465 | 204 | |
borlanic | 0:02dd72d1d465 | 205 | |
borlanic | 0:02dd72d1d465 | 206 | @pytest.mark.parametrize("depth", [1, 2, 20]) |
borlanic | 0:02dd72d1d465 | 207 | @pytest.mark.parametrize("sep", ["\\", "/"]) |
borlanic | 0:02dd72d1d465 | 208 | def test_generate_output_csv_ci(memap_parser, tmpdir, depth, sep): |
borlanic | 0:02dd72d1d465 | 209 | """ |
borlanic | 0:02dd72d1d465 | 210 | Test ensures that an output of type "csv-ci" can be generated correctly |
borlanic | 0:02dd72d1d465 | 211 | |
borlanic | 0:02dd72d1d465 | 212 | :param memap_parser: Mocked parser |
borlanic | 0:02dd72d1d465 | 213 | :param tmpdir: a unique location to place an output file |
borlanic | 0:02dd72d1d465 | 214 | :param depth: the detail of the output |
borlanic | 0:02dd72d1d465 | 215 | """ |
borlanic | 0:02dd72d1d465 | 216 | file_name = str(tmpdir.join('output.csv').realpath()) |
borlanic | 0:02dd72d1d465 | 217 | generate_test_helper(memap_parser, 'csv-ci', depth, sep, file_name) |
borlanic | 0:02dd72d1d465 | 218 | assert isfile(file_name), "Failed to create csv-ci file" |