add FS mock and improve HasFilesystemIF

This commit is contained in:
Robin Müller 2022-08-10 11:09:07 +02:00
parent 3e1fd15613
commit 28c8248f26
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
6 changed files with 106 additions and 32 deletions

View File

@ -1,6 +1,3 @@
#include "UserBase.h"
#include <array>
#include <iostream>
cfdp::UserBase::UserBase(HasFileSystemIF& vfs) : vfs(vfs) {}

View File

@ -4,10 +4,25 @@
#include <cstddef>
#include "FileSystemArgsIF.h"
#include "fsfw/ipc/MessageQueueIF.h"
#include "fsfw/ipc/messageQueueDefinitions.h"
#include "fsfw/returnvalues/FwClassIds.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
struct FilesystemParams {
explicit FilesystemParams(const char* path) : path(path) {}
const char* path;
FileSystemArgsIF* args = nullptr;
};
struct FileOpParams : public FilesystemParams {
FileOpParams(const char* path, size_t size) : FilesystemParams(path), size(size) {}
size_t size;
size_t offset = 0;
};
/**
* @brief Generic interface for objects which expose a file system to enable
* message based file handling.
@ -37,30 +52,47 @@ class HasFileSystemIF {
//! [EXPORT] : P1: Sequence number missing
static constexpr ReturnValue_t SEQUENCE_PACKET_MISSING_READ = MAKE_RETURN_CODE(16);
virtual ~HasFileSystemIF() {}
virtual ~HasFileSystemIF() = default;
/**
* Function to get the MessageQueueId_t of the implementing object
* @return MessageQueueId_t of the object
*/
virtual MessageQueueId_t getCommandQueue() const = 0;
[[nodiscard]] virtual MessageQueueId_t getCommandQueue() const {
return MessageQueueIF::NO_QUEUE;
}
/**
* @brief Generic function to append to file.
* @param dirname Directory of the file
* @param filename The filename of the file
* @param fileOpInfo General information: File name, size to write, offset, additional arguments
* @param data The data to write to the file
* @param size The size of the data to write
* @param packetNumber Current packet number. Can be used to verify that
* there are no missing packets.
* @param args Any other arguments which an implementation might require.
* @param bytesWritten Actual bytes written to file
* For large files the write procedure must be split in multiple calls
* to writeToFile
*/
virtual ReturnValue_t appendToFile(const char* repositoryPath, const char* filename,
const uint8_t* data, size_t size, uint16_t packetNumber,
FileSystemArgsIF* args = nullptr) = 0;
virtual ReturnValue_t writeToFile(FileOpParams params, const uint8_t* data) = 0;
/**
* @brief Generic function to read from a file. This variant takes a pointer to a buffer and
* performs pointer arithmetic by incrementing the pointer by the read size
* @param fileOpInfo General information: File name, size to write, offset, additional arguments
* @param buffer [in/out] Data will be read into the provided buffer, and the pointer will be
* incremented by the read length
* @param readSize [out] Will be incremented by the read length
* @param maxSize Maximum size of the provided buffer
* @param args
* @return
*/
virtual ReturnValue_t readFromFile(FileOpParams fileOpInfo, uint8_t** buffer, size_t& readSize,
size_t maxSize) = 0;
/**
* Variant of the @readFromFile which does not perform pointer arithmetic.
* @param fileOpInfo General information: File name, size to write, offset, additional arguments
* @param buf
* @param maxSize
* @return
*/
virtual ReturnValue_t readFromFile(FileOpParams fileOpInfo, uint8_t* buf, size_t maxSize) {
size_t dummy = 0;
return readFromFile(fileOpInfo, &buf, dummy, maxSize);
}
/**
* @brief Generic function to create a new file.
@ -71,9 +103,10 @@ class HasFileSystemIF {
* @param args Any other arguments which an implementation might require
* @return
*/
virtual ReturnValue_t createFile(const char* repositoryPath, const char* filename,
const uint8_t* data = nullptr, size_t size = 0,
FileSystemArgsIF* args = nullptr) = 0;
virtual ReturnValue_t createFile(FilesystemParams params) {
return createFile(params, nullptr, 0);
}
virtual ReturnValue_t createFile(FilesystemParams params, const uint8_t* data, size_t size) = 0;
/**
* @brief Generic function to delete a file.
@ -82,8 +115,8 @@ class HasFileSystemIF {
* @param args Any other arguments which an implementation might require
* @return
*/
virtual ReturnValue_t removeFile(const char* repositoryPath, const char* filename,
FileSystemArgsIF* args = nullptr) = 0;
virtual ReturnValue_t removeFile(const char* path, FileSystemArgsIF* args) = 0;
virtual ReturnValue_t removeFile(const char* path) { return removeFile(path, nullptr); }
/**
* @brief Generic function to create a directory
@ -93,21 +126,22 @@ class HasFileSystemIF {
* @param args Any other arguments which an implementation might require
* @return
*/
virtual ReturnValue_t createDirectory(const char* repositoryPath, const char* dirname,
bool createParentDirs,
FileSystemArgsIF* args = nullptr) = 0;
virtual ReturnValue_t createDirectory(FilesystemParams params, bool createParentDirs) = 0;
/**
* @brief Generic function to remove a directory
* @param repositoryPath
* @param args Any other arguments which an implementation might require
*/
virtual ReturnValue_t removeDirectory(const char* repositoryPath, const char* dirname,
bool deleteRecurively = false,
FileSystemArgsIF* args = nullptr) = 0;
virtual ReturnValue_t removeDirectory(FilesystemParams params, bool deleteRecurively) = 0;
virtual ReturnValue_t removeDirectory(FilesystemParams params) {
return removeDirectory(params, false);
}
virtual ReturnValue_t renameFile(const char* repositoryPath, const char* oldFilename,
const char* newFilename, FileSystemArgsIF* args = nullptr) = 0;
virtual ReturnValue_t renameFile(const char* oldPath, char* newPath) {
return renameFile(oldPath, newPath, nullptr);
}
virtual ReturnValue_t renameFile(const char* oldPath, char* newPath, FileSystemArgsIF* args) = 0;
};
#endif /* FSFW_MEMORY_HASFILESYSTEMIF_H_ */

