example_test.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env python
  2. #
  3. # SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD
  4. #
  5. # SPDX-License-Identifier: CC0-1.0
  6. #
  7. from __future__ import unicode_literals
  8. import re
  9. from typing import Any
  10. import ttfw_idf
  11. @ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32', 'esp32s2', 'esp32c3'])
  12. def test_examples_timergroup(env, extra_data): # type: (Any, Any) -> None
  13. dut = env.get_dut('timer_group', 'examples/peripherals/timer_group')
  14. dut.start_app()
  15. # check auto reload function
  16. with_auto_reload = dut.expect(re.compile(r'Timer Group (\S+) auto reload'), timeout=30)[0]
  17. assert with_auto_reload == 'with'
  18. select_groups = dut.expect(re.compile(r'Group\[(\d)\], timer\[(\d)\] alarm event'))
  19. timer_group_num = int(select_groups[0])
  20. timer_instance_num = int(select_groups[1])
  21. assert timer_group_num == 0 and timer_instance_num == 0
  22. dut.expect('EVENT TIME')
  23. counter_value = dut.expect(re.compile(r'Counter:\s+(0x\d+)'))[0]
  24. counter_value = int(counter_value, 16)
  25. print('counter value at auto reload event: ', counter_value)
  26. assert counter_value < 20
  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. if __name__ == '__main__':
  33. test_examples_timergroup()