From 61d08eb70855a8ffbc7c84a93fbbe0020049d0f3 Mon Sep 17 00:00:00 2001 From: yinqingzhao Date: Tue, 28 Apr 2026 20:38:16 +0800 Subject: [PATCH] fix(test_apps): fix bugs in phy tsens test apps --- tools/test_apps/phy/phy_tsens/main/wifi_cmd.c | 20 ++++++++++++++----- .../phy/phy_tsens/pytest_phy_tsens.py | 8 ++++---- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/tools/test_apps/phy/phy_tsens/main/wifi_cmd.c b/tools/test_apps/phy/phy_tsens/main/wifi_cmd.c index 7dd16f74105..b1d6e5661a4 100644 --- a/tools/test_apps/phy/phy_tsens/main/wifi_cmd.c +++ b/tools/test_apps/phy/phy_tsens/main/wifi_cmd.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -8,6 +8,7 @@ #include #include "esp_log.h" #include "esp_wifi.h" +#include "esp_event.h" #include "esp_console.h" #include "linenoise/linenoise.h" #include "argtable3/argtable3.h" @@ -44,6 +45,11 @@ static void wifi_event_connected_handler(void* arg, esp_event_base_t event_base, s_reconnect_times = 0; } +static void wifi_event_ap_start_handler(void* arg, esp_event_base_t event_base, + int32_t event_id, void* event_data) +{ + ESP_LOGI(TAG, "WIFI_EVENT_AP_START"); +} static void ip_event_got_ip_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) @@ -60,10 +66,14 @@ static int initialize_wifi(int argc, char **argv) esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, wifi_event_any_handler, NULL); esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, wifi_event_disconnected_handler, NULL); esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_CONNECTED, wifi_event_connected_handler, NULL); + esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_AP_START, wifi_event_ap_start_handler, NULL); esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, ip_event_got_ip_handler, NULL); ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) ); ESP_ERROR_CHECK(esp_wifi_start() ); +#if CONFIG_SOC_WIFI_SUPPORT_5G + ESP_ERROR_CHECK(esp_wifi_set_band_mode(WIFI_BAND_MODE_AUTO)); +#endif /* always enable wifi sleep */ ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_MIN_MODEM)); ESP_LOGI(TAG, "initialize_wifi DONE."); @@ -111,7 +121,7 @@ static int cmd_do_ap_set(int argc, char **argv) wifi_config.ap.authmode = WIFI_AUTH_WPA2_PSK; // set default auth mode } if (ap_set_args.channel->count > 0) { - wifi_config.sta.channel = (uint8_t)(ap_set_args.channel->ival[0]); + wifi_config.ap.channel = (uint8_t)(ap_set_args.channel->ival[0]); } if (ap_set_args.authmode->count > 0) { wifi_config.ap.authmode = ap_set_args.authmode->ival[0]; @@ -178,10 +188,10 @@ static int cmd_do_sta_connect(int argc, char **argv) }; const char *ssid = connect_args.ssid->sval[0]; - memcpy((char *) wifi_config.sta.ssid, ssid, sizeof(wifi_config.sta.ssid)); + strncpy((char *) wifi_config.sta.ssid, ssid, sizeof(wifi_config.sta.ssid)); const char *pass = connect_args.password->sval[0]; if (connect_args.password->count > 0) { - memcpy((char *) wifi_config.sta.password, pass, sizeof(wifi_config.sta.password)); + strncpy((char *) wifi_config.sta.password, pass, sizeof(wifi_config.sta.password)); wifi_config.sta.threshold.authmode = WIFI_AUTH_WEP; } if (connect_args.channel->count > 0) { @@ -237,7 +247,7 @@ static int cmd_do_light_sleep(int argc, char **argv) ESP_ERROR_CHECK(esp_pm_configure(&pm_config)); ESP_LOGI(TAG, "LIGHT_SLEEP_ENABLED,OK"); } else { - ESP_LOGE(TAG, "invaild arg!"); + ESP_LOGE(TAG, "invalid arg!"); return 1; } diff --git a/tools/test_apps/phy/phy_tsens/pytest_phy_tsens.py b/tools/test_apps/phy/phy_tsens/pytest_phy_tsens.py index 21751fcdab2..a4f06b5437f 100644 --- a/tools/test_apps/phy/phy_tsens/pytest_phy_tsens.py +++ b/tools/test_apps/phy/phy_tsens/pytest_phy_tsens.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2021-2026 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Apache-2.0 import random import string @@ -42,7 +42,7 @@ def run_phy_tsens_test(dut: tuple[Dut, Dut]) -> None: ssid = ''.join([random.choice(string.ascii_lowercase) for i in range(10)]) password = ''.join([random.choice(string.ascii_lowercase) for i in range(10)]) ap_dut.write(f'ap_set {ssid} {password}') - ap_dut.expect('set ap config OK') + ap_dut.expect('WIFI_EVENT_AP_START') sta_dut.write(f'sta_connect {ssid} {password}') sta_dut.expect('STA_GOT_IP') @@ -89,7 +89,7 @@ def run_phy_tsens_test_init_wifi_first(dut: tuple[Dut, Dut]) -> None: ssid = ''.join([random.choice(string.ascii_lowercase) for i in range(10)]) password = ''.join([random.choice(string.ascii_lowercase) for i in range(10)]) ap_dut.write(f'ap_set {ssid} {password}') - ap_dut.expect('set ap config OK') + ap_dut.expect('WIFI_EVENT_AP_START') sta_dut.write(f'sta_connect {ssid} {password}') sta_dut.expect('STA_GOT_IP') @@ -127,7 +127,7 @@ def run_phy_tsens_test_with_light_sleep(dut: tuple[Dut, Dut]) -> None: ssid = ''.join([random.choice(string.ascii_lowercase) for i in range(10)]) password = ''.join([random.choice(string.ascii_lowercase) for i in range(10)]) ap_dut.write(f'ap_set {ssid} {password}') - ap_dut.expect('set ap config OK') + ap_dut.expect('WIFI_EVENT_AP_START') sta_dut.write(f'sta_connect {ssid} {password}') sta_dut.expect('STA_GOT_IP')