Merge branch 'ci/migrate_wifi_unit_test_app' into 'master'

CI: Migrate wifi unit tests to componment_ut

Closes IDF-5586

See merge request espressif/esp-idf!20787
This commit is contained in:
Chen Yu Dong 2022-11-11 16:24:49 +08:00
commit a05e8996ab
22 changed files with 780 additions and 765 deletions

View File

@ -216,18 +216,19 @@
- "examples/protocols/**/*"
- "examples/wifi/**/*"
- "examples/network/simple_sniffer/**/*"
- "components/esp_phy/**/*"
- "components/esp_wifi/**/*"
- "components/esp_netif/**/*"
- "components/lwip/**/*"
# components
- "components/mbedtls/port/dynamic/*"
# for cases with wifi_high_traffic marker
- "examples/system/ota/**/*"
- "components/app_update/**/*"
- "components/esp_https_ota/**/*"
.patterns-target_test-wifi: &patterns-target_test-wifi
- "components/esp_phy/**/*"
- "components/esp_wifi/**/*"
- "components/esp_netif/**/*"
- "components/lwip/**/*"
# for jobs: UT_044, UT_045
.patterns-unit_test-sdio: &patterns-unit_test-sdio
- "components/esp_serial_slave_link/**/*"
@ -556,6 +557,8 @@
changes: *patterns-downloadable-tools
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
.rules:build:component_ut-esp32:
rules:
@ -581,6 +584,8 @@
changes: *patterns-downloadable-tools
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
.rules:build:component_ut-esp32c2:
rules:
@ -602,6 +607,8 @@
changes: *patterns-downloadable-tools
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
.rules:build:component_ut-esp32c3:
rules:
@ -626,6 +633,8 @@
changes: *patterns-downloadable-tools
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
.rules:build:component_ut-esp32c6:
rules:
@ -650,6 +659,8 @@
changes: *patterns-downloadable-tools
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
.rules:build:component_ut-esp32h4:
rules:
@ -674,6 +685,8 @@
changes: *patterns-downloadable-tools
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
.rules:build:component_ut-esp32s2:
rules:
@ -698,6 +711,8 @@
changes: *patterns-downloadable-tools
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
.rules:build:component_ut-esp32s3:
rules:
@ -722,6 +737,8 @@
changes: *patterns-downloadable-tools
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
.rules:build:custom_test:
rules:
@ -749,6 +766,8 @@
changes: *patterns-downloadable-tools
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
.rules:build:custom_test-esp32:
rules:
@ -770,6 +789,8 @@
changes: *patterns-downloadable-tools
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
.rules:build:custom_test-esp32c2:
rules:
@ -788,6 +809,8 @@
changes: *patterns-downloadable-tools
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
.rules:build:custom_test-esp32c3:
rules:
@ -808,6 +831,8 @@
changes: *patterns-downloadable-tools
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
.rules:build:custom_test-esp32c6:
rules:
@ -828,6 +853,8 @@
changes: *patterns-downloadable-tools
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
.rules:build:custom_test-esp32s2:
rules:
@ -848,6 +875,8 @@
changes: *patterns-downloadable-tools
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
.rules:build:custom_test-esp32s3:
rules:
@ -868,6 +897,8 @@
changes: *patterns-downloadable-tools
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
.rules:build:docker:
rules:
@ -922,6 +953,8 @@
changes: *patterns-example_test-wifi
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
.rules:build:example_test-esp32:
rules:
@ -954,6 +987,8 @@
changes: *patterns-example_test-wifi
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
.rules:build:example_test-esp32c2:
rules:
@ -980,6 +1015,8 @@
changes: *patterns-example_test-wifi
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
.rules:build:example_test-esp32c3:
rules:
@ -1011,6 +1048,8 @@
changes: *patterns-example_test-wifi
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
.rules:build:example_test-esp32c6:
rules:
@ -1041,6 +1080,8 @@
changes: *patterns-example_test-wifi
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
.rules:build:example_test-esp32h4:
rules:
@ -1071,6 +1112,8 @@
changes: *patterns-example_test-wifi
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
.rules:build:example_test-esp32s2:
rules:
@ -1101,6 +1144,8 @@
changes: *patterns-example_test-wifi
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
.rules:build:example_test-esp32s3:
rules:
@ -1131,6 +1176,8 @@
changes: *patterns-example_test-wifi
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
.rules:build:integration_test:
rules:
@ -1232,6 +1279,8 @@
changes: *patterns-integration_test
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
- <<: *if-dev-push
changes: *patterns-unit_test
- <<: *if-dev-push
@ -1263,6 +1312,8 @@
changes: *patterns-downloadable-tools
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
- <<: *if-dev-push
changes: *patterns-unit_test
- <<: *if-dev-push
@ -1288,6 +1339,8 @@
changes: *patterns-downloadable-tools
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
- <<: *if-dev-push
changes: *patterns-unit_test
- <<: *if-dev-push
@ -1312,6 +1365,8 @@
changes: *patterns-downloadable-tools
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
- <<: *if-dev-push
changes: *patterns-unit_test-sdio
- <<: *if-dev-push
@ -1334,6 +1389,8 @@
changes: *patterns-downloadable-tools
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
- <<: *if-dev-push
changes: *patterns-unit_test
- <<: *if-dev-push
@ -1358,6 +1415,8 @@
changes: *patterns-downloadable-tools
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
- <<: *if-dev-push
changes: *patterns-unit_test
- <<: *if-dev-push
@ -1382,6 +1441,8 @@
changes: *patterns-downloadable-tools
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
- <<: *if-dev-push
changes: *patterns-unit_test
- <<: *if-dev-push
@ -1406,6 +1467,8 @@
changes: *patterns-downloadable-tools
- <<: *if-dev-push
changes: *patterns-target_test-i154
- <<: *if-dev-push
changes: *patterns-target_test-wifi
- <<: *if-dev-push
changes: *patterns-unit_test
- <<: *if-dev-push
@ -1473,6 +1536,19 @@
- <<: *if-dev-push
changes: *patterns-component_ut-adc
.rules:test:component_ut-esp32-wifi:
rules:
- <<: *if-revert-branch
when: never
- <<: *if-protected
- <<: *if-label-build-only
when: never
- <<: *if-label-component_ut
- <<: *if-label-component_ut_esp32
- <<: *if-label-target_test
- <<: *if-dev-push
changes: *patterns-target_test-wifi
.rules:test:component_ut-esp32c2:
rules:
- <<: *if-revert-branch
@ -1524,6 +1600,19 @@
- <<: *if-dev-push
changes: *patterns-component_ut-adc
.rules:test:component_ut-esp32c3-wifi:
rules:
- <<: *if-revert-branch
when: never
- <<: *if-protected
- <<: *if-label-build-only
when: never
- <<: *if-label-component_ut
- <<: *if-label-component_ut_esp32c3
- <<: *if-label-target_test
- <<: *if-dev-push
changes: *patterns-target_test-wifi
.rules:test:component_ut-esp32h4-i154:
rules:
- <<: *if-revert-branch
@ -1716,6 +1805,8 @@
- <<: *if-label-target_test
- <<: *if-dev-push
changes: *patterns-example_test-wifi
- <<: *if-dev-push
changes: *patterns-target_test-wifi
.rules:test:example_test-esp32c2:
rules:

View File

@ -306,6 +306,14 @@ component_ut_pytest_esp32_generic_multi_device:
- build_pytest_components_esp32
tags: [ esp32, generic_multi_device ]
component_ut_pytest_esp32_wifi_two_dut:
extends:
- .pytest_components_dir_template
- .rules:test:component_ut-esp32-wifi
needs:
- build_pytest_components_esp32
tags: [ esp32, wifi_two_dut ]
component_ut_pytest_esp32_adc:
extends:
- .pytest_components_dir_template
@ -484,6 +492,14 @@ component_ut_pytest_esp32c3_generic_multi_device:
- build_pytest_components_esp32c3
tags: [ esp32c3, generic_multi_device ]
component_ut_pytest_esp32c3_wifi_two_dut:
extends:
- .pytest_components_dir_template
- .rules:test:component_ut-esp32c3-wifi
needs:
- build_pytest_components_esp32c3
tags: [ esp32c3, wifi_two_dut ]
component_ut_pytest_esp32c3_adc:
extends:
- .pytest_components_dir_template

