Start of 5.X work

This commit is contained in:
Sebastien L
2025-03-18 17:38:34 -04:00
parent c0ddf0a997
commit 73bd096f37
442 changed files with 227862 additions and 21075 deletions

View File

@@ -1,35 +1,102 @@
# This is the project CMakeLists.txt file for the test subproject
# This file is in the 'test' directory of your project
cmake_minimum_required(VERSION 3.5)
set(PROJECT_VER $ENV{PROJECT_VER})
add_definitions(-DMODEL_NAME=SqueezeESP32)
if(NOT DEFINED DEPTH)
set(DEPTH "16")
endif()
# State machine hierarchy enabled and logging enabled
add_definitions(-DSTATE_MACHINE_LOGGER=1)
add_definitions(-DHIERARCHICAL_STATES=1)
add_definitions(-DTESTPROJECT=1)
# Align the nanopb library options across the entire project
# otherwise this results in nasty structures misalignment
# when implementing callbacks
add_definitions(-DPB_ENABLE_MALLOC -DPB_FIELD_32BIT)
# Include the components directory to make the main components available
set(EXTRA_COMPONENT_DIRS "../components")
# Register the test components directory
list(APPEND EXTRA_COMPONENT_DIRS "test_main")
# Include the main ESP-IDF CMakeLists file
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# Include the components directory of the main application:
#
# Set the components to include the tests for.
# This can be overriden from CMake cache:
# - when invoking CMake directly: cmake -D TEST_COMPONENTS="xxxxx" ..
# - when using idf.py: idf.py -T xxxxx build
#
set(TEST_COMPONENTS "platform_console" CACHE STRING "List of components to test")
set(COMPONENTS main)
set(TEST_COMPONENTS "platform_config" "tools" "wifi-manager" CACHE STRING "List of components to test")
# manually add the console squeezelite component
list(APPEND EXTRA_COMPONENT_DIRS ../components/platform_console/recovery )
# Set the project name
project(squeezelite-esp32-test-project)
# Freertos is included via common components, however, currently only the mock component is compatible with linux
# target.
list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/freertos/")
list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/driver/")
list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/freertos/")
list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/spi_flash/")
list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/components/unity/")
idf_build_set_property(COMPILE_DEFINITIONS "-DNO_DEBUG_STORAGE" APPEND)
# list(APPEND EXTRA_COMPONENT_DIRS "${PROJECT_SOURCE_DIR}/../components")
# list(APPEND EXTRA_COMPONENT_DIRS "${PROJECT_SOURCE_DIR}/../components/tools")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../protobuf ${CMAKE_CURRENT_BINARY_DIR}/protobuf)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../spiffs_src ${CMAKE_CURRENT_BINARY_DIR}/spiffs)
project(squeezelite_esp32_test)
# add_definitions(-include "${PROJECT_SOURCE_DIR}/../build/config/sdkconfig.h")
# get_target_property(BCA recovery.elf LINK_LIBRARIES)
# list(REMOVE_ITEM BCA "idf::app_squeezelite" "idf::app_recovery" "-Wl,--Map=${BUILD_DIR}/recovery.map" "-Wl,--cref -Wl,--Map=${BUILD_DIR}/recovery.map")
# set_target_properties(recovery.elf PROPERTIES LINK_LIBRARIES "${BCA};idf::app_recovery;-Wl,--Map=${BUILD_DIR}/recovery.map")
set_property(TARGET squeezelite_esp32_test.elf PROPERTY RECOVERY_PREFIX app_update )
# TODO: enable gcov. this was attempted, but caused some
# tasks to crash with "Cache disabled but cached memory region accessed"
# when SPIFFS was being used.
#
idf_create_coverage_report(${CMAKE_CURRENT_BINARY_DIR}/coverage_report)
idf_clean_coverage_report(${CMAKE_CURRENT_BINARY_DIR}/coverage_report)
# # This is the project CMakeLists.txt file for the test subproject
# cmake_minimum_required(VERSION 3.5)
# include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# # Include the components directory of the main application:
# #
# # Set the components to include the tests for.
# # This can be overriden from CMake cache:
# # - when invoking CMake directly: cmake -D TEST_COMPONENTS="xxxxx" ..
# # - when using idf.py: idf.py -T xxxxx build
# #
# set(TEST_COMPONENTS "platform_console" CACHE STRING "List of components to test")
# set(COMPONENTS main)
# # Freertos is included via common components, however, currently only the mock component is compatible with linux
# # target.
# list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/freertos/")
# list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/driver/")
# list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/freertos/")
# list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/spi_flash/")
# list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/components/unity/")
# idf_build_set_property(COMPILE_DEFINITIONS "-DNO_DEBUG_STORAGE" APPEND)
# # list(APPEND EXTRA_COMPONENT_DIRS "${PROJECT_SOURCE_DIR}/../components")
# # list(APPEND EXTRA_COMPONENT_DIRS "${PROJECT_SOURCE_DIR}/../components/tools")
# project(squeezelite_esp32_test)
# # add_definitions(-include "${PROJECT_SOURCE_DIR}/../build/config/sdkconfig.h")
# set_property(TARGET squeezelite_esp32_test.elf PROPERTY RECOVERY_PREFIX app_update )
add_custom_command(
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/build/coverage.info"

View File

@@ -1,2 +0,0 @@
idf_component_register(SRCS "unit_tests.c"
INCLUDE_DIRS "." "${PROJECT_SOURCE_DIR}/../components/tools" REQUIRES unity )

View File

@@ -1,131 +0,0 @@
/* Example test application for testable component.
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 <stdio.h>
#include <string.h>
#include "unity.h"
/*
* Squeezelite for esp32
*
* (c) Sebastien 2019
* Philippe G. 2019, philippe_44@outlook.com
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*
*/
#include "platform_esp32.h"
#include "led.h"
#include <stdio.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "driver/gpio.h"
#include "driver/spi_master.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#include "esp_wifi.h"
#include "esp_system.h"
#include <esp_event.h>
#include "nvs_flash.h"
#include "esp_log.h"
#include "freertos/event_groups.h"
#include "mdns.h"
#include "lwip/api.h"
#include "lwip/err.h"
#include "lwip/netdb.h"
#include "nvs_utilities.h"
#include "trace.h"
#include "network_manager.h"
#include "squeezelite-ota.h"
#include <math.h>
#include "audio_controls.h"
// #include "Configurator.h"
#pragma message("fixme: search for TODO below")
#include "telnet.h"
#include "messaging.h"
#include "gds.h"
#include "gds_default_if.h"
#include "gds_draw.h"
#include "gds_text.h"
#include "gds_font.h"
#include "display.h"
#include "accessors.h"
#include "cmd_system.h"
#include "cmd_config.h"
#include "cmd_i2ctools.h"
#include "cmd_nvs.h"
const char unknown_string_placeholder[] = "unknown";
const char null_string_placeholder[] = "null";
// as an exception _init function don't need include
extern void services_init(void);
const char * str_or_unknown(const char * str) { return (str?str:unknown_string_placeholder); }
const char * str_or_null(const char * str) { return (str?str:null_string_placeholder); }
bool is_recovery_running;
extern void initialize_console();
/* brief this is an exemple of a callback that you can setup in your own app to get notified of wifi manager event */
esp_err_t update_certificates(bool force){return ESP_OK; }
void init_commands(){
initialize_console();
/* Register commands */
register_system();
register_config_cmd();
register_nvs();
register_i2ctools();
#if CONFIG_WITH_CONFIG_UI
#endif
}
void test_init()
{
const esp_partition_t *running = esp_ota_get_running_partition();
is_recovery_running = (running->subtype == ESP_PARTITION_SUBTYPE_APP_FACTORY);
initialize_nvs();
config_init();
services_init();
init_commands();
}
static void print_banner(const char* text);
void app_main()
{
test_init();
print_banner("Running tests with [config] tag");
UNITY_BEGIN();
unity_run_tests_by_tag("[config]", false);
UNITY_END();
// print_banner("Running all the registered tests");
// UNITY_BEGIN();
// unity_run_all_tests();
// UNITY_END();
print_banner("Starting interactive test menu");
/* This function will not return, and will be busy waiting for UART input.
* Make sure that task watchdog is disabled if you use this function.
*/
unity_run_menu();
}
int main(int argc, char **argv)
{
setbuf(stdout, NULL);
app_main();
return 0;
}
static void print_banner(const char* text)
{
printf("\n#### %s #####\n\n", text);
}

View File

@@ -1,8 +1,4 @@
# Name, Type, SubType, Offset, Size, Flags
# Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild
nvs, data, nvs, 0x9000, 0x4000,
otadata, data, ota, 0xD000, 0x2000,
phy_init, data, phy, 0xF000, 0x1000,
recovery, app, factory, 0x10000, 0x140000,
ota_0, app, ota_0, , 0x2A0000,
settings, data, nvs, , 0x10000,
otadata, data, ota, 0xD000, 0x2000,
phy_init, data, phy, 0xF000, 0x1000,
recovery, app, factory, 0x10000, 0x300000,
spiffs, data, spiffs, , 0x7D000,
1 # Name, Type, SubType, Offset, Size, Flags otadata data ota 0xD000 0x2000
2 # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild phy_init data phy 0xF000 0x1000
3 nvs, data, nvs, 0x9000, 0x4000, recovery app factory 0x10000 0x300000
4 otadata, data, ota, 0xD000, 0x2000, spiffs data spiffs 0x7D000
phy_init, data, phy, 0xF000, 0x1000,
recovery, app, factory, 0x10000, 0x140000,
ota_0, app, ota_0, , 0x2A0000,
settings, data, nvs, , 0x10000,

File diff suppressed because it is too large Load Diff

1819
test/sdkconfig.test Normal file

File diff suppressed because it is too large Load Diff

125
test/test.code-workspace Normal file
View File

@@ -0,0 +1,125 @@
{
"folders": [
{
"path": "."
},
{
"path": ".."
}
],
"settings": {
"files.associations": {
"*.cps": "javascript",
"coroutine": "c",
"xmemory": "c",
"atomic": "c",
"w5500.h": "c",
"array": "c",
"bitset": "cpp",
"string_view": "cpp",
"initializer_list": "cpp",
"regex": "cpp",
"utility": "cpp",
"*.ipp": "c",
"deque": "c",
"list": "cpp",
"string": "c",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "c",
"*.tcc": "cpp",
"fstream": "cpp",
"strstream": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"codecvt": "cpp",
"condition_variable": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "c",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "c",
"iterator": "cpp",
"map": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"set": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"future": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp",
"*.inc": "c",
"*.cmake": "makefile",
"network_manager.h": "c",
"platform_esp32.h": "c",
"improv.h": "c",
"esp_err.h": "c",
"esp_bt.h": "c",
"improv_server.h": "c",
"esp_bt_defs.h": "c",
"variant": "c",
"*.h": "cpp",
"any": "cpp",
"bit": "cpp",
"charconv": "cpp",
"compare": "cpp",
"complex": "cpp",
"concepts": "cpp",
"filesystem": "cpp",
"format": "cpp",
"forward_list": "cpp",
"ios": "cpp",
"locale": "cpp",
"queue": "cpp",
"ranges": "cpp",
"span": "cpp",
"stack": "cpp",
"stop_token": "cpp",
"typeindex": "cpp",
"valarray": "cpp",
"xfacet": "cpp",
"xhash": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xstddef": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp"
}
}
}

View File

@@ -0,0 +1,4 @@
idf_component_register(SRC_DIRS "."
INCLUDE_DIRS "."
REQUIRES unity
PRIV_REQUIRES esp_common log tools services wifi-manager)

View File

@@ -0,0 +1,4 @@
menu "Test Configuration"
rsource "../../main/Kconfig.projbuild"
endmenu

View File

@@ -0,0 +1,32 @@
#include "unity.h"
#include "tools.h" // Assuming tools.h contains init_spiffs and listFiles
#include "test_common_init.h"
#include "tools_spiffs_utils.h"
static const char * TAG = "test_common";
esp_err_t start_ota_return_code=ESP_OK;
void start_ota_set_return(esp_err_t mockreturn){
start_ota_return_code = mockreturn;
}
esp_err_t start_ota(const char * bin_url, char * bin_buffer, uint32_t length) {
ESP_LOGI(TAG,"Received OTA Request url %s/bin buffer size: %d. returning: %s",bin_url,length,esp_err_to_name(start_ota_return_code));
return start_ota_return_code;
}
esp_log_level_t SetLogLevels(esp_log_level_t level) {
esp_log_level_set("*", level);
return esp_log_level_get(TAG);
}
TEST_CASE("Raise Log Level","[test]") {
TEST_ASSERT_TRUE(SetLogLevels(ESP_LOG_DEBUG) == ESP_LOG_DEBUG );
}
TEST_CASE("Lower Log Level","[test]") {
TEST_ASSERT_TRUE(SetLogLevels(ESP_LOG_INFO) == ESP_LOG_INFO );
}
TEST_CASE("List dir content", "[tools]") {
common_test_init();
listFiles("/spiffs");
TEST_ASSERT_TRUE(true);
}

View File

@@ -0,0 +1,11 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "esp_log.h"
#include "esp_system.h"
extern void common_test_init();
void start_ota_set_return(esp_err_t mockreturn);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,77 @@
/* Example test application for testable component.
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 <stdio.h>
#include <string.h>
#include "unity.h"
#include "esp_log.h"
#include "test_common_init.h"
#include "tools.h" // Assuming tools.h contains init_spiffs and listFiles
#include "freertos/task.h"
#include "network_manager.h"
#include "messaging.h"
#include "tools_spiffs_utils.h"
#include "bootstate.h"
static const char * TAG = "test_runner";
bool spiffs_started=false;
bool dummycond=false;
static EXT_RAM_ATTR RingbufHandle_t messaging;
static void print_banner(const char* text)
{
printf("\n#### %s #####\n\n", text);
}
void common_test_init() {
if(!spiffs_started){
spiffs_started = true;
init_spiffs();
listFiles(spiffs_base_path);
}
}
void app_main() {
esp_log_level_set("*", ESP_LOG_DEBUG);
messaging_service_init();
bootstate_handle_boot();
init_spiffs();
if (esp_log_level_get(TAG) >= ESP_LOG_DEBUG) {
listFiles(spiffs_base_path);
}
// Start the network task at this point; this is critical
// as various subsequent init steps will post events to the queue
network_initialize_task();
// also register a subscriber in case we need to check for results in tests
messaging = messaging_register_subscriber(10, "test_runner");
/* These are the different ways of running registered tests.
* In practice, only one of them is usually needed.
*
* UNITY_BEGIN() and UNITY_END() calls tell Unity to print a summary
* (number of tests executed/failed/ignored) of tests executed between these calls.
*/
UNITY_BEGIN();
unity_run_all_tests();
UNITY_END();
print_banner("Starting interactive test menu");
/* This function will not return, and will be busy waiting for UART input.
* Make sure that task watchdog is disabled if you use this function.
*/
unity_run_menu();
}