example_test.py 1.5 KB

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