example_test.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 sys
  8. import hashlib
  9. try:
  10. import IDF
  11. from IDF.IDFDUT import ESP32DUT
  12. except ImportError:
  13. # This environment variable is expected on the host machine
  14. test_fw_path = os.getenv("TEST_FW_PATH")
  15. if test_fw_path and test_fw_path not in sys.path:
  16. sys.path.insert(0, test_fw_path)
  17. import IDF
  18. import Utility
  19. def verify_elf_sha256_embedding(dut):
  20. elf_file = os.path.join(dut.app.binary_path, "blink.elf")
  21. sha256 = hashlib.sha256()
  22. with open(elf_file, "rb") as f:
  23. sha256.update(f.read())
  24. sha256_expected = sha256.hexdigest()
  25. dut.reset()
  26. sha256_reported = dut.expect(re.compile(r'ELF file SHA256:\s+([a-f0-9]+)'), timeout=5)[0]
  27. Utility.console_log('ELF file SHA256: %s' % sha256_expected)
  28. Utility.console_log('ELF file SHA256 (reported by the app): %s' % sha256_reported)
  29. # the app reports only the first several hex characters of the SHA256, check that they match
  30. if not sha256_expected.startswith(sha256_reported):
  31. raise ValueError('ELF file SHA256 mismatch')
  32. @IDF.idf_example_test(env_tag="Example_WIFI")
  33. def test_examples_blink(env, extra_data):
  34. dut = env.get_dut("blink", "examples/get-started/blink", dut_class=ESP32DUT)
  35. binary_file = os.path.join(dut.app.binary_path, "blink.bin")
  36. bin_size = os.path.getsize(binary_file)
  37. IDF.log_performance("blink_bin_size", "{}KB".format(bin_size // 1024))
  38. IDF.check_performance("blink_bin_size", bin_size // 1024)
  39. dut.start_app()
  40. verify_elf_sha256_embedding(dut)
  41. if __name__ == '__main__':
  42. test_examples_blink()