apply clang format to unittest folder as well
Some checks failed
EIVE/eive-obsw/pipeline/pr-develop There was a failure building this commit

This commit is contained in:
Robin Müller 2022-03-01 15:06:59 +01:00
parent be122038ed
commit 9e03f9babe
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
14 changed files with 69 additions and 67 deletions

View File

@ -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_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 ./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 ./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

View File

@ -2,6 +2,5 @@
#include "fsfw_tests/unit/CatchRunner.h" #include "fsfw_tests/unit/CatchRunner.h"
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
// fsfwtest::customMain(argc, argv); // fsfwtest::customMain(argc, argv);
} }

View File

@ -1,14 +1,15 @@
#include "conf.h"
#include "HasActionsIF.h"
#include "CoreController.h" #include "CoreController.h"
#include "SdCardManager.h"
#include "event.h"
#include "libxiphos.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include <iostream>
#include <fstream>
#include <filesystem> #include <filesystem>
#include <fstream>
#include <iostream>
#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::Chip CoreController::CURRENT_CHIP = xsc::Chip::NO_CHIP;
xsc::Copy CoreController::CURRENT_COPY = xsc::Copy::NO_COPY; xsc::Copy CoreController::CURRENT_COPY = xsc::Copy::NO_COPY;
@ -436,15 +437,15 @@ void CoreController::rewriteRebootFile(RebootFile file) {
<< "\nimg00lock: " << file.img00Lock << "\nimg01lock: " << file.img01Lock << "\nimg00lock: " << file.img00Lock << "\nimg01lock: " << file.img01Lock
<< "\nimg10lock: " << file.img10Lock << "\nimg11lock: " << file.img11Lock << "\nimg10lock: " << file.img10Lock << "\nimg11lock: " << file.img11Lock
<< "\nbootflag: " << file.bootFlag << "\nlast: " << static_cast<int>(file.lastChip) << "\nbootflag: " << file.bootFlag << "\nlast: " << static_cast<int>(file.lastChip)
<< " " << static_cast<int>(file.lastCopy) << "\nnext: " << " " << static_cast<int>(file.lastCopy)
<< static_cast<int>(file.mechanismNextChip) << " " << "\nnext: " << static_cast<int>(file.mechanismNextChip) << " "
<< static_cast<int>(file.mechanismNextCopy) << "\n"; << static_cast<int>(file.mechanismNextCopy) << "\n";
} }
} }
ReturnValue_t CoreController::executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, ReturnValue_t CoreController::executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
const uint8_t *data, size_t size) { const uint8_t *data, size_t size) {
switch (actionId) { switch (actionId) {
case (SWITCH_REBOOT_FILE_HANDLING): { case (SWITCH_REBOOT_FILE_HANDLING): {
if (size < 1) { if (size < 1) {
return HasActionsIF::INVALID_PARAMETERS; return HasActionsIF::INVALID_PARAMETERS;
@ -464,10 +465,10 @@ switch (actionId) {
return HasActionsIF::EXECUTION_FINISHED; return HasActionsIF::EXECUTION_FINISHED;
} }
case (RESET_REBOOT_COUNTERS): { case (RESET_REBOOT_COUNTERS): {
if(size == 0) { if (size == 0) {
resetRebootCount(xsc::ALL_CHIP, xsc::ALL_COPY); resetRebootCount(xsc::ALL_CHIP, xsc::ALL_COPY);
} else if (size == 2) { } else if (size == 2) {
if(data[0] > 1 or data[1] > 1) { if (data[0] > 1 or data[1] > 1) {
return HasActionsIF::INVALID_PARAMETERS; return HasActionsIF::INVALID_PARAMETERS;
} }
resetRebootCount(static_cast<xsc::Chip>(data[0]), static_cast<xsc::Copy>(data[1])); resetRebootCount(static_cast<xsc::Chip>(data[0]), static_cast<xsc::Copy>(data[1]));
@ -475,18 +476,18 @@ switch (actionId) {
return HasActionsIF::EXECUTION_FINISHED; return HasActionsIF::EXECUTION_FINISHED;
} }
case (SWITCH_IMG_LOCK): { case (SWITCH_IMG_LOCK): {
if(size != 3) { if (size != 3) {
return HasActionsIF::INVALID_PARAMETERS; return HasActionsIF::INVALID_PARAMETERS;
} }
if(data[1] > 1 or data[2] > 1) { if (data[1] > 1 or data[2] > 1) {
return HasActionsIF::INVALID_PARAMETERS; return HasActionsIF::INVALID_PARAMETERS;
} }
setRebootMechanismLock(data[0], static_cast<xsc::Chip>(data[1]), setRebootMechanismLock(data[0], static_cast<xsc::Chip>(data[1]),
static_cast<xsc::Copy>(data[2])); static_cast<xsc::Copy>(data[2]));
return HasActionsIF::EXECUTION_FINISHED; return HasActionsIF::EXECUTION_FINISHED;
} }
case(SET_MAX_REBOOT_CNT): { case (SET_MAX_REBOOT_CNT): {
if(size < 1) { if (size < 1) {
return HasActionsIF::INVALID_PARAMETERS; return HasActionsIF::INVALID_PARAMETERS;
} }
std::string path = sdcMan->getCurrentMountPrefix(sdInfo.pref) + REBOOT_FILE; std::string path = sdcMan->getCurrentMountPrefix(sdInfo.pref) + REBOOT_FILE;

View File

@ -1,12 +1,12 @@
#pragma once #pragma once
#include "definitions.h"
#include "SdCardManager.h"
#include <cstdint>
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <string> #include <string>
#include "SdCardManager.h"
#include "definitions.h"
namespace xsc { namespace xsc {
enum Chip : int { CHIP_0, CHIP_1, NO_CHIP, SELF_CHIP, ALL_CHIP }; 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 } // namespace xsc
struct RebootFile { struct RebootFile {
static constexpr uint8_t DEFAULT_MAX_BOOT_CNT = 10; static constexpr uint8_t DEFAULT_MAX_BOOT_CNT = 10;
@ -39,7 +38,7 @@ struct RebootFile {
class SdCardManager; class SdCardManager;
class CoreController { class CoreController {
public: public:
static constexpr char REBOOT_FILE[] = "/conf/reboot.txt"; static constexpr char REBOOT_FILE[] = "/conf/reboot.txt";
//! [EXPORT] : [COMMENT] The reboot mechanism was triggered. //! [EXPORT] : [COMMENT] The reboot mechanism was triggered.
//! P1: First 16 bits: Last Chip, Last 16 bits: Last Copy, //! 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); static void setCurrentBootCopy(xsc::Chip chip, xsc::Copy copy);
ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, 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 performRebootFileHandling(bool recreateFile);
void determineAndExecuteReboot(RebootFile& rf, bool& needsReboot, xsc::Chip& tgtChip, 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 setRebootMechanismLock(bool lock, xsc::Chip tgtChip, xsc::Copy tgtCopy);
void resetRebootCount(xsc::Chip tgtChip, xsc::Copy tgtCopy); void resetRebootCount(xsc::Chip tgtChip, xsc::Copy tgtCopy);
bool parseRebootFile(std::string path, RebootFile& file); bool parseRebootFile(std::string path, RebootFile& file);
void rewriteRebootFile(RebootFile file); void rewriteRebootFile(RebootFile file);
private:
private:
struct SdInfo { struct SdInfo {
sd::SdCard pref = sd::SdCard::NONE; sd::SdCard pref = sd::SdCard::NONE;
sd::SdState prefState = sd::SdState::OFF; sd::SdState prefState = sd::SdState::OFF;

View File

@ -1,7 +1,7 @@
#include "definitions.h" #include "definitions.h"
class HasActionsIF { class HasActionsIF {
public: public:
static const ReturnValue_t IS_BUSY = 1; static const ReturnValue_t IS_BUSY = 1;
static const ReturnValue_t INVALID_PARAMETERS = 2; static const ReturnValue_t INVALID_PARAMETERS = 2;
static const ReturnValue_t EXECUTION_FINISHED = 3; static const ReturnValue_t EXECUTION_FINISHED = 3;

View File

@ -1,9 +1,5 @@
#include "SdCardManager.h" #include "SdCardManager.h"
std::string SdCardManager::getCurrentMountPrefix(sd::SdCard prefSdCard) { std::string SdCardManager::getCurrentMountPrefix(sd::SdCard prefSdCard) { return "/tmp"; }
return "/tmp";
}
bool SdCardManager::isSdCardMounted(sd::SdCard sdCard) { bool SdCardManager::isSdCardMounted(sd::SdCard sdCard) { return true; }
return true;
}

View File

@ -17,7 +17,7 @@ enum SdCard : uint8_t { SLOT_0 = 0, SLOT_1 = 1, BOTH, NONE };
} // namespace sd } // namespace sd
class SdCardManager { class SdCardManager {
public: public:
std::string getCurrentMountPrefix(sd::SdCard prefSdCard); std::string getCurrentMountPrefix(sd::SdCard prefSdCard);
bool isSdCardMounted(sd::SdCard sdCard); bool isSdCardMounted(sd::SdCard sdCard);
}; };

View File

@ -1,4 +1,5 @@
#include "event.h" #include "event.h"
#include <queue> #include <queue>
std::queue<EventInfo> EVENT_QUEUE = {}; std::queue<EventInfo> EVENT_QUEUE = {};
@ -13,7 +14,7 @@ void triggerEvent(Event event, uint32_t p1, uint32_t p2) {
void eventWasCalled(EventInfo& eventInfo, uint32_t& numEvents) { void eventWasCalled(EventInfo& eventInfo, uint32_t& numEvents) {
numEvents = EVENT_QUEUE.size(); numEvents = EVENT_QUEUE.size();
if(not EVENT_QUEUE.empty()) { if (not EVENT_QUEUE.empty()) {
eventInfo = std::move(EVENT_QUEUE.back()); eventInfo = std::move(EVENT_QUEUE.back());
EVENT_QUEUE.pop(); EVENT_QUEUE.pop();
} }

View File

@ -1,9 +1,10 @@
#pragma once #pragma once
#include "definitions.h"
#include <cstdint> #include <cstdint>
#include <iostream> #include <iostream>
#include "definitions.h"
struct EventInfo { struct EventInfo {
// That was just for testing, follow rule of 0 // That was just for testing, follow rule of 0
/* /*

View File

@ -1,9 +1,8 @@
#ifndef FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_ #ifndef FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_
#define FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_ #define FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_
#include "fsfw/FSFW.h"
#include "ServiceInterfaceBuffer.h" #include "ServiceInterfaceBuffer.h"
#include "fsfw/FSFW.h"
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1

View File

@ -1,15 +1,16 @@
#include "libxiphos.h" #include "libxiphos.h"
#include "CoreController.h" #include "CoreController.h"
bool rebootWasCalled = false; bool rebootWasCalled = false;
xsc_libnor_chip_t lastChip; xsc_libnor_chip_t lastChip;
xsc_libnor_copy_t lastCopy; 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; tgtChip = lastChip;
tgtCopy = lastCopy; tgtCopy = lastCopy;
bool tmp = rebootWasCalled; bool tmp = rebootWasCalled;
if(rebootWasCalled) { if (rebootWasCalled) {
rebootWasCalled = false; rebootWasCalled = false;
} }
return tmp; return tmp;
@ -19,5 +20,6 @@ void xsc_boot_copy(xsc_libnor_chip_t boot_chip, xsc_libnor_copy_t boot_copy) {
rebootWasCalled = true; rebootWasCalled = true;
lastChip = boot_chip; lastChip = boot_chip;
lastCopy = boot_copy; lastCopy = boot_copy;
CoreController::setCurrentBootCopy(static_cast<xsc::Chip>(boot_chip), static_cast<xsc::Copy>(boot_copy)); CoreController::setCurrentBootCopy(static_cast<xsc::Chip>(boot_chip),
static_cast<xsc::Copy>(boot_copy));
} }

View File

@ -2,16 +2,16 @@
/** Type for identifying the nominal or the gold (redundant) flash copy */ /** Type for identifying the nominal or the gold (redundant) flash copy */
typedef enum { typedef enum {
XSC_LIBNOR_COPY_NOMINAL, XSC_LIBNOR_COPY_NOMINAL,
XSC_LIBNOR_COPY_GOLD, XSC_LIBNOR_COPY_GOLD,
XSC_LIBNOR_COPY_TOTAL_NUMBER XSC_LIBNOR_COPY_TOTAL_NUMBER
} xsc_libnor_copy_t; } xsc_libnor_copy_t;
/** Type for identifying on of the two NOR flash chips */ /** Type for identifying on of the two NOR flash chips */
typedef enum { typedef enum {
XSC_LIBNOR_CHIP_0, /* First NOR flash chip */ XSC_LIBNOR_CHIP_0, /* First NOR flash chip */
XSC_LIBNOR_CHIP_1, /* Second NOR flash chip */ XSC_LIBNOR_CHIP_1, /* Second NOR flash chip */
XSC_LIBNOR_CHIP_TOTAL_NUMBER XSC_LIBNOR_CHIP_TOTAL_NUMBER
} xsc_libnor_chip_t; } xsc_libnor_chip_t;
/** /**
@ -20,6 +20,6 @@ typedef enum {
* @param tgtChip * @param tgtChip
* @param tgtCopy * @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); void xsc_boot_copy(xsc_libnor_chip_t boot_chip, xsc_libnor_copy_t boot_copy);

View File

@ -1,13 +1,13 @@
#include <catch2/catch_test_macros.hpp>
#include <filesystem>
#include <fstream>
#include <iostream>
#include "CoreController.h" #include "CoreController.h"
#include "libxiphos.h"
#include "HasActionsIF.h" #include "HasActionsIF.h"
#include "event.h" #include "event.h"
#include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/serviceinterface/ServiceInterface.h"
#include "libxiphos.h"
#include <catch2/catch_test_macros.hpp>
#include <iostream>
#include <fstream>
#include <filesystem>
static constexpr bool CAT_FILE_TO_CONSOLE = false; static constexpr bool CAT_FILE_TO_CONSOLE = false;
const std::string CONF_PATH = "/tmp/conf"; const std::string CONF_PATH = "/tmp/conf";
@ -20,14 +20,14 @@ ServiceInterfaceStream sif::info("INFO");
ServiceInterfaceStream sif::warning("WARNING"); ServiceInterfaceStream sif::warning("WARNING");
ServiceInterfaceStream sif::error("ERROR", false, false, true); ServiceInterfaceStream sif::error("ERROR", false, false, true);
TEST_CASE( "Core Controller Reboot File Handling", "[reboot-file]" ) { TEST_CASE("Core Controller Reboot File Handling", "[reboot-file]") {
if(not std::filesystem::exists(CONF_PATH)) { if (not std::filesystem::exists(CONF_PATH)) {
std::filesystem::create_directory(CONF_PATH); std::filesystem::create_directory(CONF_PATH);
} }
CoreController ctrl; CoreController ctrl;
std::array<uint8_t, 12> cmdData = {}; std::array<uint8_t, 12> cmdData = {};
SECTION ("Primary") { SECTION("Primary") {
xsc_libnor_chip_t chip; xsc_libnor_chip_t chip;
xsc_libnor_copy_t copy; xsc_libnor_copy_t copy;
RebootFile rf = {}; RebootFile rf = {};
@ -57,7 +57,8 @@ TEST_CASE( "Core Controller Reboot File Handling", "[reboot-file]" ) {
REQUIRE(rf.lastChip == xsc::CHIP_0); REQUIRE(rf.lastChip == xsc::CHIP_0);
REQUIRE(rf.lastCopy == xsc::COPY_0); REQUIRE(rf.lastCopy == xsc::COPY_0);
uint8_t newRebootCnt = 3; 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); ctrl.parseRebootFile(REBOOT_FILE, rf);
REQUIRE(rf.enabled == 1); REQUIRE(rf.enabled == 1);
REQUIRE(rf.maxCount == 3); 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_CHIP == xsc::CHIP_1);
REQUIRE(CoreController::CURRENT_COPY == xsc::COPY_0); 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); std::uintmax_t n = std::filesystem::remove_all(CONF_PATH);
CHECK(n == 2); CHECK(n == 2);
} }
} }
void catFileToConsole() { void catFileToConsole() {
if(CAT_FILE_TO_CONSOLE) { if (CAT_FILE_TO_CONSOLE) {
std::ifstream file(REBOOT_FILE); std::ifstream file(REBOOT_FILE);
if (file.is_open()) { if (file.is_open()) {
std::cout << file.rdbuf(); std::cout << file.rdbuf();

View File

@ -1,5 +1,5 @@
#include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h>
void printChar(const char* character, bool errStream) { void printChar(const char* character, bool errStream) {
if (errStream) { if (errStream) {