2018-09-03 07:48:32 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
import os
|
2021-01-19 00:39:30 -05:00
|
|
|
import sys
|
2018-09-03 07:48:32 -04:00
|
|
|
import unittest
|
|
|
|
|
2018-12-04 07:06:46 -05:00
|
|
|
try:
|
2021-01-19 00:39:30 -05:00
|
|
|
from corefile.elf import ESPCoreDumpElfFile
|
|
|
|
from corefile.loader import ESPCoreDumpFileLoader, ESPCoreDumpLoaderError
|
2018-12-04 07:06:46 -05:00
|
|
|
except ImportError:
|
|
|
|
idf_path = os.getenv('IDF_PATH')
|
|
|
|
if idf_path:
|
|
|
|
sys.path.insert(0, os.path.join(idf_path, 'components', 'espcoredump'))
|
2021-01-19 00:39:30 -05:00
|
|
|
else:
|
|
|
|
sys.path.insert(0, '..')
|
|
|
|
from corefile.elf import ESPCoreDumpElfFile
|
|
|
|
from corefile.loader import ESPCoreDumpFileLoader, ESPCoreDumpLoaderError
|
|
|
|
|
|
|
|
|
|
|
|
class TestESPCoreDumpElfFile(unittest.TestCase):
|
|
|
|
def test_read_elf(self):
|
|
|
|
elf = ESPCoreDumpElfFile('core.elf')
|
|
|
|
assert elf.load_segments
|
|
|
|
assert elf.note_segments
|
2018-12-04 07:06:46 -05:00
|
|
|
|
2018-09-03 07:48:32 -04:00
|
|
|
|
|
|
|
class TestESPCoreDumpFileLoader(unittest.TestCase):
|
2021-01-19 00:39:30 -05:00
|
|
|
def test_load_wrong_encode_core_bin(self):
|
|
|
|
with self.assertRaises(ESPCoreDumpLoaderError):
|
|
|
|
ESPCoreDumpFileLoader(path='coredump.b64', is_b64=False)
|
2018-09-03 07:48:32 -04:00
|
|
|
|
|
|
|
def test_create_corefile(self):
|
2021-01-19 00:39:30 -05:00
|
|
|
loader = ESPCoreDumpFileLoader(path='coredump.b64', is_b64=True)
|
2020-05-20 14:04:14 -04:00
|
|
|
loader.create_corefile()
|
2018-09-03 07:48:32 -04:00
|
|
|
|
2018-12-04 07:06:46 -05:00
|
|
|
|
2018-09-03 07:48:32 -04:00
|
|
|
if __name__ == '__main__':
|
|
|
|
# The purpose of these tests is to increase the code coverage at places which are sensitive to issues related to
|
|
|
|
# Python 2&3 compatibility.
|
|
|
|
# The espcoredump is not suited for through unit testting. There lot of nested functions, interactive
|
|
|
|
# communication with the developement board and GDB, ...
|
|
|
|
unittest.main()
|