Merge pull request 'Use better defines in internal unit tester' (#465) from mueller/int-unittest-osal-defines-update into development

Reviewed-on: fsfw/fsfw#465
This commit is contained in:
Ulrich Mohr 2021-09-20 15:28:55 +02:00
commit 9429f6b868
4 changed files with 20 additions and 14 deletions

View File

@ -16,15 +16,18 @@ InternalUnitTester::~InternalUnitTester() {}
ReturnValue_t InternalUnitTester::performTests(
const struct InternalUnitTester::TestConfig& testConfig) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "Running internal unit tests.." << std::endl;
sif::info << "Running internal unit tests.. Error messages might follow" <<
std::endl;
#else
sif::printInfo("Running internal unit tests..\n");
#endif
testserialize::test_serialization();
testmq::testMq();
testsemaph::testBinSemaph();
testsemaph::testCountingSemaph();
if(testConfig.testSemaphores) {
testsemaph::testBinSemaph();
testsemaph::testCountingSemaph();
}
testmutex::testMutex();
if(testConfig.testArrayPrinter) {
arrayprinter::testArrayPrinter();

View File

@ -18,6 +18,7 @@ class InternalUnitTester: public HasReturnvaluesIF {
public:
struct TestConfig {
bool testArrayPrinter = false;
bool testSemaphores = true;
};
InternalUnitTester();

View File

@ -1,10 +1,12 @@
#include "fsfw_tests/internal/osal/IntTestMutex.h"
#include "fsfw_tests/internal/UnittDefinitions.h"
#include "fsfw/platform.h"
#include <fsfw/ipc/MutexFactory.h>
#if defined(WIN32) || defined(UNIX)
#include <fsfw/osal/host/Mutex.h>
#if defined PLATFORM_WIN || defined PLATFORM_UNIX
#include "fsfw/osal/host/Mutex.h"
#include <thread>
#include <future>
#endif
@ -20,7 +22,7 @@ void testmutex::testMutex() {
// timed_mutex from the C++ library specifies undefined behaviour if
// the timed mutex is locked twice from the same thread.
// TODO: we should pass a define like FSFW_OSAL_HOST to the build.
#if defined(WIN32) || defined(UNIX)
#if defined PLATFORM_WIN || defined PLATFORM_UNIX
// This calls the function from
// another thread and stores the returnvalue in a future.
auto future = std::async(&MutexIF::lockMutex, mutex, MutexIF::TimeoutType::WAITING, 1);
@ -37,8 +39,7 @@ void testmutex::testMutex() {
unitt::put_error(id);
}
// TODO: we should pass a define like FSFW_OSAL_HOST to the build.
#if !defined(WIN32) && !defined(UNIX)
#if !defined PLATFORM_WIN && !defined PLATFORM_UNIX
result = mutex->unlockMutex();
if(result != MutexIF::CURR_THREAD_DOES_NOT_OWN_MUTEX) {
unitt::put_error(id);

View File

@ -1,9 +1,10 @@
#include "fsfw/FSFW.h"
#include "fsfw_tests/internal/osal/IntTestSemaphore.h"
#include "fsfw_tests/internal/UnittDefinitions.h"
#include <fsfw/tasks/SemaphoreFactory.h>
#include <fsfw/serviceinterface/ServiceInterface.h>
#include <fsfw/timemanager/Stopwatch.h>
#include "fsfw/tasks/SemaphoreFactory.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/timemanager/Stopwatch.h"
#include <cstdlib>
@ -16,7 +17,7 @@ void testsemaph::testBinSemaph() {
}
testBinSemaphoreImplementation(binSemaph, id);
SemaphoreFactory::instance()->deleteSemaphore(binSemaph);
#if defined(freeRTOS)
#if defined FSFW_OSAL_FREERTOS
SemaphoreIF* binSemaphUsingTask =
SemaphoreFactory::instance()->createBinarySemaphore(1);
testBinSemaphoreImplementation(binSemaphUsingTask, id);
@ -36,7 +37,7 @@ void testsemaph::testCountingSemaph() {
}
testBinSemaphoreImplementation(countingSemaph, id);
SemaphoreFactory::instance()->deleteSemaphore(countingSemaph);
#if defined(freeRTOS)
#if defined FSFW_OSAL_FREERTOS
countingSemaph = SemaphoreFactory::instance()->
createCountingSemaphore(1, 1, 1);
testBinSemaphoreImplementation(countingSemaph, id);
@ -50,7 +51,7 @@ void testsemaph::testCountingSemaph() {
createCountingSemaphore(3,3);
testCountingSemaphImplementation(countingSemaph, id);
SemaphoreFactory::instance()->deleteSemaphore(countingSemaph);
#if defined(freeRTOS)
#if defined FSFW_OSAL_FREERTOS
countingSemaph = SemaphoreFactory::instance()->
createCountingSemaphore(3, 0, 1);
uint8_t semaphCount = countingSemaph->getSemaphoreCounter();