1from __future__ import print_function
2
3import ttfw_idf
4
5TASK_ITERATION_LIMIT = 10
6
7TASK_ITERATION_POSTING = 'posting TASK_EVENTS:TASK_ITERATION_EVENT to {}, iteration {} out of ' + str(TASK_ITERATION_LIMIT)
8TASK_ITERATION_HANDLING = 'handling TASK_EVENTS:TASK_ITERATION_EVENT from {}, iteration {}'
9
10
11@ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32', 'esp32c3'])
12def test_user_event_loops_example(env, extra_data):
13    dut = env.get_dut('user_event_loops', 'examples/system/esp_event/user_event_loops')
14
15    dut.start_app()
16
17    dut.expect('setting up')
18    dut.expect('starting event source')
19    dut.expect('starting application task')
20    print('Finished setup')
21
22    for iteration in range(1, TASK_ITERATION_LIMIT + 1):
23        loop = None
24
25        if (iteration % 2 == 0):
26            loop = 'loop_with_task'
27        else:
28            loop = 'loop_without_task'
29
30        dut.expect(TASK_ITERATION_POSTING.format(loop, iteration))
31        print('Posted iteration {} to {}'.format(iteration, loop))
32        dut.expect(TASK_ITERATION_HANDLING.format(loop, iteration))
33        print('Handled iteration {} from {}'.format(iteration, loop))
34
35    dut.expect('deleting task event source')
36    print('Deleted task event source')
37
38
39if __name__ == '__main__':
40    test_user_event_loops_example()
41