mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
ESP-NETIF: add CI compile only tests for common init/config pattern in C/C++
This commit is contained in:
parent
50588ff3f7
commit
9bdcd40f2b
@ -0,0 +1,6 @@
|
||||
# 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.5)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(esp_netif_build_config)
|
11
tools/test_apps/protocols/esp_netif/build_config/README.md
Normal file
11
tools/test_apps/protocols/esp_netif/build_config/README.md
Normal file
@ -0,0 +1,11 @@
|
||||
# Build only test for C++/C configuration
|
||||
|
||||
This test application aims to exercise different configuration options using standard espressif initialization pattern:
|
||||
```
|
||||
component_config cfg = COMPONENT_DEFAULT_CFG();
|
||||
cfg.member1 = custom_config_for_member1;
|
||||
...
|
||||
cfg.memberN = custom_config_for_memberN;
|
||||
esp_err_t = component_init(cfg);
|
||||
```
|
||||
To be build with both C++ and C compilers.
|
@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "netif_init_c99.c" "main.cpp" "netif_init_cpp.cpp"
|
||||
INCLUDE_DIRS ".")
|
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "esp_compiler.h"
|
||||
|
||||
typedef struct {
|
||||
const char * char_star;
|
||||
const char char_array[10];
|
||||
int x;
|
||||
float y;
|
||||
struct var_struct_t {
|
||||
} var_struct;
|
||||
} g_netif_test_struct_t;
|
||||
|
||||
#define NETIF_TEST_STRUCT_EMPTY() \
|
||||
{ \
|
||||
ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(char_star) \
|
||||
ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(char_array) \
|
||||
.x = 0, \
|
||||
.y = 0.0, \
|
||||
ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(var_struct) \
|
||||
}
|
||||
|
||||
#define NETIF_TEST_STRUCT_DEFAULT() \
|
||||
{ \
|
||||
.char_star = "Espressif", \
|
||||
ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_STR(char_array, "Espressif") \
|
||||
.x = 42, \
|
||||
.y = 42.192, \
|
||||
ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(var_struct) \
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
/* Test only application
|
||||
|
||||
This example 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 "esp_system.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
static const char *TAG = "build only test";
|
||||
|
||||
extern "C" void esp_netif_compile_test_c99();
|
||||
void esp_netif_compile_test_cpp(void);
|
||||
|
||||
extern "C" void app_main(void)
|
||||
{
|
||||
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_LOGE(TAG, "This is app is test only! It is not supposed to be executed!");
|
||||
// Calling CPP initialization tests
|
||||
esp_netif_compile_test_cpp();
|
||||
// Calling C initialization tests
|
||||
esp_netif_compile_test_c99();
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
/* Test only application
|
||||
|
||||
This example 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 "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
#include "init_macro.h"
|
||||
#include "esp_wps.h"
|
||||
|
||||
|
||||
static void s_init_wifi_netif(esp_netif_inherent_config_t* esp_netif_config)
|
||||
{
|
||||
esp_netif_config->if_desc = "custom wifi station";
|
||||
esp_netif_config->route_prio = 1;
|
||||
esp_netif_create_wifi(WIFI_IF_STA, esp_netif_config);
|
||||
esp_wifi_set_default_wifi_sta_handlers();
|
||||
}
|
||||
|
||||
static void s_use_test_config_struct(g_netif_test_struct_t* cfg)
|
||||
{
|
||||
printf("%s\n", cfg->char_star);
|
||||
}
|
||||
|
||||
static void test_wifi_init_custom(void)
|
||||
{
|
||||
|
||||
{
|
||||
esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_WIFI_STA();
|
||||
s_init_wifi_netif(&esp_netif_config);
|
||||
}
|
||||
|
||||
{
|
||||
esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_WIFI_AP();
|
||||
s_init_wifi_netif(&esp_netif_config);
|
||||
}
|
||||
|
||||
{
|
||||
esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_ETH();
|
||||
s_init_wifi_netif(&esp_netif_config);
|
||||
}
|
||||
|
||||
{
|
||||
esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_PPP();
|
||||
s_init_wifi_netif(&esp_netif_config);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_common_init_field(void)
|
||||
{
|
||||
{
|
||||
g_netif_test_struct_t cfg = NETIF_TEST_STRUCT_EMPTY();
|
||||
s_use_test_config_struct(&cfg);
|
||||
}
|
||||
{
|
||||
g_netif_test_struct_t cfg = NETIF_TEST_STRUCT_DEFAULT();
|
||||
s_use_test_config_struct(&cfg);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_wps_init(void)
|
||||
{
|
||||
esp_wps_config_t config = WPS_CONFIG_INIT_DEFAULT(WPS_TYPE_DISABLE);
|
||||
ESP_ERROR_CHECK(esp_wifi_wps_enable(&config));
|
||||
ESP_ERROR_CHECK(esp_wifi_wps_start(0));
|
||||
}
|
||||
|
||||
|
||||
void esp_netif_compile_test_c99(void)
|
||||
{
|
||||
test_wifi_init_custom();
|
||||
test_common_init_field();
|
||||
test_wps_init();
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
/* Test only application
|
||||
|
||||
This example 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 "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event.h"
|
||||
#include "init_macro.h"
|
||||
#include "esp_wps.h"
|
||||
|
||||
static void s_init_wifi_netif(esp_netif_inherent_config_t& esp_netif_config)
|
||||
{
|
||||
esp_netif_config.if_desc = "custom wifi station";
|
||||
esp_netif_config.route_prio = 1;
|
||||
esp_netif_create_wifi(WIFI_IF_STA, &esp_netif_config);
|
||||
esp_wifi_set_default_wifi_sta_handlers();
|
||||
}
|
||||
|
||||
static void s_use_test_config_struct(g_netif_test_struct_t& cfg)
|
||||
{
|
||||
printf("%s\n", cfg.char_star);
|
||||
}
|
||||
|
||||
static void test_wifi_init_custom(void)
|
||||
{
|
||||
|
||||
{
|
||||
esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_WIFI_STA();
|
||||
s_init_wifi_netif(esp_netif_config);
|
||||
}
|
||||
|
||||
{
|
||||
esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_WIFI_AP();
|
||||
s_init_wifi_netif(esp_netif_config);
|
||||
}
|
||||
|
||||
{
|
||||
esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_ETH();
|
||||
s_init_wifi_netif(esp_netif_config);
|
||||
}
|
||||
|
||||
{
|
||||
esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_PPP();
|
||||
s_init_wifi_netif(esp_netif_config);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_common_init_field(void)
|
||||
{
|
||||
{
|
||||
g_netif_test_struct_t cfg = NETIF_TEST_STRUCT_EMPTY();
|
||||
s_use_test_config_struct(cfg);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_wps_init(void)
|
||||
{
|
||||
esp_wps_config_t config = WPS_CONFIG_INIT_DEFAULT(WPS_TYPE_DISABLE);
|
||||
ESP_ERROR_CHECK(esp_wifi_wps_enable(&config));
|
||||
ESP_ERROR_CHECK(esp_wifi_wps_start(0));
|
||||
}
|
||||
|
||||
|
||||
void esp_netif_compile_test_cpp(void)
|
||||
{
|
||||
test_wifi_init_custom();
|
||||
test_common_init_field();
|
||||
test_wps_init();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user