test_espcoredump.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. class TestESPCoreDumpElfFile(unittest.TestCase):
  31. def test_read_elf(self):
  32. elf = ESPCoreDumpElfFile('core.elf')
  33. assert elf.load_segments
  34. assert elf.note_segments
  35. class TestESPCoreDumpFileLoader(unittest.TestCase):
  36. def test_load_wrong_encode_core_bin(self):
  37. with self.assertRaises(ESPCoreDumpLoaderError):
  38. ESPCoreDumpFileLoader(path='coredump.b64', is_b64=False)
  39. def test_create_corefile(self):
  40. loader = ESPCoreDumpFileLoader(path='coredump.b64', is_b64=True)
  41. loader.create_corefile()
  42. if __name__ == '__main__':
  43. # The purpose of these tests is to increase the code coverage at places which are sensitive to issues related to
  44. # Python 2&3 compatibility.
  45. # The espcoredump is not suited for through unit testting. There lot of nested functions, interactive
  46. # communication with the developement board and GDB, ...
  47. unittest.main()