-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/add_ci_for_esp_wifi_powersave_example_v5.1' int…
…o 'release/v5.1' ci(wifi): add pytest case for wifi powersave example (backport v5.1) See merge request espressif/esp-idf!25499
- Loading branch information
Showing
12 changed files
with
217 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
idf_component_register(SRCS "power_save.c" | ||
"get_ap_info.c" | ||
INCLUDE_DIRS ".") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Unlicense OR CC0-1.0 | ||
*/ | ||
#include <string.h> | ||
#include "sdkconfig.h" | ||
#include "esp_log.h" | ||
#include "esp_vfs_dev.h" | ||
#include "driver/uart.h" | ||
|
||
#if CONFIG_EXAMPLE_GET_AP_INFO_FROM_STDIN | ||
static const char *TAG = "power_save"; | ||
static char stdin_ssid[32]; | ||
static char stdin_password[64]; | ||
|
||
void get_ap_info_from_stdin(void) | ||
{ | ||
// Initialize VFS & UART so we can use std::cout/cin | ||
setvbuf(stdin, NULL, _IONBF, 0); | ||
/* Install UART driver for interrupt-driven reads and writes */ | ||
ESP_ERROR_CHECK( uart_driver_install( (uart_port_t)CONFIG_ESP_CONSOLE_UART_NUM, | ||
256, 0, 0, NULL, 0) ); | ||
|
||
/* Tell VFS to use UART driver */ | ||
esp_vfs_dev_uart_use_driver(CONFIG_ESP_CONSOLE_UART_NUM); | ||
esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR); | ||
/* Move the caret to the beginning of the next line on '\n' */ | ||
esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF); | ||
|
||
ESP_LOGI(TAG, "Input SSID:"); | ||
|
||
if (fgets(stdin_ssid, 32, stdin) == NULL) { | ||
ESP_LOGE(TAG, "Failed to get SSID"); | ||
} else { | ||
stdin_ssid[strcspn(stdin_ssid, "\n")] = '\0'; | ||
} | ||
|
||
ESP_LOGI(TAG, "Input Password:"); | ||
if (fgets(stdin_password, 64, stdin) == NULL) { | ||
ESP_LOGE(TAG, "Failed to get password"); | ||
} else { | ||
stdin_password[strcspn(stdin_password, "\n")] = '\0'; | ||
} | ||
|
||
/* Back to use non-blocking vfs console*/ | ||
esp_vfs_dev_uart_use_nonblocking(CONFIG_ESP_CONSOLE_UART_NUM); | ||
uart_driver_delete(CONFIG_ESP_CONSOLE_UART_NUM); | ||
} | ||
#endif | ||
|
||
char *get_ap_ssid(void) | ||
{ | ||
#if CONFIG_EXAMPLE_GET_AP_INFO_FROM_STDIN | ||
return stdin_ssid; | ||
#else | ||
return CONFIG_EXAMPLE_WIFI_SSID; | ||
#endif | ||
} | ||
|
||
char *get_ap_password(void) | ||
{ | ||
#if CONFIG_EXAMPLE_GET_AP_INFO_FROM_STDIN | ||
return stdin_password; | ||
#else | ||
return CONFIG_EXAMPLE_WIFI_PASSWORD; | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Unlicense OR CC0-1.0 | ||
*/ | ||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
|
||
#if CONFIG_EXAMPLE_GET_AP_INFO_FROM_STDIN | ||
/** | ||
* Initialize vfs console and prompt user input the AP info | ||
*/ | ||
void get_ap_info_from_stdin(void); | ||
#endif | ||
|
||
/** | ||
* Get the AP ssid from user input or configure | ||
* @return The string of SSID | ||
*/ | ||
char *get_ap_ssid(void); | ||
|
||
/** | ||
* Get the AP password from user input or configure | ||
* @return The string of password | ||
*/ | ||
char *get_ap_password(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import logging | ||
|
||
import pexpect | ||
import pytest | ||
from common_test_methods import get_env_config_variable | ||
from pytest_embedded import Dut | ||
|
||
bad_event_str = [ | ||
'bcn_timout', | ||
'm f probe req l', | ||
'abort() was called', | ||
'Guru Meditation Error', | ||
] | ||
|
||
|
||
def _run_test(dut: Dut) -> None: | ||
if dut.app.sdkconfig.get('EXAMPLE_GET_AP_INFO_FROM_STDIN') is True: | ||
env_name = 'wifi_ap' | ||
ap_ssid = get_env_config_variable(env_name, 'ap_ssid') | ||
ap_password = get_env_config_variable(env_name, 'ap_password') | ||
tag = 'power_save' | ||
dut.expect(f'{tag}: Input SSID:', timeout=5) | ||
dut.write(f'{ap_ssid}') | ||
dut.expect(f'{tag}: Input Password:', timeout=5) | ||
dut.write(f'{ap_password}') | ||
else: | ||
# for local test may config ssid/password from menuconfig | ||
pass | ||
|
||
try: | ||
dut.expect(r'got ip: (\d+\.\d+\.\d+\.\d+)[^\d]', timeout=20) | ||
log_after_got_ip = dut.expect(pexpect.TIMEOUT, timeout=10).decode() | ||
if any(s in log_after_got_ip for s in bad_event_str): | ||
logging.info('Abnormal connection log:') | ||
logging.info('\n' + log_after_got_ip) | ||
raise RuntimeError('Something abnormal happened after got ip') | ||
except pexpect.exceptions.TIMEOUT: | ||
raise RuntimeError('Failed to get ip in power save mode') | ||
|
||
|
||
@pytest.mark.esp32 | ||
@pytest.mark.esp32c2 | ||
@pytest.mark.esp32s2 | ||
@pytest.mark.esp32c3 | ||
@pytest.mark.esp32s3 | ||
@pytest.mark.esp32c6 | ||
@pytest.mark.wifi_ap | ||
def test_wifi_power_save(dut: Dut) -> None: | ||
_run_test(dut) | ||
|
||
|
||
@pytest.mark.esp32c6 | ||
@pytest.mark.wifi_ap | ||
@pytest.mark.parametrize( | ||
'config', | ||
[ | ||
'pd_top', | ||
], | ||
indirect=True, | ||
) | ||
def test_wifi_power_save_pd_top(dut: Dut) -> None: | ||
_run_test(dut) | ||
|
||
|
||
@pytest.mark.esp32c2 | ||
@pytest.mark.wifi_ap | ||
@pytest.mark.xtal_26mhz | ||
@pytest.mark.parametrize( | ||
'config, baud', [ | ||
('c2_xtal26m', '74880'), | ||
], indirect=True | ||
) | ||
def test_wifi_power_save_esp32c2_26mhz(dut: Dut) -> None: | ||
_run_test(dut) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CONFIG_IDF_TARGET="esp32c2" | ||
CONFIG_XTAL_FREQ_26=y | ||
CONFIG_EXAMPLE_GET_AP_INFO_FROM_STDIN=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CONFIG_EXAMPLE_GET_AP_INFO_FROM_STDIN=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CONFIG_EXAMPLE_GET_AP_INFO_FROM_STDIN=y | ||
CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP=y | ||
CONFIG_ESP_PHY_MAC_BB_PD=y | ||
CONFIG_MBEDTLS_HARDWARE_AES=n |