windows building again
This commit is contained in:
parent
e37af4fe70
commit
3e8446ba8b
@ -2,7 +2,6 @@
|
|||||||
#define FSFW_MEMORY_HASFILESYSTEMIF_H_
|
#define FSFW_MEMORY_HASFILESYSTEMIF_H_
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <filesystem>
|
|
||||||
|
|
||||||
#include "FileSystemArgsIF.h"
|
#include "FileSystemArgsIF.h"
|
||||||
#include "fsfw/ipc/MessageQueueIF.h"
|
#include "fsfw/ipc/MessageQueueIF.h"
|
||||||
@ -11,17 +10,16 @@
|
|||||||
#include "fsfw/returnvalues/returnvalue.h"
|
#include "fsfw/returnvalues/returnvalue.h"
|
||||||
|
|
||||||
struct FilesystemParams {
|
struct FilesystemParams {
|
||||||
explicit FilesystemParams(const std::filesystem::path::value_type* path) : path(path) {}
|
explicit FilesystemParams(const char* path) : path(path) {}
|
||||||
|
|
||||||
const std::filesystem::path::value_type* path;
|
const char* path;
|
||||||
FileSystemArgsIF* args = nullptr;
|
FileSystemArgsIF* args = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FileOpParams {
|
struct FileOpParams {
|
||||||
FileOpParams(const std::filesystem::path::value_type* path, size_t size)
|
FileOpParams(const char* path, size_t size) : fsParams(path), size(size) {}
|
||||||
: fsParams(path), size(size) {}
|
|
||||||
|
|
||||||
[[nodiscard]] const std::filesystem::path::value_type* path() const { return fsParams.path; }
|
[[nodiscard]] const char* path() const { return fsParams.path; }
|
||||||
|
|
||||||
[[nodiscard]] FileSystemArgsIF* args() const { return fsParams.args; }
|
[[nodiscard]] FileSystemArgsIF* args() const { return fsParams.args; }
|
||||||
|
|
||||||
@ -141,11 +139,8 @@ class HasFileSystemIF {
|
|||||||
* @param args Any other arguments which an implementation might require
|
* @param args Any other arguments which an implementation might require
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t removeFile(const std::filesystem::path::value_type* path,
|
virtual ReturnValue_t removeFile(const char* path, FileSystemArgsIF* args) = 0;
|
||||||
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) {
|
|
||||||
return removeFile(path, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Generic function to create a directory
|
* @brief Generic function to create a directory
|
||||||
@ -170,12 +165,10 @@ class HasFileSystemIF {
|
|||||||
return removeDirectory(params, false);
|
return removeDirectory(params, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ReturnValue_t rename(const std::filesystem::path::value_type* oldPath,
|
virtual ReturnValue_t rename(const char* oldPath, const char* newPath) {
|
||||||
const std::filesystem::path::value_type* newPath) {
|
|
||||||
return rename(oldPath, newPath, nullptr);
|
return rename(oldPath, newPath, nullptr);
|
||||||
}
|
}
|
||||||
virtual ReturnValue_t rename(const std::filesystem::path::value_type* oldPath,
|
virtual ReturnValue_t rename(const char* oldPath, const char* newPath,
|
||||||
const std::filesystem::path::value_type* newPath,
|
|
||||||
FileSystemArgsIF* args) = 0;
|
FileSystemArgsIF* args) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -24,8 +24,11 @@
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <windows.h>
|
// Thanks, windows
|
||||||
|
// clang-format off
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
|
#include <windows.h>
|
||||||
|
// clang-format on
|
||||||
#if REG_DWORD == REG_DWORD_LITTLE_ENDIAN
|
#if REG_DWORD == REG_DWORD_LITTLE_ENDIAN
|
||||||
#define BYTE_ORDER_SYSTEM LITTLE_ENDIAN
|
#define BYTE_ORDER_SYSTEM LITTLE_ENDIAN
|
||||||
#else
|
#else
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
#ifdef PLATFORM_WIN
|
#ifdef PLATFORM_WIN
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <ws2tcpip.h>
|
|
||||||
typedef SSIZE_T ssize_t;
|
typedef SSIZE_T ssize_t;
|
||||||
#elif defined(PLATFORM_UNIX)
|
#elif defined(PLATFORM_UNIX)
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
@ -5,8 +5,11 @@
|
|||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
#include <processthreadsapi.h>
|
// Thanks, windows
|
||||||
|
// clang-format off
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <processthreadsapi.h>
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
namespace tasks {
|
namespace tasks {
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
target_sources(
|
target_sources(
|
||||||
${LIB_FSFW_NAME}
|
${LIB_FSFW_NAME}
|
||||||
PRIVATE CCSDSTime.cpp Countdown.cpp Stopwatch.cpp TimeMessage.cpp
|
PRIVATE CCSDSTime.cpp Countdown.cpp Stopwatch.cpp TimeMessage.cpp
|
||||||
CdsShortTimeStamper.cpp ClockCommon.cpp)
|
CdsShortTimeStamper.cpp ClockCommon.cpp boost_timegm.cpp)
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
|
#include "boost_timegm.h"
|
||||||
|
|
||||||
#include "fsfw/ipc/MutexGuard.h"
|
#include "fsfw/ipc/MutexGuard.h"
|
||||||
#include "fsfw/timemanager/Clock.h"
|
#include "fsfw/timemanager/Clock.h"
|
||||||
|
|
||||||
@ -56,8 +58,9 @@ ReturnValue_t Clock::getLeapSeconds(uint16_t* leapSeconds_) {
|
|||||||
ReturnValue_t Clock::convertTimevalToTimeOfDay(const timeval* from, TimeOfDay_t* to) {
|
ReturnValue_t Clock::convertTimevalToTimeOfDay(const timeval* from, TimeOfDay_t* to) {
|
||||||
struct tm time_tm;
|
struct tm time_tm;
|
||||||
// WINDOWS does not provide gmtime_r, but gmtime_s
|
// WINDOWS does not provide gmtime_r, but gmtime_s
|
||||||
#ifdef PLATFORM_WIN
|
#ifdef _MSC_VER
|
||||||
errno_t result = gmtime_s(&time_tm, &from->tv_sec);
|
time_t seconds = from->tv_sec;
|
||||||
|
errno_t result = gmtime_s(&time_tm, &seconds);
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
return returnvalue::FAILED;
|
return returnvalue::FAILED;
|
||||||
}
|
}
|
||||||
@ -92,28 +95,11 @@ ReturnValue_t Clock::convertTimeOfDayToTimeval(const TimeOfDay_t* from, timeval*
|
|||||||
|
|
||||||
time_tm.tm_isdst = 0;
|
time_tm.tm_isdst = 0;
|
||||||
|
|
||||||
// Windows:
|
time_t seconds = internal_timegm(&time_tm);
|
||||||
// time_t seconds = _mkgmtime(&time_tm);
|
|
||||||
// Glibc:
|
|
||||||
// time_t seconds = timegm(&time_tm);
|
|
||||||
// Portable (?)
|
|
||||||
char* tz;
|
|
||||||
tz = getenv("TZ");
|
|
||||||
setenv("TZ", "", 1);
|
|
||||||
tzset();
|
|
||||||
time_t seconds = mktime(&time_tm);
|
|
||||||
if (tz)
|
|
||||||
setenv("TZ", tz, 1);
|
|
||||||
else
|
|
||||||
unsetenv("TZ");
|
|
||||||
tzset();
|
|
||||||
to->tv_sec = seconds;
|
to->tv_sec = seconds;
|
||||||
to->tv_usec = from->usecond;
|
to->tv_usec = from->usecond;
|
||||||
|
|
||||||
if (seconds == (time_t)-1) {
|
|
||||||
return returnvalue::FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnvalue::OK;
|
return returnvalue::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef FSFW_TIMEMANAGER_TIMEREADERIF_H
|
#ifndef FSFW_TIMEMANAGER_TIMEREADERIF_H
|
||||||
#define FSFW_TIMEMANAGER_TIMEREADERIF_H
|
#define FSFW_TIMEMANAGER_TIMEREADERIF_H
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <ctime>
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@ -10,8 +10,8 @@
|
|||||||
|
|
||||||
#ifdef PLATFORM_WIN
|
#ifdef PLATFORM_WIN
|
||||||
// wtf? Required for timeval!
|
// wtf? Required for timeval!
|
||||||
#include <winsock.h>
|
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
|
#include <winsock.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "TimeStampIF.h"
|
#include "TimeStampIF.h"
|
||||||
|
69
src/fsfw/timemanager/boost_timegm.cpp
Normal file
69
src/fsfw/timemanager/boost_timegm.cpp
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
// (C) Copyright Howard Hinnant
|
||||||
|
// (C) Copyright 2010-2011 Vicente J. Botet Escriba
|
||||||
|
// Use, modification and distribution are subject to the Boost Software License,
|
||||||
|
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt).
|
||||||
|
|
||||||
|
//===-------------------------- locale ------------------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||||
|
// Source Licenses. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// This code was adapted by Vicente from Howard Hinnant's experimental work
|
||||||
|
// on chrono i/o to Boost and some functions from libc++/locale to emulate the missing
|
||||||
|
// time_get::get()
|
||||||
|
|
||||||
|
|
||||||
|
#include "boost_timegm.h"
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
|
||||||
|
int32_t is_leap(int32_t year) {
|
||||||
|
if (year % 400 == 0) return 1;
|
||||||
|
if (year % 100 == 0) return 0;
|
||||||
|
if (year % 4 == 0) return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int32_t days_from_0(int32_t year) {
|
||||||
|
year--;
|
||||||
|
return 365 * year + (year / 400) - (year / 100) + (year / 4);
|
||||||
|
}
|
||||||
|
int32_t days_from_1970(int32_t year) {
|
||||||
|
static const int32_t days_from_0_to_1970 = days_from_0(1970);
|
||||||
|
return days_from_0(year) - days_from_0_to_1970;
|
||||||
|
}
|
||||||
|
int32_t days_from_1jan(int32_t year, int32_t month, int32_t day) {
|
||||||
|
static const int32_t days[2][12] = {{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334},
|
||||||
|
{0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}};
|
||||||
|
|
||||||
|
return days[is_leap(year)][month - 1] + day - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
time_t internal_timegm(std::tm const *t) {
|
||||||
|
int year = t->tm_year + 1900;
|
||||||
|
int month = t->tm_mon;
|
||||||
|
if (month > 11) {
|
||||||
|
year += month / 12;
|
||||||
|
month %= 12;
|
||||||
|
} else if (month < 0) {
|
||||||
|
int years_diff = (-month + 11) / 12;
|
||||||
|
year -= years_diff;
|
||||||
|
month += 12 * years_diff;
|
||||||
|
}
|
||||||
|
month++;
|
||||||
|
int day = t->tm_mday;
|
||||||
|
int day_of_year = days_from_1jan(year, month, day);
|
||||||
|
int days_since_epoch = days_from_1970(year) + day_of_year;
|
||||||
|
|
||||||
|
time_t seconds_in_day = 3600 * 24;
|
||||||
|
time_t result =
|
||||||
|
seconds_in_day * days_since_epoch + 3600 * t->tm_hour + 60 * t->tm_min + t->tm_sec;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
5
src/fsfw/timemanager/boost_timegm.h
Normal file
5
src/fsfw/timemanager/boost_timegm.h
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#include <ctime>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
time_t internal_timegm(std::tm const *t);
|
@ -69,7 +69,7 @@ ReturnValue_t HostFilesystem::createFile(FilesystemParams params, const uint8_t
|
|||||||
return returnvalue::OK;
|
return returnvalue::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t HostFilesystem::removeFile(const std::filesystem::path::value_type *path_,
|
ReturnValue_t HostFilesystem::removeFile(const char *path_,
|
||||||
FileSystemArgsIF *args) {
|
FileSystemArgsIF *args) {
|
||||||
if (path_ == nullptr) {
|
if (path_ == nullptr) {
|
||||||
return returnvalue::FAILED;
|
return returnvalue::FAILED;
|
||||||
@ -133,8 +133,7 @@ ReturnValue_t HostFilesystem::removeDirectory(FilesystemParams params, bool dele
|
|||||||
return HasFileSystemIF::GENERIC_DIR_ERROR;
|
return HasFileSystemIF::GENERIC_DIR_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t HostFilesystem::rename(const std::filesystem::path::value_type *oldPath_,
|
ReturnValue_t HostFilesystem::rename(const char *oldPath_, const char *newPath_,
|
||||||
const std::filesystem::path::value_type *newPath_,
|
|
||||||
FileSystemArgsIF *args) {
|
FileSystemArgsIF *args) {
|
||||||
if (oldPath_ == nullptr or newPath_ == nullptr) {
|
if (oldPath_ == nullptr or newPath_ == nullptr) {
|
||||||
return returnvalue::FAILED;
|
return returnvalue::FAILED;
|
||||||
|
@ -15,12 +15,11 @@ class HostFilesystem : public HasFileSystemIF {
|
|||||||
ReturnValue_t readFromFile(FileOpParams fileOpInfo, uint8_t **buffer, size_t &readSize,
|
ReturnValue_t readFromFile(FileOpParams fileOpInfo, uint8_t **buffer, size_t &readSize,
|
||||||
size_t maxSize) override;
|
size_t maxSize) override;
|
||||||
ReturnValue_t createFile(FilesystemParams params, const uint8_t *data, size_t size) override;
|
ReturnValue_t createFile(FilesystemParams params, const uint8_t *data, size_t size) override;
|
||||||
ReturnValue_t removeFile(const std::filesystem::path::value_type *path,
|
ReturnValue_t removeFile(const char *path,
|
||||||
FileSystemArgsIF *args) override;
|
FileSystemArgsIF *args) override;
|
||||||
ReturnValue_t createDirectory(FilesystemParams params, bool createParentDirs) override;
|
ReturnValue_t createDirectory(FilesystemParams params, bool createParentDirs) override;
|
||||||
ReturnValue_t removeDirectory(FilesystemParams params, bool deleteRecurively) override;
|
ReturnValue_t removeDirectory(FilesystemParams params, bool deleteRecurively) override;
|
||||||
ReturnValue_t rename(const std::filesystem::path::value_type *oldPath,
|
ReturnValue_t rename(const char *oldPath, const char *newPath,
|
||||||
const std::filesystem::path::value_type *newPath,
|
|
||||||
FileSystemArgsIF *args) override;
|
FileSystemArgsIF *args) override;
|
||||||
|
|
||||||
std::error_code errorCode;
|
std::error_code errorCode;
|
||||||
|
@ -11,7 +11,9 @@ TEST_CASE("Filesystem Mock", "[mocks]") {
|
|||||||
SECTION("Create File") {
|
SECTION("Create File") {
|
||||||
FilesystemParams params("hello.txt");
|
FilesystemParams params("hello.txt");
|
||||||
CHECK(fsMock.createFile(params) == returnvalue::OK);
|
CHECK(fsMock.createFile(params) == returnvalue::OK);
|
||||||
auto iter = fsMock.fileMap.find("hello.txt");
|
std::string filename_c("hello.txt");
|
||||||
|
std::filesystem::path::string_type filename(filename_c.cbegin(), filename_c.cend());
|
||||||
|
auto iter = fsMock.fileMap.find(filename);
|
||||||
REQUIRE(iter != fsMock.fileMap.end());
|
REQUIRE(iter != fsMock.fileMap.end());
|
||||||
FilesystemMock::FileInfo &stats = iter->second;
|
FilesystemMock::FileInfo &stats = iter->second;
|
||||||
CHECK(stats.fileSegQueue.empty());
|
CHECK(stats.fileSegQueue.empty());
|
||||||
@ -23,7 +25,9 @@ TEST_CASE("Filesystem Mock", "[mocks]") {
|
|||||||
FileOpParams params("hello.txt", testData.size());
|
FileOpParams params("hello.txt", testData.size());
|
||||||
CHECK(fsMock.writeToFile(params, reinterpret_cast<const uint8_t *>(testData.data())) ==
|
CHECK(fsMock.writeToFile(params, reinterpret_cast<const uint8_t *>(testData.data())) ==
|
||||||
returnvalue::OK);
|
returnvalue::OK);
|
||||||
auto iter = fsMock.fileMap.find("hello.txt");
|
std::string filename_c("hello.txt");
|
||||||
|
std::filesystem::path::string_type filename(filename_c.cbegin(), filename_c.cend());
|
||||||
|
auto iter = fsMock.fileMap.find(filename);
|
||||||
REQUIRE(iter != fsMock.fileMap.end());
|
REQUIRE(iter != fsMock.fileMap.end());
|
||||||
FilesystemMock::FileInfo &stats = iter->second;
|
FilesystemMock::FileInfo &stats = iter->second;
|
||||||
CHECK(not stats.fileSegQueue.empty());
|
CHECK(not stats.fileSegQueue.empty());
|
||||||
@ -40,7 +44,9 @@ TEST_CASE("Filesystem Mock", "[mocks]") {
|
|||||||
FilesystemParams params("hello");
|
FilesystemParams params("hello");
|
||||||
CHECK(fsMock.createDirectory(params) == returnvalue::OK);
|
CHECK(fsMock.createDirectory(params) == returnvalue::OK);
|
||||||
REQUIRE(not fsMock.dirMap.empty());
|
REQUIRE(not fsMock.dirMap.empty());
|
||||||
auto iter = fsMock.dirMap.find("hello");
|
std::string filename_c("hello");
|
||||||
|
std::filesystem::path::string_type filename(filename_c.cbegin(), filename_c.cend());
|
||||||
|
auto iter = fsMock.dirMap.find(filename);
|
||||||
REQUIRE(iter != fsMock.dirMap.end());
|
REQUIRE(iter != fsMock.dirMap.end());
|
||||||
auto &dirInfo = iter->second;
|
auto &dirInfo = iter->second;
|
||||||
CHECK(dirInfo.createCallCount == 1);
|
CHECK(dirInfo.createCallCount == 1);
|
||||||
|
@ -26,30 +26,30 @@ TEST_CASE("Host Filesystem", "[hal][host]") {
|
|||||||
REQUIRE_NOTHROW(fs::remove_all(dir0));
|
REQUIRE_NOTHROW(fs::remove_all(dir0));
|
||||||
|
|
||||||
SECTION("Create file") {
|
SECTION("Create file") {
|
||||||
FilesystemParams params(file0.c_str());
|
FilesystemParams params(file0.string().c_str());
|
||||||
REQUIRE(hostFs.createFile(params) == returnvalue::OK);
|
REQUIRE(hostFs.createFile(params) == returnvalue::OK);
|
||||||
CHECK(fs::is_regular_file(file0));
|
CHECK(fs::is_regular_file(file0));
|
||||||
REQUIRE(fs::exists(file0));
|
REQUIRE(fs::exists(file0));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Remove File") {
|
SECTION("Remove File") {
|
||||||
FilesystemParams params(file0.c_str());
|
FilesystemParams params(file0.string().c_str());
|
||||||
REQUIRE(hostFs.createFile(params) == returnvalue::OK);
|
REQUIRE(hostFs.createFile(params) == returnvalue::OK);
|
||||||
CHECK(fs::is_regular_file(file0));
|
CHECK(fs::is_regular_file(file0));
|
||||||
REQUIRE(fs::exists(file0));
|
REQUIRE(fs::exists(file0));
|
||||||
REQUIRE(hostFs.removeFile(file0.c_str()) == returnvalue::OK);
|
REQUIRE(hostFs.removeFile(file0.string().c_str()) == returnvalue::OK);
|
||||||
REQUIRE(not fs::exists(file0));
|
REQUIRE(not fs::exists(file0));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Create Directory") {
|
SECTION("Create Directory") {
|
||||||
FilesystemParams params(dir0.c_str());
|
FilesystemParams params(dir0.string().c_str());
|
||||||
REQUIRE(hostFs.createDirectory(params) == returnvalue::OK);
|
REQUIRE(hostFs.createDirectory(params) == returnvalue::OK);
|
||||||
CHECK(fs::is_directory(dir0));
|
CHECK(fs::is_directory(dir0));
|
||||||
REQUIRE(fs::exists(dir0));
|
REQUIRE(fs::exists(dir0));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Remove Directory") {
|
SECTION("Remove Directory") {
|
||||||
FilesystemParams params(dir0.c_str());
|
FilesystemParams params(dir0.string().c_str());
|
||||||
REQUIRE(hostFs.createDirectory(params) == returnvalue::OK);
|
REQUIRE(hostFs.createDirectory(params) == returnvalue::OK);
|
||||||
REQUIRE(fs::exists(dir0));
|
REQUIRE(fs::exists(dir0));
|
||||||
REQUIRE(hostFs.removeDirectory(params) == returnvalue::OK);
|
REQUIRE(hostFs.removeDirectory(params) == returnvalue::OK);
|
||||||
@ -57,16 +57,16 @@ TEST_CASE("Host Filesystem", "[hal][host]") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Rename File") {
|
SECTION("Rename File") {
|
||||||
FilesystemParams params(file0.c_str());
|
FilesystemParams params(file0.string().c_str());
|
||||||
REQUIRE(hostFs.createFile(params) == returnvalue::OK);
|
REQUIRE(hostFs.createFile(params) == returnvalue::OK);
|
||||||
CHECK(fs::is_regular_file(file0));
|
CHECK(fs::is_regular_file(file0));
|
||||||
REQUIRE(fs::exists(file0));
|
REQUIRE(fs::exists(file0));
|
||||||
REQUIRE(hostFs.rename(file0.c_str(), file1.c_str()) == returnvalue::OK);
|
REQUIRE(hostFs.rename(file0.string().c_str(), file1.string().c_str()) == returnvalue::OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Write To File") {
|
SECTION("Write To File") {
|
||||||
std::string data = "hello world!";
|
std::string data = "hello world!";
|
||||||
FileOpParams params(file0.c_str(), data.size());
|
FileOpParams params(file0.string().c_str(), data.size());
|
||||||
REQUIRE(hostFs.createFile(params.fsParams) == returnvalue::OK);
|
REQUIRE(hostFs.createFile(params.fsParams) == returnvalue::OK);
|
||||||
CHECK(fs::is_regular_file(file0));
|
CHECK(fs::is_regular_file(file0));
|
||||||
REQUIRE(fs::exists(file0));
|
REQUIRE(fs::exists(file0));
|
||||||
@ -88,7 +88,7 @@ TEST_CASE("Host Filesystem", "[hal][host]") {
|
|||||||
for (uint8_t& byte : randData) {
|
for (uint8_t& byte : randData) {
|
||||||
byte = distU8(rng);
|
byte = distU8(rng);
|
||||||
}
|
}
|
||||||
FileOpParams params(file0.c_str(), randData.size() - 256);
|
FileOpParams params(file0.string().c_str(), randData.size() - 256);
|
||||||
REQUIRE(hostFs.createFile(params.fsParams) == returnvalue::OK);
|
REQUIRE(hostFs.createFile(params.fsParams) == returnvalue::OK);
|
||||||
CHECK(fs::is_regular_file(file0));
|
CHECK(fs::is_regular_file(file0));
|
||||||
REQUIRE(fs::exists(file0));
|
REQUIRE(fs::exists(file0));
|
||||||
@ -107,7 +107,7 @@ TEST_CASE("Host Filesystem", "[hal][host]") {
|
|||||||
|
|
||||||
SECTION("Read From File") {
|
SECTION("Read From File") {
|
||||||
std::string data = "hello world!";
|
std::string data = "hello world!";
|
||||||
FileOpParams params(file0.c_str(), data.size());
|
FileOpParams params(file0.string().c_str(), data.size());
|
||||||
REQUIRE(hostFs.createFile(params.fsParams) == returnvalue::OK);
|
REQUIRE(hostFs.createFile(params.fsParams) == returnvalue::OK);
|
||||||
CHECK(fs::is_regular_file(file0));
|
CHECK(fs::is_regular_file(file0));
|
||||||
ofstream of(file0);
|
ofstream of(file0);
|
||||||
@ -138,35 +138,35 @@ TEST_CASE("Host Filesystem", "[hal][host]") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Create File but already exists") {
|
SECTION("Create File but already exists") {
|
||||||
FilesystemParams params(file0.c_str());
|
FilesystemParams params(file0.string().c_str());
|
||||||
REQUIRE(hostFs.createFile(params) == returnvalue::OK);
|
REQUIRE(hostFs.createFile(params) == returnvalue::OK);
|
||||||
REQUIRE(hostFs.createFile(params) == HasFileSystemIF::FILE_ALREADY_EXISTS);
|
REQUIRE(hostFs.createFile(params) == HasFileSystemIF::FILE_ALREADY_EXISTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Remove File but does not exist") {
|
SECTION("Remove File but does not exist") {
|
||||||
REQUIRE(hostFs.removeFile(file0.c_str()) == HasFileSystemIF::FILE_DOES_NOT_EXIST);
|
REQUIRE(hostFs.removeFile(file0.string().c_str()) == HasFileSystemIF::FILE_DOES_NOT_EXIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Create Directory but already exists") {
|
SECTION("Create Directory but already exists") {
|
||||||
FileOpParams params(file0.c_str(), 12);
|
FileOpParams params(file0.string().c_str(), 12);
|
||||||
REQUIRE(hostFs.createDirectory(params.fsParams) == returnvalue::OK);
|
REQUIRE(hostFs.createDirectory(params.fsParams) == returnvalue::OK);
|
||||||
REQUIRE(hostFs.createDirectory(params.fsParams) == HasFileSystemIF::DIRECTORY_ALREADY_EXISTS);
|
REQUIRE(hostFs.createDirectory(params.fsParams) == HasFileSystemIF::DIRECTORY_ALREADY_EXISTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Remove Directory but does not exist") {
|
SECTION("Remove Directory but does not exist") {
|
||||||
FilesystemParams params(dir0.c_str());
|
FilesystemParams params(dir0.string().c_str());
|
||||||
REQUIRE(hostFs.removeDirectory(params) == HasFileSystemIF::DIRECTORY_DOES_NOT_EXIST);
|
REQUIRE(hostFs.removeDirectory(params) == HasFileSystemIF::DIRECTORY_DOES_NOT_EXIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Remove Directory but is file") {
|
SECTION("Remove Directory but is file") {
|
||||||
ofstream of(file0);
|
ofstream of(file0);
|
||||||
FilesystemParams params(file0.c_str());
|
FilesystemParams params(file0.string().c_str());
|
||||||
REQUIRE(hostFs.removeDirectory(params) == HasFileSystemIF::NOT_A_DIRECTORY);
|
REQUIRE(hostFs.removeDirectory(params) == HasFileSystemIF::NOT_A_DIRECTORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Read from file but does not exist") {
|
SECTION("Read from file but does not exist") {
|
||||||
std::string data = "hello world!";
|
std::string data = "hello world!";
|
||||||
FileOpParams params(file0.c_str(), data.size());
|
FileOpParams params(file0.string().c_str(), data.size());
|
||||||
std::array<uint8_t, 10> readBuf{};
|
std::array<uint8_t, 10> readBuf{};
|
||||||
uint8_t* readPtr = readBuf.data();
|
uint8_t* readPtr = readBuf.data();
|
||||||
size_t readSize = 0;
|
size_t readSize = 0;
|
||||||
@ -176,39 +176,41 @@ TEST_CASE("Host Filesystem", "[hal][host]") {
|
|||||||
|
|
||||||
SECTION("Write to file but does not exist") {
|
SECTION("Write to file but does not exist") {
|
||||||
std::string data = "hello world!";
|
std::string data = "hello world!";
|
||||||
FileOpParams params(file0.c_str(), data.size());
|
FileOpParams params(file0.string().c_str(), data.size());
|
||||||
CHECK(hostFs.writeToFile(params, reinterpret_cast<const uint8_t*>(data.c_str())) ==
|
CHECK(hostFs.writeToFile(params, reinterpret_cast<const uint8_t*>(data.c_str())) ==
|
||||||
HasFileSystemIF::FILE_DOES_NOT_EXIST);
|
HasFileSystemIF::FILE_DOES_NOT_EXIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Remove recursively") {
|
SECTION("Remove recursively") {
|
||||||
fs::create_directory(dir0.c_str());
|
fs::create_directory(dir0.string().c_str());
|
||||||
ofstream of(fileInDir0);
|
ofstream of(fileInDir0);
|
||||||
CHECK(fs::is_directory(dir0));
|
CHECK(fs::is_directory(dir0));
|
||||||
CHECK(fs::is_regular_file(fileInDir0));
|
CHECK(fs::is_regular_file(fileInDir0));
|
||||||
REQUIRE(hostFs.removeDirectory(FilesystemParams(dir0.c_str()), true) == returnvalue::OK);
|
REQUIRE(hostFs.removeDirectory(FilesystemParams(dir0.string().c_str()), true) ==
|
||||||
|
returnvalue::OK);
|
||||||
CHECK(not fs::is_directory(dir0));
|
CHECK(not fs::is_directory(dir0));
|
||||||
CHECK(not fs::is_regular_file(fileInDir0));
|
CHECK(not fs::is_regular_file(fileInDir0));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Non-Recursive Removal Fails") {
|
SECTION("Non-Recursive Removal Fails") {
|
||||||
fs::create_directory(dir0.c_str());
|
fs::create_directory(dir0.string().c_str());
|
||||||
ofstream of(fileInDir0);
|
ofstream of(fileInDir0);
|
||||||
CHECK(fs::is_directory(dir0));
|
CHECK(fs::is_directory(dir0));
|
||||||
CHECK(fs::is_regular_file(fileInDir0));
|
CHECK(fs::is_regular_file(fileInDir0));
|
||||||
REQUIRE(hostFs.removeDirectory(FilesystemParams(dir0.c_str())) ==
|
REQUIRE(hostFs.removeDirectory(FilesystemParams(dir0.string().c_str())) ==
|
||||||
HasFileSystemIF::DIRECTORY_NOT_EMPTY);
|
HasFileSystemIF::DIRECTORY_NOT_EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Create directory with parent directory") {
|
SECTION("Create directory with parent directory") {
|
||||||
CHECK(hostFs.createDirectory(FilesystemParams(dirWithParent.c_str()), true) == returnvalue::OK);
|
CHECK(hostFs.createDirectory(FilesystemParams(dirWithParent.string().c_str()), true) ==
|
||||||
|
returnvalue::OK);
|
||||||
CHECK(fs::is_directory(dir0));
|
CHECK(fs::is_directory(dir0));
|
||||||
CHECK(fs::is_directory(dirWithParent));
|
CHECK(fs::is_directory(dirWithParent));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Read but provided buffer too small") {
|
SECTION("Read but provided buffer too small") {
|
||||||
std::string data = "hello world!";
|
std::string data = "hello world!";
|
||||||
FileOpParams params(file0.c_str(), data.size());
|
FileOpParams params(file0.string().c_str(), data.size());
|
||||||
ofstream of(file0);
|
ofstream of(file0);
|
||||||
of.write(data.c_str(), static_cast<unsigned int>(data.size()));
|
of.write(data.c_str(), static_cast<unsigned int>(data.size()));
|
||||||
of.close();
|
of.close();
|
||||||
|
@ -6,14 +6,14 @@
|
|||||||
|
|
||||||
ReturnValue_t FilesystemMock::feedFile(const std::string &filename, std::ifstream &file) {
|
ReturnValue_t FilesystemMock::feedFile(const std::string &filename, std::ifstream &file) {
|
||||||
// not multibyte encoding safe!
|
// not multibyte encoding safe!
|
||||||
std::basic_string<std::filesystem::path::value_type> native_filename(filename.begin(),
|
std::filesystem::path::string_type native_filename(filename.begin(),
|
||||||
filename.end());
|
filename.end());
|
||||||
|
|
||||||
if (not std::filesystem::exists(native_filename)) {
|
if (not std::filesystem::exists(native_filename)) {
|
||||||
return returnvalue::FAILED;
|
return returnvalue::FAILED;
|
||||||
}
|
}
|
||||||
size_t fileSize = std::filesystem::file_size(native_filename);
|
size_t fileSize = std::filesystem::file_size(native_filename);
|
||||||
FileOpParams params(native_filename.c_str(), fileSize);
|
FileOpParams params(filename.c_str(), fileSize);
|
||||||
std::vector<uint8_t> rawData(fileSize);
|
std::vector<uint8_t> rawData(fileSize);
|
||||||
file.read(reinterpret_cast<char *>(rawData.data()), static_cast<unsigned int>(rawData.size()));
|
file.read(reinterpret_cast<char *>(rawData.data()), static_cast<unsigned int>(rawData.size()));
|
||||||
createOrAddToFile(params, rawData.data());
|
createOrAddToFile(params, rawData.data());
|
||||||
@ -27,7 +27,8 @@ ReturnValue_t FilesystemMock::writeToFile(FileOpParams params, const uint8_t *da
|
|||||||
|
|
||||||
ReturnValue_t FilesystemMock::readFromFile(FileOpParams params, uint8_t **buffer, size_t &readSize,
|
ReturnValue_t FilesystemMock::readFromFile(FileOpParams params, uint8_t **buffer, size_t &readSize,
|
||||||
size_t maxSize) {
|
size_t maxSize) {
|
||||||
std::basic_string<std::filesystem::path::value_type> filename(params.path());
|
std::string filename_c(params.fsParams.path);
|
||||||
|
std::filesystem::path::string_type filename(filename_c.cbegin(), filename_c.cend());
|
||||||
auto iter = fileMap.find(filename);
|
auto iter = fileMap.find(filename);
|
||||||
if (iter == fileMap.end()) {
|
if (iter == fileMap.end()) {
|
||||||
return HasFileSystemIF::FILE_DOES_NOT_EXIST;
|
return HasFileSystemIF::FILE_DOES_NOT_EXIST;
|
||||||
@ -57,9 +58,10 @@ ReturnValue_t FilesystemMock::createFile(FilesystemParams params, const uint8_t
|
|||||||
return returnvalue::OK;
|
return returnvalue::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t FilesystemMock::removeFile(const std::filesystem::path::value_type *path,
|
ReturnValue_t FilesystemMock::removeFile(const char *path,
|
||||||
FileSystemArgsIF *args) {
|
FileSystemArgsIF *args) {
|
||||||
std::basic_string<std::filesystem::path::value_type> filename(path);
|
std::string filename_c(path);
|
||||||
|
std::filesystem::path::string_type filename(filename_c.cbegin(), filename_c.cend());
|
||||||
|
|
||||||
auto iter = fileMap.find(filename);
|
auto iter = fileMap.find(filename);
|
||||||
if (iter == fileMap.end()) {
|
if (iter == fileMap.end()) {
|
||||||
@ -71,28 +73,31 @@ ReturnValue_t FilesystemMock::removeFile(const std::filesystem::path::value_type
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t FilesystemMock::createDirectory(FilesystemParams params, bool createParentDirs) {
|
ReturnValue_t FilesystemMock::createDirectory(FilesystemParams params, bool createParentDirs) {
|
||||||
auto dirPath = params.path;
|
std::string dirPath_c(params.path);
|
||||||
|
std::filesystem::path::string_type dirPath(dirPath_c.cbegin(), dirPath_c.cend());
|
||||||
dirMap[dirPath].createCallCount++;
|
dirMap[dirPath].createCallCount++;
|
||||||
dirMap[dirPath].wihParentDir.push(createParentDirs);
|
dirMap[dirPath].wihParentDir.push(createParentDirs);
|
||||||
return returnvalue::OK;
|
return returnvalue::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t FilesystemMock::removeDirectory(FilesystemParams params, bool deleteRecurively) {
|
ReturnValue_t FilesystemMock::removeDirectory(FilesystemParams params, bool deleteRecurively) {
|
||||||
auto dirPath = params.path;
|
std::string dirPath_c(params.path);
|
||||||
|
std::filesystem::path::string_type dirPath(dirPath_c.cbegin(), dirPath_c.cend());
|
||||||
dirMap[dirPath].delCallCount++;
|
dirMap[dirPath].delCallCount++;
|
||||||
dirMap[dirPath].recursiveDeletion.push(deleteRecurively);
|
dirMap[dirPath].recursiveDeletion.push(deleteRecurively);
|
||||||
return returnvalue::OK;
|
return returnvalue::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t FilesystemMock::rename(const std::filesystem::path::value_type *oldPath,
|
ReturnValue_t FilesystemMock::rename(const char *oldPath,
|
||||||
const std::filesystem::path::value_type *newPath,
|
const char *newPath,
|
||||||
FileSystemArgsIF *args) {
|
FileSystemArgsIF *args) {
|
||||||
renameQueue.push(RenameInfo(oldPath, newPath));
|
renameQueue.push(RenameInfo(oldPath, newPath));
|
||||||
return returnvalue::OK;
|
return returnvalue::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilesystemMock::createOrAddToFile(FileOpParams params, const uint8_t *data) {
|
void FilesystemMock::createOrAddToFile(FileOpParams params, const uint8_t *data) {
|
||||||
auto filename(params.path());
|
std::string filename_c(params.fsParams.path);
|
||||||
|
std::filesystem::path::string_type filename(filename_c.cbegin(), filename_c.cend());
|
||||||
auto iter = fileMap.find(filename);
|
auto iter = fileMap.find(filename);
|
||||||
if (iter == fileMap.end()) {
|
if (iter == fileMap.end()) {
|
||||||
FileSegmentQueue queue;
|
FileSegmentQueue queue;
|
||||||
@ -133,7 +138,8 @@ void FilesystemMock::reset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool FilesystemMock::fileExists(FilesystemParams params) {
|
bool FilesystemMock::fileExists(FilesystemParams params) {
|
||||||
auto filename(params.path);
|
std::string filename_c(params.path);
|
||||||
|
std::filesystem::path::string_type filename(filename_c.cbegin(), filename_c.cend());
|
||||||
auto iter = fileMap.find(filename);
|
auto iter = fileMap.find(filename);
|
||||||
if (iter == fileMap.end()) {
|
if (iter == fileMap.end()) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <queue>
|
#include <queue>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
#include "fsfw/filesystem.h"
|
#include "fsfw/filesystem.h"
|
||||||
|
|
||||||
@ -20,13 +21,13 @@
|
|||||||
class FilesystemMock : public HasFileSystemIF {
|
class FilesystemMock : public HasFileSystemIF {
|
||||||
public:
|
public:
|
||||||
struct FileWriteInfo {
|
struct FileWriteInfo {
|
||||||
FileWriteInfo(std::basic_string<std::filesystem::path::value_type> filename, size_t offset,
|
FileWriteInfo(std::filesystem::path::string_type filename, size_t offset,
|
||||||
const uint8_t *data, size_t len)
|
const uint8_t *data, size_t len)
|
||||||
: offset(offset) {
|
: offset(offset) {
|
||||||
this->filename = filename;
|
this->filename = filename;
|
||||||
this->data.insert(this->data.end(), data, data + len);
|
this->data.insert(this->data.end(), data, data + len);
|
||||||
}
|
}
|
||||||
std::basic_string<std::filesystem::path::value_type> filename;
|
std::filesystem::path::string_type filename;
|
||||||
size_t offset;
|
size_t offset;
|
||||||
std::vector<uint8_t> data;
|
std::vector<uint8_t> data;
|
||||||
};
|
};
|
||||||
@ -37,7 +38,7 @@ class FilesystemMock : public HasFileSystemIF {
|
|||||||
std::vector<uint8_t> fileRaw;
|
std::vector<uint8_t> fileRaw;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::map<std::basic_string<std::filesystem::path::value_type>, FileInfo> fileMap;
|
std::map<std::filesystem::path::string_type, FileInfo> fileMap;
|
||||||
|
|
||||||
struct DirInfo {
|
struct DirInfo {
|
||||||
size_t createCallCount = 0;
|
size_t createCallCount = 0;
|
||||||
@ -45,18 +46,17 @@ class FilesystemMock : public HasFileSystemIF {
|
|||||||
std::queue<bool> wihParentDir;
|
std::queue<bool> wihParentDir;
|
||||||
std::queue<bool> recursiveDeletion;
|
std::queue<bool> recursiveDeletion;
|
||||||
};
|
};
|
||||||
std::map<std::basic_string<std::filesystem::path::value_type>, DirInfo> dirMap;
|
std::map<std::filesystem::path::string_type, DirInfo> dirMap;
|
||||||
|
|
||||||
struct RenameInfo {
|
struct RenameInfo {
|
||||||
RenameInfo(std::basic_string<std::filesystem::path::value_type> oldName,
|
RenameInfo(const char* oldName, const char *newName)
|
||||||
std::basic_string<std::filesystem::path::value_type> newName)
|
|
||||||
: oldName(std::move(oldName)), newName(std::move(newName)) {}
|
: oldName(std::move(oldName)), newName(std::move(newName)) {}
|
||||||
|
|
||||||
std::basic_string<std::filesystem::path::value_type> oldName;
|
const char *oldName;
|
||||||
std::basic_string<std::filesystem::path::value_type> newName;
|
const char *newName;
|
||||||
};
|
};
|
||||||
std::queue<RenameInfo> renameQueue;
|
std::queue<RenameInfo> renameQueue;
|
||||||
std::basic_string<std::filesystem::path::value_type> truncateCalledOnFile;
|
const char* truncateCalledOnFile;
|
||||||
ReturnValue_t feedFile(const std::string &filename, std::ifstream &file);
|
ReturnValue_t feedFile(const std::string &filename, std::ifstream &file);
|
||||||
|
|
||||||
bool fileExists(FilesystemParams params) override;
|
bool fileExists(FilesystemParams params) override;
|
||||||
@ -66,12 +66,12 @@ class FilesystemMock : public HasFileSystemIF {
|
|||||||
ReturnValue_t readFromFile(FileOpParams params, uint8_t **buffer, size_t &readSize,
|
ReturnValue_t readFromFile(FileOpParams params, uint8_t **buffer, size_t &readSize,
|
||||||
size_t maxSize) override;
|
size_t maxSize) override;
|
||||||
ReturnValue_t createFile(FilesystemParams params, const uint8_t *data, size_t size) override;
|
ReturnValue_t createFile(FilesystemParams params, const uint8_t *data, size_t size) override;
|
||||||
ReturnValue_t removeFile(const std::filesystem::path::value_type *path,
|
ReturnValue_t removeFile(const char *path,
|
||||||
FileSystemArgsIF *args) override;
|
FileSystemArgsIF *args) override;
|
||||||
ReturnValue_t createDirectory(FilesystemParams params, bool createParentDirs) override;
|
ReturnValue_t createDirectory(FilesystemParams params, bool createParentDirs) override;
|
||||||
ReturnValue_t removeDirectory(FilesystemParams params, bool deleteRecurively) override;
|
ReturnValue_t removeDirectory(FilesystemParams params, bool deleteRecurively) override;
|
||||||
ReturnValue_t rename(const std::filesystem::path::value_type *oldPath,
|
ReturnValue_t rename(const char *oldPath,
|
||||||
const std::filesystem::path::value_type *newPath,
|
const char *newPath,
|
||||||
FileSystemArgsIF *args) override;
|
FileSystemArgsIF *args) override;
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user