View File

@ -0,0 +1,15 @@
# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps
components/esp_wifi/test_apps/wifi_connect:
disable:
- if: IDF_TARGET == "esp32c6"
temporary: true
reason: target esp32c6 is not supported yet
disable_test:
- if: IDF_TARGET not in ["esp32", "esp32c3"]
reason: leak of runner
components/esp_wifi/test_apps/wifi_function:
disable:
- if: IDF_TARGET == "esp32c6"
temporary: true
reason: target esp32c6 is not supported yet

View File

@ -1,356 +0,0 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*
* This test code is in the Public Domain (or CC0 licensed, at your option.)
*
* Unless required by applicable law or agreed to in writing, this
* software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied.
*/
#include "string.h"
#include "unity.h"
#include "esp_mac.h"
#include "esp_event.h"
#include "esp_wifi.h"
#include "esp_wifi_types.h"
#include "esp_log.h"
#include "nvs_flash.h"
#include "test_utils.h"
#include "memory_checks.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#define DEFAULT_SSID "TEST_SSID"
#define DEFAULT_PWD "TEST_PASS"
#define GOT_IP_EVENT 0x00000001
#define DISCONNECT_EVENT 0x00000002
#define EVENT_HANDLER_FLAG_DO_NOT_AUTO_RECONNECT 0x00000001
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2, ESP32S3, ESP32C3, ESP32C2)
/* TODO IDF-2618, IDF-5046 */
//IDF-5046
static const char* TAG = "test_wifi";
static uint32_t wifi_event_handler_flag;
static EventGroupHandle_t wifi_events;
static void wifi_event_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data)
{
printf("wifi ev_handle_called.\n");
switch(event_id) {
case WIFI_EVENT_STA_START:
ESP_LOGI(TAG, "WIFI_EVENT_STA_START");
//do not actually connect in test case
//;
break;
case WIFI_EVENT_STA_DISCONNECTED:
ESP_LOGI(TAG, "WIFI_EVENT_STA_DISCONNECTED");
if (! (EVENT_HANDLER_FLAG_DO_NOT_AUTO_RECONNECT & wifi_event_handler_flag) ) {
TEST_ESP_OK(esp_wifi_connect());
}
if (wifi_events) {
xEventGroupSetBits(wifi_events, DISCONNECT_EVENT);
}
break;
default:
break;
}
return;
}
static void ip_event_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data)
{
ip_event_got_ip_t *event;
printf("ip ev_handle_called.\n");
switch(event_id) {
case IP_EVENT_STA_GOT_IP:
event = (ip_event_got_ip_t*)event_data;
ESP_LOGI(TAG, "IP_EVENT_STA_GOT_IP");
ESP_LOGI(TAG, "got ip:" IPSTR "\n", IP2STR(&event->ip_info.ip));
if (wifi_events) {
xEventGroupSetBits(wifi_events, GOT_IP_EVENT);
}
break;
default:
break;
}
return;
}
static esp_err_t event_init(void)
{
ESP_ERROR_CHECK(esp_event_loop_create_default());
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL));
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, &ip_event_handler, NULL));
esp_netif_create_default_wifi_sta();
esp_netif_create_default_wifi_ap();
return ESP_OK;
}
#define EMPH_STR(s) "****** "s" ******"
static void test_wifi_init_deinit(wifi_init_config_t *cfg, wifi_config_t* wifi_config)
{
ESP_LOGI(TAG, EMPH_STR("esp_wifi_deinit"));
TEST_ESP_ERR(ESP_ERR_WIFI_NOT_INIT, esp_wifi_deinit());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_get_mode"));
wifi_mode_t mode_get;
TEST_ESP_ERR(ESP_ERR_WIFI_NOT_INIT, esp_wifi_get_mode(&mode_get));
ESP_LOGI(TAG, EMPH_STR("esp_wifi_init"));
TEST_ESP_OK(esp_wifi_init(cfg));
ESP_LOGI(TAG, EMPH_STR("esp_wifi_set_mode"));
TEST_ESP_OK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_LOGI(TAG, EMPH_STR("esp_wifi_set_config"));
TEST_ESP_OK(esp_wifi_set_config(WIFI_IF_STA, wifi_config));
ESP_LOGI(TAG, EMPH_STR("esp_wifi_deinit..."));
TEST_ESP_OK(esp_wifi_deinit());
}
static void test_wifi_start_stop(wifi_init_config_t *cfg, wifi_config_t* wifi_config)
{
ESP_LOGI(TAG, EMPH_STR("esp_wifi_stop"));
TEST_ESP_ERR(ESP_ERR_WIFI_NOT_INIT, esp_wifi_stop());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_init"));
TEST_ESP_OK(esp_wifi_init(cfg));
ESP_LOGI(TAG, EMPH_STR("esp_wifi_set_mode"));
TEST_ESP_OK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_LOGI(TAG, EMPH_STR("esp_wifi_set_config"));
TEST_ESP_OK(esp_wifi_set_config(WIFI_IF_STA, wifi_config));
//now start wifi
ESP_LOGI(TAG, EMPH_STR("esp_wifi_start..."));
TEST_ESP_OK(esp_wifi_start());
//wifi stop
ESP_LOGI(TAG, EMPH_STR("esp_wifi_stop..."));
TEST_ESP_OK( esp_wifi_stop() );
ESP_LOGI(TAG, EMPH_STR("esp_wifi_deinit..."));
TEST_ESP_OK(esp_wifi_deinit());
}
TEST_CASE("wifi stop and deinit","[wifi]")
{
test_case_uses_tcpip();
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
wifi_config_t wifi_config = {
.sta = {
.ssid = DEFAULT_SSID,
.password = DEFAULT_PWD
},
};
//init nvs
ESP_LOGI(TAG, EMPH_STR("nvs_flash_init"));
esp_err_t r = nvs_flash_init();
if (r == ESP_ERR_NVS_NO_FREE_PAGES || r == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_LOGI(TAG, EMPH_STR("no free pages or nvs version mismatch, erase.."));
TEST_ESP_OK(nvs_flash_erase());
r = nvs_flash_init();
}
TEST_ESP_OK(r);
//init tcpip
ESP_LOGI(TAG, EMPH_STR("esp_netif_init"));
esp_netif_init();
//init event loop
ESP_LOGI(TAG, EMPH_STR("event_init"));
event_init();
ESP_LOGI(TAG, "test wifi init & deinit...");
test_wifi_init_deinit(&cfg, &wifi_config);
ESP_LOGI(TAG, "wifi init & deinit seem to be OK.");
ESP_LOGI(TAG, "test wifi start & stop...");
test_wifi_start_stop(&cfg, &wifi_config);
ESP_LOGI(TAG, "wifi start & stop seem to be OK.");
ESP_LOGI(TAG, EMPH_STR("nvs_flash_deinit..."));
nvs_flash_deinit();
ESP_LOGI(TAG, "test passed...");
TEST_IGNORE_MESSAGE("this test case is ignored due to the critical memory leak of esp_netif and event_loop.");
}
static void start_wifi_as_softap(void)
{
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
cfg.nvs_enable = false;
wifi_config_t w_config = {
.ap.ssid = DEFAULT_SSID,
.ap.password = DEFAULT_PWD,
.ap.ssid_len = 0,
.ap.channel = 1,
.ap.authmode = WIFI_AUTH_WPA2_PSK,
.ap.ssid_hidden = false,
.ap.max_connection = 4,
.ap.beacon_interval = 100,
};
event_init();
// can't deinit event loop, need to reset leak check
test_utils_record_free_mem();
if (wifi_events == NULL) {
wifi_events = xEventGroupCreate();
}
TEST_ESP_OK(esp_wifi_init(&cfg));
TEST_ESP_OK(esp_wifi_set_mode(WIFI_MODE_AP));
TEST_ESP_OK(esp_wifi_set_config(WIFI_IF_AP, &w_config));
TEST_ESP_OK(esp_wifi_start());
}
static void start_wifi_as_sta(void)
{
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
cfg.nvs_enable = false;
// do not auto connect
wifi_event_handler_flag |= EVENT_HANDLER_FLAG_DO_NOT_AUTO_RECONNECT;
event_init();
// can't deinit event loop, need to reset leak check
test_utils_record_free_mem();
if (wifi_events == NULL) {
wifi_events = xEventGroupCreate();
} else {
xEventGroupClearBits(wifi_events, 0x00ffffff);
}
TEST_ESP_OK(esp_wifi_init(&cfg));
TEST_ESP_OK(esp_wifi_set_mode(WIFI_MODE_STA));
TEST_ESP_OK(esp_wifi_start());
}
static void stop_wifi(void)
{
printf("stop wifi\n");
TEST_ESP_OK(esp_wifi_stop());
TEST_ESP_OK(esp_wifi_deinit());
if (wifi_events) {
vEventGroupDelete(wifi_events);
wifi_events = NULL;
}
vTaskDelay(1000/portTICK_PERIOD_MS);
}
static void receive_ds2ds_packet(void)
{
test_case_uses_tcpip();
start_wifi_as_softap();
unity_wait_for_signal("sender ready");
unity_send_signal("receiver ready");
// wait for sender to send packets
vTaskDelay(1000/portTICK_PERIOD_MS);
stop_wifi();
}
static const char ds2ds_pdu[] = {
0x48, 0x03, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xE8, 0x65, 0xD4, 0xCB, 0x74, 0x19, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x60, 0x94, 0xE8, 0x65, 0xD4, 0xCB, 0x74, 0x1C, 0x26, 0xB9,
0x0D, 0x02, 0x7D, 0x13, 0x00, 0x00, 0x01, 0xE8, 0x65, 0xD4, 0xCB, 0x74,
0x1C, 0x00, 0x00, 0x26, 0xB9, 0x00, 0x00, 0x00, 0x00
};
static void send_ds2ds_packet(void)
{
test_case_uses_tcpip();
start_wifi_as_softap();
unity_send_signal("sender ready");
unity_wait_for_signal("receiver ready");
// send packet 20 times to make sure receiver will get this packet
for (uint16_t i = 0; i < 20; i++) {
esp_wifi_80211_tx(WIFI_IF_AP, ds2ds_pdu, sizeof(ds2ds_pdu), true);
vTaskDelay(50 / portTICK_PERIOD_MS);
}
stop_wifi();
}
TEST_CASE_MULTIPLE_DEVICES("receive ds2ds packet without exception", "[wifi][test_env=UT_T2_1]", receive_ds2ds_packet, send_ds2ds_packet);
static void wifi_connect_by_bssid(uint8_t *bssid)
{
EventBits_t bits;
wifi_config_t w_config = {
.sta.ssid = DEFAULT_SSID,
.sta.password = DEFAULT_PWD,
.sta.bssid_set = true,
};
memcpy(w_config.sta.bssid, bssid, 6);
TEST_ESP_OK(esp_wifi_set_config(WIFI_IF_STA, &w_config));
TEST_ESP_OK(esp_wifi_connect());
ESP_LOGI(TAG, "called esp_wifi_connect()");
bits = xEventGroupWaitBits(wifi_events, GOT_IP_EVENT, 1, 0, 7000/portTICK_PERIOD_MS);
TEST_ASSERT(bits == GOT_IP_EVENT);
}
static void test_wifi_connection_sta(void)
{
char mac_str[19];
uint8_t mac[6];
EventBits_t bits;
test_case_uses_tcpip();
start_wifi_as_sta();
unity_wait_for_signal_param("SoftAP mac", mac_str, 19);
TEST_ASSERT_TRUE(unity_util_convert_mac_from_string(mac_str, mac));
wifi_connect_by_bssid(mac);
unity_send_signal("STA connected");
bits = xEventGroupWaitBits(wifi_events, DISCONNECT_EVENT, 1, 0, 60000 / portTICK_PERIOD_MS);
// disconnect event not triggered
printf("wait finish\n");
TEST_ASSERT(bits == 0);
stop_wifi();
}
static void test_wifi_connection_softap(void)
{
char mac_str[19] = {0};
uint8_t mac[6];
test_case_uses_tcpip();
start_wifi_as_softap();
TEST_ESP_OK(esp_wifi_get_mac(WIFI_IF_AP, mac));
sprintf(mac_str, MACSTR, MAC2STR(mac));
unity_send_signal_param("SoftAP mac", mac_str);
unity_wait_for_signal("STA connected");
vTaskDelay(60000 / portTICK_PERIOD_MS);
stop_wifi();
}
TEST_CASE_MULTIPLE_DEVICES("test wifi retain connection for 60s", "[wifi][test_env=UT_T2_1][timeout=90]", test_wifi_connection_sta, test_wifi_connection_softap);
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(...)

