example_test.py 1.1 KB

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