example_test.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. from __future__ import print_function
  2. import os
  3. import sys
  4. import hashlib
  5. try:
  6. import IDF
  7. except ImportError:
  8. test_fw_path = os.getenv('TEST_FW_PATH')
  9. if test_fw_path and test_fw_path not in sys.path:
  10. sys.path.insert(0, test_fw_path)
  11. import IDF
  12. @IDF.idf_example_test(env_tag='Example_WIFI')
  13. def test_examples_spiffsgen(env, extra_data):
  14. # Test with default build configurations
  15. dut = env.get_dut('spiffsgen', 'examples/storage/spiffsgen')
  16. dut.start_app()
  17. base_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'spiffs_image')
  18. # Expect hello.txt is read successfully
  19. with open(os.path.join(base_dir, 'hello.txt'), 'r') as hello_txt:
  20. dut.expect('Read from hello.txt: ' + hello_txt.read())
  21. # Expect alice.txt MD5 hash is computed accurately
  22. with open(os.path.join(base_dir, 'sub', 'alice.txt'), 'rb') as alice_txt:
  23. alice_md5 = hashlib.md5(alice_txt.read()).hexdigest()
  24. dut.expect('Computed MD5 hash of alice.txt: ' + alice_md5)
  25. if __name__ == '__main__':
  26. test_examples_spiffsgen()