View File

@ -1,387 +0,0 @@
#include "unity.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_log.h"
#include "nvs_flash.h"
#include "test_utils.h"
#include "freertos/event_groups.h"
#include "unity_test_utils.h"
#define GOT_IP_EVENT 0x00000001
#define DISCONNECT_EVENT 0x00000002
#define EVENT_HANDLER_FLAG_DO_NOT_AUTO_RECONNECT 0x00000001
#define EMPH_STR(s) "****** "s" ******"
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)
//IDF-5046
static const char* TAG = "test_wifi_init";
static uint32_t wifi_event_handler_flag;
static EventGroupHandle_t wifi_events;
static void wifi_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data)
{
printf("wifi ev_handle_called.\n");
switch(event_id) {
case WIFI_EVENT_STA_START:
ESP_LOGI(TAG, "WIFI_EVENT_STA_START");
break;
case WIFI_EVENT_STA_DISCONNECTED:
ESP_LOGI(TAG, "WIFI_EVENT_STA_DISCONNECTED");
if (! (EVENT_HANDLER_FLAG_DO_NOT_AUTO_RECONNECT & wifi_event_handler_flag) ) {
TEST_ESP_OK(esp_wifi_connect());
}
if (wifi_events) {
xEventGroupSetBits(wifi_events, DISCONNECT_EVENT);
}
break;
default:
break;
}
return;
}
static void ip_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data)
{
ip_event_got_ip_t *event;
printf("ip ev_handle_called.\n");
switch(event_id) {
case IP_EVENT_STA_GOT_IP:
event = (ip_event_got_ip_t*)event_data;
ESP_LOGI(TAG, "IP_EVENT_STA_GOT_IP");
ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
if (wifi_events) {
xEventGroupSetBits(wifi_events, GOT_IP_EVENT);
}
break;
default:
break;
}
return;
}
static esp_err_t event_init(void)
{
ESP_ERROR_CHECK(esp_event_loop_create_default());
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL));
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, &ip_event_handler, NULL));
return ESP_OK;
}
static esp_err_t event_deinit(void)
{
ESP_ERROR_CHECK(esp_event_handler_unregister(WIFI_EVENT,ESP_EVENT_ANY_ID,&wifi_event_handler));
ESP_ERROR_CHECK(esp_event_handler_unregister(IP_EVENT,ESP_EVENT_ANY_ID,&ip_event_handler));
ESP_ERROR_CHECK(esp_event_loop_delete_default());
return ESP_OK;
}
static void wifi_driver_can_start_on_APP_CPU_task(void* arg)
{
SemaphoreHandle_t *sema = (SemaphoreHandle_t *) arg;
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_LOGI(TAG, EMPH_STR("nvs_flash_init"));
esp_err_t r = nvs_flash_init();
if (r == ESP_ERR_NVS_NO_FREE_PAGES || r == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_LOGI(TAG, EMPH_STR("no free pages or NFS version mismatch, erase.."));
TEST_ESP_OK(nvs_flash_erase());
r = nvs_flash_init();
}
TEST_ESP_OK(r);
ESP_LOGI(TAG, EMPH_STR("event_init"));
TEST_ESP_OK(event_init());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_init"));
TEST_ESP_OK(esp_wifi_init(&cfg));
ESP_LOGI(TAG, EMPH_STR("esp_wifi_deinit..."));
TEST_ESP_OK(esp_wifi_deinit());
ESP_LOGI(TAG, EMPH_STR("event_deinit"));
TEST_ESP_OK(event_deinit());
ESP_LOGI(TAG, EMPH_STR("nvs_flash_deinit..."));
TEST_ESP_OK(nvs_flash_deinit());
ESP_LOGI(TAG, "exit task...");
xSemaphoreGive(*sema);
vTaskSuspend(NULL);
}
TEST_CASE("wifi driver can start on APP CPU", "[wifi_init]")
{
test_case_uses_tcpip();
TaskHandle_t th = NULL;
SemaphoreHandle_t sema = xSemaphoreCreateBinary();
TEST_ASSERT_NOT_NULL(sema);
printf("Creating tasks\n");
#ifndef CONFIG_FREERTOS_UNICORE
xTaskCreatePinnedToCore(wifi_driver_can_start_on_APP_CPU_task, "wifi_driver_can_start_on_APP_CPU_task", 2048*2, &sema, 3, &th, 1);
#else
xTaskCreate(wifi_driver_can_start_on_APP_CPU_task, "wifi_driver_can_start_on_APP_CPU_task", 2048*2, &sema, 3, &th);
#endif
TEST_ASSERT_NOT_NULL(th);
xSemaphoreTake(sema, portMAX_DELAY);
vSemaphoreDelete(sema);
sema = NULL;
unity_utils_task_delete(th);
}
static void wifi_start_stop_task(void* arg)
{
SemaphoreHandle_t *sema = (SemaphoreHandle_t *) arg;
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_LOGI(TAG, EMPH_STR("nvs_flash_init"));
esp_err_t r = nvs_flash_init();
if (r == ESP_ERR_NVS_NO_FREE_PAGES || r == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_LOGI(TAG, EMPH_STR("no free pages or NFS version mismatch, erase.."));
TEST_ESP_OK(nvs_flash_erase());
r = nvs_flash_init();
}
TEST_ESP_OK(r);
//init tcpip stack
test_case_uses_tcpip();
ESP_LOGI(TAG, EMPH_STR("event_init"));
TEST_ESP_OK(event_init());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_init"));
TEST_ESP_OK(esp_wifi_init(&cfg));
ESP_LOGI(TAG, EMPH_STR("esp_wifi_start"));
TEST_ESP_OK(esp_wifi_start());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_stop"));
TEST_ESP_OK(esp_wifi_stop());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_stop"));
TEST_ESP_OK(esp_wifi_stop());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_deinit"));
TEST_ESP_OK(esp_wifi_deinit());
ESP_LOGI(TAG, EMPH_STR("event_deinit"));
TEST_ESP_OK(event_deinit());
ESP_LOGI(TAG, EMPH_STR("nvs_flash_deinit..."));
nvs_flash_deinit();
ESP_LOGI(TAG, "test passed...");
xSemaphoreGive(*sema);
vTaskSuspend(NULL);
}
TEST_CASE("Calling esp_wifi_stop() with start", "[wifi_init]")
{
TaskHandle_t th = NULL;
SemaphoreHandle_t sema = xSemaphoreCreateBinary();
TEST_ASSERT_NOT_NULL(sema);
printf("Creating tasks\n");
#ifndef CONFIG_FREERTOS_UNICORE
xTaskCreatePinnedToCore(wifi_start_stop_task, "wifi_start_stop_task", 2048*2, &sema, 3, &th, 0);
#else
xTaskCreate(wifi_start_stop_task, "wifi_start_stop_task", 2048*2, &sema, 3, &th);
#endif
TEST_ASSERT_NOT_NULL(th);
xSemaphoreTake(sema, portMAX_DELAY);
vSemaphoreDelete(sema);
sema = NULL;
unity_utils_task_delete(th);
}
static void wifi_stop_task(void* arg)
{
SemaphoreHandle_t *sema = (SemaphoreHandle_t *) arg;
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_LOGI(TAG, EMPH_STR("nvs_flash_init"));
esp_err_t r = nvs_flash_init();
if (r == ESP_ERR_NVS_NO_FREE_PAGES || r == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_LOGI(TAG, EMPH_STR("no free pages or NFS version mismatch, erase.."));
TEST_ESP_OK(nvs_flash_erase());
r = nvs_flash_init();
}
TEST_ESP_OK(r);
ESP_LOGI(TAG, EMPH_STR("event_init"));
TEST_ESP_OK(event_init());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_init"));
TEST_ESP_OK(esp_wifi_init(&cfg));
ESP_LOGI(TAG, EMPH_STR("esp_wifi_stop"));
TEST_ESP_OK(esp_wifi_stop());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_stop"));
TEST_ESP_OK(esp_wifi_stop());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_deinit"));
TEST_ESP_OK(esp_wifi_deinit());
ESP_LOGI(TAG, EMPH_STR("event_deinit"));
TEST_ESP_OK(event_deinit());
ESP_LOGI(TAG, EMPH_STR("nvs_flash_deinit..."));
nvs_flash_deinit();
ESP_LOGI(TAG, "test passed...");
xSemaphoreGive(*sema);
vTaskSuspend(NULL);
}
TEST_CASE("Calling esp_wifi_stop() without start", "[wifi_init]")
{
test_case_uses_tcpip();
TaskHandle_t th = NULL;
SemaphoreHandle_t sema = xSemaphoreCreateBinary();
TEST_ASSERT_NOT_NULL(sema);
printf("Creating tasks\n");
#ifndef CONFIG_FREERTOS_UNICORE
xTaskCreatePinnedToCore(wifi_stop_task, "wifi_stop_task", 2048*2, &sema, 3, &th, 0);
#else
xTaskCreate(wifi_stop_task, "wifi_stop_task", 2048*2, &sema, 3, &th);
#endif
TEST_ASSERT_NOT_NULL(th);
xSemaphoreTake(sema, portMAX_DELAY);
vSemaphoreDelete(sema);
sema = NULL;
unity_utils_task_delete(th);
}
static void wifi_deinit_task(void* arg)
{
SemaphoreHandle_t *sema = (SemaphoreHandle_t *) arg;
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_LOGI(TAG, EMPH_STR("nvs_flash_init"));
esp_err_t r = nvs_flash_init();
if (r == ESP_ERR_NVS_NO_FREE_PAGES || r == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_LOGI(TAG, EMPH_STR("no free pages or NFS version mismatch, erase.."));
TEST_ESP_OK(nvs_flash_erase());
r = nvs_flash_init();
}
TEST_ESP_OK(r);
//init tcpip stack
test_case_uses_tcpip();
ESP_LOGI(TAG, EMPH_STR("event_init"));
TEST_ESP_OK(event_init());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_init"));
TEST_ESP_OK(esp_wifi_init(&cfg));
ESP_LOGI(TAG, EMPH_STR("esp_wifi_start"));
TEST_ESP_OK(esp_wifi_start());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_deinit"));
TEST_ESP_ERR(ESP_ERR_WIFI_NOT_STOPPED, esp_wifi_deinit());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_stop"));
TEST_ESP_OK(esp_wifi_stop());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_deinit"));
TEST_ESP_OK(esp_wifi_deinit());
ESP_LOGI(TAG, EMPH_STR("event_deinit"));
TEST_ESP_OK(event_deinit());
ESP_LOGI(TAG, EMPH_STR("nvs_flash_deinit..."));
nvs_flash_deinit();
ESP_LOGI(TAG, "test passed...");
xSemaphoreGive(*sema);
vTaskSuspend(NULL);
}
TEST_CASE("Calling esp_wifi_deinit() without stop", "[wifi_init]")
{
TaskHandle_t th = NULL;
SemaphoreHandle_t sema = xSemaphoreCreateBinary();
TEST_ASSERT_NOT_NULL(sema);
printf("Creating tasks\n");
#ifndef CONFIG_FREERTOS_UNICORE
xTaskCreatePinnedToCore(wifi_deinit_task, "wifi_deinit_task", 2048*2, &sema, 3, &th, 0);
#else
xTaskCreate(wifi_deinit_task, "wifi_deinit_task", 2048*2, &sema, 3, &th);
#endif
TEST_ASSERT_NOT_NULL(th);
xSemaphoreTake(sema, portMAX_DELAY);
vSemaphoreDelete(sema);
sema = NULL;
unity_utils_task_delete(th);
}
static void wifi_country_code_task(void* arg)
{
SemaphoreHandle_t *sema = (SemaphoreHandle_t *) arg;
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_LOGI(TAG, EMPH_STR("nvs_flash_erase"));
nvs_flash_erase();
ESP_LOGI(TAG, EMPH_STR("nvs_flash_init"));
esp_err_t r = nvs_flash_init();
if (r == ESP_ERR_NVS_NO_FREE_PAGES || r == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_LOGI(TAG, EMPH_STR("no free pages or NFS version mismatch, erase.."));
TEST_ESP_OK(nvs_flash_erase());
r = nvs_flash_init();
}
TEST_ESP_OK(r);
//init tcpip stack
test_case_uses_tcpip();
ESP_LOGI(TAG, EMPH_STR("event_init"));
TEST_ESP_OK(event_init());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_init"));
TEST_ESP_OK(esp_wifi_init(&cfg));
wifi_country_t country;
wifi_country_t country_01 = {.cc="01", .schan=1, .nchan=11, .policy=WIFI_COUNTRY_POLICY_MANUAL};
wifi_country_t country_CN = {.cc="CN", .schan=1, .nchan=13, .policy=WIFI_COUNTRY_POLICY_MANUAL};
ESP_LOGI(TAG, EMPH_STR("esp_wifi_get_country"));
TEST_ESP_OK(esp_wifi_get_country(&country));
TEST_ASSERT(country.cc[0] == country_01.cc[0] && country.cc[1] == country_01.cc[1]);
ESP_LOGI(TAG, EMPH_STR("esp_wifi_set_country"));
TEST_ESP_OK(esp_wifi_set_country(&country_CN));
ESP_LOGI(TAG, EMPH_STR("esp_wifi_get_country"));
TEST_ESP_OK(esp_wifi_get_country(&country));
TEST_ASSERT(country.cc[0] == country_CN.cc[0] && country.cc[1] == country_CN.cc[1]);
ESP_LOGI(TAG, EMPH_STR("esp_wifi_deinit"));
TEST_ESP_OK(esp_wifi_deinit());
ESP_LOGI(TAG, EMPH_STR("event_deinit"));
TEST_ESP_OK(event_deinit());
ESP_LOGI(TAG, EMPH_STR("nvs_flash_deinit..."));
nvs_flash_deinit();
ESP_LOGI(TAG, EMPH_STR("nvs_flash_erase"));
nvs_flash_erase();
ESP_LOGI(TAG, EMPH_STR("nvs_flash_init"));
r = nvs_flash_init();
if (r == ESP_ERR_NVS_NO_FREE_PAGES || r == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_LOGI(TAG, EMPH_STR("no free pages or NFS version mismatch, erase.."));
TEST_ESP_OK(nvs_flash_erase());
r = nvs_flash_init();
}
TEST_ESP_OK(r);
//init tcpip stack
test_case_uses_tcpip();
ESP_LOGI(TAG, EMPH_STR("event_init"));
TEST_ESP_OK(event_init());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_init"));
TEST_ESP_OK(esp_wifi_init(&cfg));
char country_code_string[3];
char country_code_string_01[3] = "01";
char country_code_string_CN[3] = "CN";
ESP_LOGI(TAG, EMPH_STR("esp_wifi_get_country_code"));
TEST_ESP_OK(esp_wifi_get_country_code(&country_code_string[0]));
TEST_ASSERT(country_code_string[0] == country_code_string_01[0] && country_code_string[1] == country_code_string_01[1]);
ESP_LOGI(TAG, EMPH_STR("esp_wifi_set_country_code"));
TEST_ESP_OK(esp_wifi_set_country_code(&country_code_string_CN[0], false));
ESP_LOGI(TAG, EMPH_STR("esp_wifi_get_country_code"));
TEST_ESP_OK(esp_wifi_get_country_code(&country_code_string[0]));
TEST_ASSERT(country_code_string[0] == country_code_string_CN[0] && country_code_string[1] == country_code_string_CN[1]);
ESP_LOGI(TAG, EMPH_STR("esp_wifi_deinit"));
TEST_ESP_OK(esp_wifi_deinit());
ESP_LOGI(TAG, EMPH_STR("event_deinit"));
TEST_ESP_OK(event_deinit());
ESP_LOGI(TAG, EMPH_STR("nvs_flash_deinit..."));
nvs_flash_deinit();
ESP_LOGI(TAG, "test passed...");
xSemaphoreGive(*sema);
vTaskSuspend(NULL);
}
TEST_CASE("wifi set country code", "[wifi_init]")
{
TaskHandle_t th = NULL;
SemaphoreHandle_t sema = xSemaphoreCreateBinary();
TEST_ASSERT_NOT_NULL(sema);
printf("Creating tasks\n");
#ifndef CONFIG_FREERTOS_UNICORE
xTaskCreatePinnedToCore(wifi_country_code_task, "wifi_country_code_task", 2048*2, &sema, 3, &th, 0);
#else
xTaskCreate(wifi_country_code_task, "wifi_country_code_task", 2048*2, &sema, 3, &th);
#endif
TEST_ASSERT_NOT_NULL(th);
xSemaphoreTake(sema, portMAX_DELAY);
vSemaphoreDelete(sema);
sema = NULL;
unity_utils_task_delete(th);
}
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)

