host filesystem continued
This commit is contained in:
parent
2e52d7a31d
commit
23f514039a
@ -19,13 +19,9 @@ struct FilesystemParams {
|
|||||||
struct FileOpParams {
|
struct FileOpParams {
|
||||||
FileOpParams(const char* path, size_t size) : fsParams(path), size(size) {}
|
FileOpParams(const char* path, size_t size) : fsParams(path), size(size) {}
|
||||||
|
|
||||||
[[nodiscard]] const char* path() const {
|
[[nodiscard]] const char* path() const { return fsParams.path; }
|
||||||
return fsParams.path;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] FileSystemArgsIF* args() const {
|
[[nodiscard]] FileSystemArgsIF* args() const { return fsParams.args; }
|
||||||
return fsParams.args;
|
|
||||||
}
|
|
||||||
|
|
||||||
FilesystemParams fsParams;
|
FilesystemParams fsParams;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
@ -134,7 +134,8 @@ ReturnValue_t PusDistributor::initialize() {
|
|||||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||||
}
|
}
|
||||||
if (verifyChannel == nullptr) {
|
if (verifyChannel == nullptr) {
|
||||||
verifyChannel = ObjectManager::instance()->get<VerificationReporterIF>(objects::VERIFICATION_REPORTER);
|
verifyChannel =
|
||||||
|
ObjectManager::instance()->get<VerificationReporterIF>(objects::VERIFICATION_REPORTER);
|
||||||
if (verifyChannel == nullptr) {
|
if (verifyChannel == nullptr) {
|
||||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||||
}
|
}
|
||||||
|
@ -40,14 +40,14 @@ ReturnValue_t HostFilesystem::readFromFile(FileOpParams params, uint8_t **buffer
|
|||||||
if (file.fail()) {
|
if (file.fail()) {
|
||||||
return HasFileSystemIF::GENERIC_FILE_ERROR;
|
return HasFileSystemIF::GENERIC_FILE_ERROR;
|
||||||
}
|
}
|
||||||
auto readLen = static_cast<unsigned int>(params.offset);
|
auto sizeToRead = static_cast<unsigned int>(params.size);
|
||||||
file.seekg(readLen);
|
file.seekg(static_cast<unsigned int>(params.offset));
|
||||||
if (readSize + params.size > maxSize) {
|
if (readSize + sizeToRead > maxSize) {
|
||||||
return SerializeIF::BUFFER_TOO_SHORT;
|
return SerializeIF::BUFFER_TOO_SHORT;
|
||||||
}
|
}
|
||||||
file.read(reinterpret_cast<char *>(*buffer), readLen);
|
file.read(reinterpret_cast<char *>(*buffer), sizeToRead);
|
||||||
readSize += readLen;
|
readSize += sizeToRead;
|
||||||
*buffer += readLen;
|
*buffer += sizeToRead;
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch_test_macros.hpp>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
#include "fsfw_hal/host/HostFilesystem.h"
|
#include "fsfw_hal/host/HostFilesystem.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
TEST_CASE("Host Filesystem", "[hal][host]") {
|
TEST_CASE("Host Filesystem", "[hal][host]") {
|
||||||
namespace fs = std::filesystem;
|
namespace fs = filesystem;
|
||||||
auto hostFs = HostFilesystem();
|
auto hostFs = HostFilesystem();
|
||||||
auto tmpDir = fs::temp_directory_path();
|
auto tmpDir = fs::temp_directory_path();
|
||||||
fs::path file0 = tmpDir / "hello.txt";
|
fs::path file0 = tmpDir / "hello.txt";
|
||||||
@ -62,8 +65,35 @@ TEST_CASE("Host Filesystem", "[hal][host]") {
|
|||||||
REQUIRE(hostFs.createFile(params.fsParams) == result::OK);
|
REQUIRE(hostFs.createFile(params.fsParams) == result::OK);
|
||||||
CHECK(fs::is_regular_file(file0));
|
CHECK(fs::is_regular_file(file0));
|
||||||
REQUIRE(fs::exists(file0));
|
REQUIRE(fs::exists(file0));
|
||||||
hostFs.writeToFile(params, reinterpret_cast<const uint8_t*>(data.c_str()));
|
CHECK(hostFs.writeToFile(params, reinterpret_cast<const uint8_t*>(data.c_str())) ==
|
||||||
// TODO: Read back file and verify content
|
HasReturnvaluesIF::RETURN_OK);
|
||||||
|
CHECK(fs::file_size(file0) == data.size());
|
||||||
|
ifstream ifile(file0);
|
||||||
|
char readBuf[524]{};
|
||||||
|
ifile.read(readBuf, sizeof(readBuf));
|
||||||
|
std::string readBackString(readBuf);
|
||||||
|
CHECK(data == readBackString);
|
||||||
|
REQUIRE_NOTHROW(fs::remove(file1));
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("Read From File") {
|
||||||
|
std::string data = "hello world!";
|
||||||
|
FileOpParams params(file0.c_str(), data.size());
|
||||||
|
REQUIRE(hostFs.createFile(params.fsParams) == result::OK);
|
||||||
|
CHECK(fs::is_regular_file(file0));
|
||||||
|
ofstream of(file0);
|
||||||
|
of.write(data.c_str(), static_cast<unsigned int>(data.size()));
|
||||||
|
of.close();
|
||||||
|
CHECK(fs::file_size(file0) == data.size());
|
||||||
|
REQUIRE(fs::exists(file0));
|
||||||
|
std::array<uint8_t, 256> readBuf{};
|
||||||
|
uint8_t* readPtr = readBuf.data();
|
||||||
|
size_t readSize = 0;
|
||||||
|
CHECK(hostFs.readFromFile(params, &readPtr, readSize, readBuf.size()) ==
|
||||||
|
HasReturnvaluesIF::RETURN_OK);
|
||||||
|
std::string readBackString(reinterpret_cast<const char*>(readBuf.data()));
|
||||||
|
CHECK(readSize == data.size());
|
||||||
|
CHECK(data == readBackString);
|
||||||
REQUIRE_NOTHROW(fs::remove(file1));
|
REQUIRE_NOTHROW(fs::remove(file1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1 @@
|
|||||||
target_sources(${FSFW_TEST_TGT} PRIVATE
|
target_sources(${FSFW_TEST_TGT} PRIVATE testUnsignedByteField.cpp)
|
||||||
testUnsignedByteField.cpp
|
|
||||||
)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user