-
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/wifi_mock' into 'master'
feat(linux): added very simple esp_wifi mock Closes IDFGH-9190 See merge request espressif/esp-idf!24400
- Loading branch information
Showing
13 changed files
with
212 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# NOTE: This kind of mocking currently works on Linux targets only. | ||
# On Espressif chips, too many dependencies are missing at the moment. | ||
message(STATUS "building ESP NETIF MOCKS") | ||
|
||
idf_component_get_property(original_esp_netif_dir esp_netif COMPONENT_OVERRIDEN_DIR) | ||
|
||
set(include_dirs | ||
"include" | ||
"${original_esp_netif_dir}/include" | ||
"${original_esp_netif_dir}/linux/stubs/include") | ||
|
||
idf_component_mock(INCLUDE_DIRS ${include_dirs} | ||
REQUIRES esp_event | ||
MOCK_HEADER_FILES ${original_esp_netif_dir}/include/esp_netif.h) |
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,15 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
/** | ||
* Since esp_netif_obj is an opaque type (not defined, just declared), we define it here | ||
* since its size is required by some of the mock functions. | ||
*/ | ||
struct esp_netif_obj { | ||
void *dummy; | ||
}; |
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,12 @@ | ||
:cmock: | ||
:includes_c_pre_header: | ||
# This is to define the esp_netif_t object, CMock needs its size for expect functions | ||
- esp_netif_mock.h | ||
:plugins: | ||
- expect | ||
- expect_any_args | ||
- return_thru_ptr | ||
- array | ||
- ignore | ||
- ignore_arg | ||
- callback |
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,26 @@ | ||
# NOTE: This kind of mocking currently works on Linux targets only. | ||
# On Espressif chips, too many dependencies are missing at the moment. | ||
message(STATUS "building ESP WIFI MOCKS") | ||
|
||
idf_component_get_property(original_esp_wifi_dir esp_wifi COMPONENT_OVERRIDEN_DIR) | ||
|
||
set(include_dirs | ||
"${original_esp_wifi_dir}/include") | ||
|
||
idf_component_mock(INCLUDE_DIRS ${include_dirs} | ||
REQUIRES esp_event esp_netif lwip | ||
MOCK_HEADER_FILES ${original_esp_wifi_dir}/include/esp_wifi.h | ||
${original_esp_wifi_dir}/include/esp_wifi_default.h | ||
${original_esp_wifi_dir}/include/esp_wifi_netif.h | ||
${original_esp_wifi_dir}/include/esp_wifi_he.h | ||
${original_esp_wifi_dir}/include/esp_wifi_ap_get_sta_list.h | ||
${original_esp_wifi_dir}/include/esp_smartconfig.h | ||
${original_esp_wifi_dir}/include/esp_mesh.h | ||
${original_esp_wifi_dir}/include/esp_now.h | ||
${original_esp_wifi_dir}/include/smartconfig_ack.h) | ||
|
||
# -Warray-parameter has been introduced in GCC 11 | ||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL "11.0.0") | ||
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-array-parameter) | ||
endif() | ||
target_sources(${COMPONENT_LIB} PRIVATE "global_symbols_mock.c") |
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,22 @@ | ||
# Mock Kconfig file to provide definitions | ||
menu "Wi-Fi" | ||
config ESP_WIFI_STATIC_RX_BUFFER_NUM | ||
int "Max number of WiFi static RX buffers" | ||
range 2 25 | ||
default 10 | ||
|
||
config ESP_WIFI_DYNAMIC_RX_BUFFER_NUM | ||
int "Max number of WiFi dynamic RX buffers" | ||
range 0 1024 | ||
default 32 | ||
|
||
config ESP_WIFI_TX_BUFFER_TYPE | ||
int | ||
default 1 | ||
|
||
config ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM | ||
int "Maximum espnow encrypt peers number" | ||
range 0 17 | ||
default 7 | ||
|
||
endmenu # Wi-Fi |
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,17 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "esp_wifi.h" | ||
|
||
/** | ||
* The following global objects are defined when WiFi is mocked. | ||
*/ | ||
|
||
const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs = { }; | ||
|
||
wifi_osi_funcs_t g_wifi_osi_funcs = { }; | ||
|
||
uint64_t g_wifi_feature_caps = 0; |
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,19 @@ | ||
:cmock: | ||
:includes_h_pre_header: | ||
- esp_netif_types.h | ||
:includes_c_pre_header: | ||
# Some types are not directly included in header files | ||
- esp_netif_types.h | ||
- esp_wifi_types.h | ||
- esp_netif_mock.h | ||
- esp_smartconfig.h | ||
:plugins: | ||
- expect | ||
- expect_any_args | ||
- return_thru_ptr | ||
- array | ||
- ignore | ||
- ignore_arg | ||
- callback | ||
:strippables: | ||
- '(?:ESP_EVENT_DECLARE_BASE\s*\([\s\w\*_,]*\))' |
11 changes: 11 additions & 0 deletions
11
tools/test_apps/linux_compatible/wifi_build_test/CMakeLists.txt
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,11 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
|
||
set(COMPONENTS main) | ||
list(APPEND EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/tools/mocks/esp_wifi) | ||
list(APPEND EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/tools/mocks/esp_netif) | ||
list(APPEND EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/tools/mocks/esp_event) | ||
list(APPEND EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/tools/mocks/lwip) | ||
|
||
project(wifi_build_test) |
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 @@ | ||
| Supported Targets | Linux | | ||
| ----------------- | ----- | | ||
|
||
This application is a build test. It checks that the WiFi mocks can be built correctly. Running it is possible but not useful. |
3 changes: 3 additions & 0 deletions
3
tools/test_apps/linux_compatible/wifi_build_test/main/CMakeLists.txt
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 @@ | ||
idf_component_register(SRCS "wifi_build_test.c" | ||
INCLUDE_DIRS "." | ||
PRIV_REQUIRES esp_wifi) |
68 changes: 68 additions & 0 deletions
68
tools/test_apps/linux_compatible/wifi_build_test/main/wifi_build_test.c
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 <stdio.h> | ||
|
||
#include "sdkconfig.h" | ||
#include "esp_wifi.h" | ||
#include "Mockesp_wifi.h" | ||
#include "Mockesp_wifi_default.h" | ||
#include "Mockesp_wifi_netif.h" | ||
#include "Mockesp_wifi_he.h" | ||
#include "Mockesp_wifi_ap_get_sta_list.h" | ||
#include "Mockesp_netif.h" | ||
#include "Mockesp_mesh.h" | ||
#include "Mockesp_now.h" | ||
#include "Mockesp_smartconfig.h" | ||
#include "Mocksmartconfig_ack.h" | ||
|
||
void app_main(void) | ||
{ | ||
esp_netif_init_IgnoreAndReturn(ESP_OK); | ||
ESP_ERROR_CHECK(esp_netif_init()); | ||
|
||
esp_netif_create_default_wifi_sta_IgnoreAndReturn(ESP_OK); | ||
esp_netif_create_default_wifi_sta(); | ||
|
||
esp_netif_create_default_wifi_ap_IgnoreAndReturn(ESP_OK); | ||
esp_netif_create_default_wifi_ap(); | ||
|
||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); | ||
esp_wifi_init_IgnoreAndReturn(ESP_OK); | ||
ESP_ERROR_CHECK(esp_wifi_init(&cfg)); | ||
|
||
esp_wifi_set_mode_IgnoreAndReturn(ESP_OK); | ||
esp_wifi_set_config_IgnoreAndReturn(ESP_OK); | ||
esp_wifi_start_IgnoreAndReturn(ESP_OK); | ||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) ); | ||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, NULL) ); | ||
ESP_ERROR_CHECK(esp_wifi_start() ); | ||
|
||
esp_wifi_connect_IgnoreAndReturn(ESP_OK); | ||
esp_wifi_connect(); | ||
|
||
esp_wifi_create_if_driver_IgnoreAndReturn(NULL); | ||
esp_wifi_create_if_driver((wifi_interface_t) NULL); | ||
|
||
esp_wifi_ap_get_sta_list_with_ip_IgnoreAndReturn(ESP_OK); | ||
esp_wifi_ap_get_sta_list_with_ip(NULL, NULL); | ||
|
||
esp_wifi_sta_itwt_setup_IgnoreAndReturn(ESP_OK); | ||
esp_wifi_sta_itwt_setup((wifi_twt_setup_config_t*) NULL); | ||
|
||
sc_send_ack_stop_Ignore(); | ||
sc_send_ack_stop(); | ||
|
||
esp_smartconfig_get_version_IgnoreAndReturn(NULL); | ||
esp_smartconfig_get_version(); | ||
|
||
esp_mesh_init_IgnoreAndReturn(ESP_OK); | ||
ESP_ERROR_CHECK(esp_mesh_init()); | ||
|
||
esp_now_init_IgnoreAndReturn(ESP_OK); | ||
ESP_ERROR_CHECK(esp_now_init()); | ||
|
||
printf("WiFi build test done\n"); | ||
} |
1 change: 1 addition & 0 deletions
1
tools/test_apps/linux_compatible/wifi_build_test/sdkconfig.defaults
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_IDF_TARGET="linux" |