test_espcoredump.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. import os
  17. import sys
  18. import unittest
  19. try:
  20. from corefile.elf import ESPCoreDumpElfFile
  21. from corefile.loader import ESPCoreDumpFileLoader, ESPCoreDumpLoaderError
  22. except ImportError:
  23. idf_path = os.getenv('IDF_PATH')
  24. if idf_path:
  25. sys.path.insert(0, os.path.join(idf_path, 'components', 'espcoredump'))
  26. else:
  27. sys.path.insert(0, '..')
  28. from corefile.elf import ESPCoreDumpElfFile
  29. from corefile.loader import ESPCoreDumpFileLoader, ESPCoreDumpLoaderError
  30. SUPPORTED_TARGET = ['esp32', 'esp32s2', 'esp32c3']
  31. class TestESPCoreDumpElfFile(unittest.TestCase):
  32. def test_read_elf(self):
  33. for target in SUPPORTED_TARGET:
  34. elf = ESPCoreDumpElfFile(os.path.join(target, 'core.elf'))
  35. assert elf.load_segments
  36. assert elf.note_segments
  37. class TestESPCoreDumpFileLoader(unittest.TestCase):
  38. def test_load_wrong_encode_core_bin(self):
  39. for target in SUPPORTED_TARGET:
  40. with self.assertRaises(ESPCoreDumpLoaderError):
  41. ESPCoreDumpFileLoader(path=os.path.join(target, 'coredump.b64'), is_b64=False)
  42. def test_create_corefile(self):
  43. for target in SUPPORTED_TARGET:
  44. loader = ESPCoreDumpFileLoader(path=os.path.join(target, 'coredump.b64'), is_b64=True)
  45. loader.create_corefile()
  46. if __name__ == '__main__':
  47. # The purpose of these tests is to increase the code coverage at places which are sensitive to issues related to
  48. # Python 2&3 compatibility.
  49. # The espcoredump is not suited for through unit testing. There lot of nested functions, interactive
  50. # communication with the development board and GDB, ...
  51. unittest.main()