From 8c2c402821297dc2d61f4ecad108193104a9318f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 28 Feb 2022 16:47:36 +0100 Subject: [PATCH] continued tests, first fixes --- bsp_q7s/core/CoreController.cpp | 10 ++++---- bsp_q7s/core/CoreController.h | 16 +++++++------ bsp_q7s/core/InitMission.cpp | 2 +- unittest/rebootLogic/.vscode/settings.json | 5 +++- unittest/rebootLogic/CoreController.cpp | 4 ++-- unittest/rebootLogic/CoreController.h | 10 ++++---- unittest/rebootLogic/main.cpp | 27 ++++++++++++++++++++++ 7 files changed, 53 insertions(+), 21 deletions(-) diff --git a/bsp_q7s/core/CoreController.cpp b/bsp_q7s/core/CoreController.cpp index d9022b57..535d12ed 100644 --- a/bsp_q7s/core/CoreController.cpp +++ b/bsp_q7s/core/CoreController.cpp @@ -1198,8 +1198,8 @@ void CoreController::performRebootFileHandling(bool recreateFile) { if (rebootFile.bootFlag) { // Trigger event to inform ground that a reboot was triggered uint32_t p1 = rebootFile.lastChip << 16 | rebootFile.lastCopy; - uint32_t p2 = rebootFile.img00Cnt << 24 | rebootFile.img01Cnt << 16 | - rebootFile.img10Cnt << 8 | rebootFile.img11Cnt; + uint32_t p2 = rebootFile.img00Cnt << 24 | rebootFile.img01Cnt << 16 | rebootFile.img10Cnt << 8 | + rebootFile.img11Cnt; triggerEvent(REBOOT_MECHANISM_TRIGGERED, p1, p2); // Clear the boot flag rebootFile.bootFlag = false; @@ -1512,12 +1512,12 @@ void CoreController::resetRebootCount(xsc::Chip tgtChip, xsc::Copy tgtCopy) { } void CoreController::performMountedSdCardOperations() { - if(doPerformMountedSdCardOps) { + if (doPerformMountedSdCardOps) { bool sdCardMounted = false; sdCardMounted = sdcMan->isSdCardMounted(sdInfo.pref); - if(sdCardMounted) { + if (sdCardMounted) { std::string path = sdcMan->getCurrentMountPrefix(sdInfo.pref) + "/" + CONF_FOLDER; - if(not std::filesystem::exists(path)) { + if (not std::filesystem::exists(path)) { std::filesystem::create_directory(path); } initVersionFile(); diff --git a/bsp_q7s/core/CoreController.h b/bsp_q7s/core/CoreController.h index 6a8bb8cd..29b7676b 100644 --- a/bsp_q7s/core/CoreController.h +++ b/bsp_q7s/core/CoreController.h @@ -25,11 +25,11 @@ struct RebootFile { bool enabled = false; size_t maxCount = DEFAULT_MAX_BOOT_CNT; - uint8_t img00Cnt = 0; - uint8_t img01Cnt = 0; - uint8_t img10Cnt = 0; - uint8_t img11Cnt = 0; - uint8_t relevantBootCnt = 0; + uint32_t img00Cnt = 0; + uint32_t img01Cnt = 0; + uint32_t img10Cnt = 0; + uint32_t img11Cnt = 0; + uint32_t relevantBootCnt = 0; bool bootFlag = false; xsc::Chip lastChip = xsc::Chip::CHIP_0; xsc::Copy lastCopy = xsc::Copy::COPY_0; @@ -46,8 +46,10 @@ class CoreController : public ExtendedControllerBase { static constexpr char CONF_FOLDER[] = "conf"; static constexpr char VERSION_FILE_NAME[] = "version.txt"; static constexpr char REBOOT_FILE_NAME[] = "reboot.txt"; - const std::string VERSION_FILE = "/" + std::string(CONF_FOLDER) + "/" + std::string(VERSION_FILE_NAME); - const std::string REBOOT_FILE = "/" + std::string(CONF_FOLDER) + "/" + std::string(REBOOT_FILE_NAME); + const std::string VERSION_FILE = + "/" + std::string(CONF_FOLDER) + "/" + std::string(VERSION_FILE_NAME); + const std::string REBOOT_FILE = + "/" + std::string(CONF_FOLDER) + "/" + std::string(REBOOT_FILE_NAME); static constexpr ActionId_t LIST_DIRECTORY_INTO_FILE = 0; static constexpr ActionId_t SWITCH_REBOOT_FILE_HANDLING = 5; diff --git a/bsp_q7s/core/InitMission.cpp b/bsp_q7s/core/InitMission.cpp index 76807438..b265ce33 100644 --- a/bsp_q7s/core/InitMission.cpp +++ b/bsp_q7s/core/InitMission.cpp @@ -266,7 +266,7 @@ void initmission::createPstTasks(TaskFactory& factory, sif::error << "InitMission::initTasks: GomSpace PST initialization failed!" << std::endl; } taskVec.push_back(gomSpacePstTask); -#else /* BOARD_TE7020 == 0 */ +#else /* BOARD_TE7020 == 0 */ FixedTimeslotTaskIF* pollingSequenceTaskTE0720 = factory.createFixedTimeslotTask( "PST_TASK_TE0720", 30, PeriodicTaskIF::MINIMUM_STACK_SIZE * 8, 3.0, missedDeadlineFunc); result = pst::pollingSequenceTE0720(pollingSequenceTaskTE0720); diff --git a/unittest/rebootLogic/.vscode/settings.json b/unittest/rebootLogic/.vscode/settings.json index ff30c446..8fcc89db 100644 --- a/unittest/rebootLogic/.vscode/settings.json +++ b/unittest/rebootLogic/.vscode/settings.json @@ -1,3 +1,6 @@ { - "editor.tabSize": 2 + "editor.tabSize": 2, + "files.associations": { + "iosfwd": "cpp" + } } \ No newline at end of file diff --git a/unittest/rebootLogic/CoreController.cpp b/unittest/rebootLogic/CoreController.cpp index d9269c06..34133ccf 100644 --- a/unittest/rebootLogic/CoreController.cpp +++ b/unittest/rebootLogic/CoreController.cpp @@ -362,7 +362,7 @@ void CoreController::rewriteRebootFile(RebootFile file) { rebootFile << "on: " << file.enabled << "\nmaxcnt: " << file.maxCount << "\nimg00: " << file.img00Cnt << "\nimg01: " << file.img01Cnt << "\nimg10: " << file.img10Cnt << "\nimg11: " << file.img11Cnt - << "\nbootflag: " << file.bootFlag << "\nlast: " << file.lastChip << " " - << file.lastCopy << "\n"; + << "\nbootflag: " << file.bootFlag << "\nlast: " << static_cast(file.lastChip) << " " + << static_cast(file.lastCopy) << "\n"; } } diff --git a/unittest/rebootLogic/CoreController.h b/unittest/rebootLogic/CoreController.h index f3fec0e2..209db0da 100644 --- a/unittest/rebootLogic/CoreController.h +++ b/unittest/rebootLogic/CoreController.h @@ -19,11 +19,11 @@ struct RebootFile { bool enabled = false; size_t maxCount = DEFAULT_MAX_BOOT_CNT; - uint8_t img00Cnt = 0; - uint8_t img01Cnt = 0; - uint8_t img10Cnt = 0; - uint8_t img11Cnt = 0; - uint8_t relevantBootCnt = 0; + uint32_t img00Cnt = 0; + uint32_t img01Cnt = 0; + uint32_t img10Cnt = 0; + uint32_t img11Cnt = 0; + uint32_t relevantBootCnt = 0; bool bootFlag = false; xsc::Chip lastChip = xsc::Chip::CHIP_0; xsc::Copy lastCopy = xsc::Copy::COPY_0; diff --git a/unittest/rebootLogic/main.cpp b/unittest/rebootLogic/main.cpp index 1a7748c9..8686c0b3 100644 --- a/unittest/rebootLogic/main.cpp +++ b/unittest/rebootLogic/main.cpp @@ -1,8 +1,35 @@ #include "CoreController.h" #include #include +#include +#include + +static constexpr bool CAT_FILE_TO_CONSOLE = true; +const std::string CONF_PATH = "/tmp/conf"; +const std::string REBOOT_FILE = CONF_PATH + "/reboot.txt"; + +void catFileToConsole(); TEST_CASE( "Core Controller Reboot File Handling", "[reboot-file]" ) { + + if(not std::filesystem::exists(CONF_PATH)) { + std::filesystem::create_directory(CONF_PATH); + } CoreController ctrl; + RebootFile rf; ctrl.performRebootFileHandling(true); + catFileToConsole(); + ctrl.parseRebootFile(REBOOT_FILE, rf); + REQUIRE(rf.enabled == 1); + REQUIRE(rf.enabled == 1); + std::filesystem::remove_all(CONF_PATH); } + +void catFileToConsole() { + if(CAT_FILE_TO_CONSOLE) { + std::ifstream file(REBOOT_FILE); + if (file.is_open()) { + std::cout << file.rdbuf(); + } + } +} \ No newline at end of file