Merge pull request 'Unittest integrated in FSFW now' (#242) from KSat/fsfw:mueller/unittest-integration-from-master into master
Reviewed-on: fsfw/fsfw#242
This commit is contained in:
commit
11a351a202
0
.gitmodules
vendored
Normal file
0
.gitmodules
vendored
Normal file
@ -4,7 +4,7 @@
|
||||
#include <stdint.h>
|
||||
#include "fwSubsystemIdRanges.h"
|
||||
//could be move to more suitable location
|
||||
#include <config/tmtc/subsystemIdRanges.h>
|
||||
#include <subsystemIdRanges.h>
|
||||
|
||||
typedef uint16_t EventId_t;
|
||||
typedef uint8_t EventSeverity_t;
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define FRAMEWORK_RETURNVALUES_HASRETURNVALUESIF_H_
|
||||
|
||||
#include "FwClassIds.h"
|
||||
#include <config/returnvalues/classIds.h>
|
||||
#include <returnvalues/classIds.h>
|
||||
#include <cstdint>
|
||||
|
||||
#define MAKE_RETURN_CODE( number ) ((INTERFACE_ID << 8) + (number))
|
||||
|
49
unittest/README.md
Normal file
49
unittest/README.md
Normal file
@ -0,0 +1,49 @@
|
||||
## FSFW Testing
|
||||
This repository contains testing and unit testing components.
|
||||
|
||||
[Catch2](https://github.com/catchorg/Catch2) has been used as a framework,
|
||||
and these unit tests can only be run on a linux host machine.
|
||||
The makefile with default settings creates the unit test binary which can be
|
||||
run in the terminal or in eclipse.
|
||||
|
||||
### Instructions
|
||||
|
||||
### Eclipse CDT settings
|
||||
|
||||
The default eclipse terminal has issues displaying the colors used
|
||||
when running the unit test binary by catch2. To fix this issue,
|
||||
install the ANSI Escape In Console package from the eclipse marketplace.
|
||||
|
||||
### GCOV integration
|
||||
|
||||
GCOV has been integrated as a code coverage tool.
|
||||
It can be enabled by adding `GCOV=1` to the build process as an additional argument.
|
||||
Coverage data will be provided in form of .gcno and .gcda files.
|
||||
These can be displayed in eclipse by looking
|
||||
for a .gcno or .gcda file in the \_obj folder, double-clicking it
|
||||
and picking the right source-binary. This will generate
|
||||
information about which lines of a file have run, provided it is open in
|
||||
eclipse.
|
||||
|
||||
### LCOV integration
|
||||
|
||||
The files generated by GCOV can also be processed by the tool LCOV.
|
||||
On ubuntu, the tool can be installed with the following command:
|
||||
|
||||
```sh
|
||||
sudo apt-get install lcov
|
||||
````
|
||||
|
||||
After that, the tool can be run by building the unit tests with `GCOV=1`,
|
||||
running them at least one time and then executing the `lcov.sh` script.
|
||||
|
||||
### Adding unit tests
|
||||
|
||||
The catch unit tests are located in unittest/testfw. To add new unit tests,
|
||||
add them to the UnitTestCatch.cpp file or add a new source file which
|
||||
includes catch.hpp.
|
||||
|
||||
For writing basics tests, the [assertion documentation](https://github.com/catchorg/Catch2/blob/master/docs/assertions.md#top)
|
||||
or the existing examples are a good guideliens.
|
||||
For more advanced tests, refer to the [catch2 documentation](https://github.com/catchorg/Catch2/blob/master/docs/Readme.md#top).
|
||||
|
11
unittest/core/CatchDefinitions.cpp
Normal file
11
unittest/core/CatchDefinitions.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include "CatchDefinitions.h"
|
||||
#include <fsfw/objectmanager/ObjectManagerIF.h>
|
||||
|
||||
StorageManagerIF* tglob::getIpcStoreHandle() {
|
||||
if(objectManager != nullptr) {
|
||||
return objectManager->get<StorageManagerIF>(objects::IPC_STORE);
|
||||
} else {
|
||||
sif::error << "Global object manager uninitialized" << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
21
unittest/core/CatchDefinitions.h
Normal file
21
unittest/core/CatchDefinitions.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef FSFW_UNITTEST_CORE_CATCHDEFINITIONS_H_
|
||||
#define FSFW_UNITTEST_CORE_CATCHDEFINITIONS_H_
|
||||
|
||||
#include <fsfw/ipc/messageQueueDefinitions.h>
|
||||
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <fsfw/storagemanager/StorageManagerIF.h>
|
||||
|
||||
namespace retval {
|
||||
static constexpr int CATCH_OK = static_cast<int>(HasReturnvaluesIF::RETURN_OK);
|
||||
static constexpr int CATCH_FAILED = static_cast<int>(HasReturnvaluesIF::RETURN_FAILED);
|
||||
}
|
||||
|
||||
namespace tconst {
|
||||
static constexpr MessageQueueId_t testQueueId = 42;
|
||||
}
|
||||
|
||||
namespace tglob {
|
||||
StorageManagerIF* getIpcStoreHandle();
|
||||
}
|
||||
|
||||
#endif /* FSFW_UNITTEST_CORE_CATCHDEFINITIONS_H_ */
|
31
unittest/core/CatchRunner.cpp
Normal file
31
unittest/core/CatchRunner.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
/**
|
||||
* @file CatchSource.cpp
|
||||
* @brief Source file to compile catch framework.
|
||||
* @details All tests should be written in other files.
|
||||
* For eclipse console output, install ANSI Escape in Console
|
||||
* from the eclipse market place to get colored characters.
|
||||
*/
|
||||
|
||||
#ifndef NO_UNIT_TEST_FRAMEWORK
|
||||
|
||||
#define CATCH_CONFIG_RUNNER
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
#if CUSTOM_UNITTEST_RUNNER == 0
|
||||
|
||||
extern int customSetup();
|
||||
|
||||
int main( int argc, char* argv[] ) {
|
||||
customSetup();
|
||||
|
||||
// Catch internal function call
|
||||
int result = Catch::Session().run( argc, argv );
|
||||
|
||||
// global clean-up
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
42
unittest/core/CatchSetup.cpp
Normal file
42
unittest/core/CatchSetup.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include "CatchDefinitions.h"
|
||||
|
||||
#include <testcfg/cdatapool/dataPoolInit.h>
|
||||
#include <testcfg/objects/Factory.h>
|
||||
|
||||
|
||||
#ifdef GCOV
|
||||
#include <gcov.h>
|
||||
#endif
|
||||
|
||||
#include "../../objectmanager/ObjectManager.h"
|
||||
#include "../../objectmanager/ObjectManagerIF.h"
|
||||
#include "../../storagemanager/StorageManagerIF.h"
|
||||
#include "../../datapool/DataPool.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
|
||||
/* Global instantiations normally done in main.cpp */
|
||||
/* Initialize Data Pool */
|
||||
//namespace glob {
|
||||
DataPool dataPool(datapool::dataPoolInit);
|
||||
//}
|
||||
|
||||
|
||||
namespace sif {
|
||||
/* Set up output streams */
|
||||
ServiceInterfaceStream debug("DEBUG");
|
||||
ServiceInterfaceStream info("INFO");
|
||||
ServiceInterfaceStream error("ERROR");
|
||||
ServiceInterfaceStream warning("WARNING");
|
||||
}
|
||||
|
||||
/* Global object manager */
|
||||
ObjectManagerIF *objectManager;
|
||||
|
||||
int customSetup() {
|
||||
// global setup
|
||||
objectManager = new ObjectManager(Factory::produce);
|
||||
objectManager -> initialize();
|
||||
return 0;
|
||||
}
|
||||
|
3
unittest/core/core.mk
Normal file
3
unittest/core/core.mk
Normal file
@ -0,0 +1,3 @@
|
||||
CXXSRC += $(wildcard $(CURRENTPATH)/*.cpp)
|
||||
|
||||
INCLUDES += $(CURRENTPATH)
|
10
unittest/core/printChar.cpp
Normal file
10
unittest/core/printChar.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include <fsfw/unittest/core/printChar.h>
|
||||
#include <cstdio>
|
||||
|
||||
void printChar(const char* character, bool errStream) {
|
||||
if(errStream) {
|
||||
std::putc(*character, stderr);
|
||||
return;
|
||||
}
|
||||
std::putc(*character, stdout);
|
||||
}
|
8
unittest/core/printChar.h
Normal file
8
unittest/core/printChar.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef FSFW_UNITTEST_CORE_PRINTCHAR_H_
|
||||
#define FSFW_UNITTEST_CORE_PRINTCHAR_H_
|
||||
|
||||
|
||||
extern "C" void printChar(const char*, bool errStream);
|
||||
|
||||
|
||||
#endif /* FSFW_UNITTEST_CORE_PRINTCHAR_H_ */
|
27
unittest/internal/InternalUnitTester.cpp
Normal file
27
unittest/internal/InternalUnitTester.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
#include "InternalUnitTester.h"
|
||||
#include "UnittDefinitions.h"
|
||||
|
||||
#include "osal/IntTestMq.h"
|
||||
#include "osal/IntTestSemaphore.h"
|
||||
#include "osal/IntTestMutex.h"
|
||||
#include "serialize/IntTestSerialization.h"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
InternalUnitTester::InternalUnitTester() {}
|
||||
|
||||
InternalUnitTester::~InternalUnitTester() {}
|
||||
|
||||
ReturnValue_t InternalUnitTester::performTests() {
|
||||
sif::info << "Running internal unit tests.." << std::endl;
|
||||
testserialize::test_serialization();
|
||||
testmq::testMq();
|
||||
testsemaph::testBinSemaph();
|
||||
testsemaph::testCountingSemaph();
|
||||
testmutex::testMutex();
|
||||
sif::info << "Internal unit tests finished." << std::endl;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
|
||||
|
29
unittest/internal/InternalUnitTester.h
Normal file
29
unittest/internal/InternalUnitTester.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef FRAMEWORK_TEST_UNITTESTCLASS_H_
|
||||
#define FRAMEWORK_TEST_UNITTESTCLASS_H_
|
||||
|
||||
#include "UnittDefinitions.h"
|
||||
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||
|
||||
/**
|
||||
* @brief Can be used for internal testing, for example for hardware specific
|
||||
* tests which can not be run on a host-machine.
|
||||
*
|
||||
* TODO: A lot of ways to improve this class. A way for tests to subscribe
|
||||
* in this central class would be nice. Right now, this is the class
|
||||
* which simply calls all other tests from other files manually.
|
||||
* Maybe there is a better way..
|
||||
*/
|
||||
class InternalUnitTester: public HasReturnvaluesIF {
|
||||
public:
|
||||
InternalUnitTester();
|
||||
virtual~ InternalUnitTester();
|
||||
|
||||
/**
|
||||
* Some function which calls all other tests
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t performTests();
|
||||
};
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_TEST_UNITTESTCLASS_H_ */
|
7
unittest/internal/UnittDefinitions.cpp
Normal file
7
unittest/internal/UnittDefinitions.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
#include <fsfw/unittest/internal/UnittDefinitions.h>
|
||||
|
||||
ReturnValue_t unitt::put_error(std::string errorId) {
|
||||
sif::error << "Unit Tester error: Failed at test ID "
|
||||
<< errorId << "\n" << std::flush;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
33
unittest/internal/UnittDefinitions.h
Normal file
33
unittest/internal/UnittDefinitions.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef UNITTEST_INTERNAL_UNITTDEFINITIONS_H_
|
||||
#define UNITTEST_INTERNAL_UNITTDEFINITIONS_H_
|
||||
|
||||
#include "../../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
namespace tv {
|
||||
// POD test values
|
||||
static const bool tv_bool = true;
|
||||
static const uint8_t tv_uint8 {5};
|
||||
static const uint16_t tv_uint16 {283};
|
||||
static const uint32_t tv_uint32 {929221};
|
||||
static const uint64_t tv_uint64 {2929329429};
|
||||
|
||||
static const int8_t tv_int8 {-16};
|
||||
static const int16_t tv_int16 {-829};
|
||||
static const int32_t tv_int32 {-2312};
|
||||
|
||||
static const float tv_float {8.2149214};
|
||||
static const float tv_sfloat = {-922.2321321};
|
||||
static const double tv_double {9.2132142141e8};
|
||||
static const double tv_sdouble {-2.2421e19};
|
||||
}
|
||||
|
||||
namespace unitt {
|
||||
ReturnValue_t put_error(std::string errorId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* UNITTEST_INTERNAL_UNITTDEFINITIONS_H_ */
|
3
unittest/internal/internal.mk
Normal file
3
unittest/internal/internal.mk
Normal file
@ -0,0 +1,3 @@
|
||||
CXXSRC += $(wildcard $(CURRENTPATH)/osal/*.cpp)
|
||||
CXXSRC += $(wildcard $(CURRENTPATH)/serialize/*.cpp)
|
||||
CXXSRC += $(wildcard $(CURRENTPATH)/*.cpp)
|
52
unittest/internal/osal/IntTestMq.cpp
Normal file
52
unittest/internal/osal/IntTestMq.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
#include <fsfw/ipc/MessageQueueIF.h>
|
||||
#include <fsfw/ipc/QueueFactory.h>
|
||||
#include <fsfw/unittest/internal/osal/IntTestMq.h>
|
||||
#include <fsfw/unittest/internal/UnittDefinitions.h>
|
||||
|
||||
#include <array>
|
||||
|
||||
using retval = HasReturnvaluesIF;
|
||||
|
||||
void testmq::testMq() {
|
||||
std::string id = "[testMq]";
|
||||
MessageQueueIF* testSenderMq =
|
||||
QueueFactory::instance()->createMessageQueue(1);
|
||||
MessageQueueId_t testSenderMqId = testSenderMq->getId();
|
||||
|
||||
MessageQueueIF* testReceiverMq =
|
||||
QueueFactory::instance()->createMessageQueue(1);
|
||||
MessageQueueId_t testReceiverMqId = testReceiverMq->getId();
|
||||
std::array<uint8_t, 20> testData { 0 };
|
||||
testData[0] = 42;
|
||||
MessageQueueMessage testMessage(testData.data(), 1);
|
||||
testSenderMq->setDefaultDestination(testReceiverMqId);
|
||||
|
||||
|
||||
auto result = testSenderMq->sendMessage(testReceiverMqId, &testMessage);
|
||||
if(result != retval::RETURN_OK) {
|
||||
unitt::put_error(id);
|
||||
}
|
||||
MessageQueueMessage recvMessage;
|
||||
result = testReceiverMq->receiveMessage(&recvMessage);
|
||||
if(result != retval::RETURN_OK or recvMessage.getData()[0] != 42) {
|
||||
unitt::put_error(id);
|
||||
}
|
||||
|
||||
result = testSenderMq->sendMessage(testReceiverMqId, &testMessage);
|
||||
if(result != retval::RETURN_OK) {
|
||||
unitt::put_error(id);
|
||||
}
|
||||
MessageQueueId_t senderId = 0;
|
||||
result = testReceiverMq->receiveMessage(&recvMessage,&senderId);
|
||||
if(result != retval::RETURN_OK or recvMessage.getData()[0] != 42) {
|
||||
unitt::put_error(id);
|
||||
}
|
||||
if(senderId != testSenderMqId) {
|
||||
unitt::put_error(id);
|
||||
}
|
||||
senderId = testReceiverMq->getLastPartner();
|
||||
if(senderId != testSenderMqId) {
|
||||
unitt::put_error(id);
|
||||
}
|
||||
|
||||
}
|
9
unittest/internal/osal/IntTestMq.h
Normal file
9
unittest/internal/osal/IntTestMq.h
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef UNITTEST_INTERNAL_INTESTMQ_H_
|
||||
#define UNITTEST_INTERNAL_INTESTMQ_H_
|
||||
|
||||
namespace testmq {
|
||||
void testMq();
|
||||
}
|
||||
|
||||
|
||||
#endif /* UNITTEST_INTERNAL_INTESTMQ_H_ */
|
42
unittest/internal/osal/IntTestMutex.cpp
Normal file
42
unittest/internal/osal/IntTestMutex.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include "IntTestMutex.h"
|
||||
|
||||
#include <fsfw/ipc/MutexFactory.h>
|
||||
#include <unittest/internal/UnittDefinitions.h>
|
||||
|
||||
#if defined(hosted)
|
||||
#include <fsfw/osal/hosted/Mutex.h>
|
||||
#include <thread>
|
||||
#include <future>
|
||||
#endif
|
||||
|
||||
|
||||
void testmutex::testMutex() {
|
||||
std::string id = "[testMutex]";
|
||||
MutexIF* mutex = MutexFactory::instance()->createMutex();
|
||||
auto result = mutex->lockMutex(MutexIF::POLLING);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
unitt::put_error(id);
|
||||
}
|
||||
// timed_mutex from the C++ library specifies undefined behaviour if
|
||||
// the timed mutex is locked twice from the same thread.
|
||||
#if defined(hosted)
|
||||
// hold on, this actually worked ? :-D This calls the function from
|
||||
// another thread and stores the returnvalue in a future.
|
||||
auto future = std::async(&MutexIF::lockMutex, mutex, 1);
|
||||
result = future.get();
|
||||
#else
|
||||
result = mutex->lockMutex(MutexIF::TimeoutType::WAITING, 1);
|
||||
#endif
|
||||
if(result != MutexIF::MUTEX_TIMEOUT) {
|
||||
unitt::put_error(id);
|
||||
}
|
||||
|
||||
result = mutex->unlockMutex();
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
unitt::put_error(id);
|
||||
}
|
||||
result = mutex->unlockMutex();
|
||||
if(result != MutexIF::CURR_THREAD_DOES_NOT_OWN_MUTEX) {
|
||||
unitt::put_error(id);
|
||||
}
|
||||
}
|
10
unittest/internal/osal/IntTestMutex.h
Normal file
10
unittest/internal/osal/IntTestMutex.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef UNITTEST_INTERNAL_INTTESTMUTEX_H_
|
||||
#define UNITTEST_INTERNAL_INTTESTMUTEX_H_
|
||||
|
||||
namespace testmutex {
|
||||
void testMutex();
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* UNITTEST_INTERNAL_INTTESTMUTEX_H_ */
|
160
unittest/internal/osal/IntTestSemaphore.cpp
Normal file
160
unittest/internal/osal/IntTestSemaphore.cpp
Normal file
@ -0,0 +1,160 @@
|
||||
#include "IntTestSemaphore.h"
|
||||
#include <fsfw/tasks/SemaphoreFactory.h>
|
||||
#include <unittest/internal/UnittDefinitions.h>
|
||||
#include <fsfw/serviceinterface/ServiceInterfaceStream.h>
|
||||
#include <fsfw/timemanager/Stopwatch.h>
|
||||
|
||||
|
||||
void testsemaph::testBinSemaph() {
|
||||
std::string id = "[BinSemaphore]";
|
||||
SemaphoreIF* binSemaph =
|
||||
SemaphoreFactory::instance()->createBinarySemaphore();
|
||||
if(binSemaph == nullptr) {
|
||||
return;
|
||||
}
|
||||
testBinSemaphoreImplementation(binSemaph, id);
|
||||
SemaphoreFactory::instance()->deleteSemaphore(binSemaph);
|
||||
#if defined(freeRTOS)
|
||||
SemaphoreIF* binSemaphUsingTask =
|
||||
SemaphoreFactory::instance()->createBinarySemaphore(1);
|
||||
testBinSemaphoreImplementation(binSemaphUsingTask, id);
|
||||
SemaphoreFactory::instance()->deleteSemaphore(binSemaphUsingTask);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void testsemaph::testCountingSemaph() {
|
||||
std::string id = "[CountingSemaph]";
|
||||
{
|
||||
// First test: create a binary semaphore by using a counting semaphore.
|
||||
SemaphoreIF* countingSemaph = SemaphoreFactory::instance()->
|
||||
createCountingSemaphore(1,1);
|
||||
if(countingSemaph == nullptr) {
|
||||
return;
|
||||
}
|
||||
testBinSemaphoreImplementation(countingSemaph, id);
|
||||
SemaphoreFactory::instance()->deleteSemaphore(countingSemaph);
|
||||
#if defined(freeRTOS)
|
||||
countingSemaph = SemaphoreFactory::instance()->
|
||||
createCountingSemaphore(1, 1, 1);
|
||||
testBinSemaphoreImplementation(countingSemaph, id);
|
||||
SemaphoreFactory::instance()->deleteSemaphore(countingSemaph);
|
||||
#endif
|
||||
}
|
||||
|
||||
{
|
||||
// Second test: counting semaphore with count 3 and init count of 3.
|
||||
SemaphoreIF* countingSemaph = SemaphoreFactory::instance()->
|
||||
createCountingSemaphore(3,3);
|
||||
testCountingSemaphImplementation(countingSemaph, id);
|
||||
SemaphoreFactory::instance()->deleteSemaphore(countingSemaph);
|
||||
#if defined(freeRTOS)
|
||||
countingSemaph = SemaphoreFactory::instance()->
|
||||
createCountingSemaphore(3, 0, 1);
|
||||
uint8_t semaphCount = countingSemaph->getSemaphoreCounter();
|
||||
if(semaphCount != 0) {
|
||||
unitt::put_error(id);
|
||||
}
|
||||
// release 3 times in a row
|
||||
for(int i = 0; i < 3; i++) {
|
||||
auto result = countingSemaph->release();
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
unitt::put_error(id);
|
||||
}
|
||||
}
|
||||
testCountingSemaphImplementation(countingSemaph, id);
|
||||
SemaphoreFactory::instance()->deleteSemaphore(countingSemaph);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void testsemaph::testBinSemaphoreImplementation(SemaphoreIF* binSemaph,
|
||||
std::string id) {
|
||||
uint8_t semaphCount = binSemaph->getSemaphoreCounter();
|
||||
if(semaphCount != 1) {
|
||||
unitt::put_error(id);
|
||||
}
|
||||
|
||||
ReturnValue_t result = binSemaph->release();
|
||||
if(result != SemaphoreIF::SEMAPHORE_NOT_OWNED) {
|
||||
unitt::put_error(id);
|
||||
}
|
||||
result = binSemaph->acquire(SemaphoreIF::BLOCKING);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
unitt::put_error(id);
|
||||
}
|
||||
|
||||
// There is not really a point in testing time related, the task
|
||||
// might get interrupted..
|
||||
{
|
||||
//Stopwatch stopwatch(false);
|
||||
result = binSemaph->acquire(SemaphoreIF::TimeoutType::WAITING, 10);
|
||||
//dur_millis_t time = stopwatch.stop();
|
||||
// if(abs(time - 10) > 2) {
|
||||
// sif::error << "UnitTester: Semaphore timeout measured incorrect."
|
||||
// << std::endl;
|
||||
// unitt::put_error(id);
|
||||
// }
|
||||
}
|
||||
|
||||
if(result != SemaphoreIF::SEMAPHORE_TIMEOUT) {
|
||||
unitt::put_error(id);
|
||||
}
|
||||
|
||||
semaphCount = binSemaph->getSemaphoreCounter();
|
||||
if(semaphCount != 0) {
|
||||
unitt::put_error(id);
|
||||
}
|
||||
|
||||
result = binSemaph->release();
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
unitt::put_error(id);
|
||||
}
|
||||
}
|
||||
|
||||
void testsemaph::testCountingSemaphImplementation(SemaphoreIF* countingSemaph,
|
||||
std::string id) {
|
||||
// check count getter function
|
||||
uint8_t semaphCount = countingSemaph->getSemaphoreCounter();
|
||||
if(semaphCount != 3) {
|
||||
unitt::put_error(id);
|
||||
}
|
||||
ReturnValue_t result = countingSemaph->release();
|
||||
if(result != SemaphoreIF::SEMAPHORE_NOT_OWNED) {
|
||||
unitt::put_error(id);
|
||||
}
|
||||
// acquire 3 times in a row
|
||||
for(int i = 0; i < 3; i++) {
|
||||
result = countingSemaph->acquire(SemaphoreIF::BLOCKING);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
unitt::put_error(id);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
Stopwatch stopwatch(false);
|
||||
// attempt to take when count is 0, measure time
|
||||
result = countingSemaph->acquire(SemaphoreIF::TimeoutType::WAITING, 10);
|
||||
dur_millis_t time = stopwatch.stop();
|
||||
if(abs(time - 10) > 1) {
|
||||
unitt::put_error(id);
|
||||
}
|
||||
}
|
||||
|
||||
if(result != SemaphoreIF::SEMAPHORE_TIMEOUT) {
|
||||
unitt::put_error(id);
|
||||
}
|
||||
|
||||
// release 3 times in a row
|
||||
for(int i = 0; i < 3; i++) {
|
||||
result = countingSemaph->release();
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
unitt::put_error(id);
|
||||
}
|
||||
}
|
||||
// assert correct full count
|
||||
if(countingSemaph->getSemaphoreCounter() != 3) {
|
||||
unitt::put_error(id);
|
||||
}
|
||||
}
|
15
unittest/internal/osal/IntTestSemaphore.h
Normal file
15
unittest/internal/osal/IntTestSemaphore.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef UNITTEST_INTERNAL_INTTESTSEMAPHORE_H_
|
||||
#define UNITTEST_INTERNAL_INTTESTSEMAPHORE_H_
|
||||
class SemaphoreIF;
|
||||
#include <string>
|
||||
|
||||
namespace testsemaph {
|
||||
void testBinSemaph();
|
||||
void testBinSemaphoreImplementation(SemaphoreIF* binSemaph, std::string id);
|
||||
void testCountingSemaph();
|
||||
void testCountingSemaphImplementation(SemaphoreIF* countingSemaph,
|
||||
std::string id);
|
||||
}
|
||||
|
||||
|
||||
#endif /* UNITTEST_INTERNAL_INTTESTSEMAPHORE_H_ */
|
230
unittest/internal/serialize/IntTestSerialization.cpp
Normal file
230
unittest/internal/serialize/IntTestSerialization.cpp
Normal file
@ -0,0 +1,230 @@
|
||||
#include "IntTestSerialization.h"
|
||||
#include <fsfw/serialize/SerializeElement.h>
|
||||
#include <fsfw/serialize/SerialBufferAdapter.h>
|
||||
#include <unittest/internal/UnittDefinitions.h>
|
||||
#include <fsfw/serialize/SerializeIF.h>
|
||||
#include <array>
|
||||
|
||||
using retval = HasReturnvaluesIF;
|
||||
std::array<uint8_t, 512> testserialize::test_array = { 0 };
|
||||
|
||||
ReturnValue_t testserialize::test_serialization() {
|
||||
// Here, we test all serialization tools. First test basic cases.
|
||||
ReturnValue_t result = test_endianness_tools();
|
||||
if(result != retval::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = test_autoserialization();
|
||||
if(result != retval::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = test_serial_buffer_adapter();
|
||||
if(result != retval::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
return retval::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t testserialize::test_endianness_tools() {
|
||||
std::string id = "[test_endianness_tools]";
|
||||
test_array[0] = 0;
|
||||
test_array[1] = 0;
|
||||
uint16_t two_byte_value = 1;
|
||||
size_t size = 0;
|
||||
uint8_t* p_array = test_array.data();
|
||||
SerializeAdapter::serialize(&two_byte_value, &p_array, &size, 2,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
// Little endian: Value one on first byte
|
||||
if(test_array[0] != 1 and test_array[1] != 0) {
|
||||
return unitt::put_error(id);
|
||||
|
||||
}
|
||||
|
||||
p_array = test_array.data();
|
||||
size = 0;
|
||||
SerializeAdapter::serialize(&two_byte_value, &p_array, &size, 2,
|
||||
SerializeIF::Endianness::BIG);
|
||||
// Big endian: Value one on second byte
|
||||
if(test_array[0] != 0 and test_array[1] != 1) {
|
||||
return unitt::put_error(id);
|
||||
}
|
||||
return retval::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t testserialize::test_autoserialization() {
|
||||
std::string id = "[test_autoserialization]";
|
||||
// Unit Test getSerializedSize
|
||||
if(SerializeAdapter::
|
||||
getSerializedSize(&tv::tv_bool) != sizeof(tv::tv_bool) or
|
||||
SerializeAdapter::
|
||||
getSerializedSize(&tv::tv_uint8) != sizeof(tv::tv_uint8) or
|
||||
SerializeAdapter::
|
||||
getSerializedSize(&tv::tv_uint16) != sizeof(tv::tv_uint16) or
|
||||
SerializeAdapter::
|
||||
getSerializedSize(&tv::tv_uint32) != sizeof(tv::tv_uint32) or
|
||||
SerializeAdapter::
|
||||
getSerializedSize(&tv::tv_uint64) != sizeof(tv::tv_uint64) or
|
||||
SerializeAdapter::
|
||||
getSerializedSize(&tv::tv_int8) != sizeof(tv::tv_int8) or
|
||||
SerializeAdapter::
|
||||
getSerializedSize(&tv::tv_double) != sizeof(tv::tv_double) or
|
||||
SerializeAdapter::
|
||||
getSerializedSize(&tv::tv_int16) != sizeof(tv::tv_int16) or
|
||||
SerializeAdapter::
|
||||
getSerializedSize(&tv::tv_int32) != sizeof(tv::tv_int32) or
|
||||
SerializeAdapter::
|
||||
getSerializedSize(&tv::tv_float) != sizeof(tv::tv_float))
|
||||
{
|
||||
return unitt::put_error(id);
|
||||
}
|
||||
|
||||
size_t serialized_size = 0;
|
||||
uint8_t * p_array = test_array.data();
|
||||
|
||||
SerializeAdapter::serialize(&tv::tv_bool, &p_array,
|
||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv::tv_uint8, &p_array,
|
||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv::tv_uint16, &p_array,
|
||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv::tv_uint32, &p_array,
|
||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv::tv_int8, &p_array,
|
||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv::tv_int16, &p_array,
|
||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv::tv_int32, &p_array,
|
||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv::tv_uint64, &p_array,
|
||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv::tv_float, &p_array,
|
||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv::tv_double, &p_array,
|
||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv::tv_sfloat, &p_array,
|
||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv::tv_sdouble, &p_array,
|
||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
// expected size is 1 + 1 + 2 + 4 + 1 + 2 + 4 + 8 + 4 + 8 + 4 + 8
|
||||
if(serialized_size != 47) {
|
||||
return unitt::put_error(id);
|
||||
}
|
||||
|
||||
p_array = test_array.data();
|
||||
size_t remaining_size = serialized_size;
|
||||
bool tv_bool;
|
||||
uint8_t tv_uint8;
|
||||
uint16_t tv_uint16;
|
||||
uint32_t tv_uint32;
|
||||
int8_t tv_int8;
|
||||
int16_t tv_int16;
|
||||
int32_t tv_int32;
|
||||
uint64_t tv_uint64;
|
||||
float tv_float;
|
||||
double tv_double;
|
||||
float tv_sfloat;
|
||||
double tv_sdouble;
|
||||
|
||||
SerializeAdapter::deSerialize(&tv_bool,
|
||||
const_cast<const uint8_t**>(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tv_uint8,
|
||||
const_cast<const uint8_t**>(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tv_uint16,
|
||||
const_cast<const uint8_t**>(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tv_uint32,
|
||||
const_cast<const uint8_t**>(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tv_int8,
|
||||
const_cast<const uint8_t**>(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tv_int16,
|
||||
const_cast<const uint8_t**>(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tv_int32,
|
||||
const_cast<const uint8_t**>(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tv_uint64,
|
||||
const_cast<const uint8_t**>(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tv_float,
|
||||
const_cast<const uint8_t**>(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tv_double,
|
||||
const_cast<const uint8_t**>(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tv_sfloat,
|
||||
const_cast<const uint8_t**>(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tv_sdouble,
|
||||
const_cast<const uint8_t**>(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE);
|
||||
|
||||
if(tv_bool != tv::tv_bool or tv_uint8 != tv::tv_uint8 or
|
||||
tv_uint16 != tv::tv_uint16 or tv_uint32 != tv::tv_uint32 or
|
||||
tv_uint64 != tv::tv_uint64 or tv_int8 != tv::tv_int8 or
|
||||
tv_int16 != tv::tv_int16 or tv_int32 != tv::tv_int32)
|
||||
{
|
||||
return unitt::put_error(id);
|
||||
}
|
||||
|
||||
// These epsilon values were just guessed.. It appears to work though.
|
||||
if(abs(tv_float - tv::tv_float) > 0.0001 or
|
||||
abs(tv_double - tv::tv_double) > 0.01 or
|
||||
abs(tv_sfloat - tv::tv_sfloat) > 0.0001 or
|
||||
abs(tv_sdouble - tv::tv_sdouble) > 0.01) {
|
||||
return unitt::put_error(id);
|
||||
}
|
||||
|
||||
// Check overflow
|
||||
return retval::RETURN_OK;
|
||||
}
|
||||
|
||||
// TODO: Also test for constant buffers.
|
||||
ReturnValue_t testserialize::test_serial_buffer_adapter() {
|
||||
std::string id = "[test_serial_buffer_adapter]";
|
||||
|
||||
// I will skip endian swapper testing, its going to be changed anyway..
|
||||
// uint8_t tv::tv_uint8_swapped = EndianSwapper::swap(tv::tv_uint8);
|
||||
|
||||
size_t serialized_size = 0;
|
||||
uint8_t * p_array = test_array.data();
|
||||
std::array<uint8_t, 5> test_serial_buffer {5, 4, 3, 2, 1};
|
||||
SerialBufferAdapter<uint8_t> tv_serial_buffer_adapter =
|
||||
SerialBufferAdapter<uint8_t>(test_serial_buffer.data(),
|
||||
test_serial_buffer.size(), false);
|
||||
uint16_t testUint16 = 16;
|
||||
|
||||
SerializeAdapter::serialize(&tv::tv_bool, &p_array,&serialized_size,
|
||||
test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv_serial_buffer_adapter, &p_array,
|
||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&testUint16, &p_array, &serialized_size,
|
||||
test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
|
||||
if(serialized_size != 8 or test_array[0] != true or test_array[1] != 5
|
||||
or test_array[2] != 4 or test_array[3] != 3 or test_array[4] != 2
|
||||
or test_array[5] != 1)
|
||||
{
|
||||
return unitt::put_error(id);
|
||||
}
|
||||
memcpy(&testUint16, test_array.data() + 6, sizeof(testUint16));
|
||||
if(testUint16 != 16) {
|
||||
return unitt::put_error(id);
|
||||
}
|
||||
|
||||
// Serialize with size field
|
||||
SerialBufferAdapter<uint8_t> tv_serial_buffer_adapter2 =
|
||||
SerialBufferAdapter<uint8_t>(test_serial_buffer.data(),
|
||||
test_serial_buffer.size(), true);
|
||||
serialized_size = 0;
|
||||
p_array = test_array.data();
|
||||
SerializeAdapter::serialize(&tv::tv_bool, &p_array,&serialized_size,
|
||||
test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv_serial_buffer_adapter2, &p_array,
|
||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&testUint16, &p_array, &serialized_size,
|
||||
test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
|
||||
if(serialized_size != 9 or test_array[0] != true or test_array[1] != 5
|
||||
or test_array[2] != 5 or test_array[3] != 4 or test_array[4] != 3
|
||||
or test_array[5] != 2 or test_array[6] != 1)
|
||||
{
|
||||
return unitt::put_error(id);
|
||||
}
|
||||
memcpy(&testUint16, test_array.data() + 7, sizeof(testUint16));
|
||||
if(testUint16 != 16) {
|
||||
return unitt::put_error(id);
|
||||
}
|
||||
return retval::RETURN_OK;
|
||||
}
|
15
unittest/internal/serialize/IntTestSerialization.h
Normal file
15
unittest/internal/serialize/IntTestSerialization.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef UNITTEST_INTERNAL_INTTESTSERIALIZATION_H_
|
||||
#define UNITTEST_INTERNAL_INTTESTSERIALIZATION_H_
|
||||
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <array>
|
||||
|
||||
namespace testserialize {
|
||||
ReturnValue_t test_serialization();
|
||||
ReturnValue_t test_endianness_tools();
|
||||
ReturnValue_t test_autoserialization();
|
||||
ReturnValue_t test_serial_buffer_adapter();
|
||||
|
||||
extern std::array<uint8_t, 512> test_array;
|
||||
}
|
||||
|
||||
#endif /* UNITTEST_INTERNAL_INTTESTSERIALIZATION_H_ */
|
3
unittest/lcov.sh
Normal file
3
unittest/lcov.sh
Normal file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
lcov --capture --directory . --output-file coverage.info
|
||||
genhtml coverage.info --output-directory _coverage
|
46
unittest/testcfg/FSFWConfig.h
Normal file
46
unittest/testcfg/FSFWConfig.h
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef CONFIG_FSFWCONFIG_H_
|
||||
#define CONFIG_FSFWCONFIG_H_
|
||||
|
||||
#include <FSFWVersion.h>
|
||||
|
||||
//! Used to determine whether C++ ostreams are used
|
||||
//! Those can lead to code bloat.
|
||||
#define FSFW_CPP_OSTREAM_ENABLED 1
|
||||
|
||||
//! Reduced printout to further decrese code size
|
||||
//! Be careful, this also turns off most diagnostic prinouts!
|
||||
#define FSFW_REDUCED_PRINTOUT 0
|
||||
|
||||
//! Can be used to enable debugging printouts for developing the FSFW
|
||||
#define FSFW_DEBUGGING 0
|
||||
|
||||
//! Defines the FIFO depth of each commanding service base which
|
||||
//! also determines how many commands a CSB service can handle in one cycle
|
||||
//! simulataneously. This will increase the required RAM for
|
||||
//! each CSB service !
|
||||
#define FSFW_CSB_FIFO_DEPTH 6
|
||||
|
||||
//! If FSFW_OBJ_EVENT_TRANSLATION is set to one,
|
||||
//! additional output which requires the translation files translateObjects
|
||||
//! and translateEvents (and their compiled source files)
|
||||
#define FSFW_OBJ_EVENT_TRANSLATION 0
|
||||
|
||||
//! If -DDEBUG is supplied in the build defines, there will be
|
||||
//! additional output which requires the translation files translateObjects
|
||||
//! and translateEvents (and their compiles source files)
|
||||
#if FSFW_OBJ_EVENT_TRANSLATION == 1
|
||||
#define FSFW_DEBUG_OUTPUT 1
|
||||
//! Specify whether info events are printed too.
|
||||
#define FSFW_DEBUG_INFO 1
|
||||
#include <translateObjects.h>
|
||||
#include <translateEvents.h>
|
||||
#else
|
||||
#define FSFW_DEBUG_OUTPUT 0
|
||||
#endif
|
||||
|
||||
//! When using the newlib nano library, C99 support for stdio facilities
|
||||
//! will not be provided. This define should be set to 1 if this is the case.
|
||||
#define FSFW_NO_C99_IO 1
|
||||
|
||||
|
||||
#endif /* CONFIG_FSFWCONFIG_H_ */
|
415
unittest/testcfg/Makefile-FSFW-Tests
Normal file
415
unittest/testcfg/Makefile-FSFW-Tests
Normal file
@ -0,0 +1,415 @@
|
||||
#-------------------------------------------------------------------------------
|
||||
# Makefile for FSFW Test
|
||||
#-------------------------------------------------------------------------------
|
||||
# User-modifiable options
|
||||
#-------------------------------------------------------------------------------
|
||||
# Fundamentals on the build process of C/C++ Software:
|
||||
# https://www3.ntu.edu.sg/home/ehchua/programming/cpp/gcc_make.html
|
||||
|
||||
# Make documentation: https://www.gnu.org/software/make/manual/make.pdf
|
||||
# Online: https://www.gnu.org/software/make/manual/make.html
|
||||
# General rules: http://make.mad-scientist.net/papers/rules-of-makefiles/#rule3
|
||||
SHELL = /bin/sh
|
||||
|
||||
# Chip & board used for compilation
|
||||
# (can be overriden by adding CHIP=chip and BOARD=board to the command-line)
|
||||
# Unit Test can only be run on host machine for now (Linux)
|
||||
FRAMEWORK_PATH = fsfw
|
||||
FILE_ROOT = $(FRAMEWORK_PATH)/unittest
|
||||
BOARD = unittest
|
||||
LINUX = 1
|
||||
OS_FSFW = linux
|
||||
CUSTOM_DEFINES += -D$(OS_FSFW)
|
||||
|
||||
# Copied from stackoverflow, can be used to differentiate between Windows
|
||||
# and Linux
|
||||
ifeq ($(OS),Windows_NT)
|
||||
CUSTOM_DEFINES += -DWIN32
|
||||
ifeq ($(PROCESSOR_ARCHITEW6432),AMD64)
|
||||
CUSTOM_DEFINES += -DAMD64
|
||||
else
|
||||
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
|
||||
CUSTOM_DEFINES += -DAMD64
|
||||
endif
|
||||
ifeq ($(PROCESSOR_ARCHITECTURE),x86)
|
||||
CUSTOM_DEFINES += -DIA32
|
||||
endif
|
||||
endif
|
||||
else
|
||||
UNAME_S := $(shell uname -s)
|
||||
ifeq ($(UNAME_S),Linux)
|
||||
DETECTED_OS = LINUX
|
||||
CUSTOM_DEFINES += -DLINUX
|
||||
endif
|
||||
ifeq ($(UNAME_S),Darwin)
|
||||
CUSTOM_DEFINES += -DOSX
|
||||
endif
|
||||
UNAME_P := $(shell uname -p)
|
||||
ifeq ($(UNAME_P),x86_64)
|
||||
CUSTOM_DEFINES += -DAMD64
|
||||
endif
|
||||
ifneq ($(filter %86,$(UNAME_P)),)
|
||||
CUSTOM_DEFINES += -DIA32
|
||||
endif
|
||||
ifneq ($(filter arm%,$(UNAME_P)),)
|
||||
CUSTOM_DEFINES += -DARM
|
||||
endif
|
||||
endif
|
||||
|
||||
UNIT_TEST = 1
|
||||
# General folder paths
|
||||
CONFIG_PATH = $(FILE_ROOT)/config
|
||||
UNIT_TEST_PATH = $(FILE_ROOT)/tests
|
||||
CORE_PATH = $(FILE_ROOT)/core
|
||||
|
||||
# Output file basename
|
||||
BASENAME = fsfw
|
||||
BINARY_NAME := $(BASENAME)-$(BOARD)
|
||||
# Output files will be put in this directory inside
|
||||
OUTPUT_FOLDER = $(OS)
|
||||
|
||||
# Optimization level. Optimized for debugging.
|
||||
OPTIMIZATION = -O0
|
||||
|
||||
# Default debug output. Optimized for debugging.
|
||||
DEBUG_LEVEL = -g3
|
||||
|
||||
ifdef GCOV
|
||||
CUSTOM_DEFINES += -DGCOV
|
||||
endif
|
||||
|
||||
|
||||
# Output directories
|
||||
BUILDPATH = _bin
|
||||
DEPENDPATH = _dep
|
||||
OBJECTPATH = _obj
|
||||
|
||||
ifeq ($(MAKECMDGOALS),mission)
|
||||
BUILD_FOLDER = mission
|
||||
else
|
||||
BUILD_FOLDER = devel
|
||||
endif
|
||||
|
||||
DEPENDDIR = $(DEPENDPATH)/$(OUTPUT_FOLDER)/$(BUILD_FOLDER)
|
||||
OBJDIR = $(OBJECTPATH)/$(OUTPUT_FOLDER)/$(BUILD_FOLDER)
|
||||
BINDIR = $(BUILDPATH)
|
||||
|
||||
CLEANDEP = $(DEPENDPATH)/$(OUTPUT_FOLDER)
|
||||
CLEANOBJ = $(OBJECTPATH)/$(OUTPUT_FOLDER)
|
||||
CLEANBIN = $(BUILDPATH)
|
||||
#-------------------------------------------------------------------------------
|
||||
# Tools and Includes
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
# Tool suffix when cross-compiling
|
||||
CROSS_COMPILE =
|
||||
|
||||
# C Compiler
|
||||
CC = $(CROSS_COMPILE)gcc
|
||||
|
||||
# C++ compiler
|
||||
CXX = $(CROSS_COMPILE)g++
|
||||
|
||||
# Additional Tools
|
||||
SIZE = $(CROSS_COMPILE)size
|
||||
STRIP = $(CROSS_COMPILE)strip
|
||||
CP = $(CROSS_COMPILE)objcopy
|
||||
|
||||
HEXCOPY = $(CP) -O ihex
|
||||
BINCOPY = $(CP) -O binary
|
||||
# files to be compiled, will be filled in by include makefiles
|
||||
# := assignment is neccessary so we get all paths right
|
||||
# https://www.gnu.org/software/make/manual/html_node/Flavors.html
|
||||
CSRC :=
|
||||
CXXSRC :=
|
||||
ASRC :=
|
||||
INCLUDES :=
|
||||
|
||||
# Directories where $(directoryname).mk files should be included from
|
||||
SUBDIRS := $(FRAMEWORK_PATH) $(TEST_PATH) $(UNIT_TEST_PATH) $(CONFIG_PATH) \
|
||||
$(CORE_PATH)
|
||||
|
||||
|
||||
I_INCLUDES += $(addprefix -I, $(INCLUDES))
|
||||
|
||||
# This is a hack from http://make.mad-scientist.net/the-eval-function/
|
||||
#
|
||||
# The problem is, that included makefiles should be aware of their relative path
|
||||
# but not need to guess or hardcode it. So we set $(CURRENTPATH) for them. If
|
||||
# we do this globally and the included makefiles want to include other makefiles as
|
||||
# well, they would overwrite $(CURRENTPATH), screwing the include after them.
|
||||
#
|
||||
# By using a for-loop with an eval'd macro, we can generate the code to include all
|
||||
# sub-makefiles (with the correct $(CURRENTPATH) set) before actually evaluating
|
||||
# (and by this possibly changing $(CURRENTPATH)) them.
|
||||
#
|
||||
# This works recursively, if an included makefile wants to include, it can safely set
|
||||
# $(SUBDIRS) (which has already been evaluated here) and do
|
||||
# "$(foreach S,$(SUBDIRS),$(eval $(INCLUDE_FILE)))"
|
||||
# $(SUBDIRS) must be relative to the project root, so to include subdir foo, set
|
||||
# $(SUBDIRS) = $(CURRENTPATH)/foo.
|
||||
define INCLUDE_FILE
|
||||
CURRENTPATH := $S
|
||||
include $(S)/$(notdir $S).mk
|
||||
endef
|
||||
$(foreach S,$(SUBDIRS),$(eval $(INCLUDE_FILE)))
|
||||
|
||||
INCLUDES += $(FILE_ROOT)
|
||||
INCLUDES += $(FILE_ROOT)/catch2/
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Source Files
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
# All source files which are not includes by the .mk files are added here
|
||||
# Please ensure that no files are included by both .mk file and here !
|
||||
|
||||
# if a target is not listed in the current directory,
|
||||
# make searches in the directories specified with VPATH
|
||||
|
||||
# All C Sources included by .mk files are assigned here
|
||||
# Add the objects to sources so dependency handling works
|
||||
C_OBJECTS += $(CSRC:.c=.o)
|
||||
|
||||
# Objects built from Assembly source files
|
||||
ASM_OBJECTS = $(ASRC:.S=.o)
|
||||
|
||||
# Objects built from C++ source files
|
||||
CXX_OBJECTS += $(CXXSRC:.cpp=.o)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Build Configuration + Output
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
TARGET = Debug build.
|
||||
DEBUG_MESSAGE = Off
|
||||
OPTIMIZATION_MESSAGE = Off
|
||||
|
||||
# Define Messages
|
||||
MSG_INFO = Software: Hosted unittest \(Catch2\) for the FSFW.
|
||||
MSG_OPTIMIZATION = Optimization: $(OPTIMIZATION), $(OPTIMIZATION_MESSAGE)
|
||||
MSG_TARGET = Target Build: $(TARGET)
|
||||
MSG_DEBUG = Debug level: $(DEBUG_LEVEL), FSFW Debugging: $(DEBUG_MESSAGE)
|
||||
|
||||
MSG_LINKING = Linking:
|
||||
MSG_COMPILING = Compiling:
|
||||
MSG_ASSEMBLING = Assembling:
|
||||
MSG_DEPENDENCY = Collecting dependencies for:
|
||||
MSG_BINARY = Generate binary:
|
||||
|
||||
# See https://stackoverflow.com/questions/6687630/how-to-remove-unused-c-c-symbols-with-gcc-and-ld
|
||||
# Used to throw away unused code. Reduces code size significantly !
|
||||
# -Wl,--gc-sections: needs to be passed to the linker to throw aways unused code
|
||||
ifdef KEEP_UNUSED_CODE
|
||||
PROTOTYPE_OPTIMIZATION =
|
||||
UNUSED_CODE_REMOVAL =
|
||||
else
|
||||
PROTOTYPE_OPTIMIZATION = -ffunction-sections -fdata-sections
|
||||
UNUSED_CODE_REMOVAL = -Wl,--gc-sections
|
||||
# Link time optimization
|
||||
# See https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html for reference
|
||||
# Link time is larger and size of object files can not be retrieved
|
||||
# but resulting binary is smaller. Could be used in mission/deployment build
|
||||
# Requires -ffunction-section in linker call
|
||||
LINK_TIME_OPTIMIZATION = -flto
|
||||
OPTIMIZATION += $(PROTOTYPE_OPTIMIZATION)
|
||||
endif
|
||||
|
||||
# Dependency Flags
|
||||
# These flags tell the compiler to build dependencies
|
||||
# See: https://www.gnu.org/software/make/manual/html_node/Automatic-Prerequisites.html
|
||||
# Using following guide: http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#combine
|
||||
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPENDDIR)/$*.d
|
||||
|
||||
# Flags for the compiler call
|
||||
# - std: Which C++ version to use. Common versions: c++11, c++14 and c++17
|
||||
# - Wall: enable all warnings
|
||||
# - Wextra: enable extra warnings
|
||||
# - g: defines debug level
|
||||
# - fmessage-length: to control the formatting algorithm for diagnostic messages;
|
||||
# =0 means no line-wrapping is done; each error message appears on a single line
|
||||
# - fno-exceptions: stops generating extra code needed to propagate exceptions,
|
||||
# which can produce significant data size overhead
|
||||
CUSTOM_DEFINES += -DUNIT_TEST
|
||||
WARNING_FLAGS = -Wall -Wshadow=local -Wextra -Wimplicit-fallthrough=1 \
|
||||
-Wno-unused-parameter
|
||||
|
||||
CXXDEFINES := $(CUSTOM_DEFINES)
|
||||
CFLAGS +=
|
||||
CXXFLAGS += -I. $(DEBUG_LEVEL) $(WARNING_FLAGS) $(DEPFLAGS) -fmessage-length=0 $(OPTIMIZATION)\
|
||||
$(I_INCLUDES) $(CXXDEFINES)
|
||||
CPPFLAGS += -std=c++11
|
||||
|
||||
# Flags for the linker call
|
||||
# LINK_INCLUDES specify the path to used libraries and the linker script
|
||||
# LINK_LIBRARIES: Link real time support
|
||||
LDFLAGS := $(DEBUG_LEVEL) $(UNUSED_CODE_REMOVAL) $(OPTIMIZATION) -pthread
|
||||
LINK_INCLUDES :=
|
||||
LINK_LIBRARIES :=
|
||||
|
||||
ifdef LINUX
|
||||
LINK_LIBRARIES += -lrt
|
||||
endif
|
||||
|
||||
ifeq ($(OS),Windows_NT)
|
||||
LINK_LIBRARIES += -lwsock32 -lws2_32
|
||||
LDFLASGS += -fuse-ld=lld
|
||||
endif
|
||||
|
||||
# Gnu Coverage Tools Flags
|
||||
ifdef GCOV
|
||||
GCOV_CXXFLAGS = -fprofile-arcs -ftest-coverage --coverage -fno-inline \
|
||||
-fno-inline-small-functions -fno-default-inline
|
||||
CXXFLAGS += $(GCOV_CXXFLAGS)
|
||||
GCOV_LINKER_LIBS = -lgcov -fprofile-arcs -ftest-coverage
|
||||
LINK_LIBRARIES += $(GCOV_LINKER_LIBS)
|
||||
endif
|
||||
|
||||
# $(info $${CXXFLAGS} is [${CXXFLAGS}])
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Rules
|
||||
#-------------------------------------------------------------------------------
|
||||
# the call function assigns parameters to temporary variables
|
||||
# https://www.gnu.org/software/make/manual/make.html#Call-Function
|
||||
# $(1) = Memory names
|
||||
# Rules are called for each memory type
|
||||
# Two Expansion Symbols $$ are to escape the dollar sign for eval.
|
||||
# See: http://make.mad-scientist.net/the-eval-function/
|
||||
|
||||
default: all
|
||||
|
||||
# Cleans all files
|
||||
hardclean:
|
||||
-rm -rf $(BUILDPATH)
|
||||
-rm -rf $(OBJECTPATH)
|
||||
-rm -rf $(DEPENDPATH)
|
||||
|
||||
# Only clean files for current build
|
||||
clean:
|
||||
-rm -rf $(CLEANOBJ)
|
||||
-rm -rf $(CLEANBIN)
|
||||
-rm -rf $(CLEANDEP)
|
||||
|
||||
# Only clean binaries. Useful for changing the binary type when object files
|
||||
# are already compiled so complete rebuild is not necessary
|
||||
cleanbin:
|
||||
-rm -rf $(CLEANBIN)
|
||||
|
||||
# In this section, the binaries are built for all selected memories
|
||||
# notestfw: all
|
||||
all: executable
|
||||
|
||||
# Build target configuration
|
||||
release: OPTIMIZATION = -Os $(PROTOTYPE_OPTIMIZATION) $(LINK_TIME_OPTIMIZATION)
|
||||
release: LINK_TIME_OPTIMIZATION = -flto
|
||||
release: TARGET = Mission build.
|
||||
release: OPTIMIZATION_MESSAGE = On with Link Time Optimization
|
||||
|
||||
debug: CXXDEFINES += -DDEBUG
|
||||
debug: TARGET = Debug
|
||||
debug: DEBUG_MESSAGE = On
|
||||
|
||||
ifndef KEEP_UNUSED_CODE
|
||||
debug release: OPTIMIZATION_MESSAGE += , no unused code removal
|
||||
endif
|
||||
|
||||
debug release notestfw: executable
|
||||
|
||||
executable: $(BINDIR)/$(BINARY_NAME).elf
|
||||
@echo
|
||||
@echo $(MSG_INFO)
|
||||
@echo $(MSG_TARGET)
|
||||
@echo $(MSG_OPTIMIZATION)
|
||||
@echo $(MSG_DEBUG)
|
||||
|
||||
C_OBJECTS_PREFIXED = $(addprefix $(OBJDIR)/, $(C_OBJECTS))
|
||||
CXX_OBJECTS_PREFIXED = $(addprefix $(OBJDIR)/, $(CXX_OBJECTS))
|
||||
ASM_OBJECTS_PREFIXED = $(addprefix $(OBJDIR)/, $(ASM_OBJECTS))
|
||||
ALL_OBJECTS = $(ASM_OBJECTS_PREFIXED) $(C_OBJECTS_PREFIXED) \
|
||||
$(CXX_OBJECTS_PREFIXED)
|
||||
|
||||
# Useful for debugging the Makefile
|
||||
# Also see: https://www.oreilly.com/openbook/make3/book/ch12.pdf
|
||||
# $(info $${ALL_OBJECTS} is [${ALL_OBJECTS}])
|
||||
# $(info $${CXXSRC} is [${CXXSRC}])
|
||||
|
||||
# Automatic variables are used here extensively. Some of them
|
||||
# are escaped($$) to suppress immediate evaluation. The most important ones are:
|
||||
# $@: Name of Target (left side of rule)
|
||||
# $<: Name of the first prerequisite (right side of rule)
|
||||
# @^: List of all prerequisite, omitting duplicates
|
||||
# @D: Directory and file-within-directory part of $@
|
||||
|
||||
# Generates binary and displays all build properties
|
||||
# -p with mkdir ignores error and creates directory when needed.
|
||||
|
||||
# SHOW_DETAILS = 1
|
||||
|
||||
|
||||
# Link with required libraries: HAL (Hardware Abstraction Layer) and
|
||||
# HCC (File System Library)
|
||||
$(BINDIR)/$(BINARY_NAME).elf: $(ALL_OBJECTS)
|
||||
@echo
|
||||
@echo $(MSG_LINKING) Target $@
|
||||
@mkdir -p $(@D)
|
||||
ifdef SHOW_DETAILS
|
||||
$(CXX) $(LDFLAGS) $(LINK_INCLUDES) -o $@ $^ $(LINK_LIBRARIES)
|
||||
else
|
||||
@$(CXX) $(LDFLAGS) $(LINK_INCLUDES) -o $@ $^ $(LINK_LIBRARIES)
|
||||
endif
|
||||
ifeq ($(BUILD_FOLDER), mission)
|
||||
# With Link Time Optimization, section size is not available
|
||||
$(SIZE) $@
|
||||
else
|
||||
$(SIZE) $^ $@
|
||||
endif
|
||||
|
||||
$(BINDIR)/$(BINARY_NAME).hex: $(BINDIR)/$(BINARY_NAME).elf
|
||||
@echo
|
||||
@echo $(MSG_BINARY)
|
||||
@mkdir -p $(@D)
|
||||
$(HEXCOPY) $< $@
|
||||
|
||||
# Build new objects for changed dependencies.
|
||||
$(OBJDIR)/%.o: %.cpp
|
||||
$(OBJDIR)/%.o: %.cpp $(DEPENDDIR)/%.d | $(DEPENDDIR)
|
||||
@echo
|
||||
@echo $(MSG_COMPILING) $<
|
||||
@mkdir -p $(@D)
|
||||
ifdef SHOW_DETAILS
|
||||
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
|
||||
else
|
||||
@$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
|
||||
endif
|
||||
|
||||
$(OBJDIR)/%.o: %.c
|
||||
$(OBJDIR)/%.o: %.c $(DEPENDDIR)/%.d | $(DEPENDDIR)
|
||||
@echo
|
||||
@echo $(MSG_COMPILING) $<
|
||||
@mkdir -p $(@D)
|
||||
ifdef SHOW_DETAILS
|
||||
$(CC) $(CXXFLAGS) $(CFLAGS) -c -o $@ $<
|
||||
else
|
||||
@$(CC) $(CXXFLAGS) $(CFLAGS) -c -o $@ $<
|
||||
endif
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Dependency Handling
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
# Dependency Handling according to following guide:
|
||||
# http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/
|
||||
$(DEPENDDIR):
|
||||
@mkdir -p $(@D)
|
||||
DEPENDENCY_RELATIVE = $(CSRC:.c=.d) $(CXXSRC:.cpp=.d)
|
||||
# This is the list of all dependencies
|
||||
DEPFILES = $(addprefix $(DEPENDDIR)/, $(DEPENDENCY_RELATIVE))
|
||||
# Create subdirectories for dependencies
|
||||
$(DEPFILES):
|
||||
@mkdir -p $(@D)
|
||||
# Include all dependencies
|
||||
include $(wildcard $(DEPFILES))
|
||||
|
||||
# .PHONY tells make that these targets aren't files
|
||||
.PHONY: clean release debug all hardclean cleanbin
|
8
unittest/testcfg/TestsConfig.h
Normal file
8
unittest/testcfg/TestsConfig.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef FSFW_UNITTEST_CONFIG_TESTSCONFIG_H_
|
||||
#define FSFW_UNITTEST_CONFIG_TESTSCONFIG_H_
|
||||
|
||||
|
||||
#define CUSTOM_UNITTEST_RUNNER 0
|
||||
|
||||
|
||||
#endif /* FSFW_UNITTEST_CONFIG_TESTSCONFIG_H_ */
|
5
unittest/testcfg/cdatapool/dataPoolInit.cpp
Normal file
5
unittest/testcfg/cdatapool/dataPoolInit.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
#include "dataPoolInit.h"
|
||||
|
||||
void datapool::dataPoolInit(std::map<uint32_t, PoolEntryIF*> * poolMap) {
|
||||
|
||||
}
|
17
unittest/testcfg/cdatapool/dataPoolInit.h
Normal file
17
unittest/testcfg/cdatapool/dataPoolInit.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef HOSTED_CONFIG_CDATAPOOL_DATAPOOLINIT_H_
|
||||
#define HOSTED_CONFIG_CDATAPOOL_DATAPOOLINIT_H_
|
||||
|
||||
#include <fsfw/datapoolglob/GlobalDataPool.h>
|
||||
#include <fsfw/datapool/PoolEntryIF.h>
|
||||
#include <map>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
namespace datapool {
|
||||
void dataPoolInit(std::map<uint32_t, PoolEntryIF*> * poolMap);
|
||||
|
||||
enum datapoolvariables {
|
||||
NO_PARAMETER = 0,
|
||||
};
|
||||
}
|
||||
#endif /* CONFIG_CDATAPOOL_DATAPOOLINIT_H_ */
|
5
unittest/testcfg/devices/logicalAddresses.cpp
Normal file
5
unittest/testcfg/devices/logicalAddresses.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
#include "logicalAddresses.h"
|
||||
|
||||
|
||||
|
||||
|
15
unittest/testcfg/devices/logicalAddresses.h
Normal file
15
unittest/testcfg/devices/logicalAddresses.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef CONFIG_DEVICES_LOGICALADDRESSES_H_
|
||||
#define CONFIG_DEVICES_LOGICALADDRESSES_H_
|
||||
|
||||
#include <fsfw/devicehandlers/CookieIF.h>
|
||||
#include <fsfw/unittest/config/objects/systemObjectList.h>
|
||||
#include <cstdint>
|
||||
|
||||
namespace addresses {
|
||||
/* Logical addresses have uint32_t datatype */
|
||||
enum logicalAddresses: address_t {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif /* CONFIG_DEVICES_LOGICALADDRESSES_H_ */
|
4
unittest/testcfg/devices/powerSwitcherList.cpp
Normal file
4
unittest/testcfg/devices/powerSwitcherList.cpp
Normal file
@ -0,0 +1,4 @@
|
||||
#include "powerSwitcherList.h"
|
||||
|
||||
|
||||
|
12
unittest/testcfg/devices/powerSwitcherList.h
Normal file
12
unittest/testcfg/devices/powerSwitcherList.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef CONFIG_DEVICES_POWERSWITCHERLIST_H_
|
||||
#define CONFIG_DEVICES_POWERSWITCHERLIST_H_
|
||||
|
||||
namespace switches {
|
||||
/* Switches are uint8_t datatype and go from 0 to 255 */
|
||||
enum switcherList {
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif /* CONFIG_DEVICES_POWERSWITCHERLIST_H_ */
|
18
unittest/testcfg/events/subsystemIdRanges.h
Normal file
18
unittest/testcfg/events/subsystemIdRanges.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef CONFIG_EVENTS_SUBSYSTEMIDRANGES_H_
|
||||
#define CONFIG_EVENTS_SUBSYSTEMIDRANGES_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <fsfw/events/fwSubsystemIdRanges.h>
|
||||
|
||||
/**
|
||||
* @brief Custom subsystem IDs can be added here
|
||||
* @details
|
||||
* Subsystem IDs are used to create unique events.
|
||||
*/
|
||||
namespace SUBSYSTEM_ID {
|
||||
enum: uint8_t {
|
||||
SUBSYSTEM_ID_START = FW_SUBSYSTEM_ID_RANGE,
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* CONFIG_EVENTS_SUBSYSTEMIDRANGES_H_ */
|
12
unittest/testcfg/ipc/MissionMessageTypes.cpp
Normal file
12
unittest/testcfg/ipc/MissionMessageTypes.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include |