Skip to content

Commit

Permalink
implement crit function
Browse files Browse the repository at this point in the history
  • Loading branch information
vovatrykoz committed Nov 13, 2024
1 parent 5f48df5 commit 37bb9c2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
14 changes: 14 additions & 0 deletions include/MathFramework.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,18 @@
*/
bool att(const TaskInstance& writerTask, const TaskInstance& readerTask);

/**
* @brief Determines if the writer and reader tasks overlap in execution.
*
* The more important “critical function” crit determines if
* (even in case of non-activation time travel) writer and reader
* overlap in execution:
*
* @param writerTask The task instance representing the writer.
* @param readerTask The task instance representing the reader.
* @return true if there is an overlap in execution between writer and reader.
* @return false if there is no overlap in execution.
*/
bool crit(const TaskInstance& writerTask, const TaskInstance& readerTask);

#endif
10 changes: 10 additions & 0 deletions source/MathFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@ bool att(const TaskInstance& writerTask, const TaskInstance& readerTask) {

return false;
}

bool crit(const TaskInstance& writerTask, const TaskInstance& readerTask) {
int writerTaskTerminationTime = writerTask.activationTime + writerTask.wcet;

if(readerTask.activationTime < writerTaskTerminationTime) {
return true;
}

return false;
}
20 changes: 20 additions & 0 deletions tests/MathFrameworkTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,25 @@ TEST(MathFramework, CanDetectWhenThereIsNoTimeTravel) {
bool expected = false;
bool actual = att(writerTask, readerTask);

EXPECT_EQ(expected, actual);
}

TEST(MathFramework, CritFunctionCanDetectExecutionOverlap) {
const TaskInstance writerTask(10, 5);
const TaskInstance readerTask(12, 5);

bool expected = true;
bool actual = crit(writerTask, readerTask);

EXPECT_EQ(expected, actual);
}

TEST(MathFramework, CritFunctionCanDetectWhenThereIsNoExecutionOverlap) {
const TaskInstance writerTask(10, 5);
const TaskInstance readerTask(16, 5);

bool expected = false;
bool actual = crit(writerTask, readerTask);

EXPECT_EQ(expected, actual);
}

0 comments on commit 37bb9c2

Please sign in to comment.