mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-10 04:43:33 +00:00
CI: update test cases to use different environment variables
change test environments optimize asio udp server test fix icmp echo test case use ethernet_router env to run iperf test cases
This commit is contained in:
55
examples/protocols/sntp/pytest_sntp.py
Normal file
55
examples/protocols/sntp/pytest_sntp.py
Normal file
@@ -0,0 +1,55 @@
|
||||
# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import datetime
|
||||
import logging
|
||||
from typing import Any, Tuple
|
||||
|
||||
import pytest
|
||||
from common_test_methods import get_env_config
|
||||
from pytest_embedded import Dut
|
||||
|
||||
|
||||
@pytest.mark.esp32
|
||||
@pytest.mark.wifi_nearby
|
||||
def test_get_time_from_sntp_server(dut: Dut) -> None:
|
||||
dut.expect('Time is not set yet. Connecting to WiFi and getting time over NTP.')
|
||||
if dut.app.sdkconfig.get('EXAMPLE_WIFI_SSID_PWD_FROM_STDIN') is True:
|
||||
# get env config
|
||||
env_config = get_env_config('wifi_nearby')
|
||||
ap_ssid = env_config['ap_ssid']
|
||||
ap_password = env_config['ap_password']
|
||||
dut.expect('Please input ssid password:')
|
||||
dut.write(' '.join([ap_ssid, ap_password]))
|
||||
dut.expect('IPv4 address:')
|
||||
|
||||
dut.expect('Initializing SNTP')
|
||||
dut.expect(r'Waiting for system time to be set... \(\d+/\d+\)')
|
||||
dut.expect('Notification of a time synchronization event')
|
||||
|
||||
TIME_FORMAT = '%a %b %d %H:%M:%S %Y'
|
||||
TIME_FORMAT_REGEX = r'\w+\s+\w+\s+\d{1,2}\s+\d{2}:\d{2}:\d{2} \d{4}'
|
||||
TIME_DIFF = datetime.timedelta(seconds=10 + 2) # cpu spends 10 seconds in deep sleep
|
||||
NY_time = None
|
||||
SH_time = None
|
||||
|
||||
def check_time(prev_NY_time: Any, prev_SH_time: Any) -> Tuple[Any, Any]:
|
||||
NY_str = dut.expect(r'The current date/time in New York is: ({})'.format(TIME_FORMAT_REGEX))[1].decode()
|
||||
SH_str = dut.expect(r'The current date/time in Shanghai is: ({})'.format(TIME_FORMAT_REGEX))[1].decode()
|
||||
logging.info('New York: "{}"'.format(NY_str))
|
||||
logging.info('Shanghai: "{}"'.format(SH_str))
|
||||
dut.expect('Entering deep sleep for 10 seconds')
|
||||
logging.info('Sleeping...')
|
||||
new_NY_time = datetime.datetime.strptime(NY_str, TIME_FORMAT)
|
||||
new_SH_time = datetime.datetime.strptime(SH_str, TIME_FORMAT)
|
||||
|
||||
# The initial time is not checked because datetime has problems with timezones
|
||||
assert not prev_NY_time or new_NY_time - prev_NY_time < TIME_DIFF
|
||||
assert not prev_SH_time or new_SH_time - prev_SH_time < TIME_DIFF
|
||||
|
||||
return (new_NY_time, new_SH_time)
|
||||
|
||||
NY_time, SH_time = check_time(NY_time, SH_time)
|
||||
for i in range(2, 4):
|
||||
dut.expect('example: Boot count: {}'.format(i), timeout=30)
|
||||
NY_time, SH_time = check_time(NY_time, SH_time)
|
Reference in New Issue
Block a user