View File

@ -0,0 +1,12 @@
#This is the project CMakeLists.txt file for the test subproject
cmake_minimum_required(VERSION 3.16)
set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
if($ENV{CI_PIPELINE_ID})
idf_build_set_property(COMPILE_DEFINITIONS TEST_SUFFIX_STR="_$ENV{CI_PIPELINE_ID}" APPEND)
endif()
project(wifi_conn_test)

View File

@ -0,0 +1,2 @@
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- |

View File

@ -1,5 +1,4 @@
idf_component_register(SRC_DIRS .
PRIV_INCLUDE_DIRS . ${CMAKE_CURRENT_BINARY_DIR}
PRIV_REQUIRES cmock test_utils nvs_flash ulp esp_common esp_wifi esp_event
)
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
WHOLE_ARCHIVE)

View File

@ -0,0 +1,54 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include "unity.h"
#include "nvs_flash.h"
#include "nvs.h"
#include "esp_err.h"
#include "esp_netif.h"
#include "esp_wifi.h"
#include "esp_heap_caps.h"
// Some resources are lazy allocated in wifi and lwip
#define TEST_MEMORY_LEAK_THRESHOLD (-4096)
static size_t before_free_8bit;
static size_t before_free_32bit;
static void check_leak(size_t before_free, size_t after_free, const char *type)
{
ssize_t delta = after_free - before_free;
printf("MALLOC_CAP_%s: Before %u bytes free, After %u bytes free (delta %d)\n", type, before_free, after_free, delta);
TEST_ASSERT_MESSAGE(delta >= TEST_MEMORY_LEAK_THRESHOLD, "memory leak");
}
void setUp(void)
{
before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
cfg.nvs_enable = false;
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
}
void tearDown(void)
{
ESP_ERROR_CHECK(esp_wifi_deinit());
size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
check_leak(before_free_8bit, after_free_8bit, "8BIT");
check_leak(before_free_32bit, after_free_32bit, "32BIT");
}
void app_main(void)
{
ESP_ERROR_CHECK(nvs_flash_init());
ESP_ERROR_CHECK(esp_netif_init());
unity_run_menu();
ESP_ERROR_CHECK(esp_netif_deinit());
ESP_ERROR_CHECK(nvs_flash_deinit());
}

