Restructure the project tree for unit testing
Restructure the whole project tree so that the component can be unit tested. Also update some cmake files to update the modified paths, update test cases etc.
This commit is contained in:
13
app_test/CMakeLists.txt
Normal file
13
app_test/CMakeLists.txt
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
|
||||||
|
# Define component search paths
|
||||||
|
# IMPORTANT: We should tell to the ESP-IDF
|
||||||
|
# where it can find relay_chn component.
|
||||||
|
# We add the 'relay_chn' directory to the COMPONENT_DIRS by specifying: ../relay_chn
|
||||||
|
set(EXTRA_COMPONENT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../relay_chn")
|
||||||
|
|
||||||
|
# Include ESP-IDF project build system
|
||||||
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
|
|
||||||
|
# Define the name of this project
|
||||||
|
project(relay_chn_app_test)
|
||||||
3
app_test/main/CMakeLists.txt
Normal file
3
app_test/main/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
idf_component_register(SRCS "test_relay_chn.c"
|
||||||
|
INCLUDE_DIRS "."
|
||||||
|
REQUIRES unity relay_chn)
|
||||||
@@ -2,6 +2,9 @@
|
|||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
#include "unity_test_utils.h"
|
#include "unity_test_utils.h"
|
||||||
#include "relay_chn.h"
|
#include "relay_chn.h"
|
||||||
|
#include <esp_log.h>
|
||||||
|
#include <freertos/FreeRTOS.h>
|
||||||
|
#include <freertos/task.h>
|
||||||
|
|
||||||
|
|
||||||
const gpio_num_t gpio_map[] = {GPIO_NUM_4, GPIO_NUM_5, GPIO_NUM_18, GPIO_NUM_19};
|
const gpio_num_t gpio_map[] = {GPIO_NUM_4, GPIO_NUM_5, GPIO_NUM_18, GPIO_NUM_19};
|
||||||
@@ -27,7 +30,7 @@ void tearDown(void) {
|
|||||||
for (uint8_t i = 0; i < relay_chn_count; i++) {
|
for (uint8_t i = 0; i < relay_chn_count; i++) {
|
||||||
relay_chn_stop(i);
|
relay_chn_stop(i);
|
||||||
}
|
}
|
||||||
vTaskDelay(pdMS_to_TICKS(100));
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Relay channels run forward and update state", "[relay_chn][forward]")
|
TEST_CASE("Relay channels run forward and update state", "[relay_chn][forward]")
|
||||||
@@ -91,3 +94,11 @@ TEST_CASE("Relay channels do not change state for invalid channel", "[relay_chn]
|
|||||||
relay_chn_flip_direction(relay_chn_count);
|
relay_chn_flip_direction(relay_chn_count);
|
||||||
check_channels_state_unchanged();
|
check_channels_state_unchanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void app_main(void) {
|
||||||
|
ESP_LOGI("APP_MAIN", "Starting relay_chn unit tests...");
|
||||||
|
unity_run_all_tests();
|
||||||
|
ESP_LOGI("APP_MAIN", "All relay_chn tests completed. Restarting in 10 seconds...");
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(10000));
|
||||||
|
esp_restart();
|
||||||
|
}
|
||||||
2072
app_test/sdkconfig
Normal file
2072
app_test/sdkconfig
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,8 +0,0 @@
|
|||||||
# Create a component for test component
|
|
||||||
idf_component_register(SRCS_DIRS "."
|
|
||||||
INCLUDE_DIRS "."
|
|
||||||
REQUIRES unity relay_chn)
|
|
||||||
|
|
||||||
# Mark this as a test component
|
|
||||||
# 'relay_chn' is the name of the main component.
|
|
||||||
idf_build_set_property(TEST_COMPONENTS "relay_chn" APPEND)
|
|
||||||
Reference in New Issue
Block a user