2022-01-02 03:17:44 -05:00
|
|
|
# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
|
|
|
# SPDX-License-Identifier: CC0-1.0
|
|
|
|
|
|
|
|
import pytest
|
2022-01-20 04:39:30 -05:00
|
|
|
from pytest_embedded import Dut
|
2022-01-02 03:17:44 -05:00
|
|
|
|
|
|
|
|
2021-12-03 02:39:18 -05:00
|
|
|
@pytest.mark.supported_targets
|
2022-01-02 03:17:44 -05:00
|
|
|
@pytest.mark.generic
|
|
|
|
def test_gptimer_example(dut: Dut) -> None:
|
2022-01-17 01:46:28 -05:00
|
|
|
dut.expect_exact('Create timer handle', timeout=5)
|
|
|
|
dut.expect_exact('Start timer, stop it at alarm event', timeout=5)
|
2022-01-02 03:17:44 -05:00
|
|
|
res = dut.expect(r'Timer stopped, count=(\d+)', timeout=30)
|
|
|
|
stopped_count = res.group(1).decode('utf8')
|
2022-09-14 01:42:11 -04:00
|
|
|
assert (1000000 - 20) < int(stopped_count) < (1000000 + 20)
|
2022-01-02 03:17:44 -05:00
|
|
|
|
2022-01-17 01:46:28 -05:00
|
|
|
dut.expect_exact('Set count value')
|
|
|
|
dut.expect_exact('Get count value')
|
2022-01-02 03:17:44 -05:00
|
|
|
res = dut.expect(r'Timer count value=(\d+)', timeout=5)
|
|
|
|
count_val = res.group(1).decode('utf8')
|
|
|
|
assert int(count_val) == 100
|
|
|
|
|
2022-01-17 01:46:28 -05:00
|
|
|
dut.expect_exact('Start timer, auto-reload at alarm event', timeout=5)
|
2022-01-02 03:17:44 -05:00
|
|
|
res = dut.expect(r'Timer reloaded, count=(\d+)', timeout=5)
|
|
|
|
reloaded_count = res.group(1).decode('utf8')
|
2023-06-21 03:24:42 -04:00
|
|
|
assert 0 <= int(reloaded_count) < 20
|
2022-01-02 03:17:44 -05:00
|
|
|
|
2022-01-17 01:46:28 -05:00
|
|
|
dut.expect_exact('Stop timer')
|
2022-04-23 06:59:38 -04:00
|
|
|
dut.expect_exact('Start timer, update alarm value dynamically')
|
2022-01-02 03:17:44 -05:00
|
|
|
for i in range(1,5):
|
|
|
|
res = dut.expect(r'Timer alarmed, count=(\d+)', timeout=5)
|
|
|
|
alarm_count = res.group(1).decode('utf8')
|
2023-05-17 11:30:35 -04:00
|
|
|
assert (i * 1000000 - 20) < int(alarm_count) < (i * 1000000 + 20)
|
2022-01-02 03:17:44 -05:00
|
|
|
|
2022-01-17 01:46:28 -05:00
|
|
|
dut.expect_exact('Stop timer')
|
|
|
|
dut.expect_exact('Delete timer')
|