View File

@ -0,0 +1,268 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*
* This test code is in the Public Domain (or CC0 licensed, at your option.)
*
* Unless required by applicable law or agreed to in writing, this
* software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include <string.h>
#include "unity.h"
#include "esp_mac.h"
#include "esp_event.h"
#include "esp_wifi.h"
#include "esp_wifi_types.h"
#include "esp_log.h"
#include "nvs_flash.h"
#include "test_utils.h"
#include "memory_checks.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#ifndef TEST_SUFFIX_STR
#define TEST_SUFFIX_STR "_0000"
#endif
#define TEST_DEFAULT_SSID "SSID_" CONFIG_IDF_TARGET TEST_SUFFIX_STR
#define TEST_DEFAULT_PWD "PASS_" CONFIG_IDF_TARGET TEST_SUFFIX_STR
#define TEST_DEFAULT_CHANNEL (1)
#define CONNECT_TIMEOUT_MS (7000)
#define GOT_IP_EVENT (1)
#define WIFI_DISCONNECT_EVENT (1<<1)
#define WIFI_STA_CONNECTED (1<<2)
#define WIFI_AP_STA_CONNECTED (1<<3)
#define EVENT_HANDLER_FLAG_DO_NOT_AUTO_RECONNECT 0x00000001
static const char* TAG = "test_wifi";
static uint32_t wifi_event_handler_flag;
static esp_netif_t* s_ap_netif = NULL;
static esp_netif_t* s_sta_netif = NULL;
static EventGroupHandle_t wifi_events;
static void wifi_event_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data)
{
ESP_LOGI(TAG, "wifi event handler: %"PRIi32, event_id);
switch(event_id) {
case WIFI_EVENT_STA_START:
ESP_LOGI(TAG, "WIFI_EVENT_STA_START");
break;
case WIFI_EVENT_AP_STACONNECTED:
ESP_LOGI(TAG, "WIFI_EVENT_AP_STACONNECTED");
if (wifi_events) {
xEventGroupSetBits(wifi_events, WIFI_AP_STA_CONNECTED);
}
break;
case WIFI_EVENT_STA_CONNECTED:
ESP_LOGI(TAG, "WIFI_EVENT_STA_CONNECTED");
if (wifi_events) {
xEventGroupSetBits(wifi_events, WIFI_AP_STA_CONNECTED);
}
break;
case WIFI_EVENT_STA_DISCONNECTED:
ESP_LOGI(TAG, "WIFI_EVENT_STA_DISCONNECTED");
if (! (EVENT_HANDLER_FLAG_DO_NOT_AUTO_RECONNECT & wifi_event_handler_flag) ) {
TEST_ESP_OK(esp_wifi_connect());
}
if (wifi_events) {
xEventGroupSetBits(wifi_events, WIFI_DISCONNECT_EVENT);
}
break;
default:
break;
}
return;
}
static void ip_event_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data)
{
ip_event_got_ip_t *event;
ESP_LOGI(TAG, "ip event handler");
switch(event_id) {
case IP_EVENT_STA_GOT_IP:
event = (ip_event_got_ip_t*)event_data;
ESP_LOGI(TAG, "IP_EVENT_STA_GOT_IP");
ESP_LOGI(TAG, "got ip:" IPSTR "\n", IP2STR(&event->ip_info.ip));
if (wifi_events) {
xEventGroupSetBits(wifi_events, GOT_IP_EVENT);
}
break;
default:
break;
}
return;
}
static esp_err_t event_init(void)
{
ESP_ERROR_CHECK(esp_event_loop_create_default());
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL));
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, &ip_event_handler, NULL));
s_sta_netif = esp_netif_create_default_wifi_sta();
s_ap_netif = esp_netif_create_default_wifi_ap();
return ESP_OK;
}
static esp_err_t event_deinit(void)
{
ESP_ERROR_CHECK(esp_event_handler_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler));
ESP_ERROR_CHECK(esp_event_handler_unregister(IP_EVENT, ESP_EVENT_ANY_ID, &ip_event_handler));
esp_netif_destroy_default_wifi(s_sta_netif);
esp_netif_destroy_default_wifi(s_ap_netif);
ESP_ERROR_CHECK(esp_event_loop_delete_default());
return ESP_OK;
}
#define EMPH_STR(s) "****** "s" ******"
static void start_wifi_as_softap(void)
{
wifi_config_t w_config = {
.ap.ssid = TEST_DEFAULT_SSID,
.ap.password = TEST_DEFAULT_PWD,
.ap.ssid_len = strlen(TEST_DEFAULT_SSID),
.ap.channel = TEST_DEFAULT_CHANNEL,
.ap.authmode = WIFI_AUTH_WPA2_PSK,
.ap.ssid_hidden = false,
.ap.max_connection = 4,
.ap.beacon_interval = 100,
};
event_init();
if (wifi_events == NULL) {
wifi_events = xEventGroupCreate();
}
xEventGroupClearBits(wifi_events, 0x00ffffff);
TEST_ESP_OK(esp_wifi_set_mode(WIFI_MODE_AP));
TEST_ESP_OK(esp_wifi_set_config(WIFI_IF_AP, &w_config));
TEST_ESP_OK(esp_wifi_start());
ESP_LOGI(TAG, "start wifi softap: %s", TEST_DEFAULT_SSID);
}
static void start_wifi_as_sta(void)
{
event_init();
if (wifi_events == NULL) {
wifi_events = xEventGroupCreate();
}
xEventGroupClearBits(wifi_events, 0x00ffffff);
TEST_ESP_OK(esp_wifi_set_mode(WIFI_MODE_STA));
TEST_ESP_OK(esp_wifi_start());
}
static void stop_wifi(void)
{
TEST_ESP_OK(esp_wifi_stop());
event_deinit();
if (wifi_events) {
vEventGroupDelete(wifi_events);
wifi_events = NULL;
}
vTaskDelay(500/portTICK_PERIOD_MS);
}
static void receive_ds2ds_packet(void)
{
start_wifi_as_softap();
// wait for sender to send packets
vTaskDelay(1000/portTICK_PERIOD_MS);
stop_wifi();
}
static const char ds2ds_pdu[] = {
0x48, 0x03, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xE8, 0x65, 0xD4, 0xCB, 0x74, 0x19, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x60, 0x94, 0xE8, 0x65, 0xD4, 0xCB, 0x74, 0x1C, 0x26, 0xB9,
0x0D, 0x02, 0x7D, 0x13, 0x00, 0x00, 0x01, 0xE8, 0x65, 0xD4, 0xCB, 0x74,
0x1C, 0x00, 0x00, 0x26, 0xB9, 0x00, 0x00, 0x00, 0x00
};
static void send_ds2ds_packet(void)
{
start_wifi_as_softap();
// send packet 20 times to make sure receiver will get this packet
for (uint16_t i = 0; i < 20; i++) {
esp_wifi_80211_tx(WIFI_IF_AP, ds2ds_pdu, sizeof(ds2ds_pdu), true);
vTaskDelay(50 / portTICK_PERIOD_MS);
}
vTaskDelay(500/portTICK_PERIOD_MS);
stop_wifi();
}
TEST_CASE_MULTIPLE_DEVICES("send receive ds2ds packet without exception", "[wifi]", receive_ds2ds_packet, send_ds2ds_packet);
static void wifi_connect(void)
{
EventBits_t bits;
wifi_config_t w_config = {
.sta.ssid = TEST_DEFAULT_SSID,
.sta.password = TEST_DEFAULT_PWD,
};
TEST_ESP_OK(esp_wifi_set_config(WIFI_IF_STA, &w_config));
TEST_ESP_OK(esp_wifi_connect());
ESP_LOGI(TAG, "start esp_wifi_connect: %s", TEST_DEFAULT_SSID);
bits = xEventGroupWaitBits(wifi_events, GOT_IP_EVENT, 1, 0, CONNECT_TIMEOUT_MS/portTICK_PERIOD_MS);
TEST_ASSERT(bits & GOT_IP_EVENT);
}
static void test_wifi_connection_sta(void)
{
EventBits_t bits;
start_wifi_as_sta();
// make sure softap has started
vTaskDelay(1000/portTICK_PERIOD_MS);
wifi_connect();
// do not auto reconnect after connected
xEventGroupClearBits(wifi_events, WIFI_DISCONNECT_EVENT);
wifi_event_handler_flag |= EVENT_HANDLER_FLAG_DO_NOT_AUTO_RECONNECT;
// disconnect event not triggered after 60s
bits = xEventGroupWaitBits(wifi_events, WIFI_DISCONNECT_EVENT, 1, 0, 60000 / portTICK_PERIOD_MS);
TEST_ASSERT((bits & WIFI_DISCONNECT_EVENT) == 0);
stop_wifi();
}
static void test_wifi_connection_softap(void)
{
EventBits_t bits;
start_wifi_as_softap();
// wait station connected
bits = xEventGroupWaitBits(wifi_events, WIFI_AP_STA_CONNECTED, 1, 0, CONNECT_TIMEOUT_MS/portTICK_PERIOD_MS);
TEST_ASSERT(bits & WIFI_AP_STA_CONNECTED);
// wait 70s (longer than station side)
vTaskDelay((60000 + CONNECT_TIMEOUT_MS) / portTICK_PERIOD_MS);
stop_wifi();
}
TEST_CASE_MULTIPLE_DEVICES("test wifi retain connection for 60s", "[wifi][timeout=90]", test_wifi_connection_sta, test_wifi_connection_softap);

