adding freeRtos API from different project

This commit is contained in:
2024-11-16 15:50:59 +01:00
parent 49b3b46ffe
commit deccb3186c
14 changed files with 1061 additions and 0 deletions
+88
View File
@@ -0,0 +1,88 @@
#include "test.hpp"
#include <Task.hpp>
#include <array>
using namespace fos;
TEST_CASE("Test Delay", "[freeRtos][task]") {
TickType_t start = xTaskGetTickCount();
Task::delayMs(5 * portTICK_PERIOD_MS);
TickType_t end = xTaskGetTickCount();
TEST_ASSERT_GREATER_OR_EQUAL(5, (end - start));
TEST_ASSERT_LESS_OR_EQUAL(6, (end - start));
}
static bool taskWasCalled = false;
static void callableTask() {
taskWasCalled = true;
while (true) {
vTaskDelay(100);
}
}
TEST_CASE("Test creation and deletion", "[freeRtos][task]") {
static Task task(callableTask, "task1");
Task::delayMs(50);
TEST_ASSERT_TRUE(taskWasCalled);
task.kill();
}
static void callableTask2() {
taskWasCalled = true;
while (true) {
vTaskDelay(100);
}
}
TEST_CASE("Test if task can be killed", "[freeRtos][task]") {
static Task task(callableTask2, "task2");
auto handle = task.getHandle();
configASSERT(handle);
TEST_ASSERT_TRUE(eTaskState::eReady == task.getState() ||
eTaskState::eBlocked == task.getState());
Task::delayMs(50);
TEST_ASSERT_TRUE(taskWasCalled);
task.kill();
TEST_ASSERT_EQUAL(eTaskState::eDeleted, eTaskGetState(handle));
}
static std::array<int, 2> values;
static void oneOfMultiple(int idx) {
static std::array<int, 2> c{1, -1};
for (size_t i = 0; i < 10; i++) {
values.at(idx) += c.at(idx);
}
while (true) {
vTaskDelay(100);
}
}
TEST_CASE("Test if tasks do not interfere", "[freeRtos][task]") {
// Both tasks are run by starting the same static function body
int param1 = 0;
TaskT<int> task1(oneOfMultiple, param1, "pTask1");
int param2 = 1;
TaskT<int> task2(oneOfMultiple, param2, "pTask2");
Task::delayMs(50);
TEST_ASSERT_EQUAL(10, values[0]);
TEST_ASSERT_EQUAL(-10, values[1]);
}
TEST_CASE("Test if tasks can be joined correctly", "[freeRtos][task]") {
// Both tasks are run by starting the same static function body
int param1 = 0;
Task task1(oneOfMultiple, param1, "pTask1");
int param2 = 1;
TaskT<int> task2(oneOfMultiple, param2, "pTask2");
Task::delayMs(50);
TEST_ASSERT_EQUAL(10, values[0]);
TEST_ASSERT_EQUAL(-10, values[1]);
}