Merge remote-tracking branch 'origin/development' into mueller/cfdp-update-without-handlers

This commit is contained in:
Robin Müller 2022-11-14 14:25:36 +01:00
commit b48e0fdc0d
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
11 changed files with 92 additions and 55 deletions

View File

@ -140,7 +140,7 @@ find_program( GCOV_PATH gcov )
find_program( LCOV_PATH NAMES lcov lcov.bat lcov.exe lcov.perl) find_program( LCOV_PATH NAMES lcov lcov.bat lcov.exe lcov.perl)
find_program( FASTCOV_PATH NAMES fastcov fastcov.py ) find_program( FASTCOV_PATH NAMES fastcov fastcov.py )
find_program( GENHTML_PATH NAMES genhtml genhtml.perl genhtml.bat ) find_program( GENHTML_PATH NAMES genhtml genhtml.perl genhtml.bat )
find_program( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/scripts/test) find_program( GCOVR_PATH gcovr )
find_program( CPPFILT_PATH NAMES c++filt ) find_program( CPPFILT_PATH NAMES c++filt )
if(NOT GCOV_PATH) if(NOT GCOV_PATH)

View File

@ -1,8 +1,8 @@
#include "fsfw/globalfunctions/timevalOperations.h" #include "fsfw/globalfunctions/timevalOperations.h"
timeval& operator+=(timeval& lhs, const timeval& rhs) { timeval& operator+=(timeval& lhs, const timeval& rhs) {
int64_t sum = lhs.tv_sec * 1000000. + lhs.tv_usec; int64_t sum = static_cast<int64_t>(lhs.tv_sec) * 1000000. + lhs.tv_usec;
sum += rhs.tv_sec * 1000000. + rhs.tv_usec; sum += static_cast<int64_t>(rhs.tv_sec) * 1000000. + rhs.tv_usec;
lhs.tv_sec = sum / 1000000; lhs.tv_sec = sum / 1000000;
lhs.tv_usec = sum - lhs.tv_sec * 1000000; lhs.tv_usec = sum - lhs.tv_sec * 1000000;
return lhs; return lhs;

View File

@ -1,6 +1,7 @@
#include "fsfw/osal/common/TcpIpBase.h" #include "fsfw/osal/common/TcpIpBase.h"
#include "fsfw/platform.h" #include "fsfw/platform.h"
#include "fsfw/serviceinterface.h"
#ifdef PLATFORM_UNIX #ifdef PLATFORM_UNIX
#include <errno.h> #include <errno.h>

View File

@ -8,6 +8,7 @@
#if defined(PLATFORM_WIN) #if defined(PLATFORM_WIN)
#include <sysinfoapi.h> #include <sysinfoapi.h>
#define timegm _mkgmtime
#elif defined(PLATFORM_UNIX) #elif defined(PLATFORM_UNIX)
#include <fstream> #include <fstream>
#endif #endif

View File

@ -1,5 +1,7 @@
#include "fsfw/osal/windows/winTaskHelpers.h" #include "fsfw/osal/windows/winTaskHelpers.h"
#include <windows.h>
#include <mutex> #include <mutex>
TaskPriority tasks::makeWinPriority(PriorityClass prioClass, PriorityNumber prioNumber) { TaskPriority tasks::makeWinPriority(PriorityClass prioClass, PriorityNumber prioNumber) {

View File

@ -1,10 +1,12 @@
#include <map> #include <map>
#include <thread> #include <thread>
#include "../../tasks/TaskFactory.h" #include "fsfw/tasks/TaskFactory.h"
#ifdef _WIN32 #ifdef _WIN32
#include <minwindef.h>
namespace tasks { namespace tasks {
enum PriorityClass : uint16_t { enum PriorityClass : uint16_t {

View File

@ -61,10 +61,16 @@ ReturnValue_t Clock::convertTimevalToTimeOfDay(const timeval* from, TimeOfDay_t*
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
MutexGuard helper(timeMutex);
// gmtime writes its output in a global buffer which is not Thread Safe // gmtime writes its output in a global buffer which is not Thread Safe
// Therefore we have to use a Mutex here // Therefore we have to use a Mutex here
MutexGuard helper(timeMutex);
#ifdef PLATFORM_WIN
time_t time;
time = from->tv_sec;
timeInfo = gmtime(&time);
#else
timeInfo = gmtime(&from->tv_sec); timeInfo = gmtime(&from->tv_sec);
#endif
to->year = timeInfo->tm_year + 1900; to->year = timeInfo->tm_year + 1900;
to->month = timeInfo->tm_mon + 1; to->month = timeInfo->tm_mon + 1;
to->day = timeInfo->tm_mday; to->day = timeInfo->tm_mday;

View File

@ -1,8 +1,16 @@
#ifndef FSFW_TIMEMANAGER_TIMEREADERIF_H #ifndef FSFW_TIMEMANAGER_TIMEREADERIF_H
#define FSFW_TIMEMANAGER_TIMEREADERIF_H #define FSFW_TIMEMANAGER_TIMEREADERIF_H
#include <cstdio>
#include <cstdlib> #include <cstdlib>
#include "fsfw/platform.h"
#ifdef PLATFORM_WIN
// wtf? Required for timeval!
#include <winsock.h>
#endif
#include "TimeStampIF.h" #include "TimeStampIF.h"
#include "fsfw/returnvalues/returnvalue.h" #include "fsfw/returnvalues/returnvalue.h"
#include "fsfw/serialize/SerializeIF.h" #include "fsfw/serialize/SerializeIF.h"

View File

@ -5,6 +5,14 @@
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#ifdef PLATFORM_WIN
// Defined in Windows header for whatever reason, and leads to nameclash issues with
// class enums which have entries of the same name.
#undef IN
#undef OUT
#undef CALLBACK
#endif
using gpioId_t = uint16_t; using gpioId_t = uint16_t;
namespace gpio { namespace gpio {

View File

@ -56,61 +56,65 @@ TEST_CASE("TimevalTest", "[timevalOperations]") {
} }
SECTION("Operators") { SECTION("Operators") {
timeval t1; timeval t1;
t1.tv_sec = 1648227422; if (sizeof(t1.tv_sec) == 8) {
t1.tv_usec = 123456; t1.tv_sec = 1648227422;
timeval t2; t1.tv_usec = 123456;
t2.tv_sec = 1648227422; timeval t2;
t2.tv_usec = 123456; t2.tv_sec = 1648227422;
timeval t3 = t1 - t2; t2.tv_usec = 123456;
REQUIRE(t3.tv_sec == 0); timeval t3 = t1 - t2;
REQUIRE(t3.tv_usec == 0); REQUIRE(t3.tv_sec == 0);
timeval t4 = t1 - t3; REQUIRE(t3.tv_usec == 0);
REQUIRE(t4.tv_sec == 1648227422); timeval t4 = t1 - t3;
REQUIRE(t4.tv_usec == 123456); REQUIRE(t4.tv_sec == 1648227422);
timeval t5 = t3 - t1; REQUIRE(t4.tv_usec == 123456);
REQUIRE(t5.tv_sec == -1648227422); timeval t5 = t3 - t1;
REQUIRE(t5.tv_usec == -123456); REQUIRE(t5.tv_sec == -1648227422);
REQUIRE(t5.tv_usec == -123456);
timeval t6; timeval t6;
t6.tv_sec = 1648227400; t6.tv_sec = 1648227400;
t6.tv_usec = 999999; t6.tv_usec = 999999;
timeval t7 = t6 + t1; timeval t7 = t6 + t1;
REQUIRE(t7.tv_sec == (1648227422ull + 1648227400ull + 1ull)); // Overflow test
REQUIRE(t7.tv_usec == 123455); REQUIRE(t7.tv_sec == (1648227422ull + 1648227400ull + 1ull));
timeval t8 = t1 - t6; REQUIRE(t7.tv_usec == 123455);
REQUIRE(t8.tv_sec == 1648227422 - 1648227400 - 1);
REQUIRE(t8.tv_usec == 123457);
double scalar = 2; timeval t8 = t1 - t6;
timeval t9 = t1 * scalar; REQUIRE(t8.tv_sec == 1648227422 - 1648227400 - 1);
REQUIRE(t9.tv_sec == 3296454844); REQUIRE(t8.tv_usec == 123457);
REQUIRE(t9.tv_usec == 246912);
timeval t10 = scalar * t1;
REQUIRE(t10.tv_sec == 3296454844);
REQUIRE(t10.tv_usec == 246912);
timeval t11 = t6 * scalar;
REQUIRE(t11.tv_sec == (3296454800 + 1));
REQUIRE(t11.tv_usec == 999998);
timeval t12 = t1 / scalar; double scalar = 2;
REQUIRE(t12.tv_sec == 824113711); timeval t9 = t1 * scalar;
REQUIRE(t12.tv_usec == 61728); REQUIRE(t9.tv_sec == 3296454844);
REQUIRE(t9.tv_usec == 246912);
timeval t10 = scalar * t1;
REQUIRE(t10.tv_sec == 3296454844);
REQUIRE(t10.tv_usec == 246912);
timeval t11 = t6 * scalar;
REQUIRE(t11.tv_sec == (3296454800 + 1));
REQUIRE(t11.tv_usec == 999998);
timeval t13 = t6 / scalar; timeval t12 = t1 / scalar;
REQUIRE(t13.tv_sec == 824113700); REQUIRE(t12.tv_sec == 824113711);
// Rounding issue REQUIRE(t12.tv_usec == 61728);
REQUIRE(t13.tv_usec == 499999);
double scalar2 = t9 / t1; timeval t13 = t6 / scalar;
REQUIRE(scalar2 == Catch::Approx(2.0)); REQUIRE(t13.tv_sec == 824113700);
double scalar3 = t1 / t6; // Rounding issue
REQUIRE(scalar3 == Catch::Approx(1.000000013)); REQUIRE(t13.tv_usec == 499999);
double scalar4 = t3 / t1;
REQUIRE(scalar4 == Catch::Approx(0)); double scalar2 = t9 / t1;
double scalar5 = t12 / t1; REQUIRE(scalar2 == Catch::Approx(2.0));
REQUIRE(scalar5 == Catch::Approx(0.5)); double scalar3 = t1 / t6;
REQUIRE(scalar3 == Catch::Approx(1.000000013));
double scalar4 = t3 / t1;
REQUIRE(scalar4 == Catch::Approx(0));
double scalar5 = t12 / t1;
REQUIRE(scalar5 == Catch::Approx(0.5));
}
} }
SECTION("timevalOperations::toTimeval") { SECTION("timevalOperations::toTimeval") {

View File

@ -1,2 +1,7 @@
target_sources(${FSFW_TEST_TGT} PRIVATE testCommandExecutor.cpp target_sources(${FSFW_TEST_TGT} PRIVATE testHostFilesystem.cpp testFsMock.cpp)
testHostFilesystem.cpp testFsMock.cpp)
if(UNIX)
target_sources(${FSFW_TEST_TGT} PRIVATE
testCommandExecutor.cpp
)
endif()