test_espcoredump.py 2.1 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 sys
  17. import os
  18. import unittest
  19. try:
  20. import espcoredump
  21. except ImportError:
  22. idf_path = os.getenv('IDF_PATH')
  23. if idf_path:
  24. sys.path.insert(0, os.path.join(idf_path, 'components', 'espcoredump'))
  25. import espcoredump
  26. class TestESPCoreDumpFileLoader(unittest.TestCase):
  27. def setUp(self):
  28. self.tmp_file = 'tmp'
  29. self.dloader = espcoredump.ESPCoreDumpFileLoader(path='coredump.b64', b64=True)
  30. self.assertIsInstance(self.dloader, espcoredump.ESPCoreDumpFileLoader)
  31. def tearDown(self):
  32. self.dloader.cleanup()
  33. def testESPCoreDumpFileLoaderWithoutB64(self):
  34. t = espcoredump.ESPCoreDumpFileLoader(path='coredump.b64', b64=False)
  35. self.assertIsInstance(t, espcoredump.ESPCoreDumpFileLoader) # invoke for coverage of open()
  36. t.cleanup()
  37. def test_cannot_remove_dir(self):
  38. self.dloader.remove_tmp_file(fname='.') # silent failure (but covers exception inside)
  39. def test_create_corefile(self):
  40. self.assertEqual(self.dloader.create_corefile(core_fname=self.tmp_file, off=0, rom_elf=None), self.tmp_file)
  41. if __name__ == '__main__':
  42. # The purpose of these tests is to increase the code coverage at places which are sensitive to issues related to
  43. # Python 2&3 compatibility.
  44. # The espcoredump is not suited for through unit testting. There lot of nested functions, interactive
  45. # communication with the developement board and GDB, ...
  46. unittest.main()