Skip to content

Commit

Permalink
[ReadHandler] Removal of test flags (#28421)
Browse files Browse the repository at this point in the history
* Removed reportScheduler test flags and made TestReadInteractin.cpp wait for min/max instead of setting flags. Modified subscription times in the test to minimise the impact of waiting.

* Restyled by clang-format

* Added a driveAndServiceIO after waiting for max in test where we should wait for max to expire to ensure the run gets scheduled reliably

* Moved ctx.GetIOContext().DriveIO(); after each tests to garantee this will run after maxInterval is expired

* Implemented a mock clock in TestReadInteraction to reduce wait loops

* Removed more loops and added comment on loop left in the code

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Dec 15, 2023
1 parent 6f243d6 commit 1384722
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 163 deletions.
49 changes: 1 addition & 48 deletions src/app/reporting/ReportScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,6 @@ class ReportScheduler : public ReadHandler::Observer, public ICDStateObserver
class ReadHandlerNode : public TimerContext
{
public:
#ifdef CONFIG_BUILD_FOR_HOST_UNIT_TEST
/// Test flags to allow TestReadInteraction to simulate expiration of the minimal and maximal intervals without
/// waiting
enum class TestFlags : uint8_t{
MinIntervalElapsed = (1 << 0),
MaxIntervalElapsed = (1 << 1),
};
void SetTestFlags(TestFlags aFlag, bool aValue) { mFlags.Set(aFlag, aValue); }
bool GetTestFlags(TestFlags aFlag) const { return mFlags.Has(aFlag); }
#endif // CONFIG_BUILD_FOR_HOST_UNIT_TEST

ReadHandlerNode(ReadHandler * aReadHandler, TimerDelegate * aTimerDelegate, ReportScheduler * aScheduler) :
mTimerDelegate(aTimerDelegate), mScheduler(aScheduler)
{
Expand All @@ -93,29 +82,12 @@ class ReportScheduler : public ReadHandler::Observer, public ICDStateObserver
{
Timestamp now = mTimerDelegate->GetCurrentMonotonicTimestamp();

#ifdef CONFIG_BUILD_FOR_HOST_UNIT_TEST
return (mReadHandler->IsGeneratingReports() && (now >= mMinTimestamp || mFlags.Has(TestFlags::MinIntervalElapsed)) &&
(mReadHandler->IsDirty() || (now >= mMaxTimestamp || mFlags.Has(TestFlags::MaxIntervalElapsed)) ||
now >= mSyncTimestamp));
#else
return (mReadHandler->IsGeneratingReports() &&
(now >= mMinTimestamp && (mReadHandler->IsDirty() || now >= mMaxTimestamp || now >= mSyncTimestamp)));
#endif // CONFIG_BUILD_FOR_HOST_UNIT_TEST
}

bool IsEngineRunScheduled() const { return mEngineRunScheduled; }
void SetEngineRunScheduled(bool aEngineRunScheduled)
{
mEngineRunScheduled = aEngineRunScheduled;
#ifdef CONFIG_BUILD_FOR_HOST_UNIT_TEST
// If the engine becomes unscheduled, this means a run just took place so we reset the test flags
if (!mEngineRunScheduled)
{
mFlags.Set(TestFlags::MinIntervalElapsed, false);
mFlags.Set(TestFlags::MaxIntervalElapsed, false);
}
#endif // CONFIG_BUILD_FOR_HOST_UNIT_TEST
}
void SetEngineRunScheduled(bool aEngineRunScheduled) { mEngineRunScheduled = aEngineRunScheduled; }

void SetIntervalTimeStamps(ReadHandler * aReadHandler)
{
Expand Down Expand Up @@ -146,9 +118,6 @@ class ReportScheduler : public ReadHandler::Observer, public ICDStateObserver
System::Clock::Timestamp GetSyncTimestamp() const { return mSyncTimestamp; }

private:
#ifdef CONFIG_BUILD_FOR_HOST_UNIT_TEST
BitFlags<TestFlags> mFlags;
#endif // CONFIG_BUILD_FOR_HOST_UNIT_TEST
TimerDelegate * mTimerDelegate;
ReadHandler * mReadHandler;
ReportScheduler * mScheduler;
Expand Down Expand Up @@ -180,22 +149,6 @@ class ReportScheduler : public ReadHandler::Observer, public ICDStateObserver
size_t GetNumReadHandlers() const { return mNodesPool.Allocated(); }

#ifdef CONFIG_BUILD_FOR_HOST_UNIT_TEST
void RunNodeCallbackForHandler(const ReadHandler * aReadHandler)
{
ReadHandlerNode * node = FindReadHandlerNode(aReadHandler);
node->TimerFired();
}
void SetFlagsForHandler(const ReadHandler * aReadHandler, ReadHandlerNode::TestFlags aFlag, bool aValue)
{
ReadHandlerNode * node = FindReadHandlerNode(aReadHandler);
node->SetTestFlags(aFlag, aValue);
}

bool CheckFlagsForHandler(const ReadHandler * aReadHandler, ReadHandlerNode::TestFlags aFlag)
{
ReadHandlerNode * node = FindReadHandlerNode(aReadHandler);
return node->GetTestFlags(aFlag);
}
Timestamp GetMinTimestampForHandler(const ReadHandler * aReadHandler)
{
ReadHandlerNode * node = FindReadHandlerNode(aReadHandler);
Expand Down
Loading

0 comments on commit 1384722

Please sign in to comment.