Merge branch 'ci/add_size_check_for_wifi_configs' into 'master'

ci: add compare wifi bin size between different components

See merge request espressif/esp-idf!38499
This commit is contained in:
Chen Yu Dong
2025-05-08 22:35:50 +08:00
10 changed files with 133 additions and 5 deletions

View File

@@ -1,9 +1,5 @@
# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps
components/esp_wifi/test_apps/wifi_connect:
disable:
- if: SOC_WIFI_SUPPORTED != 1
components/esp_wifi/test_apps/wifi_function:
components/esp_wifi/test_apps/:
disable:
- if: SOC_WIFI_SUPPORTED != 1

View File

@@ -0,0 +1,8 @@
# The following five lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# "Trim" the build. Include the minimal set of components, main, and anything it depends on.
idf_build_set_property(MINIMAL_BUILD ON)
project(bin_size)

View File

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

View File

@@ -0,0 +1,3 @@
idf_component_register(SRCS "main.c"
PRIV_REQUIRES esp_wifi nvs_flash
INCLUDE_DIRS ".")

View File

@@ -0,0 +1,37 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include <string.h>
#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_log.h"
#include "nvs_flash.h"
static const char *TAG = "wifi-bin-size";
void app_main(void)
{
//Initialize NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
esp_netif_create_default_wifi_ap();
esp_netif_create_default_wifi_sta();
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_APSTA));
ESP_ERROR_CHECK(esp_wifi_start());
ESP_LOGI(TAG, "wifi_init finished.");
ESP_LOGI(TAG, "FREE_HEAP_SIZE: %u", esp_get_free_heap_size());
}

View File

@@ -0,0 +1,80 @@
# SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Unlicense OR CC0-1.0
import os
from typing import Callable
from typing import Tuple
import pytest
from pytest_embedded import Dut
from pytest_embedded_idf.utils import idf_parametrize
# The standard value has 30~100 bytes fault tolerance
SAVE_BIN_SIZE_TH = {
'disable_sae_h2e': {
'esp32': 16800,
'esp32c2': 19700,
'esp32c3': 19600,
'esp32c5': 19650,
'esp32c6': 19650,
'esp32c61': 19700,
'esp32s2': 16600,
'esp32s3': 16550,
'default': 16000,
},
'disable_nan': {
'esp32': 29600,
'esp32c5': 32400,
'esp32c61': 32400,
'esp32s2': 28000,
# other chips does not support nan
'default': 0,
},
}
def _get_diff_th(
config_name: str,
target: str,
) -> int:
assert config_name in SAVE_BIN_SIZE_TH
diff_threshold = SAVE_BIN_SIZE_TH[config_name]
return diff_threshold.get(target) or diff_threshold['default']
@pytest.mark.wifi_two_dut
@pytest.mark.parametrize(
'count, config, skip_autoflash',
[
(2, 'default|disable_sae_h2e', 'y'),
(2, 'default|enable_nan', 'y'),
],
indirect=True,
)
@idf_parametrize(
'target',
['esp32', 'esp32c2', 'esp32c3', 'esp32s2', 'esp32s3', 'esp32c5', 'esp32c6', 'esp32c61'],
indirect=['target'],
)
def test_wifi_bin_size_apsta(
dut: Tuple[Dut, Dut],
config: Tuple[str, str],
log_performance: Callable[[str, object], None],
) -> None:
# dut logs are not needed
dut[0].serial.close()
dut[1].serial.close()
target = dut[0].target
config_name = config[1]
app_default = dut[0].app
app_config = dut[1].app
diff = os.path.getsize(app_default.bin_file) - os.path.getsize(app_config.bin_file)
if 'enable' in config_name:
# always log disable-xxx performance
config_name = config_name.replace('enable', 'disable')
diff = -diff
log_performance(f'wifi_{config_name}_save_bin_size', f'{diff} bytes')
diff_threshold = _get_diff_th(config_name, target)
assert diff >= diff_threshold

View File

@@ -0,0 +1 @@
CONFIG_ESP_WIFI_ENABLE_SAE_H2E=n

View File

@@ -0,0 +1 @@
CONFIG_ESP_WIFI_NAN_ENABLE=y