Greg Steiert / maxim_dev

Dependents:   sensomed

Committer:
switches
Date:
Tue Nov 08 18:27:11 2016 +0000
Revision:
0:0e018d759a2a
Initial commit

Who changed what in which revision?

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