test_espcoredump.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env python
  2. #
  3. # SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD
  4. # SPDX-License-Identifier: Apache-2.0
  5. import os
  6. import unittest
  7. try:
  8. from esp_coredump.corefile import ESPCoreDumpLoaderError
  9. from esp_coredump.corefile.elf import ESPCoreDumpElfFile
  10. from esp_coredump.corefile.loader import ESPCoreDumpFileLoader
  11. except ImportError:
  12. raise ModuleNotFoundError('No module named "esp_coredump" please install esp_coredump by running '
  13. '"python -m pip install esp-coredump"')
  14. SUPPORTED_TARGET = ['esp32', 'esp32s2', 'esp32c3', 'esp32s3']
  15. class TestESPCoreDumpElfFile(unittest.TestCase):
  16. def test_read_elf(self):
  17. for target in SUPPORTED_TARGET:
  18. elf = ESPCoreDumpElfFile(os.path.join(target, 'core.elf'))
  19. assert elf.load_segments
  20. assert elf.note_segments
  21. class TestESPCoreDumpFileLoader(unittest.TestCase):
  22. def test_load_wrong_encode_core_bin(self):
  23. for target in SUPPORTED_TARGET:
  24. with self.assertRaises(ESPCoreDumpLoaderError):
  25. ESPCoreDumpFileLoader(path=os.path.join(target, 'coredump.b64'), is_b64=False)
  26. def test_create_corefile(self):
  27. for target in SUPPORTED_TARGET:
  28. loader = ESPCoreDumpFileLoader(path=os.path.join(target, 'coredump.b64'), is_b64=True)
  29. loader.create_corefile()
  30. if __name__ == '__main__':
  31. # The purpose of these tests is to increase the code coverage at places which are sensitive to issues related to
  32. # Python 2&3 compatibility.
  33. # The espcoredump is not suited for through unit testing. There lot of nested functions, interactive
  34. # communication with the development board and GDB, ...
  35. unittest.main()