2018-06-01 06:36:34 -04:00
|
|
|
from __future__ import print_function
|
|
|
|
import re
|
2019-11-26 22:58:07 -05:00
|
|
|
|
|
|
|
import ttfw_idf
|
2018-06-01 06:36:34 -04:00
|
|
|
|
|
|
|
STARTING_TIMERS_REGEX = re.compile(r'Started timers, time since boot: (\d+) us')
|
|
|
|
|
|
|
|
# name, period, next_alarm, times_started, times_fired, cb_exec_time
|
|
|
|
TIMER_DUMP_LINE_REGEX = re.compile(r'([\w-]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)')
|
|
|
|
|
|
|
|
PERIODIC_TIMER_REGEX = re.compile(r'Periodic timer called, time since boot: (\d+) us')
|
|
|
|
|
|
|
|
LIGHT_SLEEP_ENTER_REGEX = re.compile(r'Entering light sleep for 0\.5s, time since boot: (\d+) us')
|
|
|
|
LIGHT_SLEEP_EXIT_REGEX = re.compile(r'Woke up from light sleep, time since boot: (\d+) us')
|
|
|
|
|
|
|
|
ONE_SHOT_REGEX = re.compile(r'One\-shot timer called, time since boot: (\d+) us')
|
|
|
|
|
|
|
|
RESTART_REGEX = re.compile(r'Restarted periodic timer with 1s period, time since boot: (\d+) us')
|
|
|
|
|
|
|
|
STOP_REGEX = re.compile(r'Stopped and deleted timers')
|
|
|
|
|
|
|
|
INITIAL_TIMER_PERIOD = 500000
|
|
|
|
FINAL_TIMER_PERIOD = 1000000
|
|
|
|
LIGHT_SLEEP_TIME = 500000
|
|
|
|
ONE_SHOT_TIMER_PERIOD = 5000000
|
|
|
|
|
2018-12-04 02:32:48 -05:00
|
|
|
|
2019-11-26 22:58:07 -05:00
|
|
|
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
2018-06-01 06:36:34 -04:00
|
|
|
def test_examples_system_esp_timer(env, extra_data):
|
|
|
|
dut = env.get_dut('esp_timer_example', 'examples/system/esp_timer')
|
|
|
|
# start test
|
|
|
|
dut.start_app()
|
|
|
|
groups = dut.expect(STARTING_TIMERS_REGEX, timeout=30)
|
|
|
|
start_time = int(groups[0])
|
|
|
|
print('Start time: {} us'.format(start_time))
|
2018-12-04 02:32:48 -05:00
|
|
|
|
2018-06-01 06:36:34 -04:00
|
|
|
groups = dut.expect(TIMER_DUMP_LINE_REGEX, timeout=2)
|
|
|
|
assert(groups[0] == 'periodic' and int(groups[1]) == INITIAL_TIMER_PERIOD)
|
|
|
|
groups = dut.expect(TIMER_DUMP_LINE_REGEX, timeout=2)
|
|
|
|
assert(groups[0] == 'one-shot' and int(groups[1]) == 0)
|
2018-12-04 02:32:48 -05:00
|
|
|
|
2018-06-01 06:36:34 -04:00
|
|
|
for i in range(0, 5):
|
|
|
|
groups = dut.expect(PERIODIC_TIMER_REGEX, timeout=2)
|
|
|
|
cur_time = int(groups[0])
|
|
|
|
diff = start_time + (i + 1) * INITIAL_TIMER_PERIOD - cur_time
|
|
|
|
print('Callback #{}, time: {} us, diff: {} us'.format(i, cur_time, diff))
|
|
|
|
assert(abs(diff) < 100)
|
|
|
|
|
|
|
|
groups = dut.expect(ONE_SHOT_REGEX, timeout=3)
|
|
|
|
one_shot_timer_time = int(groups[0])
|
|
|
|
diff = start_time + ONE_SHOT_TIMER_PERIOD - one_shot_timer_time
|
|
|
|
print('One-shot timer, time: {} us, diff: {}'.format(one_shot_timer_time, diff))
|
|
|
|
assert(abs(diff) < 200)
|
|
|
|
|
|
|
|
groups = dut.expect(RESTART_REGEX, timeout=3)
|
|
|
|
start_time = int(groups[0])
|
|
|
|
print('Timer restarted, time: {} us'.format(start_time))
|
|
|
|
|
|
|
|
for i in range(0, 5):
|
|
|
|
groups = dut.expect(PERIODIC_TIMER_REGEX, timeout=2)
|
|
|
|
cur_time = int(groups[0])
|
|
|
|
diff = start_time + (i + 1) * FINAL_TIMER_PERIOD - cur_time
|
|
|
|
print('Callback #{}, time: {} us, diff: {} us'.format(i, cur_time, diff))
|
|
|
|
assert(abs(diff) < 100)
|
|
|
|
|
|
|
|
groups = dut.expect(LIGHT_SLEEP_ENTER_REGEX, timeout=2)
|
|
|
|
sleep_enter_time = int(groups[0])
|
|
|
|
groups = dut.expect(LIGHT_SLEEP_EXIT_REGEX, timeout=2)
|
|
|
|
sleep_exit_time = int(groups[0])
|
|
|
|
sleep_time = sleep_exit_time - sleep_enter_time
|
|
|
|
|
|
|
|
print('Enter sleep: {}, exit sleep: {}, slept: {}'.format(
|
|
|
|
sleep_enter_time, sleep_exit_time, sleep_time))
|
|
|
|
|
|
|
|
assert(abs(sleep_time - LIGHT_SLEEP_TIME) < 1000)
|
|
|
|
|
|
|
|
for i in range(5, 7):
|
|
|
|
groups = dut.expect(PERIODIC_TIMER_REGEX, timeout=2)
|
|
|
|
cur_time = int(groups[0])
|
|
|
|
diff = abs(start_time + (i + 1) * FINAL_TIMER_PERIOD - cur_time)
|
|
|
|
print('Callback #{}, time: {} us, diff: {} us'.format(i, cur_time, diff))
|
|
|
|
assert(diff < 100)
|
|
|
|
|
|
|
|
dut.expect(STOP_REGEX, timeout=2)
|
|
|
|
|
2018-12-04 02:32:48 -05:00
|
|
|
|
2018-06-01 06:36:34 -04:00
|
|
|
if __name__ == '__main__':
|
|
|
|
test_examples_system_esp_timer()
|