3 Commits

Author SHA1 Message Date
11786b7a06 Remove unnecessary unity functions. 2025-03-04 09:49:04 +03:00
7c18ddcc04 Fix declarations as per the documents. 2025-03-04 09:48:24 +03:00
e8303a9418 Fix test directory structure. 2025-03-03 16:20:29 +03:00
5 changed files with 111 additions and 146 deletions

180
.gitignore vendored
View File

@@ -1,111 +1,107 @@
.config # ---> C
# Prerequisites
*.d
# Object files
*.o *.o
*.pyc *.ko
*.obj
*.elf
# gtags # Linker output
GTAGS *.ilk
GRTAGS *.map
GPATH *.exp
# emacs # Precompiled Headers
.dir-locals.el *.gch
*.pch
# emacs temp file suffixes # Libraries
*~ *.lib
.#* *.a
\#*# *.la
*.lo
# eclipse setting # Shared objects (inc. Windows DLLs)
.settings *.dll
*.so
*.so.*
*.dylib
# MacOS directory files # Executables
.DS_Store *.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# cache dir # Debug files
.cache/ *.dSYM/
*.su
*.idb
*.pdb
# Doc build artifacts # Kernel Module Compile Results
docs/_build/ *.mod*
docs/doxygen_sqlite3.db *.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
# Downloaded font files # ---> C++
docs/_static/DejaVuSans.ttf # Prerequisites
docs/_static/NotoSansSC-Regular.otf *.d
# Components Unit Test Apps files # Compiled Object files
components/**/build/ *.slo
components/**/build_*_*/ *.lo
components/**/sdkconfig *.o
components/**/sdkconfig.old *.obj
# Example project files # Precompiled Headers
examples/**/build/ *.gch
examples/**/build_*_*/ *.pch
examples/**/sdkconfig
examples/**/sdkconfig.old
# Unit test app files # Compiled Dynamic libraries
tools/unit-test-app/build *.so
tools/unit-test-app/build_*_*/ *.dylib
tools/unit-test-app/sdkconfig *.dll
tools/unit-test-app/sdkconfig.old
# test application build files # Fortran module files
tools/test_apps/**/build/ *.mod
tools/test_apps/**/build_*_*/ *.smod
tools/test_apps/**/sdkconfig
tools/test_apps/**/sdkconfig.old
TEST_LOGS/ # Compiled Static libraries
build_summary_*.xml *.lai
*.la
*.a
*.lib
# gcov coverage reports # Executables
*.gcda *.exe
*.gcno *.out
coverage.info *.app
coverage_report/
test_multi_heap_host # ---> CMake
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
CMakeUserPresets.json
# VS Code Settings # Build directory
.vscode/
# VIM files
*.swp
*.swo
# Sublime Text files
*.sublime-project
*.sublime-workspace
# Clion IDE CMake build & config
.idea/
cmake-build-*/
# Results for the checking of the Python coding style and static analysis
.mypy_cache
flake8_output.txt
# ESP-IDF default build directory name
build build
# lock files for examples and components # unity-app directory
dependencies.lock unity-app
# managed_components for examples
managed_components
# pytest log
pytest-embedded/
# legacy one
pytest_embedded_log/
list_job*.txt
size_info*.txt
XUNIT_RESULT*.xml
.manifest_sha
# clang config (for LSP)
.clangd
# Vale
.vale/styles/*

View File

@@ -15,7 +15,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "esp_err.h" #include "esp_err.h"
#include "esp_check.h"
#include "esp_log.h" #include "esp_log.h"
#include "esp_task.h" #include "esp_task.h"
#include "driver/gpio.h" #include "driver/gpio.h"
@@ -280,8 +279,7 @@ static esp_err_t relay_chn_create_event_loop()
.task_core_id = tskNO_AFFINITY .task_core_id = tskNO_AFFINITY
}; };
esp_err_t ret = esp_event_loop_create(&loop_args, &relay_chn_event_loop); esp_err_t ret = esp_event_loop_create(&loop_args, &relay_chn_event_loop);
ESP_RETURN_ON_ERROR(ret, TAG, "Failed to create event loop for relay channel"); ret |= esp_event_handler_register_with(relay_chn_event_loop,
ret = esp_event_handler_register_with(relay_chn_event_loop,
RELAY_CHN_CMD_EVENT, RELAY_CHN_CMD_EVENT,
ESP_EVENT_ANY_ID, ESP_EVENT_ANY_ID,
relay_chn_event_handler, NULL); relay_chn_event_handler, NULL);
@@ -322,14 +320,14 @@ esp_err_t relay_chn_create(const gpio_num_t* gpio_map, uint8_t gpio_count)
// Initialize the GPIOs // Initialize the GPIOs
ret = gpio_reset_pin(forward_pin); ret = gpio_reset_pin(forward_pin);
ESP_RETURN_ON_ERROR(ret, TAG, "Failed to reset GPIO forward pin for channel %d", i); ret |= gpio_set_direction(forward_pin, GPIO_MODE_OUTPUT);
ret = gpio_set_direction(forward_pin, GPIO_MODE_OUTPUT);
ESP_RETURN_ON_ERROR(ret, TAG, "Failed to set GPIO direction for forward pin for channel %d", i);
ret = gpio_reset_pin(reverse_pin); ret |= gpio_reset_pin(reverse_pin);
ESP_RETURN_ON_ERROR(ret, TAG, "Failed to reset GPIO reverse pin for channel %d", i); ret |= gpio_set_direction(reverse_pin, GPIO_MODE_OUTPUT);
ret = gpio_set_direction(reverse_pin, GPIO_MODE_OUTPUT); if (ret != ESP_OK) {
ESP_RETURN_ON_ERROR(ret, TAG, "Failed to set GPIO direction for reverse pin for channel %d", i); ESP_LOGE(TAG, "Failed to initialize GPIOs relay channel %d!", i);
return ret;
}
// Initialize the GPIOs // Initialize the GPIOs
// Initialize the relay channel // Initialize the relay channel
@@ -341,22 +339,22 @@ esp_err_t relay_chn_create(const gpio_num_t* gpio_map, uint8_t gpio_count)
relay_chn->state = RELAY_CHN_STATE_FREE; relay_chn->state = RELAY_CHN_STATE_FREE;
relay_chn->pending_cmd = RELAY_CHN_CMD_NONE; relay_chn->pending_cmd = RELAY_CHN_CMD_NONE;
relay_chn->run_info.last_run_cmd = RELAY_CHN_CMD_NONE; relay_chn->run_info.last_run_cmd = RELAY_CHN_CMD_NONE;
ret = relay_chn_init_timer(relay_chn); // Create direction change inertia timer ret |= relay_chn_init_timer(relay_chn); // Create direction change inertia timer
ESP_RETURN_ON_ERROR(ret, TAG, "Failed to create relay channel timer for channel %d", i);
#if RELAY_CHN_ENABLE_TILTING == 1 #if RELAY_CHN_ENABLE_TILTING == 1
ret = relay_chn_init_tilt_control(relay_chn); ret |= relay_chn_init_tilt_control(relay_chn);
ESP_RETURN_ON_ERROR(ret, TAG, "Failed to initialize tilt control for channel %d", i);
#endif #endif
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to initialize relay channel %d!", i);
return ret;
}
} }
// Create relay channel command event loop // Create relay channel command event loop
ret = relay_chn_create_event_loop(); ret |= relay_chn_create_event_loop();
ESP_RETURN_ON_ERROR(ret, TAG, "Failed to create relay channel event loop");
#if RELAY_CHN_ENABLE_TILTING == 1 #if RELAY_CHN_ENABLE_TILTING == 1
// Must call after the event loop is initialized // Must call after the event loop is initialized
ret = relay_chn_tilt_init(); // Initialize tilt feature ret |= relay_chn_tilt_init(); // Initialize tilt feature
ESP_RETURN_ON_ERROR(ret, TAG, "Failed to initialize tilt feature");
#endif #endif
// Init the state listener manager // Init the state listener manager
@@ -702,8 +700,7 @@ static esp_err_t relay_chn_output_stop(relay_chn_t *relay_chn)
{ {
esp_err_t ret; esp_err_t ret;
ret = gpio_set_level(relay_chn->output.forward_pin, 0); ret = gpio_set_level(relay_chn->output.forward_pin, 0);
ESP_RETURN_ON_ERROR(ret, TAG, "Failed to set forward pin to LOW for relay channel #%d", relay_chn->id); ret |= gpio_set_level(relay_chn->output.reverse_pin, 0);
ret = gpio_set_level(relay_chn->output.reverse_pin, 0);
return ret; return ret;
} }
@@ -711,8 +708,7 @@ static esp_err_t relay_chn_output_forward(relay_chn_t *relay_chn)
{ {
esp_err_t ret; esp_err_t ret;
ret = gpio_set_level(relay_chn->output.forward_pin, 1); ret = gpio_set_level(relay_chn->output.forward_pin, 1);
ESP_RETURN_ON_ERROR(ret, TAG, "Failed to set forward pin to HIGH for relay channel #%d", relay_chn->id); ret |= gpio_set_level(relay_chn->output.reverse_pin, 0);
ret = gpio_set_level(relay_chn->output.reverse_pin, 0);
return ret; return ret;
} }
@@ -720,8 +716,7 @@ static esp_err_t relay_chn_output_reverse(relay_chn_t *relay_chn)
{ {
esp_err_t ret; esp_err_t ret;
ret = gpio_set_level(relay_chn->output.forward_pin, 0); ret = gpio_set_level(relay_chn->output.forward_pin, 0);
ESP_RETURN_ON_ERROR(ret, TAG, "Failed to set forward pin to LOW for relay channel #%d", relay_chn->id); ret |= gpio_set_level(relay_chn->output.reverse_pin, 1);
ret = gpio_set_level(relay_chn->output.reverse_pin, 1);
return ret; return ret;
} }

View File

@@ -1,8 +1,3 @@
# The following lines of boilerplate have to be in your project's CMakeLists idf_component_register(SRCS_DIRS "."
# in this exact order for cmake to work correctly INCLUDE_DIRS "."
cmake_minimum_required(VERSION 3.5) REQUIRES unity relay_chn)
set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components"
"../../relay_chn")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(relay_chn_test)

View File

@@ -1,3 +0,0 @@
idf_component_register(SRCS_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES unity test_utils relay_chn)

View File

@@ -74,22 +74,4 @@ TEST_CASE("Relay channels do not change state for invalid channel", "[relay_chn]
check_channels_state_unchanged(); check_channels_state_unchanged();
relay_chn_flip_direction(relay_chn_count + 1); // Flip the direction relay_chn_flip_direction(relay_chn_count + 1); // Flip the direction
check_channels_state_unchanged(); check_channels_state_unchanged();
} }
void setUp(void)
{
// Run before each test
}
void tearDown(void)
{
// Run after each test
}
// Test app entry point
void app_main(void)
{
// Run the Unity tests menu
unity_run_menu();
}