mirror of
https://github.com/nasa/fprime.git
synced 2025-12-10 00:44:37 -06:00
Modify LinuxTimer interface for consistency (#4087)
* Use Fw::TimeInterval in LinuxTimer * Fix Linux FD typo * Fix interval timer UT * Format * Fix assert casts * Fix ComLogger UTs * Fix FppTest microseconds * Fix casting * Fix overflow
This commit is contained in:
parent
8b9ac2197d
commit
10f2b49d3f
@ -20,7 +20,7 @@ ActiveTestTester ::ActiveTestTester()
|
|||||||
arrayBuf(arrayData, sizeof(arrayData)),
|
arrayBuf(arrayData, sizeof(arrayData)),
|
||||||
structBuf(structData, sizeof(structData)),
|
structBuf(structData, sizeof(structData)),
|
||||||
serialBuf(serialData, sizeof(serialData)),
|
serialBuf(serialData, sizeof(serialData)),
|
||||||
time(STest::Pick::any(), STest::Pick::any()) {
|
time(STest::Pick::any(), STest::Pick::lowerUpper(0, 999999)) {
|
||||||
this->initComponents();
|
this->initComponents();
|
||||||
this->connectPorts();
|
this->connectPorts();
|
||||||
this->connectAsyncPorts();
|
this->connectAsyncPorts();
|
||||||
|
|||||||
@ -20,7 +20,7 @@ PassiveTestTester ::PassiveTestTester()
|
|||||||
arrayBuf(arrayData, sizeof(arrayData)),
|
arrayBuf(arrayData, sizeof(arrayData)),
|
||||||
structBuf(structData, sizeof(structData)),
|
structBuf(structData, sizeof(structData)),
|
||||||
serialBuf(serialData, sizeof(serialData)),
|
serialBuf(serialData, sizeof(serialData)),
|
||||||
time(STest::Pick::any(), STest::Pick::any()) {
|
time(STest::Pick::any(), STest::Pick::lowerUpper(0, 999999)) {
|
||||||
this->initComponents();
|
this->initComponents();
|
||||||
this->connectPorts();
|
this->connectPorts();
|
||||||
this->component.registerExternalParameters(&this->paramTesterDelegate);
|
this->component.registerExternalParameters(&this->paramTesterDelegate);
|
||||||
|
|||||||
@ -20,7 +20,7 @@ QueuedTestTester ::QueuedTestTester()
|
|||||||
arrayBuf(arrayData, sizeof(arrayData)),
|
arrayBuf(arrayData, sizeof(arrayData)),
|
||||||
structBuf(structData, sizeof(structData)),
|
structBuf(structData, sizeof(structData)),
|
||||||
serialBuf(serialData, sizeof(serialData)),
|
serialBuf(serialData, sizeof(serialData)),
|
||||||
time(STest::Pick::any(), STest::Pick::any()) {
|
time(STest::Pick::any(), STest::Pick::lowerUpper(0, 999999)) {
|
||||||
this->initComponents();
|
this->initComponents();
|
||||||
this->connectPorts();
|
this->connectPorts();
|
||||||
this->connectAsyncPorts();
|
this->connectAsyncPorts();
|
||||||
|
|||||||
@ -19,7 +19,7 @@
|
|||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
void Tester ::testTime() {
|
void Tester ::testTime() {
|
||||||
Fw::Time random_time(STest::Pick::any(), STest::Pick::any());
|
Fw::Time random_time(STest::Pick::any(), STest::Pick::lowerUpper(0, 999999));
|
||||||
Fw::Time zero_time(TimeBase::TB_NONE, 0, 0);
|
Fw::Time zero_time(TimeBase::TB_NONE, 0, 0);
|
||||||
Fw::Time result;
|
Fw::Time result;
|
||||||
|
|
||||||
|
|||||||
@ -39,6 +39,8 @@ Time::Time(TimeBase timeBase, FwTimeContextStoreType context, U32 seconds, U32 u
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Time::set(TimeBase timeBase, FwTimeContextStoreType context, U32 seconds, U32 useconds) {
|
void Time::set(TimeBase timeBase, FwTimeContextStoreType context, U32 seconds, U32 useconds) {
|
||||||
|
// Assert microseconds portion is less than 10^6
|
||||||
|
FW_ASSERT(useconds < 1000000, static_cast<FwAssertArgType>(useconds));
|
||||||
this->m_val.set(timeBase, context, seconds, useconds);
|
this->m_val.set(timeBase, context, seconds, useconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,6 +11,8 @@ TimeInterval::TimeInterval(U32 seconds, U32 useconds) : Serializable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TimeInterval::set(U32 seconds, U32 useconds) {
|
void TimeInterval::set(U32 seconds, U32 useconds) {
|
||||||
|
// Assert microseconds portion is less than 10^6
|
||||||
|
FW_ASSERT(useconds < 1000000, static_cast<FwAssertArgType>(useconds));
|
||||||
this->m_val.set(seconds, useconds);
|
this->m_val.set(seconds, useconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,6 +123,8 @@ void TimeInterval::add(U32 seconds, U32 useconds) {
|
|||||||
newSeconds += 1;
|
newSeconds += 1;
|
||||||
newUSeconds -= 1000000;
|
newUSeconds -= 1000000;
|
||||||
}
|
}
|
||||||
|
// Assert microseconds portion is less than 10^6
|
||||||
|
FW_ASSERT(newUSeconds < 1000000, static_cast<FwAssertArgType>(newUSeconds));
|
||||||
this->m_val.set(newSeconds, newUSeconds);
|
this->m_val.set(newSeconds, newUSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,4 +135,4 @@ std::ostream& operator<<(std::ostream& os, const TimeInterval& val) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace Fw
|
} // namespace Fw
|
||||||
|
|||||||
@ -85,12 +85,12 @@ void setupTopology(const TopologyState& state) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void startRateGroups(Fw::TimeInterval interval) {
|
void startRateGroups(const Fw::TimeInterval& interval) {
|
||||||
// This timer drives the fundamental tick rate of the system.
|
// This timer drives the fundamental tick rate of the system.
|
||||||
// Svc::RateGroupDriver will divide this down to the slower rate groups.
|
// Svc::RateGroupDriver will divide this down to the slower rate groups.
|
||||||
// This call will block until the stopRateGroups() call is made.
|
// This call will block until the stopRateGroups() call is made.
|
||||||
// For this Linux demo, that call is made from a signal handler.
|
// For this Linux demo, that call is made from a signal handler.
|
||||||
linuxTimer.startTimer(interval.getSeconds()*1000+interval.getUSeconds()/1000);
|
linuxTimer.startTimer(interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stopRateGroups() {
|
void stopRateGroups() {
|
||||||
|
|||||||
@ -77,7 +77,7 @@ void teardownTopology(const TopologyState& state);
|
|||||||
* This loop is stopped via a stopRateGroups call.
|
* This loop is stopped via a stopRateGroups call.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void startRateGroups(Fw::TimeInterval interval);
|
void startRateGroups(const Fw::TimeInterval& interval);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief stop the rate groups
|
* \brief stop the rate groups
|
||||||
|
|||||||
@ -76,9 +76,9 @@ void ComLoggerTester ::testLogging() {
|
|||||||
|
|
||||||
for (int j = 0; j < 3; j++) {
|
for (int j = 0; j < 3; j++) {
|
||||||
// Test times for the different iterations:
|
// Test times for the different iterations:
|
||||||
Fw::Time testTime(TimeBase::TB_NONE, j, 9876543);
|
Fw::Time testTime(TimeBase::TB_NONE, j, 987654);
|
||||||
Fw::Time testTimePrev(TimeBase::TB_NONE, j - 1, 9876543);
|
Fw::Time testTimePrev(TimeBase::TB_NONE, j - 1, 987654);
|
||||||
Fw::Time testTimeNext(TimeBase::TB_NONE, j + 1, 9876543);
|
Fw::Time testTimeNext(TimeBase::TB_NONE, j + 1, 987654);
|
||||||
|
|
||||||
// File names for the different iterations:
|
// File names for the different iterations:
|
||||||
memset(fileName, 0, sizeof(fileName));
|
memset(fileName, 0, sizeof(fileName));
|
||||||
@ -312,7 +312,7 @@ void ComLoggerTester ::openError() {
|
|||||||
const U8 data[COM_BUFFER_LENGTH] = {0xde, 0xad, 0xbe, 0xef};
|
const U8 data[COM_BUFFER_LENGTH] = {0xde, 0xad, 0xbe, 0xef};
|
||||||
Fw::ComBuffer buffer(data, sizeof(data));
|
Fw::ComBuffer buffer(data, sizeof(data));
|
||||||
|
|
||||||
Fw::Time testTime(TimeBase::TB_NONE, 4, 9876543);
|
Fw::Time testTime(TimeBase::TB_NONE, 4, 987654);
|
||||||
setTestTime(testTime);
|
setTestTime(testTime);
|
||||||
|
|
||||||
snprintf(fileName, sizeof(fileName), "%s_%d_%d_%06d.com", filePrefix, static_cast<U32>(testTime.getTimeBase()),
|
snprintf(fileName, sizeof(fileName), "%s_%d_%d_%06d.com", filePrefix, static_cast<U32>(testTime.getTimeBase()),
|
||||||
@ -384,7 +384,7 @@ void ComLoggerTester ::writeError() {
|
|||||||
const U8 data[4] = {0xde, 0xad, 0xbe, 0xef};
|
const U8 data[4] = {0xde, 0xad, 0xbe, 0xef};
|
||||||
Fw::ComBuffer buffer(data, sizeof(data));
|
Fw::ComBuffer buffer(data, sizeof(data));
|
||||||
|
|
||||||
Fw::Time testTime(TimeBase::TB_NONE, 5, 9876543);
|
Fw::Time testTime(TimeBase::TB_NONE, 5, 987654);
|
||||||
setTestTime(testTime);
|
setTestTime(testTime);
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
@ -457,7 +457,7 @@ void ComLoggerTester ::closeFileCommand() {
|
|||||||
Os::File::Status ret;
|
Os::File::Status ret;
|
||||||
|
|
||||||
// Form filenames:
|
// Form filenames:
|
||||||
Fw::Time testTime(TimeBase::TB_NONE, 6, 9876543);
|
Fw::Time testTime(TimeBase::TB_NONE, 6, 987654);
|
||||||
setTestTime(testTime);
|
setTestTime(testTime);
|
||||||
memset(fileName, 0, sizeof(fileName));
|
memset(fileName, 0, sizeof(fileName));
|
||||||
snprintf(fileName, sizeof(fileName), "%s_%d_%d_%06d.com", FILE_STR,
|
snprintf(fileName, sizeof(fileName), "%s_%d_%d_%06d.com", FILE_STR,
|
||||||
@ -541,9 +541,9 @@ void ComLoggerTester ::testLoggingWithInit() {
|
|||||||
|
|
||||||
for (int j = 0; j < 3; j++) {
|
for (int j = 0; j < 3; j++) {
|
||||||
// Test times for the different iterations:
|
// Test times for the different iterations:
|
||||||
Fw::Time testTime(TimeBase::TB_NONE, j, 9876543);
|
Fw::Time testTime(TimeBase::TB_NONE, j, 987654);
|
||||||
Fw::Time testTimePrev(TimeBase::TB_NONE, j - 1, 9876543);
|
Fw::Time testTimePrev(TimeBase::TB_NONE, j - 1, 987654);
|
||||||
Fw::Time testTimeNext(TimeBase::TB_NONE, j + 1, 9876543);
|
Fw::Time testTimeNext(TimeBase::TB_NONE, j + 1, 987654);
|
||||||
|
|
||||||
// File names for the different iterations:
|
// File names for the different iterations:
|
||||||
memset(fileName, 0, sizeof(fileName));
|
memset(fileName, 0, sizeof(fileName));
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
#ifndef LinuxTimer_HPP
|
#ifndef LinuxTimer_HPP
|
||||||
#define LinuxTimer_HPP
|
#define LinuxTimer_HPP
|
||||||
|
|
||||||
|
#include "Fw/Time/TimeInterval.hpp"
|
||||||
#include "Os/Mutex.hpp"
|
#include "Os/Mutex.hpp"
|
||||||
#include "Os/RawTime.hpp"
|
#include "Os/RawTime.hpp"
|
||||||
#include "Svc/LinuxTimer/LinuxTimerComponentAc.hpp"
|
#include "Svc/LinuxTimer/LinuxTimerComponentAc.hpp"
|
||||||
@ -35,7 +36,7 @@ class LinuxTimer final : public LinuxTimerComponentBase {
|
|||||||
~LinuxTimer();
|
~LinuxTimer();
|
||||||
|
|
||||||
//! Start timer
|
//! Start timer
|
||||||
void startTimer(FwSizeType interval); //!< interval in milliseconds
|
void startTimer(const Fw::TimeInterval& interval); //!< interval in milliseconds
|
||||||
|
|
||||||
//! Quit timer
|
//! Quit timer
|
||||||
void quit();
|
void quit();
|
||||||
|
|||||||
@ -20,19 +20,19 @@
|
|||||||
|
|
||||||
namespace Svc {
|
namespace Svc {
|
||||||
|
|
||||||
void LinuxTimer::startTimer(FwSizeType interval) {
|
void LinuxTimer::startTimer(const Fw::TimeInterval& interval) {
|
||||||
int fd;
|
int fd;
|
||||||
struct itimerspec itval;
|
struct itimerspec itval;
|
||||||
|
|
||||||
/* Create the timer */
|
/* Create the timer */
|
||||||
fd = timerfd_create(CLOCK_MONOTONIC, 0);
|
fd = timerfd_create(CLOCK_MONOTONIC, 0);
|
||||||
const FwSizeType interval_secs = interval / 1000;
|
time_t seconds_value = static_cast<time_t>(interval.getSeconds());
|
||||||
FW_ASSERT(static_cast<FwSizeType>(std::numeric_limits<I32>::max()) >= interval_secs,
|
// Ensure an overflow did not occur
|
||||||
static_cast<FwAssertArgType>(interval));
|
FW_ASSERT(seconds_value == interval.getSeconds());
|
||||||
itval.it_interval.tv_sec = static_cast<I32>(interval_secs);
|
itval.it_interval.tv_sec = static_cast<time_t>(seconds_value);
|
||||||
itval.it_interval.tv_nsec = static_cast<I32>((interval * 1000000) % 1000000000);
|
itval.it_interval.tv_nsec = static_cast<long>(interval.getUSeconds() * 1000);
|
||||||
itval.it_value.tv_sec = static_cast<I32>(interval_secs);
|
itval.it_value.tv_sec = static_cast<time_t>(seconds_value);
|
||||||
itval.it_value.tv_nsec = static_cast<I32>((interval * 1000000) % 1000000000);
|
itval.it_value.tv_nsec = static_cast<long>(interval.getUSeconds() * 1000);
|
||||||
|
|
||||||
timerfd_settime(fd, 0, &itval, nullptr);
|
timerfd_settime(fd, 0, &itval, nullptr);
|
||||||
|
|
||||||
|
|||||||
@ -16,11 +16,9 @@
|
|||||||
|
|
||||||
namespace Svc {
|
namespace Svc {
|
||||||
|
|
||||||
void LinuxTimer::startTimer(FwSizeType interval) {
|
void LinuxTimer::startTimer(const Fw::TimeInterval& interval) {
|
||||||
FW_ASSERT(std::numeric_limits<U32>::max() / 1000 >= interval); // Overflow
|
|
||||||
while (true) {
|
while (true) {
|
||||||
Os::Task::delay(
|
Os::Task::delay(interval);
|
||||||
Fw::TimeInterval(static_cast<U32>(interval / 1000), static_cast<U32>((interval % 1000) * 1000)));
|
|
||||||
this->m_mutex.lock();
|
this->m_mutex.lock();
|
||||||
bool quit = this->m_quit;
|
bool quit = this->m_quit;
|
||||||
this->m_mutex.unLock();
|
this->m_mutex.unLock();
|
||||||
|
|||||||
@ -35,7 +35,7 @@ LinuxTimerTester ::~LinuxTimerTester() {}
|
|||||||
|
|
||||||
void LinuxTimerTester ::runCycles() {
|
void LinuxTimerTester ::runCycles() {
|
||||||
this->m_numCalls = 5;
|
this->m_numCalls = 5;
|
||||||
this->component.startTimer(1000);
|
this->component.startTimer(Fw::TimeInterval(1, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user