added utils from different project
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
# This is the project CMakeLists.txt file for the test subproject
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
# Include the components directory of the main application:
|
||||
#
|
||||
set(EXTRA_COMPONENT_DIRS "../components ../managed_components")
|
||||
|
||||
# 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 "testable freeRtosApi hwHal" CACHE STRING "List of components to test")
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(unit_test_test)
|
||||
@@ -0,0 +1,35 @@
|
||||
# Unit Testing
|
||||
|
||||
Unit Test based on unity-library [Unity](https://github.com/ThrowTheSwitch/Unity).
|
||||
|
||||
* _Assertions_ (`TEST_ASSERT` and similar) are used when writing the test cases. See [the reference](https://github.com/ThrowTheSwitch/Unity/blob/master/docs/UnityAssertionsReference.md) for more information about assertions.
|
||||
|
||||
* `UNITY_BEGIN()` and `UNITY_END()` macros allow Unity to count the number of tests which have passed or failed, and display the summary.
|
||||
|
||||
In addition to features of Unity, _test registration_ feature of ESP-IDF is used. This feature works when unit test functions are declared using `TEST_CASE` macro. Such functions from all the object files in the program are automatically collected into a list, and run-time facilities are provided to run functions from this list.
|
||||
|
||||
Note testable components have a *test* subdirectory which is included in the *test project*
|
||||
When the main application project is compiled, tests are not included.
|
||||
Test project includes the tests by setting `TEST_COMPONENTS` variable in the project makefile.
|
||||
|
||||
## Build and flash production code
|
||||
|
||||
* Start an ESP-IDF-Terminal
|
||||
* Run `idf.py -p PORT flash monitor` in the current directory (`unit_test`).
|
||||
* Observe the output: a list of random numbers and their mean value.
|
||||
To exit the serial monitor, type ``Ctrl-]``.
|
||||
|
||||
## Build and flash test code
|
||||
|
||||
* Start an ESP-IDF-Terminal
|
||||
* Enter `test` directory (`unit_test/test`), and run `idf.py -p PORT flash monitor`.
|
||||
To exit the serial monitor, type ``Ctrl-]``.
|
||||
* Observe the output: results of test case execution.
|
||||
|
||||
This is the test menu, which is launched by `unity_run_menu` function in the test project. It allows running the tests in a few ways:
|
||||
* Run specific test by its index: type the number and press ENTER.
|
||||
* Run a group of tests with a certain tag: type the tag, including square brackets, and press ENTER.
|
||||
* nRu all tests except the ones with a certain tag: press `!`, then type the tag, including the square brackets, then press ENTER.
|
||||
* Run test with a specific name: type the name of the test, including quotes, and press ENTER.
|
||||
* Run all the tests: press `*` and then ENTER.
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
dependencies:
|
||||
idf:
|
||||
component_hash: null
|
||||
source:
|
||||
type: idf
|
||||
version: 5.3.0
|
||||
manifest_hash: c4f4ec05313d427eb56c633f78ce213e553379725bf2af3c511665f930571beb
|
||||
target: esp32c6
|
||||
version: 1.0.0
|
||||
@@ -0,0 +1,4 @@
|
||||
idf_component_register(
|
||||
SRCS "unitTest.cpp"
|
||||
INCLUDE_DIRS "."
|
||||
)
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* @file unitTest.cpp
|
||||
* @author Gustice
|
||||
* @brief Unit/Integration-Test frame for hardware bound components
|
||||
*
|
||||
* @copyright Copyright (c) 2024
|
||||
*/
|
||||
|
||||
#include "unity.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
extern "C" { // This switch allows the ROS C-implementation to find this main
|
||||
void app_main(void);
|
||||
}
|
||||
|
||||
void app_main(void) {
|
||||
printf("\n#### Running all the registered tests #####\n\n");
|
||||
UNITY_BEGIN();
|
||||
unity_run_all_tests();
|
||||
// Alternatively:
|
||||
// "Executing one test by its name"
|
||||
// unity_run_test_by_name("Mean of an empty array is zero");
|
||||
// Running tests with [mean] tag"
|
||||
// unity_run_tests_by_tag("[mean]", false);
|
||||
// print_banner("Running tests without [fails] tag");
|
||||
// unity_run_tests_by_tag("[fails]", true);
|
||||
UNITY_END();
|
||||
|
||||
printf("\n#### Starting interactive test menu: ####\n");
|
||||
printf("# - run explicit #\n");
|
||||
printf("- run all with *, \n");
|
||||
printf("# - run tagged with [tag], \n");
|
||||
printf("# - run all other than ![tag])\n");
|
||||
printf("# Exit with 'Ctrl-]'\n");
|
||||
unity_run_menu();
|
||||
}
|
||||
+2150
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,3 @@
|
||||
CONFIG_COMPILER_CXX_EXCEPTIONS=y
|
||||
|
||||
CONFIG_ESP_TASK_WDT_EN=n
|
||||
Reference in New Issue
Block a user