View File

@ -0,0 +1,12 @@
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Unlicense OR CC0-1.0
import pytest
@pytest.mark.esp32
@pytest.mark.esp32c3
@pytest.mark.wifi_two_dut
@pytest.mark.parametrize('count', [2], indirect=True)
def test_wifi_connect_cases(case_tester) -> None: # type: ignore
case_tester.run_all_cases()

View File

@ -0,0 +1,3 @@
# ignore task watchdog triggered by unity_run_menu
CONFIG_ESP_TASK_WDT=n

View File

@ -0,0 +1,7 @@
#This is the project CMakeLists.txt file for the test subproject
cmake_minimum_required(VERSION 3.16)
set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(wifi_test)

View File

@ -0,0 +1,3 @@
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- |

View File

@ -0,0 +1,4 @@
idf_component_register(SRC_DIRS .
PRIV_INCLUDE_DIRS . ${CMAKE_CURRENT_BINARY_DIR}
PRIV_REQUIRES cmock test_utils nvs_flash ulp esp_common esp_wifi esp_event
WHOLE_ARCHIVE)

View File

@ -0,0 +1,49 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include "unity.h"
#include "nvs_flash.h"
#include "nvs.h"
#include "esp_err.h"
#include "esp_netif.h"
#include "esp_heap_caps.h"
// Some resources are lazy allocated in wifi or event handler
#define TEST_MEMORY_LEAK_THRESHOLD (-4096)
static size_t before_free_8bit;
static size_t before_free_32bit;
static void check_leak(size_t before_free, size_t after_free, const char *type)
{
ssize_t delta = after_free - before_free;
printf("MALLOC_CAP_%s: Before %u bytes free, After %u bytes free (delta %d)\n", type, before_free, after_free, delta);
TEST_ASSERT_MESSAGE(delta >= TEST_MEMORY_LEAK_THRESHOLD, "memory leak");
}
void setUp(void)
{
before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
}
void tearDown(void)
{
size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
check_leak(before_free_8bit, after_free_8bit, "8BIT");
check_leak(before_free_32bit, after_free_32bit, "32BIT");
}
void app_main(void)
{
ESP_ERROR_CHECK(nvs_flash_init());
ESP_ERROR_CHECK(esp_netif_init());
unity_run_menu();
ESP_ERROR_CHECK(esp_netif_deinit());
ESP_ERROR_CHECK(nvs_flash_deinit());
}

