ESP32 OTA firmware updates via WiFi mesh network. https://hendrikschutter.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

223 lines
6.8 KiB

#include <limits.h>
#include "unity.h"
#include "mesh_ota.h"
#include "test_image_hex.h"
// ### ### ### distinguish newer image version ### ### ###
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) );
}
// ### ### ### find start offset in firmware image ### ### ###
TEST_CASE("with http response + 0.0.1", "[find start offset in firmware image]")
{
uint32_t u32StartOffset;
uint32_t u32DataLenght = sizeof(dataWithHttpRespone0_0_1)/sizeof(dataWithHttpRespone0_0_1[0]);
esp_err_t err = errFindImageStart(dataWithHttpRespone0_0_1, &u32DataLenght, &u32StartOffset);
if(err == ESP_OK)
{
TEST_ASSERT_EQUAL_INT(305, u32StartOffset);
}
else
{
TEST_ASSERT_EQUAL_INT(ESP_OK, err);
}
}
TEST_CASE("without http response + 0.0.1", "[find start offset in firmware image]")
{
uint32_t u32StartOffset;
uint32_t u32DataLenght = sizeof(dataWithoutHttpRespone0_0_1)/sizeof(dataWithoutHttpRespone0_0_1[0]);
esp_err_t err = errFindImageStart(dataWithoutHttpRespone0_0_1, &u32DataLenght, &u32StartOffset);
if(err == ESP_OK)
{
TEST_ASSERT_EQUAL_INT(0, u32StartOffset);
}
else
{
TEST_ASSERT_EQUAL_INT(ESP_OK, err);
}
}
TEST_CASE("with http response + 999.999.999", "[find start offset in firmware image]")
{
uint32_t u32StartOffset;
uint32_t u32DataLenght = sizeof(dataWithHttpRespone999_999_999)/sizeof(dataWithHttpRespone999_999_999[0]);
esp_err_t err = errFindImageStart(dataWithHttpRespone999_999_999, &u32DataLenght, &u32StartOffset);
if(err == ESP_OK)
{
TEST_ASSERT_EQUAL_INT(305, u32StartOffset);
}
else
{
TEST_ASSERT_EQUAL_INT(ESP_OK, err);
}
}
TEST_CASE("without http response + 999.999.999", "[find start offset in firmware image]")
{
uint32_t u32StartOffset;
uint32_t u32DataLenght = sizeof(dataWithoutHttpRespone999_999_999)/sizeof(dataWithoutHttpRespone999_999_999[0]);
esp_err_t err = errFindImageStart(dataWithoutHttpRespone999_999_999, &u32DataLenght, &u32StartOffset);
if(err == ESP_OK)
{
TEST_ASSERT_EQUAL_INT(0, u32StartOffset);
}
else
{
TEST_ASSERT_EQUAL_INT(ESP_OK, err);
}
}
TEST_CASE("with http response + 999.9.999", "[find start offset in firmware image]")
{
uint32_t u32StartOffset;
uint32_t u32DataLenght = sizeof(dataWithHttpRespone999_9_999)/sizeof(dataWithHttpRespone999_9_999[0]);
esp_err_t err = errFindImageStart(dataWithHttpRespone999_9_999, &u32DataLenght, &u32StartOffset);
if(err == ESP_OK)
{
TEST_ASSERT_EQUAL_INT(302, u32StartOffset);
}
else
{
TEST_ASSERT_EQUAL_INT(ESP_OK, err);
}
}
TEST_CASE("with http response + 999.99.999", "[find start offset in firmware image]")
{
uint32_t u32StartOffset;
uint32_t u32DataLenght = sizeof(dataWithHttpRespone999_99_999)/sizeof(dataWithHttpRespone999_99_999[0]);
esp_err_t err = errFindImageStart(dataWithHttpRespone999_99_999, &u32DataLenght, &u32StartOffset);
if(err == ESP_OK)
{
TEST_ASSERT_EQUAL_INT(299, u32StartOffset);
}
else
{
TEST_ASSERT_EQUAL_INT(ESP_OK, err);
}
}
// ### ### ### distinguish newer image version ### ### ###
TEST_CASE("extract version 0.0.1", "[extract image version number]")
{
char versionLocal[] = "0.0.0"; //current running image
char versionRemote[12];//image from server
uint32_t u32DataLenght = sizeof(dataWithHttpRespone0_0_1)/sizeof(dataWithHttpRespone0_0_1[0]);
esp_err_t err = errExtractVersionNumber(dataWithHttpRespone0_0_1, &u32DataLenght, versionRemote);
if(err == ESP_OK)
{
TEST_ASSERT_TRUE( bNewerVersion(versionLocal, versionRemote) );
}
else
{
TEST_ASSERT_EQUAL_INT(ESP_OK, err);
}
}
TEST_CASE("extract version 999.999.999", "[extract image version number]")
{
char versionLocal[] = "0.0.0"; //current running image
char versionRemote[12];//image from server
uint32_t u32DataLenght = sizeof(dataWithHttpRespone999_999_999)/sizeof(dataWithHttpRespone999_999_999[0]);
esp_err_t err = errExtractVersionNumber(dataWithHttpRespone999_999_999, &u32DataLenght, versionRemote);
if(err == ESP_OK)
{
TEST_ASSERT_TRUE( bNewerVersion(versionLocal, versionRemote) );
}
else
{
TEST_ASSERT_EQUAL_INT(ESP_OK, err);
}
}
TEST_CASE("extract version 999.99.999", "[extract image version number]")
{
char versionLocal[] = "999.100.999"; //current running image
char versionRemote[12];//image from server
uint32_t u32DataLenght = sizeof(dataWithHttpRespone999_99_999)/sizeof(dataWithHttpRespone999_99_999[0]);
esp_err_t err = errExtractVersionNumber(dataWithHttpRespone999_99_999, &u32DataLenght, versionRemote);
if(err == ESP_OK)
{
TEST_ASSERT_FALSE( bNewerVersion(versionLocal, versionRemote) );
}
else
{
TEST_ASSERT_EQUAL_INT(ESP_OK, err);
}
}

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close