2018-09-03 07:48:32 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
2022-02-17 02:27:34 -05:00
|
|
|
# SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2018-09-03 07:48:32 -04:00
|
|
|
|
|
|
|
import os
|
|
|
|
import unittest
|
|
|
|
|
2018-12-04 07:06:46 -05:00
|
|
|
try:
|
2022-02-17 02:27:34 -05:00
|
|
|
from esp_coredump.corefile import ESPCoreDumpLoaderError
|
|
|
|
from esp_coredump.corefile.elf import ESPCoreDumpElfFile
|
|
|
|
from esp_coredump.corefile.loader import ESPCoreDumpFileLoader
|
2018-12-04 07:06:46 -05:00
|
|
|
except ImportError:
|
2022-02-17 02:27:34 -05:00
|
|
|
raise ModuleNotFoundError('No module named "esp_coredump" please install esp_coredump by running '
|
|
|
|
'"python -m pip install esp-coredump"')
|
2021-01-19 00:39:30 -05:00
|
|
|
|
2022-02-17 02:27:34 -05:00
|
|
|
SUPPORTED_TARGET = ['esp32', 'esp32s2', 'esp32c3', 'esp32s3']
|
2021-07-07 03:22:17 -04:00
|
|
|
|
2021-01-19 00:39:30 -05:00
|
|
|
|
|
|
|
class TestESPCoreDumpElfFile(unittest.TestCase):
|
|
|
|
def test_read_elf(self):
|
2021-07-07 03:22:17 -04:00
|
|
|
for target in SUPPORTED_TARGET:
|
|
|
|
elf = ESPCoreDumpElfFile(os.path.join(target, '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):
|
2021-07-07 03:22:17 -04:00
|
|
|
for target in SUPPORTED_TARGET:
|
|
|
|
with self.assertRaises(ESPCoreDumpLoaderError):
|
|
|
|
ESPCoreDumpFileLoader(path=os.path.join(target, 'coredump.b64'), is_b64=False)
|
2018-09-03 07:48:32 -04:00
|
|
|
|
|
|
|
def test_create_corefile(self):
|
2021-07-07 03:22:17 -04:00
|
|
|
for target in SUPPORTED_TARGET:
|
|
|
|
loader = ESPCoreDumpFileLoader(path=os.path.join(target, 'coredump.b64'), is_b64=True)
|
|
|
|
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.
|
2021-07-07 03:22:17 -04:00
|
|
|
# The espcoredump is not suited for through unit testing. There lot of nested functions, interactive
|
|
|
|
# communication with the development board and GDB, ...
|
2018-09-03 07:48:32 -04:00
|
|
|
unittest.main()
|