From 6a0b18ffd09cae9778a840948098df901b5b7a80 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 11 Apr 2024 10:49:29 +0200 Subject: [PATCH] that should do the job --- bsp_hosted/OBSWConfig.h.in | 1 + linux/payload/plocMpsocHelpers.h | 8 +++++--- unittest/CMakeLists.txt | 3 ++- unittest/mpsocTests.cpp | 14 ++++++++++++++ 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 unittest/mpsocTests.cpp diff --git a/bsp_hosted/OBSWConfig.h.in b/bsp_hosted/OBSWConfig.h.in index 6e525e5a..41515578 100644 --- a/bsp_hosted/OBSWConfig.h.in +++ b/bsp_hosted/OBSWConfig.h.in @@ -48,6 +48,7 @@ #define OBSW_SWITCH_TO_NORMAL_MODE_AFTER_STARTUP 1 #define OBSW_PRINT_MISSED_DEADLINES 1 +#define OBSW_MPSOC_JTAG_BOOT 0 #define OBSW_SYRLINKS_SIMULATED 1 #define OBSW_ADD_TEST_CODE 0 #define OBSW_ADD_TEST_TASK 0 diff --git a/linux/payload/plocMpsocHelpers.h b/linux/payload/plocMpsocHelpers.h index ef03359d..2c9645d8 100644 --- a/linux/payload/plocMpsocHelpers.h +++ b/linux/payload/plocMpsocHelpers.h @@ -850,7 +850,9 @@ class TcSimplexSendFile : public TcBase { if (result != returnvalue::OK) { return result; } - if (chunkParameter == 0) { + /// No chunks makes no sense, and DIV str can not be longer than whats representable with 3 + /// decimal digits. + if (chunkParameter == 0 or chunkParameter > 999) { return INVALID_PARAMETER; } std::string fileName(reinterpret_cast(*dataPtr)); @@ -860,8 +862,8 @@ class TcSimplexSendFile : public TcBase { size_t currentCopyIdx = 0; size_t payloadLen = fileName.length() + sizeof(NULL_TERMINATOR) + CRC_SIZE; if (chunkParameter > 1) { - char divStr[12]{}; - sprintf(divStr, "DIV%03d", chunkParameter); + char divStr[16]{}; + sprintf(divStr, "DIV%03u", chunkParameter); std::memcpy(payloadStart, divStr, DIV_STR_LEN); payloadLen += DIV_STR_LEN; currentCopyIdx += DIV_STR_LEN; diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index e9a01891..808a68ef 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -6,5 +6,6 @@ target_sources(${UNITTEST_NAME} PRIVATE testEnvironment.cpp testGenericFilesystem.cpp hdlcEncodingRw.cpp + mpsocTests.cpp printChar.cpp -) \ No newline at end of file +) diff --git a/unittest/mpsocTests.cpp b/unittest/mpsocTests.cpp new file mode 100644 index 00000000..2ab11b21 --- /dev/null +++ b/unittest/mpsocTests.cpp @@ -0,0 +1,14 @@ + +#include + +TEST_CASE("MPSoC helper tests", "[payload]") { + char divStr[16]{}; + uint32_t divParam = 0; + + SECTION("Simple Test") { + divParam = 3; + CHECK(divParam < 999); + sprintf(divStr, "DIV%03u", divParam); + REQUIRE(strcmp(divStr, "DIV003") == 0); + } +}