1from __future__ import unicode_literals
2
3import re
4from typing import Any
5
6import ttfw_idf
7
8
9@ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32', 'esp32c3'])
10def test_examples_timergroup(env, extra_data):  # type: (Any, Any) -> None
11    dut = env.get_dut('timer_group', 'examples/peripherals/timer_group')
12    dut.start_app()
13
14    # check auto reload function
15    with_auto_reload = dut.expect(re.compile(r'Timer Group (\S+) auto reload'), timeout=30)[0]
16    assert with_auto_reload == 'with'
17    select_groups = dut.expect(re.compile(r'Group\[(\d)\], timer\[(\d)\] alarm event'))
18    timer_group_num = int(select_groups[0])
19    timer_instance_num = int(select_groups[1])
20    assert timer_group_num == 0 and timer_instance_num == 0
21    dut.expect('EVENT TIME')
22    counter_value = dut.expect(re.compile(r'Counter:\s+(0x\d+)'))[0]
23    counter_value = int(counter_value, 16)
24    print('counter value at auto reload event: ', counter_value)
25    assert counter_value < 20
26
27    # check timer interval
28    dut.expect('Timer Group without auto reload', timeout=5)
29    dut.expect('EVENT TIME')
30    event_time0 = dut.expect(re.compile(r'Time\s+:\s+(\d+\.\d+)\s+s'))[0]
31    print('event0={}'.format(event_time0))
32
33
34if __name__ == '__main__':
35    test_examples_timergroup()
36