added test-framework
This commit is contained in:
parent
fb5924cff1
commit
563a7b19a8
|
@ -53,3 +53,7 @@ Mkfile.old
|
|||
dkms.conf
|
||||
|
||||
build/
|
||||
|
||||
test/build/
|
||||
|
||||
*.old
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
idf_component_register(SRCS "mesh_ota.c"
|
||||
INCLUDE_DIRS "include")
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
|
||||
|
||||
#include <string.h>
|
||||
#include "esp_system.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
|
||||
|
||||
|
||||
bool bNewerVersion(const char* pu8Local, const char* pu8Remote);
|
|
@ -0,0 +1,42 @@
|
|||
#include "mesh_ota.h"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* 999.999.999
|
||||
* Return true if remote version is newer (higher) than local version
|
||||
*/
|
||||
bool bNewerVersion(const char* pu8Local, const char* pu8Remote){
|
||||
|
||||
char u8LocalTmp[12];
|
||||
char u8RemoteTmp[12];
|
||||
|
||||
char* pu8saveptrLocal;
|
||||
char* pu8saveptrRemote;
|
||||
|
||||
strcpy(u8LocalTmp, pu8Local);
|
||||
strcpy(u8RemoteTmp, pu8Remote);
|
||||
|
||||
char* pu8TokenLocal = strtok_r(u8LocalTmp, ".", &pu8saveptrLocal);
|
||||
char* pu8TokenRemote = strtok_r(u8RemoteTmp, ".", &pu8saveptrRemote) ;
|
||||
|
||||
|
||||
bool bReturn = false;
|
||||
|
||||
uint8_t u8Index = 0;
|
||||
|
||||
while( (u8Index <= 2) && (bReturn == false)){
|
||||
|
||||
u8Index++;
|
||||
|
||||
if(atoi(pu8TokenLocal) < atoi(pu8TokenRemote))
|
||||
{
|
||||
bReturn = true;
|
||||
}
|
||||
|
||||
pu8TokenLocal = strtok_r(NULL, ".", &pu8saveptrLocal);
|
||||
pu8TokenRemote = strtok_r(NULL, ".", &pu8saveptrRemote) ;
|
||||
}
|
||||
|
||||
return bReturn;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
idf_component_register(SRC_DIRS "."
|
||||
INCLUDE_DIRS "."
|
||||
REQUIRES cmock mesh_ota)
|
|
@ -0,0 +1,7 @@
|
|||
# This is the minimal test component makefile.
|
||||
#
|
||||
# The following line is needed to force the linker to include all the object
|
||||
# files into the application, even if the functions in these object files
|
||||
# are not referenced from outside (which is usually the case for unit tests).
|
||||
#
|
||||
COMPONENT_ADD_LDFLAGS = -Wl,--whole-archive -l$(COMPONENT_NAME) -Wl,--no-whole-archive
|
|
@ -0,0 +1,59 @@
|
|||
#include <limits.h>
|
||||
#include "unity.h"
|
||||
#include "mesh_ota.h"
|
||||
|
||||
TEST_CASE("Remote got patch", "[distinguish newer image version]")
|
||||
{
|
||||
char versionLocal[] = "1.2.3"; //current running image
|
||||
char versionRemote[] = "1.2.4"; //image from server
|
||||
TEST_ASSERT_TRUE( bNewerVersion(versionLocal, versionRemote) );
|
||||
}
|
||||
|
||||
TEST_CASE("Remote got minor", "[distinguish newer image version]")
|
||||
{
|
||||
char versionLocal[] = "1.2.3"; //current running image
|
||||
char versionRemote[] = "1.3.3"; //image from server
|
||||
TEST_ASSERT_TRUE( bNewerVersion(versionLocal, versionRemote) );
|
||||
}
|
||||
|
||||
TEST_CASE("Remote got major", "[distinguish newer image version]")
|
||||
{
|
||||
char versionLocal[] = "1.2.3"; //current running image
|
||||
char versionRemote[] = "2.2.3"; //image from server
|
||||
TEST_ASSERT_TRUE( bNewerVersion(versionLocal, versionRemote) );
|
||||
}
|
||||
|
||||
TEST_CASE("Local got patch", "[distinguish newer image version]")
|
||||
{
|
||||
char versionLocal[] = "1.2.4"; //current running image
|
||||
char versionRemote[] = "1.2.3"; //image from server
|
||||
TEST_ASSERT_FALSE( bNewerVersion(versionLocal, versionRemote) );
|
||||
}
|
||||
|
||||
TEST_CASE("Local got minor", "[distinguish newer image version]")
|
||||
{
|
||||
char versionLocal[] = "1.3.3"; //current running image
|
||||
char versionRemote[] = "1.2.3"; //image from server
|
||||
TEST_ASSERT_FALSE( bNewerVersion(versionLocal, versionRemote) );
|
||||
}
|
||||
|
||||
TEST_CASE("Local got major", "[distinguish newer image version]")
|
||||
{
|
||||
char versionLocal[] = "2.2.3"; //current running image
|
||||
char versionRemote[] = "1.2.3"; //image from server
|
||||
TEST_ASSERT_FALSE( bNewerVersion(versionLocal, versionRemote) );
|
||||
}
|
||||
|
||||
TEST_CASE("Remote got alpha and patch", "[distinguish newer image version]")
|
||||
{
|
||||
char versionLocal[] = "2.2.3"; //current running image
|
||||
char versionRemote[] = "a2.2.4"; //image from server
|
||||
TEST_ASSERT_TRUE( bNewerVersion(versionLocal, versionRemote) );
|
||||
}
|
||||
|
||||
TEST_CASE("Remote got max", "[distinguish newer image version]")
|
||||
{
|
||||
char versionLocal[] = "2.2.3"; //current running image
|
||||
char versionRemote[] = "999.999.999"; //image from server
|
||||
TEST_ASSERT_TRUE( bNewerVersion(versionLocal, versionRemote) );
|
||||
}
|
|
@ -1,2 +1,2 @@
|
|||
idf_component_register(SRCS "mesh_main.c"
|
||||
idf_component_register(SRCS "main.c"
|
||||
INCLUDE_DIRS ".")
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "esp_ota_ops.h"
|
||||
#include "esp_partition.h"
|
||||
|
||||
#include "mesh_ota.h"
|
||||
|
||||
|
||||
#define RX_SIZE (1234)
|
||||
|
@ -476,52 +477,6 @@ void ip_event_handler(void *arg, esp_event_base_t event_base,
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* 999.999.999
|
||||
* Return true if remote version is newer (higher) than local version
|
||||
*/
|
||||
bool bNewerVersion(const char* pu8Local, const char* pu8Remote){
|
||||
|
||||
ESP_LOGI(MESH_TAG, "Local %s", pu8Local);
|
||||
ESP_LOGI(MESH_TAG, "Remote %s", pu8Remote);
|
||||
|
||||
char u8LocalTmp[12];
|
||||
char u8RemoteTmp[12];
|
||||
|
||||
char* pu8saveptrLocal;
|
||||
char* pu8saveptrRemote;
|
||||
|
||||
strcpy(u8LocalTmp, pu8Local);
|
||||
strcpy(u8RemoteTmp, pu8Remote);
|
||||
|
||||
char* pu8TokenLocal = strtok_r(u8LocalTmp, ".", &pu8saveptrLocal);
|
||||
char* pu8TokenRemote = strtok_r(u8RemoteTmp, ".", &pu8saveptrRemote) ;
|
||||
|
||||
|
||||
bool bReturn = false;
|
||||
|
||||
uint8_t u8Index = 0;
|
||||
|
||||
while( (u8Index <= 2) && (bReturn == false)){
|
||||
|
||||
u8Index++;
|
||||
|
||||
printf("loop: %i\n", u8Index);
|
||||
|
||||
printf("tokenLocal: %s\n", pu8TokenLocal);
|
||||
printf("tokenRemote: %s\n", pu8TokenRemote);
|
||||
|
||||
if(atoi(pu8TokenLocal) < atoi(pu8TokenRemote))
|
||||
{
|
||||
bReturn = true;
|
||||
}
|
||||
|
||||
pu8TokenLocal = strtok_r(NULL, ".", &pu8saveptrLocal);
|
||||
pu8TokenRemote = strtok_r(NULL, ".", &pu8saveptrRemote) ;
|
||||
}
|
||||
|
||||
return bReturn;
|
||||
}
|
||||
|
||||
|
||||
void app_main(void)
|
||||
|
@ -640,3 +595,5 @@ void app_main(void)
|
|||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1034,7 +1034,7 @@ CONFIG_WS_BUFFER_SIZE=1024
|
|||
#
|
||||
CONFIG_UNITY_ENABLE_FLOAT=y
|
||||
CONFIG_UNITY_ENABLE_DOUBLE=y
|
||||
# CONFIG_UNITY_ENABLE_COLOR is not set
|
||||
CONFIG_UNITY_ENABLE_COLOR=y
|
||||
CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=y
|
||||
# CONFIG_UNITY_ENABLE_FIXTURE is not set
|
||||
# CONFIG_UNITY_ENABLE_BACKTRACE_ON_FAIL is not set
|
||||
|
|
|
@ -31,7 +31,8 @@ CONFIG_APP_BUILD_USE_FLASH_SECTIONS=y
|
|||
CONFIG_APP_COMPILE_TIME_DATE=y
|
||||
# CONFIG_APP_EXCLUDE_PROJECT_VER_VAR is not set
|
||||
# CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR is not set
|
||||
# CONFIG_APP_PROJECT_VER_FROM_CONFIG is not set
|
||||
CONFIG_APP_PROJECT_VER_FROM_CONFIG=y
|
||||
CONFIG_APP_PROJECT_VER="0.0.1"
|
||||
CONFIG_APP_RETRIEVE_LEN_ELF_SHA=16
|
||||
# end of Application manager
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
# This is the project CMakeLists.txt file for the test subproject
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
# Include the components directory of the main application:
|
||||
#
|
||||
set(EXTRA_COMPONENT_DIRS "../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 "mesh_ota" CACHE STRING "List of components to test")
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(unit_test_test)
|
|
@ -0,0 +1,17 @@
|
|||
#
|
||||
# This is a project Makefile for the test subproject.
|
||||
#
|
||||
|
||||
PROJECT_NAME := unit_test_test
|
||||
|
||||
# Include the components directory of the main application:
|
||||
#
|
||||
EXTRA_COMPONENT_DIRS := $(realpath ../components)
|
||||
|
||||
# Set the components to include the tests for.
|
||||
# This can be overriden from the command line
|
||||
# (e.g. 'make TEST_COMPONENTS=xxxx flash monitor')
|
||||
#
|
||||
TEST_COMPONENTS ?= mesh_ota
|
||||
|
||||
include $(IDF_PATH)/make/project.mk
|
|
@ -0,0 +1,2 @@
|
|||
idf_component_register(SRCS "example_unit_test_test.c"
|
||||
INCLUDE_DIRS ".")
|
|
@ -0,0 +1,58 @@
|
|||
/* 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"
|
||||
|
||||
static void print_banner(const char* text);
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
print_banner("Executing one test by its name");
|
||||
UNITY_BEGIN();
|
||||
unity_run_test_by_name("Mean of an empty array is zero");
|
||||
UNITY_END();
|
||||
|
||||
print_banner("Running tests with [mean] tag");
|
||||
UNITY_BEGIN();
|
||||
unity_run_tests_by_tag("[mean]", false);
|
||||
UNITY_END();
|
||||
|
||||
print_banner("Running tests without [fails] tag");
|
||||
UNITY_BEGIN();
|
||||
unity_run_tests_by_tag("[fails]", true);
|
||||
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();
|
||||
}
|
||||
|
||||
static void print_banner(const char* text)
|
||||
{
|
||||
printf("\n#### %s #####\n\n", text);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1 @@
|
|||
CONFIG_ESP_TASK_WDT=n
|
Loading…
Reference in New Issue