View File

@ -0,0 +1,63 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include "unity.h"
#include "esp_wifi.h"
#include "esp_log.h"
#include "test_utils.h"
#include "unity_test_utils.h"
#define TAG "test_wifi"
#define EMPH_STR(s) "****** "s" ******"
TEST_CASE("wifi set country code", "[wifi_init]")
{
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
cfg.nvs_enable = false;
ESP_LOGI(TAG, EMPH_STR("esp_wifi_init"));
TEST_ESP_OK(esp_wifi_init(&cfg));
wifi_country_t country;
wifi_country_t country_01 = {.cc="01", .schan=1, .nchan=11, .policy=WIFI_COUNTRY_POLICY_MANUAL};
wifi_country_t country_CN = {.cc="CN", .schan=1, .nchan=13, .policy=WIFI_COUNTRY_POLICY_MANUAL};
ESP_LOGI(TAG, EMPH_STR("esp_wifi_get_country (default)"));
TEST_ESP_OK(esp_wifi_get_country(&country));
TEST_ASSERT(country.cc[0] == country_01.cc[0] && country.cc[1] == country_01.cc[1]);
ESP_LOGI(TAG, EMPH_STR("esp_wifi_set_country"));
TEST_ESP_OK(esp_wifi_set_country(&country_CN));
ESP_LOGI(TAG, EMPH_STR("esp_wifi_get_country"));
TEST_ESP_OK(esp_wifi_get_country(&country));
TEST_ASSERT(country.cc[0] == country_CN.cc[0] && country.cc[1] == country_CN.cc[1]);
ESP_LOGI(TAG, EMPH_STR("esp_wifi_deinit"));
TEST_ESP_OK(esp_wifi_deinit());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_init"));
TEST_ESP_OK(esp_wifi_init(&cfg));
char country_code_string[3];
char country_code_string_01[3] = "01";
char country_code_string_CN[3] = "CN";
ESP_LOGI(TAG, EMPH_STR("esp_wifi_get_country_code (default)"));
TEST_ESP_OK(esp_wifi_get_country_code(&country_code_string[0]));
TEST_ASSERT(country_code_string[0] == country_code_string_01[0] && country_code_string[1] == country_code_string_01[1]);
ESP_LOGI(TAG, EMPH_STR("esp_wifi_set_country_code"));
TEST_ESP_OK(esp_wifi_set_country_code(&country_code_string_CN[0], false));
ESP_LOGI(TAG, EMPH_STR("esp_wifi_get_country_code"));
TEST_ESP_OK(esp_wifi_get_country_code(&country_code_string[0]));
TEST_ASSERT(country_code_string[0] == country_code_string_CN[0] && country_code_string[1] == country_code_string_CN[1]);
ESP_LOGI(TAG, EMPH_STR("esp_wifi_deinit"));
TEST_ESP_OK(esp_wifi_deinit());
ESP_LOGI(TAG, "test passed...");
}

View File

@ -0,0 +1,141 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include "unity.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_log.h"
#include "test_utils.h"
#include "freertos/event_groups.h"
#include "unity_test_utils.h"
#define EMPH_STR(s) "****** "s" ******"
static const char* TAG = "test_wifi_init";
static void wifi_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data)
{
printf("wifi event handle called.\n");
switch(event_id) {
case WIFI_EVENT_AP_START:
ESP_LOGI(TAG, "WIFI_EVENT_AP_START");
break;
case WIFI_EVENT_STA_START:
ESP_LOGI(TAG, "WIFI_EVENT_STA_START");
break;
case WIFI_EVENT_STA_DISCONNECTED:
ESP_LOGI(TAG, "WIFI_EVENT_STA_DISCONNECTED");
break;
default:
break;
}
return;
}
static esp_err_t event_init(void)
{
ESP_ERROR_CHECK(esp_event_loop_create_default());
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL));
return ESP_OK;
}
static esp_err_t event_deinit(void)
{
ESP_ERROR_CHECK(esp_event_handler_unregister(WIFI_EVENT,ESP_EVENT_ANY_ID,&wifi_event_handler));
ESP_ERROR_CHECK(esp_event_loop_delete_default());
return ESP_OK;
}
static void wifi_driver_can_start_on_APP_CPU_task(void* arg)
{
SemaphoreHandle_t *sema = (SemaphoreHandle_t *) arg;
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_LOGI(TAG, EMPH_STR("event_init"));
TEST_ESP_OK(event_init());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_init"));
TEST_ESP_OK(esp_wifi_init(&cfg));
ESP_LOGI(TAG, EMPH_STR("esp_wifi_deinit..."));
TEST_ESP_OK(esp_wifi_deinit());
ESP_LOGI(TAG, EMPH_STR("event_deinit"));
TEST_ESP_OK(event_deinit());
ESP_LOGI(TAG, "exit task...");
xSemaphoreGive(*sema);
vTaskSuspend(NULL); // wait to be deleted
}
TEST_CASE("wifi driver can start on APP CPU", "[wifi_init]")
{
TaskHandle_t th = NULL;
SemaphoreHandle_t sema = xSemaphoreCreateBinary();
TEST_ASSERT_NOT_NULL(sema);
printf("Creating tasks\n");
#ifndef CONFIG_FREERTOS_UNICORE
xTaskCreatePinnedToCore(wifi_driver_can_start_on_APP_CPU_task, "wifi_driver_can_start_on_APP_CPU_task", 2048*2, &sema, 3, &th, 1);
#else
xTaskCreate(wifi_driver_can_start_on_APP_CPU_task, "wifi_driver_can_start_on_APP_CPU_task", 2048*2, &sema, 3, &th);
#endif
TEST_ASSERT_NOT_NULL(th);
xSemaphoreTake(sema, portMAX_DELAY);
vSemaphoreDelete(sema);
sema = NULL;
unity_utils_task_delete(th);
}
TEST_CASE("Calling esp_wifi_stop() with start", "[wifi_init]")
{
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_LOGI(TAG, EMPH_STR("event_init"));
TEST_ESP_OK(event_init());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_init"));
TEST_ESP_OK(esp_wifi_init(&cfg));
ESP_LOGI(TAG, EMPH_STR("esp_wifi_start"));
TEST_ESP_OK(esp_wifi_start());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_stop"));
TEST_ESP_OK(esp_wifi_stop());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_deinit"));
TEST_ESP_OK(esp_wifi_deinit());
ESP_LOGI(TAG, EMPH_STR("event_deinit"));
TEST_ESP_OK(event_deinit());
ESP_LOGI(TAG, "test passed...");
}
TEST_CASE("Calling esp_wifi_stop() without start", "[wifi_init]")
{
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_LOGI(TAG, EMPH_STR("event_init"));
TEST_ESP_OK(event_init());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_init"));
TEST_ESP_OK(esp_wifi_init(&cfg));
ESP_LOGI(TAG, EMPH_STR("esp_wifi_stop"));
TEST_ESP_OK(esp_wifi_stop());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_deinit"));
TEST_ESP_OK(esp_wifi_deinit());
ESP_LOGI(TAG, EMPH_STR("event_deinit"));
TEST_ESP_OK(event_deinit());
ESP_LOGI(TAG, "test passed...");
}
TEST_CASE("Calling esp_wifi_deinit() without stop", "[wifi_init]")
{
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_LOGI(TAG, EMPH_STR("event_init"));
TEST_ESP_OK(event_init());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_init"));
TEST_ESP_OK(esp_wifi_init(&cfg));
ESP_LOGI(TAG, EMPH_STR("esp_wifi_start"));
TEST_ESP_OK(esp_wifi_start());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_deinit"));
TEST_ESP_ERR(ESP_ERR_WIFI_NOT_STOPPED, esp_wifi_deinit());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_stop"));
TEST_ESP_OK(esp_wifi_stop());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_deinit"));
TEST_ESP_OK(esp_wifi_deinit());
ESP_LOGI(TAG, EMPH_STR("event_deinit"));
TEST_ESP_OK(event_deinit());
ESP_LOGI(TAG, "test passed...");
}

