Development mbed library for MAX32630FTHR

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Dec 16 16:27:57 2016 +0000
Revision:
3:1198227e6421
Parent:
0:5c4d7b2438d3
Changed ADC scale for MAX32625 platforms to 1.2V full scale to match MAX32630 platforms

Who changed what in which revision?

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