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