example_test.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from __future__ import print_function
  2. import os
  3. import sys
  4. try:
  5. import IDF
  6. except ImportError:
  7. # this is a test case write with tiny-test-fw.
  8. # to run test cases outside tiny-test-fw,
  9. # we need to set environment variable `TEST_FW_PATH`,
  10. # then get and insert `TEST_FW_PATH` to sys path before import FW module
  11. test_fw_path = os.getenv('TEST_FW_PATH')
  12. if test_fw_path and test_fw_path not in sys.path:
  13. sys.path.insert(0, test_fw_path)
  14. import IDF
  15. TASK_ITERATION_LIMIT = 10
  16. TASK_ITERATION_POSTING = "posting TASK_EVENTS:TASK_ITERATION_EVENT to {}, iteration {} out of " + str(TASK_ITERATION_LIMIT)
  17. TASK_ITERATION_HANDLING = "handling TASK_EVENTS:TASK_ITERATION_EVENT from {}, iteration {}"
  18. @IDF.idf_example_test(env_tag='Example_WIFI')
  19. def test_user_event_loops_example(env, extra_data):
  20. dut = env.get_dut('user_event_loops', 'examples/system/esp_event/user_event_loops')
  21. dut.start_app()
  22. dut.expect("setting up")
  23. dut.expect("starting event source")
  24. dut.expect("starting application task")
  25. print("Finished setup")
  26. for iteration in range(1, TASK_ITERATION_LIMIT + 1):
  27. loop = None
  28. if (iteration % 2 == 0):
  29. loop = "loop_with_task"
  30. else:
  31. loop = "loop_without_task"
  32. dut.expect(TASK_ITERATION_POSTING.format(loop, iteration))
  33. print("Posted iteration {} to {}".format(iteration, loop))
  34. dut.expect(TASK_ITERATION_HANDLING.format(loop, iteration))
  35. print("Handled iteration {} from {}".format(iteration, loop))
  36. dut.expect("deleting task event source")
  37. print("Deleted task event source")
  38. if __name__ == '__main__':
  39. test_user_event_loops_example()