diff --git a/scripts/apply-clang-format.sh b/scripts/apply-clang-format.sh index 724b44a0..eb2f4931 100755 --- a/scripts/apply-clang-format.sh +++ b/scripts/apply-clang-format.sh @@ -10,3 +10,5 @@ find ./bsp_linux_board -iname *.h -o -iname *.cpp -o -iname *.c | xargs clang-fo find ./bsp_hosted -iname *.h -o -iname *.cpp -o -iname *.c | xargs clang-format --style=file -i find ./bsp_egse -iname *.h -o -iname *.cpp -o -iname *.c | xargs clang-format --style=file -i find ./test -iname *.h -o -iname *.cpp -o -iname *.c | xargs clang-format --style=file -i +find ./unittest -iname *.h -o -iname *.cpp -o -iname *.c -o -type d -name build -prune | \ + xargs clang-format --style=file -i diff --git a/unittest/main.cpp b/unittest/main.cpp index 811df98e..1e274ab2 100644 --- a/unittest/main.cpp +++ b/unittest/main.cpp @@ -2,6 +2,5 @@ #include "fsfw_tests/unit/CatchRunner.h" int main(int argc, char* argv[]) { - // fsfwtest::customMain(argc, argv); + // fsfwtest::customMain(argc, argv); } - diff --git a/unittest/rebootLogic/src/CoreController.cpp b/unittest/rebootLogic/src/CoreController.cpp index c01d61f8..87268b45 100644 --- a/unittest/rebootLogic/src/CoreController.cpp +++ b/unittest/rebootLogic/src/CoreController.cpp @@ -1,14 +1,15 @@ -#include "conf.h" -#include "HasActionsIF.h" #include "CoreController.h" -#include "SdCardManager.h" -#include "event.h" -#include "libxiphos.h" -#include "fsfw/serviceinterface/ServiceInterface.h" -#include -#include #include +#include +#include + +#include "HasActionsIF.h" +#include "SdCardManager.h" +#include "conf.h" +#include "event.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "libxiphos.h" xsc::Chip CoreController::CURRENT_CHIP = xsc::Chip::NO_CHIP; xsc::Copy CoreController::CURRENT_COPY = xsc::Copy::NO_COPY; @@ -123,7 +124,7 @@ void CoreController::performRebootFileHandling(bool recreateFile) { } else { rebootFile.mechanismNextChip = xsc::NO_CHIP; rebootFile.mechanismNextCopy = xsc::NO_COPY; - } + } rewriteRebootFile(rebootFile); } @@ -436,15 +437,15 @@ void CoreController::rewriteRebootFile(RebootFile file) { << "\nimg00lock: " << file.img00Lock << "\nimg01lock: " << file.img01Lock << "\nimg10lock: " << file.img10Lock << "\nimg11lock: " << file.img11Lock << "\nbootflag: " << file.bootFlag << "\nlast: " << static_cast(file.lastChip) - << " " << static_cast(file.lastCopy) << "\nnext: " - << static_cast(file.mechanismNextChip) << " " + << " " << static_cast(file.lastCopy) + << "\nnext: " << static_cast(file.mechanismNextChip) << " " << static_cast(file.mechanismNextCopy) << "\n"; } } ReturnValue_t CoreController::executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, const uint8_t *data, size_t size) { -switch (actionId) { + switch (actionId) { case (SWITCH_REBOOT_FILE_HANDLING): { if (size < 1) { return HasActionsIF::INVALID_PARAMETERS; @@ -464,10 +465,10 @@ switch (actionId) { return HasActionsIF::EXECUTION_FINISHED; } case (RESET_REBOOT_COUNTERS): { - if(size == 0) { + if (size == 0) { resetRebootCount(xsc::ALL_CHIP, xsc::ALL_COPY); } else if (size == 2) { - if(data[0] > 1 or data[1] > 1) { + if (data[0] > 1 or data[1] > 1) { return HasActionsIF::INVALID_PARAMETERS; } resetRebootCount(static_cast(data[0]), static_cast(data[1])); @@ -475,18 +476,18 @@ switch (actionId) { return HasActionsIF::EXECUTION_FINISHED; } case (SWITCH_IMG_LOCK): { - if(size != 3) { + if (size != 3) { return HasActionsIF::INVALID_PARAMETERS; } - if(data[1] > 1 or data[2] > 1) { + if (data[1] > 1 or data[2] > 1) { return HasActionsIF::INVALID_PARAMETERS; } setRebootMechanismLock(data[0], static_cast(data[1]), static_cast(data[2])); return HasActionsIF::EXECUTION_FINISHED; } - case(SET_MAX_REBOOT_CNT): { - if(size < 1) { + case (SET_MAX_REBOOT_CNT): { + if (size < 1) { return HasActionsIF::INVALID_PARAMETERS; } std::string path = sdcMan->getCurrentMountPrefix(sdInfo.pref) + REBOOT_FILE; diff --git a/unittest/rebootLogic/src/CoreController.h b/unittest/rebootLogic/src/CoreController.h index eec0d959..c79a4ccd 100644 --- a/unittest/rebootLogic/src/CoreController.h +++ b/unittest/rebootLogic/src/CoreController.h @@ -1,12 +1,12 @@ #pragma once -#include "definitions.h" -#include "SdCardManager.h" - -#include #include +#include #include +#include "SdCardManager.h" +#include "definitions.h" + namespace xsc { enum Chip : int { CHIP_0, CHIP_1, NO_CHIP, SELF_CHIP, ALL_CHIP }; @@ -14,7 +14,6 @@ enum Copy : int { COPY_0, COPY_1, NO_COPY, SELF_COPY, ALL_COPY }; } // namespace xsc - struct RebootFile { static constexpr uint8_t DEFAULT_MAX_BOOT_CNT = 10; @@ -39,7 +38,7 @@ struct RebootFile { class SdCardManager; class CoreController { -public: + public: static constexpr char REBOOT_FILE[] = "/conf/reboot.txt"; //! [EXPORT] : [COMMENT] The reboot mechanism was triggered. //! P1: First 16 bits: Last Chip, Last 16 bits: Last Copy, @@ -57,15 +56,16 @@ public: static void setCurrentBootCopy(xsc::Chip chip, xsc::Copy copy); ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, - const uint8_t* data, size_t size); + const uint8_t* data, size_t size); void performRebootFileHandling(bool recreateFile); void determineAndExecuteReboot(RebootFile& rf, bool& needsReboot, xsc::Chip& tgtChip, - xsc::Copy& tgtCopy); + xsc::Copy& tgtCopy); void setRebootMechanismLock(bool lock, xsc::Chip tgtChip, xsc::Copy tgtCopy); void resetRebootCount(xsc::Chip tgtChip, xsc::Copy tgtCopy); bool parseRebootFile(std::string path, RebootFile& file); void rewriteRebootFile(RebootFile file); -private: + + private: struct SdInfo { sd::SdCard pref = sd::SdCard::NONE; sd::SdState prefState = sd::SdState::OFF; diff --git a/unittest/rebootLogic/src/HasActionsIF.h b/unittest/rebootLogic/src/HasActionsIF.h index 773ad54f..1d56d891 100644 --- a/unittest/rebootLogic/src/HasActionsIF.h +++ b/unittest/rebootLogic/src/HasActionsIF.h @@ -1,7 +1,7 @@ #include "definitions.h" class HasActionsIF { -public: + public: static const ReturnValue_t IS_BUSY = 1; static const ReturnValue_t INVALID_PARAMETERS = 2; static const ReturnValue_t EXECUTION_FINISHED = 3; diff --git a/unittest/rebootLogic/src/SdCardManager.cpp b/unittest/rebootLogic/src/SdCardManager.cpp index 19bfa183..bf725956 100644 --- a/unittest/rebootLogic/src/SdCardManager.cpp +++ b/unittest/rebootLogic/src/SdCardManager.cpp @@ -1,9 +1,5 @@ #include "SdCardManager.h" -std::string SdCardManager::getCurrentMountPrefix(sd::SdCard prefSdCard) { - return "/tmp"; -} +std::string SdCardManager::getCurrentMountPrefix(sd::SdCard prefSdCard) { return "/tmp"; } -bool SdCardManager::isSdCardMounted(sd::SdCard sdCard) { - return true; -} \ No newline at end of file +bool SdCardManager::isSdCardMounted(sd::SdCard sdCard) { return true; } \ No newline at end of file diff --git a/unittest/rebootLogic/src/SdCardManager.h b/unittest/rebootLogic/src/SdCardManager.h index aee31d79..16aee0f4 100644 --- a/unittest/rebootLogic/src/SdCardManager.h +++ b/unittest/rebootLogic/src/SdCardManager.h @@ -17,7 +17,7 @@ enum SdCard : uint8_t { SLOT_0 = 0, SLOT_1 = 1, BOTH, NONE }; } // namespace sd class SdCardManager { -public: + public: std::string getCurrentMountPrefix(sd::SdCard prefSdCard); bool isSdCardMounted(sd::SdCard sdCard); }; diff --git a/unittest/rebootLogic/src/event.cpp b/unittest/rebootLogic/src/event.cpp index e6f6d8f8..54e5575a 100644 --- a/unittest/rebootLogic/src/event.cpp +++ b/unittest/rebootLogic/src/event.cpp @@ -1,4 +1,5 @@ #include "event.h" + #include std::queue EVENT_QUEUE = {}; @@ -13,7 +14,7 @@ void triggerEvent(Event event, uint32_t p1, uint32_t p2) { void eventWasCalled(EventInfo& eventInfo, uint32_t& numEvents) { numEvents = EVENT_QUEUE.size(); - if(not EVENT_QUEUE.empty()) { + if (not EVENT_QUEUE.empty()) { eventInfo = std::move(EVENT_QUEUE.back()); EVENT_QUEUE.pop(); } diff --git a/unittest/rebootLogic/src/event.h b/unittest/rebootLogic/src/event.h index 449836cd..fc831fe9 100644 --- a/unittest/rebootLogic/src/event.h +++ b/unittest/rebootLogic/src/event.h @@ -1,9 +1,10 @@ #pragma once -#include "definitions.h" #include #include +#include "definitions.h" + struct EventInfo { // That was just for testing, follow rule of 0 /* diff --git a/unittest/rebootLogic/src/fsfw/serviceinterface/ServiceInterfaceStream.h b/unittest/rebootLogic/src/fsfw/serviceinterface/ServiceInterfaceStream.h index bf3424a6..ca746e7d 100644 --- a/unittest/rebootLogic/src/fsfw/serviceinterface/ServiceInterfaceStream.h +++ b/unittest/rebootLogic/src/fsfw/serviceinterface/ServiceInterfaceStream.h @@ -1,9 +1,8 @@ #ifndef FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_ #define FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_ -#include "fsfw/FSFW.h" - #include "ServiceInterfaceBuffer.h" +#include "fsfw/FSFW.h" #if FSFW_CPP_OSTREAM_ENABLED == 1 diff --git a/unittest/rebootLogic/src/libxiphos.cpp b/unittest/rebootLogic/src/libxiphos.cpp index 00bbbae9..914b36e7 100644 --- a/unittest/rebootLogic/src/libxiphos.cpp +++ b/unittest/rebootLogic/src/libxiphos.cpp @@ -1,15 +1,16 @@ #include "libxiphos.h" + #include "CoreController.h" bool rebootWasCalled = false; xsc_libnor_chip_t lastChip; xsc_libnor_copy_t lastCopy; -bool getRebootWasCalled(xsc_libnor_chip_t& tgtChip, xsc_libnor_copy_t& tgtCopy) { +bool getRebootWasCalled(xsc_libnor_chip_t& tgtChip, xsc_libnor_copy_t& tgtCopy) { tgtChip = lastChip; tgtCopy = lastCopy; bool tmp = rebootWasCalled; - if(rebootWasCalled) { + if (rebootWasCalled) { rebootWasCalled = false; } return tmp; @@ -19,5 +20,6 @@ void xsc_boot_copy(xsc_libnor_chip_t boot_chip, xsc_libnor_copy_t boot_copy) { rebootWasCalled = true; lastChip = boot_chip; lastCopy = boot_copy; - CoreController::setCurrentBootCopy(static_cast(boot_chip), static_cast(boot_copy)); + CoreController::setCurrentBootCopy(static_cast(boot_chip), + static_cast(boot_copy)); } \ No newline at end of file diff --git a/unittest/rebootLogic/src/libxiphos.h b/unittest/rebootLogic/src/libxiphos.h index e6a40e45..341007c2 100644 --- a/unittest/rebootLogic/src/libxiphos.h +++ b/unittest/rebootLogic/src/libxiphos.h @@ -2,24 +2,24 @@ /** Type for identifying the nominal or the gold (redundant) flash copy */ typedef enum { - XSC_LIBNOR_COPY_NOMINAL, - XSC_LIBNOR_COPY_GOLD, - XSC_LIBNOR_COPY_TOTAL_NUMBER + XSC_LIBNOR_COPY_NOMINAL, + XSC_LIBNOR_COPY_GOLD, + XSC_LIBNOR_COPY_TOTAL_NUMBER } xsc_libnor_copy_t; /** Type for identifying on of the two NOR flash chips */ typedef enum { - XSC_LIBNOR_CHIP_0, /* First NOR flash chip */ - XSC_LIBNOR_CHIP_1, /* Second NOR flash chip */ - XSC_LIBNOR_CHIP_TOTAL_NUMBER + XSC_LIBNOR_CHIP_0, /* First NOR flash chip */ + XSC_LIBNOR_CHIP_1, /* Second NOR flash chip */ + XSC_LIBNOR_CHIP_TOTAL_NUMBER } xsc_libnor_chip_t; /** * @brief Used to verify whether reboot function was called - * - * @param tgtChip - * @param tgtCopy + * + * @param tgtChip + * @param tgtCopy */ -bool getRebootWasCalled(xsc_libnor_chip_t& tgtChip, xsc_libnor_copy_t& tgtCopy); +bool getRebootWasCalled(xsc_libnor_chip_t& tgtChip, xsc_libnor_copy_t& tgtCopy); void xsc_boot_copy(xsc_libnor_chip_t boot_chip, xsc_libnor_copy_t boot_copy); \ No newline at end of file diff --git a/unittest/rebootLogic/src/main.cpp b/unittest/rebootLogic/src/main.cpp index 14ae8be8..0a0febd7 100644 --- a/unittest/rebootLogic/src/main.cpp +++ b/unittest/rebootLogic/src/main.cpp @@ -1,13 +1,13 @@ +#include +#include +#include +#include + #include "CoreController.h" -#include "libxiphos.h" #include "HasActionsIF.h" #include "event.h" #include "fsfw/serviceinterface/ServiceInterface.h" - -#include -#include -#include -#include +#include "libxiphos.h" static constexpr bool CAT_FILE_TO_CONSOLE = false; const std::string CONF_PATH = "/tmp/conf"; @@ -20,14 +20,14 @@ ServiceInterfaceStream sif::info("INFO"); ServiceInterfaceStream sif::warning("WARNING"); ServiceInterfaceStream sif::error("ERROR", false, false, true); -TEST_CASE( "Core Controller Reboot File Handling", "[reboot-file]" ) { - if(not std::filesystem::exists(CONF_PATH)) { +TEST_CASE("Core Controller Reboot File Handling", "[reboot-file]") { + if (not std::filesystem::exists(CONF_PATH)) { std::filesystem::create_directory(CONF_PATH); } CoreController ctrl; std::array cmdData = {}; - SECTION ("Primary") { + SECTION("Primary") { xsc_libnor_chip_t chip; xsc_libnor_copy_t copy; RebootFile rf = {}; @@ -57,7 +57,8 @@ TEST_CASE( "Core Controller Reboot File Handling", "[reboot-file]" ) { REQUIRE(rf.lastChip == xsc::CHIP_0); REQUIRE(rf.lastCopy == xsc::COPY_0); uint8_t newRebootCnt = 3; - CHECK(ctrl.executeAction(CoreController::SET_MAX_REBOOT_CNT, 0, &newRebootCnt, 1) == HasActionsIF::EXECUTION_FINISHED); + CHECK(ctrl.executeAction(CoreController::SET_MAX_REBOOT_CNT, 0, &newRebootCnt, 1) == + HasActionsIF::EXECUTION_FINISHED); ctrl.parseRebootFile(REBOOT_FILE, rf); REQUIRE(rf.enabled == 1); REQUIRE(rf.maxCount == 3); @@ -396,14 +397,14 @@ TEST_CASE( "Core Controller Reboot File Handling", "[reboot-file]" ) { REQUIRE(CoreController::CURRENT_CHIP == xsc::CHIP_1); REQUIRE(CoreController::CURRENT_COPY == xsc::COPY_0); } - if(std::filesystem::exists(CONF_PATH)) { + if (std::filesystem::exists(CONF_PATH)) { std::uintmax_t n = std::filesystem::remove_all(CONF_PATH); CHECK(n == 2); } } void catFileToConsole() { - if(CAT_FILE_TO_CONSOLE) { + if (CAT_FILE_TO_CONSOLE) { std::ifstream file(REBOOT_FILE); if (file.is_open()) { std::cout << file.rdbuf(); diff --git a/unittest/rebootLogic/src/print.c b/unittest/rebootLogic/src/print.c index a59492b0..3d0d9b9d 100644 --- a/unittest/rebootLogic/src/print.c +++ b/unittest/rebootLogic/src/print.c @@ -1,5 +1,5 @@ -#include #include +#include void printChar(const char* character, bool errStream) { if (errStream) {