From 9bdcd40f2bb223bde47395162b57499d4cd63b1e Mon Sep 17 00:00:00 2001 From: David Cermak Date: Mon, 10 Feb 2020 16:20:10 +0100 Subject: [PATCH] ESP-NETIF: add CI compile only tests for common init/config pattern in C/C++ --- .../esp_netif/build_config/CMakeLists.txt | 6 ++ .../esp_netif/build_config/README.md | 11 +++ .../build_config/main/CMakeLists.txt | 2 + .../esp_netif/build_config/main/init_macro.h | 30 +++++++ .../esp_netif/build_config/main/main.cpp | 33 ++++++++ .../build_config/main/netif_init_c99.c | 80 +++++++++++++++++++ .../build_config/main/netif_init_cpp.cpp | 75 +++++++++++++++++ 7 files changed, 237 insertions(+) create mode 100644 tools/test_apps/protocols/esp_netif/build_config/CMakeLists.txt create mode 100644 tools/test_apps/protocols/esp_netif/build_config/README.md create mode 100644 tools/test_apps/protocols/esp_netif/build_config/main/CMakeLists.txt create mode 100644 tools/test_apps/protocols/esp_netif/build_config/main/init_macro.h create mode 100644 tools/test_apps/protocols/esp_netif/build_config/main/main.cpp create mode 100644 tools/test_apps/protocols/esp_netif/build_config/main/netif_init_c99.c create mode 100644 tools/test_apps/protocols/esp_netif/build_config/main/netif_init_cpp.cpp diff --git a/tools/test_apps/protocols/esp_netif/build_config/CMakeLists.txt b/tools/test_apps/protocols/esp_netif/build_config/CMakeLists.txt new file mode 100644 index 000000000..e73e4a912 --- /dev/null +++ b/tools/test_apps/protocols/esp_netif/build_config/CMakeLists.txt @@ -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) diff --git a/tools/test_apps/protocols/esp_netif/build_config/README.md b/tools/test_apps/protocols/esp_netif/build_config/README.md new file mode 100644 index 000000000..d08acda7f --- /dev/null +++ b/tools/test_apps/protocols/esp_netif/build_config/README.md @@ -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. \ No newline at end of file diff --git a/tools/test_apps/protocols/esp_netif/build_config/main/CMakeLists.txt b/tools/test_apps/protocols/esp_netif/build_config/main/CMakeLists.txt new file mode 100644 index 000000000..f8f294e94 --- /dev/null +++ b/tools/test_apps/protocols/esp_netif/build_config/main/CMakeLists.txt @@ -0,0 +1,2 @@ +idf_component_register(SRCS "netif_init_c99.c" "main.cpp" "netif_init_cpp.cpp" + INCLUDE_DIRS ".") \ No newline at end of file diff --git a/tools/test_apps/protocols/esp_netif/build_config/main/init_macro.h b/tools/test_apps/protocols/esp_netif/build_config/main/init_macro.h new file mode 100644 index 000000000..06e68f04d --- /dev/null +++ b/tools/test_apps/protocols/esp_netif/build_config/main/init_macro.h @@ -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) \ + } diff --git a/tools/test_apps/protocols/esp_netif/build_config/main/main.cpp b/tools/test_apps/protocols/esp_netif/build_config/main/main.cpp new file mode 100644 index 000000000..374ff4295 --- /dev/null +++ b/tools/test_apps/protocols/esp_netif/build_config/main/main.cpp @@ -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(); +} \ No newline at end of file diff --git a/tools/test_apps/protocols/esp_netif/build_config/main/netif_init_c99.c b/tools/test_apps/protocols/esp_netif/build_config/main/netif_init_c99.c new file mode 100644 index 000000000..f2fe9f805 --- /dev/null +++ b/tools/test_apps/protocols/esp_netif/build_config/main/netif_init_c99.c @@ -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(); +} diff --git a/tools/test_apps/protocols/esp_netif/build_config/main/netif_init_cpp.cpp b/tools/test_apps/protocols/esp_netif/build_config/main/netif_init_cpp.cpp new file mode 100644 index 000000000..296157c4d --- /dev/null +++ b/tools/test_apps/protocols/esp_netif/build_config/main/netif_init_cpp.cpp @@ -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 +#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(); +} \ No newline at end of file