View File

@ -2,12 +2,13 @@
#include "fsfw/cfdp.h"
#include "mocks/cfdp/FaultHandlerMock.h"
#include "mocks/cfdp/UserMock.h"
TEST_CASE("CFDP Dest Handler", "[cfdp]") {
using namespace cfdp;
EntityId localId = EntityId(UnsignedByteField<uint16_t>(2));
auto fhMock = FaultHandlerMock();
auto localEntityCfg = LocalEntityCfg(localId, IndicationCfg(), fhMock);
// auto userMock = UserMock();
SECTION("State") {}
}

View File

@ -14,6 +14,7 @@ target_sources(
PusDistributorMock.cpp
CcsdsCheckerMock.cpp
AcceptsTcMock.cpp
StorageManagerMock.cpp)
StorageManagerMock.cpp
FilesystemMock.cpp)
add_subdirectory(cfdp)

View File

@ -0,0 +1,22 @@
#include "FilesystemMock.h"
ReturnValue_t FilesystemMock::writeToFile(FileOpParams params, const uint8_t *data) { return 0; }
ReturnValue_t FilesystemMock::readFromFile(FileOpParams fileOpInfo, uint8_t **buffer,
size_t &readSize, size_t maxSize) {
return 0;
}
ReturnValue_t FilesystemMock::createFile(FilesystemParams params, const uint8_t *data,
size_t size) {
return 0;
}
ReturnValue_t FilesystemMock::removeFile(const char *path, FileSystemArgsIF *args) { return 0; }
ReturnValue_t FilesystemMock::createDirectory(FilesystemParams params, bool createParentDirs) {
return 0;
}
ReturnValue_t FilesystemMock::removeDirectory(FilesystemParams params, bool deleteRecurively) {
return 0;
}
ReturnValue_t FilesystemMock::renameFile(const char *oldPath, char *newPath,
FileSystemArgsIF *args) {
return 0;
}

View File

@ -0,0 +1,19 @@
#ifndef FSFW_MOCKS_FILESYSTEMMOCK_H
#define FSFW_MOCKS_FILESYSTEMMOCK_H
#include "fsfw/filesystem.h"
class FilesystemMock : public HasFileSystemIF {
public:
MessageQueueId_t getCommandQueue() const override;
ReturnValue_t writeToFile(FileOpParams params, const uint8_t *data) override;
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 createDirectory(FilesystemParams params, bool createParentDirs) override;
ReturnValue_t removeDirectory(FilesystemParams params, bool deleteRecurively) override;
ReturnValue_t renameFile(const char *oldPath, char *newPath, FileSystemArgsIF *args) override;
};
#endif // FSFW_MOCKS_FILESYSTEMMOCK_H