Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
memap_test.py
00001 """ 00002 mbed SDK 00003 Copyright (c) 2016 ARM Limited 00004 00005 Licensed under the Apache License, Version 2.0 (the "License"); 00006 you may not use this file except in compliance with the License. 00007 You may obtain a copy of the License at 00008 00009 http://www.apache.org/licenses/LICENSE-2.0 00010 00011 Unless required by applicable law or agreed to in writing, software 00012 distributed under the License is distributed on an "AS IS" BASIS, 00013 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 See the License for the specific language governing permissions and 00015 limitations under the License. 00016 """ 00017 import sys 00018 import os 00019 00020 ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "..")) 00021 sys.path.insert(0, ROOT) 00022 00023 import unittest 00024 from tools.memap import MemapParser 00025 from copy import deepcopy 00026 00027 """ 00028 Tests for test_api.py 00029 """ 00030 00031 class MemapParserTests (unittest.TestCase): 00032 """ 00033 Test cases for Test Api 00034 """ 00035 00036 def setUp (self): 00037 """ 00038 Called before each test case 00039 00040 :return: 00041 """ 00042 self.memap_parser = MemapParser() 00043 00044 self.memap_parser .modules = { 00045 "Misc": { 00046 "unknown": 0, 00047 ".ARM": 8, 00048 ".ARM.extab": 0, 00049 ".init": 12, 00050 "OUTPUT": 0, 00051 ".stack": 0, 00052 ".eh_frame": 0, 00053 ".fini_array": 4, 00054 ".heap": 0, 00055 ".stabstr": 0, 00056 ".interrupts_ram": 0, 00057 ".init_array": 0, 00058 ".stab": 0, 00059 ".ARM.attributes": 7347, 00060 ".bss": 8517, 00061 ".flash_config": 16, 00062 ".interrupts": 1024, 00063 ".data": 2325, 00064 ".ARM.exidx": 0, 00065 ".text": 59906, 00066 ".jcr": 0 00067 }, 00068 "Fill": { 00069 "unknown": 12, 00070 ".ARM": 0, 00071 ".ARM.extab": 0, 00072 ".init": 0, 00073 "OUTPUT": 0, 00074 ".stack": 0, 00075 ".eh_frame": 0, 00076 ".fini_array": 0, 00077 ".heap": 65536, 00078 ".stabstr": 0, 00079 ".interrupts_ram": 1024, 00080 ".init_array": 0, 00081 ".stab": 0, 00082 ".ARM.attributes": 0, 00083 ".bss": 2235, 00084 ".flash_config": 0, 00085 ".interrupts": 0, 00086 ".data": 3, 00087 ".ARM.exidx": 0, 00088 ".text": 136, 00089 ".jcr": 0 00090 } 00091 } 00092 00093 self.memap_parser .compute_report() 00094 00095 def tearDown (self): 00096 """ 00097 Called after each test case 00098 00099 :return: 00100 """ 00101 pass 00102 00103 def generate_test_helper (self, output_type, file_output=None): 00104 """ 00105 Helper that ensures that the member variables "modules", "mem_report", 00106 and "mem_summary" are unchanged after calling "generate_output" 00107 00108 :param output_type: type string that is passed to "generate_output" 00109 :param file_output: path to output file that is passed to "generate_output" 00110 :return: 00111 """ 00112 00113 old_modules = deepcopy(self.memap_parser.modules) 00114 old_report = deepcopy(self.memap_parser.mem_report) 00115 old_summary = deepcopy(self.memap_parser.mem_summary) 00116 self.memap_parser.generate_output(output_type, file_output) 00117 self.assertEqual(self.memap_parser.modules, old_modules, 00118 "generate_output modified the 'modules' property") 00119 self.assertEqual(self.memap_parser.mem_report, old_report, 00120 "generate_output modified the 'mem_report' property") 00121 self.assertEqual(self.memap_parser.mem_summary, old_summary, 00122 "generate_output modified the 'mem_summary' property") 00123 00124 def test_report_computed (self): 00125 """ 00126 Test ensures the report and summary are computed 00127 00128 :return: 00129 """ 00130 self.assertTrue(self.memap_parser .mem_report) 00131 self.assertTrue(self.memap_parser .mem_summary) 00132 self.assertEqual(self.memap_parser .mem_report[-1]['summary'], 00133 self.memap_parser .mem_summary, 00134 "mem_report did not contain a correct copy of mem_summary") 00135 00136 def test_generate_output_table (self): 00137 """ 00138 Test ensures that an output of type "table" can be generated correctly 00139 00140 :return: 00141 """ 00142 self.generate_test_helper ('table') 00143 00144 def test_generate_output_json (self): 00145 """ 00146 Test ensures that an output of type "json" can be generated correctly 00147 00148 :return: 00149 """ 00150 file_name = '.json_test_output.json' 00151 self.generate_test_helper ('json', file_output=file_name) 00152 self.assertTrue(os.path.exists(file_name), "Failed to create json file") 00153 os.remove(file_name) 00154 00155 def test_generate_output_csv_ci (self): 00156 """ 00157 Test ensures that an output of type "csv-ci" can be generated correctly 00158 00159 :return: 00160 """ 00161 file_name = '.csv_ci_test_output.csv' 00162 self.generate_test_helper ('csv-ci', file_output=file_name) 00163 self.assertTrue(os.path.exists(file_name), "Failed to create csv-ci file") 00164 os.remove(file_name) 00165 00166 00167 if __name__ == '__main__': 00168 unittest.main()
Generated on Tue Jul 12 2022 16:40:06 by
1.7.2