1#!/usr/bin/env python 2# 3# Copyright 2018 Espressif Systems (Shanghai) PTE LTD 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17import os 18import sys 19import unittest 20 21try: 22 from corefile.elf import ESPCoreDumpElfFile 23 from corefile.loader import ESPCoreDumpFileLoader, ESPCoreDumpLoaderError 24except ImportError: 25 idf_path = os.getenv('IDF_PATH') 26 if idf_path: 27 sys.path.insert(0, os.path.join(idf_path, 'components', 'espcoredump')) 28 else: 29 sys.path.insert(0, '..') 30 from corefile.elf import ESPCoreDumpElfFile 31 from corefile.loader import ESPCoreDumpFileLoader, ESPCoreDumpLoaderError 32 33 34class TestESPCoreDumpElfFile(unittest.TestCase): 35 def test_read_elf(self): 36 elf = ESPCoreDumpElfFile('core.elf') 37 assert elf.load_segments 38 assert elf.note_segments 39 40 41class TestESPCoreDumpFileLoader(unittest.TestCase): 42 def test_load_wrong_encode_core_bin(self): 43 with self.assertRaises(ESPCoreDumpLoaderError): 44 ESPCoreDumpFileLoader(path='coredump.b64', is_b64=False) 45 46 def test_create_corefile(self): 47 loader = ESPCoreDumpFileLoader(path='coredump.b64', is_b64=True) 48 loader.create_corefile() 49 50 51if __name__ == '__main__': 52 # The purpose of these tests is to increase the code coverage at places which are sensitive to issues related to 53 # Python 2&3 compatibility. 54 # The espcoredump is not suited for through unit testting. There lot of nested functions, interactive 55 # communication with the developement board and GDB, ... 56 unittest.main() 57