1
0

example_test.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env python
  2. from __future__ import division, print_function, unicode_literals
  3. import hashlib
  4. import os
  5. import re
  6. import ttfw_idf
  7. from tiny_test_fw import Utility
  8. def verify_elf_sha256_embedding(dut):
  9. elf_file = os.path.join(dut.app.binary_path, 'blink.elf')
  10. sha256 = hashlib.sha256()
  11. with open(elf_file, 'rb') as f:
  12. sha256.update(f.read())
  13. sha256_expected = sha256.hexdigest()
  14. dut.reset()
  15. sha256_reported = dut.expect(re.compile(r'ELF file SHA256:\s+([a-f0-9]+)'), timeout=5)[0]
  16. Utility.console_log('ELF file SHA256: %s' % sha256_expected)
  17. Utility.console_log('ELF file SHA256 (reported by the app): %s' % sha256_reported)
  18. # the app reports only the first several hex characters of the SHA256, check that they match
  19. if not sha256_expected.startswith(sha256_reported):
  20. raise ValueError('ELF file SHA256 mismatch')
  21. @ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32', 'esp32c3'])
  22. def test_examples_blink(env, extra_data):
  23. dut = env.get_dut('blink', 'examples/get-started/blink')
  24. binary_file = os.path.join(dut.app.binary_path, 'blink.bin')
  25. bin_size = os.path.getsize(binary_file)
  26. ttfw_idf.log_performance('blink_bin_size', '{}KB'.format(bin_size // 1024))
  27. dut.start_app()
  28. verify_elf_sha256_embedding(dut)
  29. if __name__ == '__main__':
  30. test_examples_blink()