example_test.py 1.6 KB

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