fsfw/unittests/osal/TestSemaphore.cpp

38 lines
1.3 KiB
C++
Raw Normal View History

2023-01-12 15:40:52 +01:00
#include <fsfw/osal/osal.h>
2020-10-20 17:11:23 +02:00
#include <fsfw/tasks/SemaphoreFactory.h>
#include <fsfw/timemanager/Stopwatch.h>
2023-01-12 15:40:52 +01:00
#include <catch2/catch_test_macros.hpp>
// binary semaphores currently only supported on linux
#ifdef FSFW_OSAL_LINUX
TEST_CASE("Binary Semaphore Test", "[BinSemaphore]") {
// perform set-up here
SemaphoreIF* binSemaph = SemaphoreFactory::instance()->createBinarySemaphore();
REQUIRE(binSemaph != nullptr);
SECTION("Simple Test") {
// set-up is run for each section
REQUIRE(binSemaph->getSemaphoreCounter() == 1);
REQUIRE(binSemaph->release() == static_cast<int>(SemaphoreIF::SEMAPHORE_NOT_OWNED));
REQUIRE(binSemaph->acquire(SemaphoreIF::POLLING) == returnvalue::OK);
{
// not precise enough on linux.. should use clock instead..
// Stopwatch stopwatch(false);
// REQUIRE(binSemaph->acquire(SemaphoreIF::TimeoutType::WAITING, 5) ==
// SemaphoreIF::SEMAPHORE_TIMEOUT);
// dur_millis_t time = stopwatch.stop();
// CHECK(time == 5);
}
REQUIRE(binSemaph->getSemaphoreCounter() == 0);
REQUIRE(binSemaph->release() == returnvalue::OK);
}
SemaphoreFactory::instance()->deleteSemaphore(binSemaph);
// perform tear-down here
2020-10-20 17:11:23 +02:00
}
2023-01-12 15:40:52 +01:00
TEST_CASE("Counting Semaphore Test", "[CountingSemaph]") {
SECTION("Simple Test") {}
2020-10-20 17:11:23 +02:00
}
2023-01-12 15:40:52 +01:00
#endif