View File

@ -0,0 +1,13 @@
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Unlicense OR CC0-1.0
import pytest
from pytest_embedded import Dut
@pytest.mark.supported_targets
@pytest.mark.generic
def test_wifi_unit_test(dut: Dut) -> None:
dut.expect_exact('Press ENTER to see the list of tests')
dut.write('*')
dut.expect_unity_test_output()

View File

@ -0,0 +1,3 @@
# ignore task watchdog triggered by unity_run_menu
CONFIG_ESP_TASK_WDT=n

View File

@ -35,7 +35,7 @@ from pytest_embedded.utils import find_by_suffix
from pytest_embedded_idf.dut import IdfDut
try:
from tools.ci.idf_unity_tester import CaseTester
from idf_unity_tester import CaseTester
except ImportError:
sys.path.append(os.path.join(os.path.dirname(__file__), 'tools', 'ci'))
from idf_unity_tester import CaseTester

View File

@ -206,7 +206,7 @@ class MultiDevCaseTester(BaseTester):
dev_res = MultiDevResource(dut)
self.group.append(dev_res)
def _wait_multi_dev_case_finish(self, timeout: int = 90) -> None:
def _wait_multi_dev_case_finish(self, timeout: int = 60) -> None:
"""
Wait until all the sub-cases of this multi_device case finished
"""
@ -216,7 +216,7 @@ class MultiDevCaseTester(BaseTester):
else:
raise TimeoutError('Wait case to finish timeout')
def _start_sub_case_thread(self, dev_res: MultiDevResource, case: UnittestMenuCase, sub_case_index: int) -> None:
def _start_sub_case_thread(self, dev_res: MultiDevResource, case: UnittestMenuCase, sub_case_index: int, timeout: int = 60) -> None:
"""
Start the thread monitoring on the corresponding dut of the sub-case
"""
@ -226,6 +226,7 @@ class MultiDevCaseTester(BaseTester):
_kwargs['dev_res'] = dev_res
_kwargs['case'] = case
_kwargs['sub_case_index'] = sub_case_index
_kwargs['timeout'] = timeout
# Create the thread of the sub-case
dev_res.thread = Thread(target=self._run, kwargs=_kwargs, daemon=True)
@ -254,6 +255,7 @@ class MultiDevCaseTester(BaseTester):
dev_res = kwargs['dev_res']
case = kwargs['case']
sub_case_index = kwargs['sub_case_index']
timeout = kwargs['timeout']
# Start the case
dut.expect(self.ready_pattern_list)
# Retry at most 30 times if not write successfully
@ -271,7 +273,7 @@ class MultiDevCaseTester(BaseTester):
# Wait for the specific patterns, only exist when the sub-case finished
while True:
pat = dut.expect(signal_pattern_list, timeout=60)
pat = dut.expect(signal_pattern_list, timeout=timeout)
if pat is not None:
match_str = pat.group().decode('utf-8')
@ -302,7 +304,7 @@ class MultiDevCaseTester(BaseTester):
# The case finished, release the semaphore to unblock the '_wait_multi_dev_case_finish'
dev_res.sem.release()
def run_all_multi_dev_cases(self, reset: bool = False, timeout: int = 90) -> None:
def run_all_multi_dev_cases(self, reset: bool = False, timeout: int = 60) -> None:
"""
Run only multi_device cases
@ -314,7 +316,7 @@ class MultiDevCaseTester(BaseTester):
# Run multi_device case on every device
self.run_multi_dev_case(case, reset, timeout)
def run_multi_dev_case(self, case: UnittestMenuCase, reset: bool = False, timeout: int = 90) -> None:
def run_multi_dev_case(self, case: UnittestMenuCase, reset: bool = False, timeout: int = 60) -> None:
"""
Run a specific multi_device case
@ -335,8 +337,8 @@ class MultiDevCaseTester(BaseTester):
index = int(sub_case['index'], 10)
else:
index = sub_case['index']
self._start_sub_case_thread(dev_res=self.group[index - 1],
case=case, sub_case_index=index)
self._start_sub_case_thread(dev_res=self.group[index - 1], case=case,
sub_case_index=index, timeout=timeout)
# Waiting all the devices to finish their test cases
self._wait_multi_dev_case_finish(timeout=timeout)
@ -351,7 +353,7 @@ class CaseTester(NormalCaseTester, MultiStageCaseTester, MultiDevCaseTester):
test_menu (List[UnittestMenuCase]): The list of the cases
"""
def run_all_cases(self, reset: bool = False, timeout: int = 90) -> None:
def run_all_cases(self, reset: bool = False, timeout: int = 60) -> None:
"""
Run all cases
@ -362,18 +364,19 @@ class CaseTester(NormalCaseTester, MultiStageCaseTester, MultiDevCaseTester):
for case in self.test_menu:
self.run_case(case, reset, timeout=timeout)
def run_case(self, case: UnittestMenuCase, reset: bool = False, timeout: int = 90) -> None:
def run_case(self, case: UnittestMenuCase, reset: bool = False, timeout: int = 60) -> None:
"""
Run a specific case
Args:
case: the specific case that parsed in test menu
reset: whether do a hardware reset before running the case
timeout: timeout in second
timeout: timeout in second, the case's timeout attribute has a higher priority than this param.
"""
_timeout = int(case.attributes.get('timeout', timeout))
if case.type == 'normal':
self.run_normal_case(case, reset, timeout=timeout)
self.run_normal_case(case, reset, timeout=_timeout)
elif case.type == 'multi_stage':
self.run_multi_stage_case(case, reset, timeout=timeout)
self.run_multi_stage_case(case, reset, timeout=_timeout)
elif case.type == 'multi_device':
self.run_multi_dev_case(case, reset, timeout=timeout)
self.run_multi_dev_case(case, reset, timeout=_timeout)