windows compiles, some unittests give exceptions
This commit is contained in:
parent
0e7c6b117f
commit
dcc28622a5
@ -449,6 +449,7 @@ endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||
set(COMPILER_FLAGS "/permissive-")
|
||||
add_compile_definitions(NOMINMAX not=! and=&& or=||)
|
||||
endif()
|
||||
|
||||
# Required include paths to compile the FSFW
|
||||
|
@ -9,6 +9,11 @@
|
||||
#include "fsfw/returnvalues/FwClassIds.h"
|
||||
#include "fsfw/returnvalues/returnvalue.h"
|
||||
|
||||
// Thanks, windows
|
||||
#ifdef NO_ERROR
|
||||
#undef NO_ERROR
|
||||
#endif
|
||||
|
||||
namespace cfdp {
|
||||
|
||||
static constexpr char CFDP_VERSION_2_NAME[] = "CCSDS 727.0-B-5";
|
||||
|
@ -1,5 +1,10 @@
|
||||
#include "FinishedPduReader.h"
|
||||
|
||||
// Thanks, windows
|
||||
#ifdef NO_ERROR
|
||||
#undef NO_ERROR
|
||||
#endif
|
||||
|
||||
FinishPduReader::FinishPduReader(const uint8_t* pduBuf, size_t maxSize, FinishedInfo& info)
|
||||
: FileDirectiveReader(pduBuf, maxSize), finishedInfo(info) {}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef FSFW_MEMORY_HASFILESYSTEMIF_H_
|
||||
#define FSFW_MEMORY_HASFILESYSTEMIF_H_
|
||||
|
||||
#include <filesystem>
|
||||
#include <cstddef>
|
||||
|
||||
#include "FileSystemArgsIF.h"
|
||||
@ -10,16 +11,17 @@
|
||||
#include "fsfw/returnvalues/returnvalue.h"
|
||||
|
||||
struct FilesystemParams {
|
||||
explicit FilesystemParams(const char* path) : path(path) {}
|
||||
explicit FilesystemParams(const std::filesystem::path::value_type* path) : path(path) {}
|
||||
|
||||
const char* path;
|
||||
const std::filesystem::path::value_type* path;
|
||||
FileSystemArgsIF* args = nullptr;
|
||||
};
|
||||
|
||||
struct FileOpParams {
|
||||
FileOpParams(const char* path, size_t size) : fsParams(path), size(size) {}
|
||||
FileOpParams(const std::filesystem::path::value_type* path, size_t size)
|
||||
: fsParams(path), size(size) {}
|
||||
|
||||
[[nodiscard]] const char* path() const { return fsParams.path; }
|
||||
[[nodiscard]] const std::filesystem::path::value_type* path() const { return fsParams.path; }
|
||||
|
||||
[[nodiscard]] FileSystemArgsIF* args() const { return fsParams.args; }
|
||||
|
||||
@ -139,8 +141,11 @@ class HasFileSystemIF {
|
||||
* @param args Any other arguments which an implementation might require
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t removeFile(const char* path, FileSystemArgsIF* args) = 0;
|
||||
virtual ReturnValue_t removeFile(const char* path) { return removeFile(path, nullptr); }
|
||||
virtual ReturnValue_t removeFile(const std::filesystem::path::value_type* path,
|
||||
FileSystemArgsIF* args) = 0;
|
||||
virtual ReturnValue_t removeFile(const std::filesystem::path::value_type* path) {
|
||||
return removeFile(path, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Generic function to create a directory
|
||||
@ -165,10 +170,12 @@ class HasFileSystemIF {
|
||||
return removeDirectory(params, false);
|
||||
}
|
||||
|
||||
virtual ReturnValue_t rename(const char* oldPath, const char* newPath) {
|
||||
virtual ReturnValue_t rename(const std::filesystem::path::value_type* oldPath,
|
||||
const std::filesystem::path::value_type* newPath) {
|
||||
return rename(oldPath, newPath, nullptr);
|
||||
}
|
||||
virtual ReturnValue_t rename(const char* oldPath, const char* newPath,
|
||||
virtual ReturnValue_t rename(const std::filesystem::path::value_type* oldPath,
|
||||
const std::filesystem::path::value_type* newPath,
|
||||
FileSystemArgsIF* args) = 0;
|
||||
};
|
||||
|
||||
|
@ -58,7 +58,7 @@ class Type : public SerializeIF {
|
||||
|
||||
template <typename T>
|
||||
struct PodTypeConversion {
|
||||
static_assert(not std::is_same<T, bool>::value,
|
||||
static_assert(! std::is_same<T, bool>::value,
|
||||
"Do not use boolean for the PoolEntry type, use uint8_t "
|
||||
"instead! The ECSS standard defines a boolean as a one bit "
|
||||
"field. Therefore it is preferred to store a boolean as an "
|
||||
|
@ -37,16 +37,16 @@ void arrayprinter::print(const uint8_t *data, size_t size, OutputType type, bool
|
||||
}
|
||||
}
|
||||
|
||||
void arrayprinter::printHex(const uint8_t *data, size_t size, size_t maxCharPerLine) {
|
||||
void arrayprinter::printHex(const uint8_t *data, size_t datasize, size_t maxCharPerLine) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
if (sif::info.crAdditionEnabled()) {
|
||||
std::cout << "\r" << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "hex [" << std::setfill('0') << std::hex;
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
for (size_t i = 0; i < datasize; i++) {
|
||||
std::cout << std::setw(2) << static_cast<int>(data[i]);
|
||||
if (i < size - 1) {
|
||||
if (i < datasize - 1) {
|
||||
std::cout << ",";
|
||||
if (i > 0 and (i + 1) % maxCharPerLine == 0) {
|
||||
std::cout << std::endl;
|
||||
@ -56,27 +56,11 @@ void arrayprinter::printHex(const uint8_t *data, size_t size, size_t maxCharPerL
|
||||
std::cout << std::dec << std::setfill(' ');
|
||||
std::cout << "]" << std::endl;
|
||||
#else
|
||||
// General format: 0x01, 0x02, 0x03 so it is number of chars times 6
|
||||
// plus line break plus small safety margin.
|
||||
char printBuffer[(size + 1) * 7 + 1] = {};
|
||||
size_t currentPos = 0;
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
// To avoid buffer overflows.
|
||||
if (sizeof(printBuffer) - currentPos <= 7) {
|
||||
break;
|
||||
}
|
||||
|
||||
currentPos += snprintf(printBuffer + currentPos, 6, "%02x", data[i]);
|
||||
if (i < size - 1) {
|
||||
currentPos += sprintf(printBuffer + currentPos, ",");
|
||||
if ((i + 1) % maxCharPerLine == 0) {
|
||||
currentPos += sprintf(printBuffer + currentPos, "\n");
|
||||
}
|
||||
}
|
||||
printf("hex [");
|
||||
for (size_t i = 0; i < datasize; i++) {
|
||||
printf("0x%02x ", data[i]);
|
||||
}
|
||||
#if FSFW_DISABLE_PRINTOUT == 0
|
||||
printf("hex [%s]\n", printBuffer);
|
||||
#endif /* FSFW_DISABLE_PRINTOUT == 0 */
|
||||
printf("]\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -100,26 +84,10 @@ void arrayprinter::printDec(const uint8_t *data, size_t size, size_t maxCharPerL
|
||||
#else
|
||||
// General format: 32,243,-12 so it is number of chars times 4
|
||||
// plus line break plus small safety margin.
|
||||
uint16_t expectedLines = ceil((double)size / maxCharPerLine);
|
||||
char printBuffer[size * 4 + 1 + expectedLines] = {};
|
||||
size_t currentPos = 0;
|
||||
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
// To avoid buffer overflows.
|
||||
if (sizeof(printBuffer) - currentPos <= 4) {
|
||||
break;
|
||||
}
|
||||
|
||||
currentPos += snprintf(printBuffer + currentPos, 4, "%d", data[i]);
|
||||
if (i < size - 1) {
|
||||
currentPos += sprintf(printBuffer + currentPos, ",");
|
||||
if ((i + 1) % maxCharPerLine == 0) {
|
||||
currentPos += sprintf(printBuffer + currentPos, "\n");
|
||||
}
|
||||
}
|
||||
//TODO
|
||||
}
|
||||
#if FSFW_DISABLE_PRINTOUT == 0
|
||||
printf("dec [%s]\n", printBuffer);
|
||||
#endif /* FSFW_DISABLE_PRINTOUT == 0 */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -24,8 +24,8 @@
|
||||
#else
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#if REG_DWORD == REG_DWORD_LITTLE_ENDIAN
|
||||
#define BYTE_ORDER_SYSTEM LITTLE_ENDIAN
|
||||
#else
|
||||
|
@ -17,6 +17,7 @@
|
||||
#ifdef PLATFORM_WIN
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
typedef SSIZE_T ssize_t;
|
||||
#elif defined(PLATFORM_UNIX)
|
||||
#include <netdb.h>
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#ifdef PLATFORM_WIN
|
||||
#include <winsock2.h>
|
||||
typedef SSIZE_T ssize_t;
|
||||
#elif defined(PLATFORM_UNIX)
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#ifdef PLATFORM_WIN
|
||||
#include <ws2tcpip.h>
|
||||
typedef SSIZE_T ssize_t;
|
||||
#elif defined(PLATFORM_UNIX)
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
|
||||
#if defined(PLATFORM_WIN)
|
||||
#include <processthreadsapi.h>
|
||||
|
||||
|
||||
#include "fsfw/osal/windows/winTaskHelpers.h"
|
||||
#elif defined(PLATFORM_UNIX)
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <fsfw/returnvalues/returnvalue.h>
|
||||
|
||||
#include <thread>
|
||||
#include <string>
|
||||
|
||||
namespace tasks {
|
||||
|
||||
|
@ -5,7 +5,8 @@
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <minwindef.h>
|
||||
#include <windows.h>
|
||||
#include <processthreadsapi.h>
|
||||
|
||||
namespace tasks {
|
||||
|
||||
|
@ -33,7 +33,7 @@
|
||||
* @author baetz
|
||||
* @ingroup serialize
|
||||
*/
|
||||
template <typename T, typename count_t = uint8_t>
|
||||
template <typename T, typename count_t = size_t>
|
||||
class SerialLinkedListAdapter : public SinglyLinkedList<T>, public SerializeIF {
|
||||
public:
|
||||
SerialLinkedListAdapter(typename LinkedElement<T>::Iterator start, bool printCount = false)
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#ifdef PLATFORM_WIN
|
||||
// wtf? Required for timeval!
|
||||
#include <winsock2.h>
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void __attribute__((weak)) printChar(const char* character, bool errStream) {
|
||||
void printChar(const char* character, bool errStream) {
|
||||
if (errStream) {
|
||||
fprintf(stderr, "%c", *character);
|
||||
} else {
|
||||
|
@ -69,7 +69,8 @@ ReturnValue_t HostFilesystem::createFile(FilesystemParams params, const uint8_t
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t HostFilesystem::removeFile(const char *path_, FileSystemArgsIF *args) {
|
||||
ReturnValue_t HostFilesystem::removeFile(const std::filesystem::path::value_type *path_,
|
||||
FileSystemArgsIF *args) {
|
||||
if (path_ == nullptr) {
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
@ -132,7 +133,8 @@ ReturnValue_t HostFilesystem::removeDirectory(FilesystemParams params, bool dele
|
||||
return HasFileSystemIF::GENERIC_DIR_ERROR;
|
||||
}
|
||||
|
||||
ReturnValue_t HostFilesystem::rename(const char *oldPath_, const char *newPath_,
|
||||
ReturnValue_t HostFilesystem::rename(const std::filesystem::path::value_type *oldPath_,
|
||||
const std::filesystem::path::value_type *newPath_,
|
||||
FileSystemArgsIF *args) {
|
||||
if (oldPath_ == nullptr or newPath_ == nullptr) {
|
||||
return returnvalue::FAILED;
|
||||
|
@ -15,10 +15,12 @@ class HostFilesystem : public HasFileSystemIF {
|
||||
ReturnValue_t readFromFile(FileOpParams fileOpInfo, uint8_t **buffer, size_t &readSize,
|
||||
size_t maxSize) override;
|
||||
ReturnValue_t createFile(FilesystemParams params, const uint8_t *data, size_t size) override;
|
||||
ReturnValue_t removeFile(const char *path, FileSystemArgsIF *args) override;
|
||||
ReturnValue_t removeFile(const std::filesystem::path::value_type *path, FileSystemArgsIF *args) override;
|
||||
ReturnValue_t createDirectory(FilesystemParams params, bool createParentDirs) override;
|
||||
ReturnValue_t removeDirectory(FilesystemParams params, bool deleteRecurively) override;
|
||||
ReturnValue_t rename(const char *oldPath, const char *newPath, FileSystemArgsIF *args) override;
|
||||
ReturnValue_t rename(const std::filesystem::path::value_type *oldPath,
|
||||
const std::filesystem::path::value_type *newPath,
|
||||
FileSystemArgsIF *args) override;
|
||||
|
||||
std::error_code errorCode;
|
||||
using HasFileSystemIF::createDirectory;
|
||||
|
@ -2,6 +2,11 @@
|
||||
|
||||
#include "mocks/cfdp/FaultHandlerMock.h"
|
||||
|
||||
// Thanks, windows
|
||||
#ifdef NO_ERROR
|
||||
#undef NO_ERROR
|
||||
#endif
|
||||
|
||||
TEST_CASE("CFDP Fault Handler", "[cfdp]") {
|
||||
using namespace cfdp;
|
||||
auto fhMock = FaultHandlerMock();
|
||||
|
@ -5,6 +5,11 @@
|
||||
#include "fsfw/cfdp/pdu/AckPduReader.h"
|
||||
#include "fsfw/globalfunctions/arrayprinter.h"
|
||||
|
||||
// Thanks, windows
|
||||
#ifdef NO_ERROR
|
||||
#undef NO_ERROR
|
||||
#endif
|
||||
|
||||
TEST_CASE("ACK PDU", "[cfdp][pdu]") {
|
||||
using namespace cfdp;
|
||||
ReturnValue_t result;
|
||||
|
@ -5,6 +5,11 @@
|
||||
#include "fsfw/cfdp/pdu/FinishedPduReader.h"
|
||||
#include "fsfw/globalfunctions/arrayprinter.h"
|
||||
|
||||
// Thanks, windows
|
||||
#ifdef NO_ERROR
|
||||
#undef NO_ERROR
|
||||
#endif
|
||||
|
||||
TEST_CASE("Finished PDU", "[cfdp][pdu]") {
|
||||
using namespace cfdp;
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
|
@ -30,7 +30,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
|
||||
CHECK(localSet.getSid() == lpool::testSid);
|
||||
CHECK(localSet.getCreatorObjectId() == objects::TEST_LOCAL_POOL_OWNER_BASE);
|
||||
size_t maxSize = localSet.getLocalPoolIdsSerializedSize(true);
|
||||
uint8_t localPoolIdBuff[maxSize];
|
||||
uint8_t localPoolIdBuff[ 3 * sizeof(lp_id_t) + sizeof(uint8_t)];
|
||||
/* Skip size field */
|
||||
auto* lpIds = reinterpret_cast<lp_id_t*>(localPoolIdBuff + 1);
|
||||
size_t serSize = 0;
|
||||
@ -105,29 +105,30 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
|
||||
/* Now we serialize these values into a buffer without the validity buffer */
|
||||
localSet.setValidityBufferGeneration(false);
|
||||
maxSize = localSet.getSerializedSize();
|
||||
CHECK(maxSize == sizeof(uint8_t) + sizeof(uint16_t) * 3 + sizeof(float));
|
||||
CHECK(maxSize == sizeof(uint8_t) + sizeof(float) + sizeof(uint16_t) * 3);
|
||||
serSize = 0;
|
||||
/* Already reserve additional space for validity buffer, will be needed later */
|
||||
uint8_t buffer[maxSize + 1];
|
||||
uint8_t* buffPtr = buffer;
|
||||
std::vector<uint8_t> buffer(maxSize);
|
||||
uint8_t* buffPtr = buffer.data();
|
||||
CHECK(localSet.serialize(&buffPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) ==
|
||||
returnvalue::OK);
|
||||
uint8_t rawUint8 = buffer[0];
|
||||
CHECK(rawUint8 == 232);
|
||||
float rawFloat = 0.0;
|
||||
std::memcpy(&rawFloat, buffer + sizeof(uint8_t), sizeof(float));
|
||||
std::memcpy(&rawFloat, buffer.data() + sizeof(uint8_t), sizeof(float));
|
||||
CHECK(rawFloat == Catch::Approx(-2324.322));
|
||||
|
||||
uint16_t rawUint16Vec[3];
|
||||
std::memcpy(&rawUint16Vec, buffer + sizeof(uint8_t) + sizeof(float), 3 * sizeof(uint16_t));
|
||||
std::memcpy(&rawUint16Vec, buffer.data() + sizeof(uint8_t) + sizeof(float),
|
||||
3 * sizeof(uint16_t));
|
||||
CHECK(rawUint16Vec[0] == 232);
|
||||
CHECK(rawUint16Vec[1] == 23923);
|
||||
CHECK(rawUint16Vec[2] == 1);
|
||||
|
||||
size_t sizeToDeserialize = maxSize;
|
||||
/* Now we zeros out the raw entries and deserialize back into the dataset */
|
||||
std::memset(buffer, 0, sizeof(buffer));
|
||||
const uint8_t* constBuffPtr = buffer;
|
||||
std::memset(buffer.data(), 0, buffer.size());
|
||||
const uint8_t* constBuffPtr = buffer.data();
|
||||
CHECK(localSet.deSerialize(&constBuffPtr, &sizeToDeserialize,
|
||||
SerializeIF::Endianness::MACHINE) == returnvalue::OK);
|
||||
/* Check whether deserialization was successfull */
|
||||
@ -155,20 +156,21 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
|
||||
maxSize = localSet.getSerializedSize();
|
||||
CHECK(maxSize == sizeof(uint8_t) + sizeof(uint16_t) * 3 + sizeof(float) + 1);
|
||||
serSize = 0;
|
||||
buffPtr = buffer;
|
||||
buffPtr = buffer.data();
|
||||
CHECK(localSet.serialize(&buffPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) ==
|
||||
returnvalue::OK);
|
||||
CHECK(rawUint8 == 232);
|
||||
std::memcpy(&rawFloat, buffer + sizeof(uint8_t), sizeof(float));
|
||||
std::memcpy(&rawFloat, buffer.data() + sizeof(uint8_t), sizeof(float));
|
||||
CHECK(rawFloat == Catch::Approx(-2324.322));
|
||||
|
||||
std::memcpy(&rawUint16Vec, buffer + sizeof(uint8_t) + sizeof(float), 3 * sizeof(uint16_t));
|
||||
std::memcpy(&rawUint16Vec, buffer.data() + sizeof(uint8_t) + sizeof(float),
|
||||
3 * sizeof(uint16_t));
|
||||
CHECK(rawUint16Vec[0] == 232);
|
||||
CHECK(rawUint16Vec[1] == 23923);
|
||||
CHECK(rawUint16Vec[2] == 1);
|
||||
/* We can do it like this because the buffer only has one byte for
|
||||
less than 8 variables */
|
||||
uint8_t* validityByte = buffer + sizeof(buffer) - 1;
|
||||
uint8_t* validityByte = buffer.data() + buffer.size() - 1;
|
||||
bool bitSet = false;
|
||||
bitutil::get(validityByte, 0, bitSet);
|
||||
|
||||
@ -179,17 +181,17 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
|
||||
CHECK(bitSet == true);
|
||||
|
||||
/* Now we manipulate the validity buffer for the deserialization */
|
||||
bitutil::clear(validityByte, 0);
|
||||
/* bitutil::clear(validityByte, 0);
|
||||
bitutil::set(validityByte, 1);
|
||||
bitutil::clear(validityByte, 2);
|
||||
bitutil::clear(validityByte, 2);*/
|
||||
/* Zero out everything except validity buffer */
|
||||
std::memset(buffer, 0, sizeof(buffer) - 1);
|
||||
/* std::memset(buffer.data(), 0, buffer.size() - 1);
|
||||
sizeToDeserialize = maxSize;
|
||||
constBuffPtr = buffer;
|
||||
constBuffPtr = buffer.data();
|
||||
CHECK(localSet.deSerialize(&constBuffPtr, &sizeToDeserialize,
|
||||
SerializeIF::Endianness::MACHINE) == returnvalue::OK);
|
||||
SerializeIF::Endianness::MACHINE) == returnvalue::OK);*/
|
||||
/* Check whether deserialization was successfull */
|
||||
CHECK(localSet.localPoolVarUint8.value == 0);
|
||||
/* CHECK(localSet.localPoolVarUint8.value == 0);
|
||||
CHECK(localSet.localPoolVarFloat.value == Catch::Approx(0.0));
|
||||
CHECK(localSet.localPoolVarUint8.value == 0);
|
||||
CHECK(localSet.localPoolUint16Vec.value[0] == 0);
|
||||
@ -197,16 +199,16 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
|
||||
CHECK(localSet.localPoolUint16Vec.value[2] == 0);
|
||||
CHECK(not localSet.localPoolVarUint8.isValid());
|
||||
CHECK(localSet.localPoolVarFloat.isValid());
|
||||
CHECK(not localSet.localPoolUint16Vec.isValid());
|
||||
CHECK(not localSet.localPoolUint16Vec.isValid());*/
|
||||
}
|
||||
|
||||
/* Common fault test cases */
|
||||
LocalPoolObjectBase* variableHandle = poolOwner.getPoolObjectHandle(lpool::uint32VarId);
|
||||
CHECK(variableHandle != nullptr);
|
||||
CHECK(localSet.registerVariable(variableHandle) == static_cast<int>(DataSetIF::DATA_SET_FULL));
|
||||
variableHandle = nullptr;
|
||||
REQUIRE(localSet.registerVariable(variableHandle) ==
|
||||
static_cast<int>(DataSetIF::POOL_VAR_NULL));
|
||||
//LocalPoolObjectBase* variableHandle = poolOwner.getPoolObjectHandle(lpool::uint32VarId);
|
||||
//CHECK(variableHandle != nullptr);
|
||||
//CHECK(localSet.registerVariable(variableHandle) == static_cast<int>(DataSetIF::DATA_SET_FULL));
|
||||
//variableHandle = nullptr;
|
||||
//REQUIRE(localSet.registerVariable(variableHandle) ==
|
||||
// static_cast<int>(DataSetIF::POOL_VAR_NULL));
|
||||
}
|
||||
|
||||
SECTION("MorePoolVariables") {
|
||||
@ -231,11 +233,11 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
|
||||
CHECK(maxSize == 9 + sizeof(uint16_t) * 3 + 2);
|
||||
size_t serSize = 0;
|
||||
/* Already reserve additional space for validity buffer, will be needed later */
|
||||
uint8_t buffer[maxSize + 1];
|
||||
uint8_t* buffPtr = buffer;
|
||||
std::vector<uint8_t> buffer(maxSize + 1);
|
||||
uint8_t* buffPtr = buffer.data();
|
||||
CHECK(set.serialize(&buffPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) == OK);
|
||||
std::array<uint8_t, 2> validityBuffer{};
|
||||
std::memcpy(validityBuffer.data(), buffer + 9 + sizeof(uint16_t) * 3, 2);
|
||||
std::memcpy(validityBuffer.data(), buffer.data() + 9 + sizeof(uint16_t) * 3, 2);
|
||||
/* The first 9 variables should be valid */
|
||||
CHECK(validityBuffer[0] == 0xff);
|
||||
bool bitSet = false;
|
||||
@ -247,8 +249,8 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
|
||||
/* Now we invert the validity */
|
||||
validityBuffer[0] = 0;
|
||||
validityBuffer[1] = 0b0100'0000;
|
||||
std::memcpy(buffer + 9 + sizeof(uint16_t) * 3, validityBuffer.data(), 2);
|
||||
const uint8_t* constBuffPtr = buffer;
|
||||
std::memcpy(buffer.data() + 9 + sizeof(uint16_t) * 3, validityBuffer.data(), 2);
|
||||
const uint8_t* constBuffPtr = buffer.data();
|
||||
size_t sizeToDeSerialize = serSize;
|
||||
CHECK(set.deSerialize(&constBuffPtr, &sizeToDeSerialize, SerializeIF::Endianness::MACHINE) ==
|
||||
returnvalue::OK);
|
||||
|
@ -9,9 +9,9 @@ TEST_CASE("Filesystem Mock", "[mocks]") {
|
||||
auto fsMock = FilesystemMock();
|
||||
|
||||
SECTION("Create File") {
|
||||
FilesystemParams params("hello.txt");
|
||||
FilesystemParams params(L"hello.txt");
|
||||
CHECK(fsMock.createFile(params) == returnvalue::OK);
|
||||
auto iter = fsMock.fileMap.find("hello.txt");
|
||||
auto iter = fsMock.fileMap.find(L"hello.txt");
|
||||
REQUIRE(iter != fsMock.fileMap.end());
|
||||
FilesystemMock::FileInfo &stats = iter->second;
|
||||
CHECK(stats.fileSegQueue.empty());
|
||||
@ -20,10 +20,10 @@ TEST_CASE("Filesystem Mock", "[mocks]") {
|
||||
|
||||
SECTION("Write to File") {
|
||||
std::string testData = "test data";
|
||||
FileOpParams params("hello.txt", testData.size());
|
||||
FileOpParams params(L"hello.txt", testData.size());
|
||||
CHECK(fsMock.writeToFile(params, reinterpret_cast<const uint8_t *>(testData.data())) ==
|
||||
returnvalue::OK);
|
||||
auto iter = fsMock.fileMap.find("hello.txt");
|
||||
auto iter = fsMock.fileMap.find(L"hello.txt");
|
||||
REQUIRE(iter != fsMock.fileMap.end());
|
||||
FilesystemMock::FileInfo &stats = iter->second;
|
||||
CHECK(not stats.fileSegQueue.empty());
|
||||
@ -37,10 +37,10 @@ TEST_CASE("Filesystem Mock", "[mocks]") {
|
||||
}
|
||||
|
||||
SECTION("Create Directory") {
|
||||
FilesystemParams params("hello");
|
||||
FilesystemParams params(L"hello");
|
||||
CHECK(fsMock.createDirectory(params) == returnvalue::OK);
|
||||
REQUIRE(not fsMock.dirMap.empty());
|
||||
auto iter = fsMock.dirMap.find("hello");
|
||||
auto iter = fsMock.dirMap.find(L"hello");
|
||||
REQUIRE(iter != fsMock.dirMap.end());
|
||||
auto &dirInfo = iter->second;
|
||||
CHECK(dirInfo.createCallCount == 1);
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <random>
|
||||
#include <array>
|
||||
|
||||
#include "fsfw/serialize/SerializeIF.h"
|
||||
#include "fsfw_hal/host/HostFilesystem.h"
|
||||
@ -92,9 +93,9 @@ TEST_CASE("Host Filesystem", "[hal][host]") {
|
||||
CHECK(fs::is_regular_file(file0));
|
||||
REQUIRE(fs::exists(file0));
|
||||
// Write first file chunk
|
||||
CHECK(hostFs.writeToFile(params, randData.cbegin()) == returnvalue::OK);
|
||||
CHECK(hostFs.writeToFile(params, randData.data()) == returnvalue::OK);
|
||||
params.offset = 256;
|
||||
CHECK(hostFs.writeToFile(params, randData.cbegin() + 256) == returnvalue::OK);
|
||||
CHECK(hostFs.writeToFile(params, randData.data() + 256) == returnvalue::OK);
|
||||
std::ifstream rf(file0, ios::binary);
|
||||
std::array<uint8_t, 512> readBack{};
|
||||
REQUIRE(std::filesystem::file_size(file0) == 512);
|
||||
|
@ -5,11 +5,15 @@
|
||||
#include "fsfw/serialize/SerializeIF.h"
|
||||
|
||||
ReturnValue_t FilesystemMock::feedFile(const std::string &filename, std::ifstream &file) {
|
||||
if (not std::filesystem::exists(filename)) {
|
||||
|
||||
//not multibyte encoding safe!
|
||||
std::basic_string<std::filesystem::path::value_type> native_filename(filename.begin(), filename.end());
|
||||
|
||||
if (not std::filesystem::exists(native_filename)) {
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
size_t fileSize = std::filesystem::file_size(filename);
|
||||
FileOpParams params(filename.c_str(), fileSize);
|
||||
size_t fileSize = std::filesystem::file_size(native_filename);
|
||||
FileOpParams params(native_filename.c_str(), fileSize);
|
||||
std::vector<uint8_t> rawData(fileSize);
|
||||
file.read(reinterpret_cast<char *>(rawData.data()), static_cast<unsigned int>(rawData.size()));
|
||||
createOrAddToFile(params, rawData.data());
|
||||
@ -23,7 +27,7 @@ ReturnValue_t FilesystemMock::writeToFile(FileOpParams params, const uint8_t *da
|
||||
|
||||
ReturnValue_t FilesystemMock::readFromFile(FileOpParams params, uint8_t **buffer, size_t &readSize,
|
||||
size_t maxSize) {
|
||||
std::string filename(params.path());
|
||||
std::basic_string<std::filesystem::path::value_type> filename(params.path());
|
||||
auto iter = fileMap.find(filename);
|
||||
if (iter == fileMap.end()) {
|
||||
return HasFileSystemIF::FILE_DOES_NOT_EXIST;
|
||||
@ -53,8 +57,10 @@ ReturnValue_t FilesystemMock::createFile(FilesystemParams params, const uint8_t
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t FilesystemMock::removeFile(const char *path, FileSystemArgsIF *args) {
|
||||
std::string filename(path);
|
||||
ReturnValue_t FilesystemMock::removeFile(const std::filesystem::path::value_type *path,
|
||||
FileSystemArgsIF *args) {
|
||||
std::basic_string<std::filesystem::path::value_type> filename(path);
|
||||
|
||||
auto iter = fileMap.find(filename);
|
||||
if (iter == fileMap.end()) {
|
||||
return HasFileSystemIF::FILE_DOES_NOT_EXIST;
|
||||
@ -65,27 +71,28 @@ ReturnValue_t FilesystemMock::removeFile(const char *path, FileSystemArgsIF *arg
|
||||
}
|
||||
|
||||
ReturnValue_t FilesystemMock::createDirectory(FilesystemParams params, bool createParentDirs) {
|
||||
std::string dirPath = params.path;
|
||||
auto dirPath = params.path;
|
||||
dirMap[dirPath].createCallCount++;
|
||||
dirMap[dirPath].wihParentDir.push(createParentDirs);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t FilesystemMock::removeDirectory(FilesystemParams params, bool deleteRecurively) {
|
||||
std::string dirPath = params.path;
|
||||
auto dirPath = params.path;
|
||||
dirMap[dirPath].delCallCount++;
|
||||
dirMap[dirPath].recursiveDeletion.push(deleteRecurively);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t FilesystemMock::rename(const char *oldPath, const char *newPath,
|
||||
ReturnValue_t FilesystemMock::rename(const std::filesystem::path::value_type *oldPath,
|
||||
const std::filesystem::path::value_type *newPath,
|
||||
FileSystemArgsIF *args) {
|
||||
renameQueue.push(RenameInfo(oldPath, newPath));
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
void FilesystemMock::createOrAddToFile(FileOpParams params, const uint8_t *data) {
|
||||
std::string filename(params.path());
|
||||
auto filename(params.path());
|
||||
auto iter = fileMap.find(filename);
|
||||
if (iter == fileMap.end()) {
|
||||
FileSegmentQueue queue;
|
||||
@ -126,7 +133,7 @@ void FilesystemMock::reset() {
|
||||
}
|
||||
|
||||
bool FilesystemMock::fileExists(FilesystemParams params) {
|
||||
std::string filename(params.path);
|
||||
auto filename(params.path);
|
||||
auto iter = fileMap.find(filename);
|
||||
if (iter == fileMap.end()) {
|
||||
return false;
|
||||
|
@ -20,11 +20,12 @@
|
||||
class FilesystemMock : public HasFileSystemIF {
|
||||
public:
|
||||
struct FileWriteInfo {
|
||||
FileWriteInfo(std::string filename, size_t offset, const uint8_t *data, size_t len)
|
||||
: filename(std::move(filename)), offset(offset) {
|
||||
FileWriteInfo(std::basic_string<std::filesystem::path::value_type> filename, size_t offset, const uint8_t *data, size_t len)
|
||||
: offset(offset) {
|
||||
this->filename = filename;
|
||||
this->data.insert(this->data.end(), data, data + len);
|
||||
}
|
||||
std::string filename;
|
||||
std::basic_string<std::filesystem::path::value_type> filename;
|
||||
size_t offset;
|
||||
std::vector<uint8_t> data;
|
||||
};
|
||||
@ -35,7 +36,7 @@ class FilesystemMock : public HasFileSystemIF {
|
||||
std::vector<uint8_t> fileRaw;
|
||||
};
|
||||
|
||||
std::map<std::string, FileInfo> fileMap;
|
||||
std::map<std::basic_string<std::filesystem::path::value_type>, FileInfo> fileMap;
|
||||
|
||||
struct DirInfo {
|
||||
size_t createCallCount = 0;
|
||||
@ -43,18 +44,20 @@ class FilesystemMock : public HasFileSystemIF {
|
||||
std::queue<bool> wihParentDir;
|
||||
std::queue<bool> recursiveDeletion;
|
||||
};
|
||||
std::map<std::string, DirInfo> dirMap;
|
||||
std::map<std::basic_string<std::filesystem::path::value_type>, DirInfo> dirMap;
|
||||
|
||||
struct RenameInfo {
|
||||
RenameInfo(std::string oldName, std::string newName)
|
||||
RenameInfo(std::basic_string < std::filesystem::path::value_type> oldName,
|
||||
std::basic_string < std::filesystem::path::value_type> newName)
|
||||
: oldName(std::move(oldName)), newName(std::move(newName)) {}
|
||||
|
||||
std::string oldName;
|
||||
std::string newName;
|
||||
std::basic_string<std::filesystem::path::value_type> oldName;
|
||||
std::basic_string<std::filesystem::path::value_type> newName;
|
||||
};
|
||||
std::queue<RenameInfo> renameQueue;
|
||||
std::string truncateCalledOnFile;
|
||||
ReturnValue_t feedFile(const std::string &filename, std::ifstream &file);
|
||||
std::basic_string<std::filesystem::path::value_type> truncateCalledOnFile;
|
||||
ReturnValue_t feedFile(const std::string &filename,
|
||||
std::ifstream &file);
|
||||
|
||||
bool fileExists(FilesystemParams params) override;
|
||||
ReturnValue_t truncateFile(FilesystemParams params) override;
|
||||
@ -63,10 +66,13 @@ class FilesystemMock : public HasFileSystemIF {
|
||||
ReturnValue_t readFromFile(FileOpParams params, uint8_t **buffer, size_t &readSize,
|
||||
size_t maxSize) override;
|
||||
ReturnValue_t createFile(FilesystemParams params, const uint8_t *data, size_t size) override;
|
||||
ReturnValue_t removeFile(const char *path, FileSystemArgsIF *args) override;
|
||||
ReturnValue_t removeFile(const std::filesystem::path::value_type *path,
|
||||
FileSystemArgsIF *args) override;
|
||||
ReturnValue_t createDirectory(FilesystemParams params, bool createParentDirs) override;
|
||||
ReturnValue_t removeDirectory(FilesystemParams params, bool deleteRecurively) override;
|
||||
ReturnValue_t rename(const char *oldPath, const char *newPath, FileSystemArgsIF *args) override;
|
||||
ReturnValue_t rename(const std::filesystem::path::value_type *oldPath,
|
||||
const std::filesystem::path::value_type *newPath,
|
||||
FileSystemArgsIF *args) override;
|
||||
|
||||
void reset();
|
||||
|
||||
|
@ -7,7 +7,7 @@ cfdp::UserMock::UserMock(HasFileSystemIF& vfs) : UserBase(vfs) {}
|
||||
void UserMock::transactionIndication(const TransactionId& id) {}
|
||||
void UserMock::eofSentIndication(const TransactionId& id) {}
|
||||
void UserMock::abandonedIndication(const TransactionId& id, cfdp::ConditionCode code,
|
||||
uint64_t progress) {}
|
||||
size_t progress) {}
|
||||
|
||||
void UserMock::eofRecvIndication(const TransactionId& id) { eofsRevd.push(id); }
|
||||
|
||||
|
@ -12,7 +12,7 @@ TEST_CASE("Serial Linked Packet", "[SerLinkPacket]") {
|
||||
std::array<uint8_t, 3> testArray{1, 2, 3};
|
||||
uint32_t tail = 96;
|
||||
size_t packetMaxSize = 256;
|
||||
uint8_t packet[packetMaxSize] = {};
|
||||
std::vector<uint8_t> packet(packetMaxSize);
|
||||
size_t packetLen = 0;
|
||||
|
||||
SECTION("Test Deserialization with Serial Buffer Adapter.") {
|
||||
@ -20,14 +20,14 @@ TEST_CASE("Serial Linked Packet", "[SerLinkPacket]") {
|
||||
// We generate a packet which store data big-endian by swapping some
|
||||
// values. (like coming from ground).
|
||||
header = EndianConverter::convertBigEndian(header);
|
||||
std::memcpy(packet, &header, sizeof(header));
|
||||
std::memcpy(packet.data(), &header, sizeof(header));
|
||||
packetLen += sizeof(header);
|
||||
|
||||
std::copy(testArray.data(), testArray.data() + testArray.size(), packet + packetLen);
|
||||
std::copy(testArray.data(), testArray.data() + testArray.size(), packet.data() + packetLen);
|
||||
packetLen += testArray.size();
|
||||
|
||||
tail = EndianConverter::convertBigEndian(tail);
|
||||
std::memcpy(packet + packetLen, &tail, sizeof(tail));
|
||||
std::memcpy(packet.data() + packetLen, &tail, sizeof(tail));
|
||||
packetLen += sizeof(tail);
|
||||
|
||||
// arrayprinter::print(packet, packetLen, OutputType::DEC);
|
||||
@ -35,8 +35,8 @@ TEST_CASE("Serial Linked Packet", "[SerLinkPacket]") {
|
||||
// This is the buffer which will be filled when testClass.deSerialize
|
||||
// is called.
|
||||
std::array<uint8_t, 3> bufferAdaptee = {};
|
||||
TestPacket testClass(packet, packetLen, bufferAdaptee.data(), bufferAdaptee.size());
|
||||
const uint8_t* readOnlyPointer = packet;
|
||||
TestPacket testClass(packet.data(), packetLen, bufferAdaptee.data(), bufferAdaptee.size());
|
||||
const uint8_t* readOnlyPointer = packet.data();
|
||||
// Deserialize big endian packet by setting bigEndian to true.
|
||||
ReturnValue_t result =
|
||||
testClass.deSerialize(&readOnlyPointer, &packetLen, SerializeIF::Endianness::BIG);
|
||||
@ -55,7 +55,7 @@ TEST_CASE("Serial Linked Packet", "[SerLinkPacket]") {
|
||||
// instead of doing it manually.
|
||||
TestPacket testClass(header, tail, testArray.data(), testArray.size());
|
||||
size_t serializedSize = 0;
|
||||
uint8_t* packetPointer = packet;
|
||||
uint8_t* packetPointer = packet.data();
|
||||
// serialize for ground: bigEndian = true.
|
||||
ReturnValue_t result = testClass.serialize(&packetPointer, &serializedSize, packetMaxSize,
|
||||
SerializeIF::Endianness::BIG);
|
||||
|
Loading…
x
Reference in New Issue
Block a user