19 changed files with 1431 additions and 49 deletions
@ -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 ".") |
||||
|
@ -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); |
||||
} |
Loading…
Reference in new issue