Merge remote-tracking branch 'origin/development' into mueller/master
This commit is contained in:
commit
bc1d6731da
@ -5,4 +5,4 @@ RUN apt-get --yes upgrade
|
||||
|
||||
#tzdata is a dependency, won't install otherwise
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
RUN apt-get --yes install gcc g++ cmake lcov git nano
|
||||
RUN apt-get --yes install gcc g++ cmake make lcov git valgrind nano
|
||||
|
13
automation/Jenkinsfile
vendored
13
automation/Jenkinsfile
vendored
@ -55,5 +55,18 @@ pipeline {
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Valgrind') {
|
||||
agent {
|
||||
dockerfile {
|
||||
dir 'automation'
|
||||
reuseNode true
|
||||
}
|
||||
}
|
||||
steps {
|
||||
dir(BUILDDIR) {
|
||||
sh 'valgrind --leak-check=full --error-exitcode=1 ./fsfw-tests'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
35
doc/CMakeLists.txt
Normal file
35
doc/CMakeLists.txt
Normal file
@ -0,0 +1,35 @@
|
||||
find_package(Doxygen REQUIRED)
|
||||
|
||||
get_target_property(LIB_FSFW_PUBLIC_HEADER_DIR ${LIB_FSFW_NAME}/fsfw INTERFACE_INCLUDE_DIRECTORIES)
|
||||
file(GLOB_RECURSE LIB_FSFW_PUBLIC_HEADERS ${CAT_CUTIFIER_PUBLIC_HEADER_DIR}/action/ActionHelper.h)
|
||||
|
||||
# Replace variables inside @@ with the current values
|
||||
set(DOXYGEN_INPUT_DIR ${PROJECT_SOURCE_DIR}/CatCutifier)
|
||||
set(DOXYGEN_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/docs/doxygen)
|
||||
set(DOXYGEN_INDEX_FILE ${DOXYGEN_OUTPUT_DIR}/html/index.html)
|
||||
set(DOXYFILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
|
||||
set(DOXYFILE_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
|
||||
|
||||
# Replace variables inside @@ with the current values
|
||||
configure_file(${DOXYFILE_IN} ${DOXYFILE_OUT} @ONLY)
|
||||
|
||||
file(MAKE_DIRECTORY ${DOXYGEN_OUTPUT_DIR}) #Doxygen won't create this for us
|
||||
add_custom_command(OUTPUT ${DOXYGEN_INDEX_FILE}
|
||||
DEPENDS ${CAT_CUTIFIER_PUBLIC_HEADERS}
|
||||
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE_OUT}
|
||||
MAIN_DEPENDENCY ${DOXYFILE_OUT} ${DOXYFILE_IN}
|
||||
COMMENT "Generating docs")
|
||||
|
||||
add_custom_target(Doxygen ALL DEPENDS ${DOXYGEN_INDEX_FILE})
|
||||
|
||||
find_package(Sphinx REQUIRED)
|
||||
|
||||
set(SPHINX_SOURCE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
set(SPHINX_BUILD ${CMAKE_CURRENT_BINARY_DIR}/docs/sphinx)
|
||||
|
||||
add_custom_target(Sphinx ALL
|
||||
COMMAND
|
||||
${SPHINX_EXECUTABLE} -b html
|
||||
${SPHINX_SOURCE} ${SPHINX_BUILD}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMENT "Generating documentation with Sphinx")
|
3
doc/Doxyfile.in
Normal file
3
doc/Doxyfile.in
Normal file
@ -0,0 +1,3 @@
|
||||
INPUT = "@DOXYGEN_INPUT_DIR@"
|
||||
|
||||
OUTPUT_DIRECTORY = "@DOXYGEN_OUTPUT_DIR@"
|
@ -186,7 +186,7 @@ ReturnValue_t MgmRM3100Handler::interpretDeviceReply(DeviceCommandId_t id, const
|
||||
uint8_t cmmValue = packet[1];
|
||||
// We clear the seventh bit in any case
|
||||
// because this one is zero sometimes for some reason
|
||||
bitutil::bitClear(&cmmValue, 6);
|
||||
bitutil::clear(&cmmValue, 6);
|
||||
if(cmmValue == cmmRegValue and internalState == InternalState::READ_CMM) {
|
||||
commandExecuted = true;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import platform
|
||||
import sys
|
||||
import time
|
||||
import argparse
|
||||
import webbrowser
|
||||
from typing import List
|
||||
|
||||
|
||||
@ -18,6 +19,10 @@ information how to set up the build folder.
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(description="Processing arguments for LCOV helper script.")
|
||||
parser.add_argument(
|
||||
'-o', '--open', action='store_true', help='Open coverage data in webbrowser'
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
build_dir_list = []
|
||||
if not os.path.isfile('README.md'):
|
||||
@ -41,6 +46,8 @@ def main():
|
||||
print("Multiple build directories found!")
|
||||
build_directory = determine_build_dir(build_dir_list)
|
||||
perform_lcov_operation(build_directory)
|
||||
if os.path.isdir('fsfw-tests_coverage') and args.open:
|
||||
webbrowser.open('fsfw-tests_coverage/index.html')
|
||||
|
||||
|
||||
def check_for_cmake_build_dir(build_dir_dict: list):
|
||||
|
3
scripts/gen-unittest.sh
Executable file
3
scripts/gen-unittest.sh
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
mkdir build-Unittest && cd build-Unittest
|
||||
cmake -DFSFW_BUILD_UNITTESTS=ON -DFSFW_OSAL=host -DCMAKE_BUILD_TYPE=Debug ..
|
@ -110,7 +110,7 @@ ReturnValue_t LocalPoolDataSetBase::serializeWithValidityBuffer(uint8_t **buffer
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
if(registeredVariables[count]->isValid()) {
|
||||
/* Set bit at correct position */
|
||||
bitutil::bitSet(validityPtr + validBufferIndex, validBufferIndexBit);
|
||||
bitutil::set(validityPtr + validBufferIndex, validBufferIndexBit);
|
||||
}
|
||||
if(validBufferIndexBit == 7) {
|
||||
validBufferIndex ++;
|
||||
@ -156,8 +156,8 @@ ReturnValue_t LocalPoolDataSetBase::deSerializeWithValidityBuffer(
|
||||
uint8_t validBufferIndexBit = 0;
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
// set validity buffer here.
|
||||
bool nextVarValid = bitutil::bitGet(*buffer +
|
||||
validBufferIndex, validBufferIndexBit);
|
||||
bool nextVarValid = false;
|
||||
bitutil::get(*buffer + validBufferIndex, validBufferIndexBit, nextVarValid);
|
||||
registeredVariables[count]->setValid(nextVarValid);
|
||||
|
||||
if(validBufferIndexBit == 7) {
|
||||
|
@ -2,43 +2,40 @@
|
||||
|
||||
|
||||
PeriodicOperationDivider::PeriodicOperationDivider(uint32_t divider,
|
||||
bool resetAutomatically): resetAutomatically(resetAutomatically),
|
||||
counter(divider), divider(divider) {
|
||||
bool resetAutomatically): resetAutomatically(resetAutomatically),
|
||||
divider(divider) {
|
||||
}
|
||||
|
||||
bool PeriodicOperationDivider::checkAndIncrement() {
|
||||
bool opNecessary = check();
|
||||
if(opNecessary) {
|
||||
if(resetAutomatically) {
|
||||
counter = 0;
|
||||
}
|
||||
return opNecessary;
|
||||
}
|
||||
counter ++;
|
||||
return opNecessary;
|
||||
bool opNecessary = check();
|
||||
if(opNecessary and resetAutomatically) {
|
||||
resetCounter();
|
||||
}
|
||||
else {
|
||||
counter++;
|
||||
}
|
||||
return opNecessary;
|
||||
}
|
||||
|
||||
bool PeriodicOperationDivider::check() {
|
||||
if(counter >= divider) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if(counter >= divider) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PeriodicOperationDivider::resetCounter() {
|
||||
counter = 0;
|
||||
counter = 1;
|
||||
}
|
||||
|
||||
void PeriodicOperationDivider::setDivider(uint32_t newDivider) {
|
||||
divider = newDivider;
|
||||
divider = newDivider;
|
||||
}
|
||||
|
||||
uint32_t PeriodicOperationDivider::getCounter() const {
|
||||
return counter;
|
||||
return counter;
|
||||
}
|
||||
|
||||
uint32_t PeriodicOperationDivider::getDivider() const {
|
||||
return divider;
|
||||
return divider;
|
||||
}
|
||||
|
@ -13,51 +13,50 @@
|
||||
*/
|
||||
class PeriodicOperationDivider {
|
||||
public:
|
||||
/**
|
||||
* Initialize with the desired divider and specify whether the internal
|
||||
* counter will be reset automatically.
|
||||
* @param divider
|
||||
* @param resetAutomatically
|
||||
*/
|
||||
PeriodicOperationDivider(uint32_t divider, bool resetAutomatically = true);
|
||||
/**
|
||||
* Initialize with the desired divider and specify whether the internal
|
||||
* counter will be reset automatically.
|
||||
* @param divider Value of 0 or 1 will cause #check and #checkAndIncrement to always return
|
||||
* true
|
||||
* @param resetAutomatically
|
||||
*/
|
||||
PeriodicOperationDivider(uint32_t divider, bool resetAutomatically = true);
|
||||
|
||||
/**
|
||||
* Check whether operation is necessary. If an operation is necessary and the class has been
|
||||
* configured to be reset automatically, the counter will be reset to 1 automatically
|
||||
*
|
||||
* @return
|
||||
* -@c true if the counter is larger or equal to the divider
|
||||
* -@c false otherwise
|
||||
*/
|
||||
bool checkAndIncrement();
|
||||
|
||||
/**
|
||||
* Check whether operation is necessary.
|
||||
* If an operation is necessary and the class has been
|
||||
* configured to be reset automatically, the counter will be reset.
|
||||
*
|
||||
* @return
|
||||
* -@c true if the counter is larger or equal to the divider
|
||||
* -@c false otherwise
|
||||
*/
|
||||
bool checkAndIncrement();
|
||||
/**
|
||||
* Checks whether an operation is necessary. This function will not increment the counter.
|
||||
* @return
|
||||
* -@c true if the counter is larger or equal to the divider
|
||||
* -@c false otherwise
|
||||
*/
|
||||
bool check();
|
||||
|
||||
/**
|
||||
* Checks whether an operation is necessary.
|
||||
* This function will not increment the counter!
|
||||
* @return
|
||||
* -@c true if the counter is larger or equal to the divider
|
||||
* -@c false otherwise
|
||||
*/
|
||||
bool check();
|
||||
/**
|
||||
* Can be used to reset the counter to 1 manually
|
||||
*/
|
||||
void resetCounter();
|
||||
uint32_t getCounter() const;
|
||||
|
||||
/**
|
||||
* Can be used to reset the counter to 0 manually.
|
||||
*/
|
||||
void resetCounter();
|
||||
uint32_t getCounter() const;
|
||||
/**
|
||||
* Can be used to set a new divider value.
|
||||
* @param newDivider
|
||||
*/
|
||||
void setDivider(uint32_t newDivider);
|
||||
uint32_t getDivider() const;
|
||||
|
||||
/**
|
||||
* Can be used to set a new divider value.
|
||||
* @param newDivider
|
||||
*/
|
||||
void setDivider(uint32_t newDivider);
|
||||
uint32_t getDivider() const;
|
||||
private:
|
||||
bool resetAutomatically = true;
|
||||
uint32_t counter = 0;
|
||||
uint32_t divider = 0;
|
||||
bool resetAutomatically = true;
|
||||
uint32_t counter = 1;
|
||||
uint32_t divider = 0;
|
||||
};
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "fsfw/globalfunctions/bitutility.h"
|
||||
|
||||
void bitutil::bitSet(uint8_t *byte, uint8_t position) {
|
||||
void bitutil::set(uint8_t *byte, uint8_t position) {
|
||||
if(position > 7) {
|
||||
return;
|
||||
}
|
||||
@ -8,7 +8,7 @@ void bitutil::bitSet(uint8_t *byte, uint8_t position) {
|
||||
*byte |= 1 << shiftNumber;
|
||||
}
|
||||
|
||||
void bitutil::bitToggle(uint8_t *byte, uint8_t position) {
|
||||
void bitutil::toggle(uint8_t *byte, uint8_t position) {
|
||||
if(position > 7) {
|
||||
return;
|
||||
}
|
||||
@ -16,7 +16,7 @@ void bitutil::bitToggle(uint8_t *byte, uint8_t position) {
|
||||
*byte ^= 1 << shiftNumber;
|
||||
}
|
||||
|
||||
void bitutil::bitClear(uint8_t *byte, uint8_t position) {
|
||||
void bitutil::clear(uint8_t *byte, uint8_t position) {
|
||||
if(position > 7) {
|
||||
return;
|
||||
}
|
||||
@ -24,10 +24,11 @@ void bitutil::bitClear(uint8_t *byte, uint8_t position) {
|
||||
*byte &= ~(1 << shiftNumber);
|
||||
}
|
||||
|
||||
bool bitutil::bitGet(const uint8_t *byte, uint8_t position) {
|
||||
bool bitutil::get(const uint8_t *byte, uint8_t position, bool& bit) {
|
||||
if(position > 7) {
|
||||
return false;
|
||||
}
|
||||
uint8_t shiftNumber = position + (7 - 2 * position);
|
||||
return *byte & (1 << shiftNumber);
|
||||
bit = *byte & (1 << shiftNumber);
|
||||
return true;
|
||||
}
|
||||
|
@ -5,13 +5,36 @@
|
||||
|
||||
namespace bitutil {
|
||||
|
||||
/* Helper functions for manipulating the individual bits of a byte.
|
||||
Position refers to n-th bit of a byte, going from 0 (most significant bit) to
|
||||
7 (least significant bit) */
|
||||
void bitSet(uint8_t* byte, uint8_t position);
|
||||
void bitToggle(uint8_t* byte, uint8_t position);
|
||||
void bitClear(uint8_t* byte, uint8_t position);
|
||||
bool bitGet(const uint8_t* byte, uint8_t position);
|
||||
// Helper functions for manipulating the individual bits of a byte.
|
||||
// Position refers to n-th bit of a byte, going from 0 (most significant bit) to
|
||||
// 7 (least significant bit)
|
||||
|
||||
/**
|
||||
* @brief Set the bit in a given byte
|
||||
* @param byte
|
||||
* @param position
|
||||
*/
|
||||
void set(uint8_t* byte, uint8_t position);
|
||||
/**
|
||||
* @brief Toggle the bit in a given byte
|
||||
* @param byte
|
||||
* @param position
|
||||
*/
|
||||
void toggle(uint8_t* byte, uint8_t position);
|
||||
/**
|
||||
* @brief Clear the bit in a given byte
|
||||
* @param byte
|
||||
* @param position
|
||||
*/
|
||||
void clear(uint8_t* byte, uint8_t position);
|
||||
/**
|
||||
* @brief Get the bit in a given byte
|
||||
* @param byte
|
||||
* @param position
|
||||
* @param If the input is valid, this will be set to true if the bit is set and false otherwise.
|
||||
* @return False if position is invalid, True otherwise
|
||||
*/
|
||||
bool get(const uint8_t* byte, uint8_t position, bool& bit);
|
||||
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief These adapters provides an interface to use the SerializeIF functions
|
||||
* with arbitrary template objects to facilitate and simplify the
|
||||
* serialization of classes with different multiple different data types
|
||||
@ -20,174 +20,250 @@
|
||||
*/
|
||||
class SerializeAdapter {
|
||||
public:
|
||||
/***
|
||||
* This function can be used to serialize a trivial copy-able type or a
|
||||
* child of SerializeIF.
|
||||
* The right template to be called is determined in the function itself.
|
||||
* For objects of non trivial copy-able type this function is almost never
|
||||
* called by the user directly. Instead helpers for specific types like
|
||||
* SerialArrayListAdapter or SerialLinkedListAdapter is the right choice here.
|
||||
*
|
||||
* @param[in] object Object to serialize, the used type is deduced from this pointer
|
||||
* @param[in/out] buffer Buffer to serialize into. Will be moved by the function.
|
||||
* @param[in/out] size Size of current written buffer. Will be incremented by the function.
|
||||
* @param[in] maxSize Max size of Buffer
|
||||
* @param[in] streamEndianness Endianness of serialized element as in according to SerializeIF::Endianness
|
||||
* @return
|
||||
* - @c BUFFER_TOO_SHORT The given buffer in is too short
|
||||
* - @c RETURN_FAILED Generic Error
|
||||
* - @c RETURN_OK Successful serialization
|
||||
*/
|
||||
template<typename T>
|
||||
static ReturnValue_t serialize(const T *object, uint8_t **buffer,
|
||||
size_t *size, size_t maxSize,
|
||||
SerializeIF::Endianness streamEndianness) {
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
return adapter.serialize(object, buffer, size, maxSize,
|
||||
streamEndianness);
|
||||
}
|
||||
/**
|
||||
* Function to return the serialized size of the object in the pointer.
|
||||
* May be a trivially copy-able object or a Child of SerializeIF
|
||||
*
|
||||
* @param object Pointer to Object
|
||||
* @return Serialized size of object
|
||||
*/
|
||||
template<typename T>
|
||||
static size_t getSerializedSize(const T *object){
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
return adapter.getSerializedSize(object);
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* Deserializes a object from a given buffer of given size.
|
||||
* Object Must be trivially copy-able or a child of SerializeIF.
|
||||
*
|
||||
* @details
|
||||
* Buffer will be moved to the current read location. Size will be decreased by the function.
|
||||
*
|
||||
* @param[in/out] buffer Buffer to deSerialize from. Will be moved by the function.
|
||||
* @param[in/out] size Remaining size of the buffer to read from. Will be decreased by function.
|
||||
* @param[in] streamEndianness Endianness as in according to SerializeIF::Endianness
|
||||
* @return
|
||||
* - @c STREAM_TOO_SHORT The input stream is too short to deSerialize the object
|
||||
* - @c TOO_MANY_ELEMENTS The buffer has more inputs than expected
|
||||
* - @c RETURN_FAILED Generic Error
|
||||
* - @c RETURN_OK Successful deserialization
|
||||
*/
|
||||
template<typename T>
|
||||
static ReturnValue_t deSerialize(T *object, const uint8_t **buffer,
|
||||
size_t *size, SerializeIF::Endianness streamEndianness) {
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
return adapter.deSerialize(object, buffer, size, streamEndianness);
|
||||
}
|
||||
/***
|
||||
* @brief Serialize a trivial copy-able type or a child of SerializeIF.
|
||||
* @details
|
||||
* The right template to be called is determined in the function itself.
|
||||
* For objects of non trivial copy-able type this function is almost never
|
||||
* called by the user directly. Instead helpers for specific types like
|
||||
* SerialArrayListAdapter or SerialLinkedListAdapter are the right choice here.
|
||||
*
|
||||
* @param[in] object: Object to serialize, the used type is deduced from this pointer
|
||||
* @param[in/out] buffer: Pointer to the buffer to serialize into. Buffer position will be
|
||||
* incremented by the function.
|
||||
* @param[in/out] size: Pointer to size of current written buffer.
|
||||
* SIze will be incremented by the function.
|
||||
* @param[in] maxSize: Max size of Buffer
|
||||
* @param[in] streamEndianness: Endianness of serialized element as in according to
|
||||
* SerializeIF::Endianness
|
||||
* @return
|
||||
* - @c BUFFER_TOO_SHORT The given buffer in is too short
|
||||
* - @c RETURN_FAILED Generic Error
|
||||
* - @c RETURN_OK Successful serialization
|
||||
*/
|
||||
template<typename T>
|
||||
static ReturnValue_t serialize(const T *object, uint8_t **buffer,
|
||||
size_t *size, size_t maxSize,
|
||||
SerializeIF::Endianness streamEndianness) {
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
return adapter.serialize(object, buffer, size, maxSize,
|
||||
streamEndianness);
|
||||
}
|
||||
|
||||
/***
|
||||
* This function can be used to serialize a trivial copy-able type or a child of SerializeIF.
|
||||
* The right template to be called is determined in the function itself.
|
||||
* For objects of non trivial copy-able type this function is almost never
|
||||
* called by the user directly. Instead helpers for specific types like
|
||||
* SerialArrayListAdapter or SerialLinkedListAdapter are the right choice here.
|
||||
*
|
||||
* @param[in] object: Object to serialize, the used type is deduced from this pointer
|
||||
* @param[in/out] buffer: Buffer to serialize into.
|
||||
* @param[out] serSize: Serialized size
|
||||
* @param[in] maxSize: Max size of buffer
|
||||
* @param[in] streamEndianness: Endianness of serialized element as in according to
|
||||
* SerializeIF::Endianness
|
||||
* @return
|
||||
* - @c BUFFER_TOO_SHORT The given buffer in is too short
|
||||
* - @c RETURN_FAILED Generic Error
|
||||
* - @c RETURN_OK Successful serialization
|
||||
*/
|
||||
template<typename T>
|
||||
static ReturnValue_t serialize(const T *object, uint8_t* const buffer, size_t* serSize,
|
||||
size_t maxSize, SerializeIF::Endianness streamEndianness) {
|
||||
if(object == nullptr or buffer == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
uint8_t** tempPtr = const_cast<uint8_t**>(&buffer);
|
||||
size_t tmpSize = 0;
|
||||
ReturnValue_t result = adapter.serialize(object, tempPtr, &tmpSize, maxSize,
|
||||
streamEndianness);
|
||||
if(serSize != nullptr) {
|
||||
*serSize = tmpSize;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function to return the serialized size of the object in the pointer.
|
||||
* @details
|
||||
* May be a trivially copy-able object or a child of SerializeIF.
|
||||
*
|
||||
* @param object Pointer to Object
|
||||
* @return Serialized size of object
|
||||
*/
|
||||
template<typename T>
|
||||
static size_t getSerializedSize(const T *object){
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
return adapter.getSerializedSize(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deserializes a object from a given buffer of given size.
|
||||
*
|
||||
* @details
|
||||
* Object Must be trivially copy-able or a child of SerializeIF.
|
||||
* Buffer will be moved to the current read location. Size will be decreased by the function.
|
||||
*
|
||||
* @param[in] object: Pointer to object to deserialize
|
||||
* @param[in/out] buffer: Pointer to the buffer to deSerialize from. Buffer position will be
|
||||
* incremented by the function
|
||||
* @param[in/out] size: Pointer to remaining size of the buffer to read from.
|
||||
* Will be decreased by function.
|
||||
* @param[in] streamEndianness: Endianness as in according to SerializeIF::Endianness
|
||||
* @return
|
||||
* - @c STREAM_TOO_SHORT The input stream is too short to deSerialize the object
|
||||
* - @c TOO_MANY_ELEMENTS The buffer has more inputs than expected
|
||||
* - @c RETURN_FAILED Generic Error
|
||||
* - @c RETURN_OK Successful deserialization
|
||||
*/
|
||||
template<typename T>
|
||||
static ReturnValue_t deSerialize(T *object, const uint8_t **buffer,
|
||||
size_t *size, SerializeIF::Endianness streamEndianness) {
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
return adapter.deSerialize(object, buffer, size, streamEndianness);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deserializes a object from a given buffer of given size.
|
||||
*
|
||||
* @details
|
||||
* Object Must be trivially copy-able or a child of SerializeIF.
|
||||
*
|
||||
* @param[in] object: Pointer to object to deserialize
|
||||
* @param[in] buffer: Buffer to deSerialize from
|
||||
* @param[out] deserSize: Deserialized length
|
||||
* @param[in] streamEndianness: Endianness as in according to SerializeIF::Endianness
|
||||
* @return
|
||||
* - @c STREAM_TOO_SHORT The input stream is too short to deSerialize the object
|
||||
* - @c TOO_MANY_ELEMENTS The buffer has more inputs than expected
|
||||
* - @c RETURN_FAILED Generic Error
|
||||
* - @c RETURN_OK Successful deserialization
|
||||
*/
|
||||
template<typename T>
|
||||
static ReturnValue_t deSerialize(T *object, const uint8_t* buffer,
|
||||
size_t* deserSize, SerializeIF::Endianness streamEndianness) {
|
||||
if(object == nullptr or buffer == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
const uint8_t** tempPtr = &buffer;
|
||||
size_t maxVal = -1;
|
||||
ReturnValue_t result = adapter.deSerialize(object, tempPtr, &maxVal, streamEndianness);
|
||||
if(deserSize != nullptr) {
|
||||
*deserSize = -1 - maxVal;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* Internal template to deduce the right function calls at compile time
|
||||
*/
|
||||
template<typename T, bool> class InternalSerializeAdapter;
|
||||
/**
|
||||
* Internal template to deduce the right function calls at compile time
|
||||
*/
|
||||
template<typename T, bool> class InternalSerializeAdapter;
|
||||
|
||||
/**
|
||||
* Template to be used if T is not a child of SerializeIF
|
||||
*
|
||||
* @tparam T T must be trivially_copyable
|
||||
*/
|
||||
template<typename T>
|
||||
class InternalSerializeAdapter<T, false> {
|
||||
static_assert (std::is_trivially_copyable<T>::value,
|
||||
"If a type needs to be serialized it must be a child of "
|
||||
"SerializeIF or trivially copy-able");
|
||||
public:
|
||||
static ReturnValue_t serialize(const T *object, uint8_t **buffer,
|
||||
size_t *size, size_t max_size,
|
||||
SerializeIF::Endianness streamEndianness) {
|
||||
size_t ignoredSize = 0;
|
||||
if (size == nullptr) {
|
||||
size = &ignoredSize;
|
||||
}
|
||||
// Check remaining size is large enough and check integer
|
||||
// overflow of *size
|
||||
size_t newSize = sizeof(T) + *size;
|
||||
if ((newSize <= max_size) and (newSize > *size)) {
|
||||
T tmp;
|
||||
switch (streamEndianness) {
|
||||
case SerializeIF::Endianness::BIG:
|
||||
tmp = EndianConverter::convertBigEndian<T>(*object);
|
||||
break;
|
||||
case SerializeIF::Endianness::LITTLE:
|
||||
tmp = EndianConverter::convertLittleEndian<T>(*object);
|
||||
break;
|
||||
default:
|
||||
case SerializeIF::Endianness::MACHINE:
|
||||
tmp = *object;
|
||||
break;
|
||||
}
|
||||
std::memcpy(*buffer, &tmp, sizeof(T));
|
||||
*size += sizeof(T);
|
||||
(*buffer) += sizeof(T);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return SerializeIF::BUFFER_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Template to be used if T is not a child of SerializeIF
|
||||
*
|
||||
* @tparam T T must be trivially_copyable
|
||||
*/
|
||||
template<typename T>
|
||||
class InternalSerializeAdapter<T, false> {
|
||||
static_assert (std::is_trivially_copyable<T>::value,
|
||||
"If a type needs to be serialized it must be a child of "
|
||||
"SerializeIF or trivially copy-able");
|
||||
public:
|
||||
static ReturnValue_t serialize(const T *object, uint8_t **buffer,
|
||||
size_t *size, size_t max_size,
|
||||
SerializeIF::Endianness streamEndianness) {
|
||||
size_t ignoredSize = 0;
|
||||
if (size == nullptr) {
|
||||
size = &ignoredSize;
|
||||
}
|
||||
// Check remaining size is large enough and check integer
|
||||
// overflow of *size
|
||||
size_t newSize = sizeof(T) + *size;
|
||||
if ((newSize <= max_size) and (newSize > *size)) {
|
||||
T tmp;
|
||||
switch (streamEndianness) {
|
||||
case SerializeIF::Endianness::BIG:
|
||||
tmp = EndianConverter::convertBigEndian<T>(*object);
|
||||
break;
|
||||
case SerializeIF::Endianness::LITTLE:
|
||||
tmp = EndianConverter::convertLittleEndian<T>(*object);
|
||||
break;
|
||||
default:
|
||||
case SerializeIF::Endianness::MACHINE:
|
||||
tmp = *object;
|
||||
break;
|
||||
}
|
||||
std::memcpy(*buffer, &tmp, sizeof(T));
|
||||
*size += sizeof(T);
|
||||
(*buffer) += sizeof(T);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return SerializeIF::BUFFER_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t deSerialize(T *object, const uint8_t **buffer,
|
||||
size_t *size, SerializeIF::Endianness streamEndianness) {
|
||||
T tmp;
|
||||
if (*size >= sizeof(T)) {
|
||||
*size -= sizeof(T);
|
||||
std::memcpy(&tmp, *buffer, sizeof(T));
|
||||
switch (streamEndianness) {
|
||||
case SerializeIF::Endianness::BIG:
|
||||
*object = EndianConverter::convertBigEndian<T>(tmp);
|
||||
break;
|
||||
case SerializeIF::Endianness::LITTLE:
|
||||
*object = EndianConverter::convertLittleEndian<T>(tmp);
|
||||
break;
|
||||
default:
|
||||
case SerializeIF::Endianness::MACHINE:
|
||||
*object = tmp;
|
||||
break;
|
||||
}
|
||||
ReturnValue_t deSerialize(T *object, const uint8_t **buffer,
|
||||
size_t *size, SerializeIF::Endianness streamEndianness) {
|
||||
T tmp;
|
||||
if (*size >= sizeof(T)) {
|
||||
*size -= sizeof(T);
|
||||
std::memcpy(&tmp, *buffer, sizeof(T));
|
||||
switch (streamEndianness) {
|
||||
case SerializeIF::Endianness::BIG:
|
||||
*object = EndianConverter::convertBigEndian<T>(tmp);
|
||||
break;
|
||||
case SerializeIF::Endianness::LITTLE:
|
||||
*object = EndianConverter::convertLittleEndian<T>(tmp);
|
||||
break;
|
||||
default:
|
||||
case SerializeIF::Endianness::MACHINE:
|
||||
*object = tmp;
|
||||
break;
|
||||
}
|
||||
|
||||
*buffer += sizeof(T);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return SerializeIF::STREAM_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
*buffer += sizeof(T);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return SerializeIF::STREAM_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t getSerializedSize(const T *object) {
|
||||
return sizeof(T);
|
||||
}
|
||||
};
|
||||
uint32_t getSerializedSize(const T *object) {
|
||||
return sizeof(T);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Template for objects that inherit from SerializeIF
|
||||
*
|
||||
* @tparam T A child of SerializeIF
|
||||
*/
|
||||
template<typename T>
|
||||
class InternalSerializeAdapter<T, true> {
|
||||
public:
|
||||
ReturnValue_t serialize(const T *object, uint8_t **buffer, size_t *size,
|
||||
size_t max_size,
|
||||
SerializeIF::Endianness streamEndianness) const {
|
||||
size_t ignoredSize = 0;
|
||||
if (size == nullptr) {
|
||||
size = &ignoredSize;
|
||||
}
|
||||
return object->serialize(buffer, size, max_size, streamEndianness);
|
||||
}
|
||||
size_t getSerializedSize(const T *object) const {
|
||||
return object->getSerializedSize();
|
||||
}
|
||||
/**
|
||||
* Template for objects that inherit from SerializeIF
|
||||
*
|
||||
* @tparam T A child of SerializeIF
|
||||
*/
|
||||
template<typename T>
|
||||
class InternalSerializeAdapter<T, true> {
|
||||
public:
|
||||
ReturnValue_t serialize(const T *object, uint8_t **buffer, size_t *size,
|
||||
size_t max_size,
|
||||
SerializeIF::Endianness streamEndianness) const {
|
||||
size_t ignoredSize = 0;
|
||||
if (size == nullptr) {
|
||||
size = &ignoredSize;
|
||||
}
|
||||
return object->serialize(buffer, size, max_size, streamEndianness);
|
||||
}
|
||||
size_t getSerializedSize(const T *object) const {
|
||||
return object->getSerializedSize();
|
||||
}
|
||||
|
||||
ReturnValue_t deSerialize(T *object, const uint8_t **buffer,
|
||||
size_t *size, SerializeIF::Endianness streamEndianness) {
|
||||
return object->deSerialize(buffer, size, streamEndianness);
|
||||
}
|
||||
};
|
||||
ReturnValue_t deSerialize(T *object, const uint8_t **buffer,
|
||||
size_t *size, SerializeIF::Endianness streamEndianness) {
|
||||
return object->deSerialize(buffer, size, streamEndianness);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
#endif /* _FSFW_SERIALIZE_SERIALIZEADAPTER_H_ */
|
||||
|
@ -73,7 +73,7 @@ namespace spacepacket {
|
||||
|
||||
constexpr uint16_t getSpacePacketIdFromApid(bool isTc, uint16_t apid,
|
||||
bool secondaryHeaderFlag = true) {
|
||||
return (((isTc << 5) & 0x10) | ((secondaryHeaderFlag << 4) & 0x08) |
|
||||
return ((isTc << 4) | (secondaryHeaderFlag << 3) |
|
||||
((apid >> 8) & 0x07)) << 8 | (apid & 0x00ff);
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ TEST_CASE("Ring Buffer Test" , "[RingBufferTest]") {
|
||||
TEST_CASE("Ring Buffer Test2" , "[RingBufferTest2]") {
|
||||
uint8_t testData[13]= {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
|
||||
uint8_t readBuffer[10] = {13, 13, 13, 13, 13, 13, 13, 13, 13, 13};
|
||||
uint8_t* newBuffer = new uint8_t[10];
|
||||
uint8_t* newBuffer = new uint8_t[15];
|
||||
SimpleRingBuffer ringBuffer(newBuffer, 10, true, 5);
|
||||
|
||||
SECTION("Simple Test") {
|
||||
@ -168,7 +168,7 @@ TEST_CASE("Ring Buffer Test2" , "[RingBufferTest2]") {
|
||||
TEST_CASE("Ring Buffer Test3" , "[RingBufferTest3]") {
|
||||
uint8_t testData[13]= {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
|
||||
uint8_t readBuffer[10] = {13, 13, 13, 13, 13, 13, 13, 13, 13, 13};
|
||||
uint8_t* newBuffer = new uint8_t[10];
|
||||
uint8_t* newBuffer = new uint8_t[25];
|
||||
SimpleRingBuffer ringBuffer(newBuffer, 10, true, 15);
|
||||
|
||||
SECTION("Simple Test") {
|
||||
|
@ -171,14 +171,19 @@ TEST_CASE("DataSetTest" , "[DataSetTest]") {
|
||||
/* We can do it like this because the buffer only has one byte for
|
||||
less than 8 variables */
|
||||
uint8_t* validityByte = buffer + sizeof(buffer) - 1;
|
||||
CHECK(bitutil::bitGet(validityByte, 0) == true);
|
||||
CHECK(bitutil::bitGet(validityByte, 1) == false);
|
||||
CHECK(bitutil::bitGet(validityByte, 2) == true);
|
||||
bool bitSet = false;
|
||||
bitutil::get(validityByte, 0, bitSet);
|
||||
|
||||
CHECK(bitSet == true);
|
||||
bitutil::get(validityByte, 1, bitSet);
|
||||
CHECK(bitSet == false);
|
||||
bitutil::get(validityByte, 2, bitSet);
|
||||
CHECK(bitSet == true);
|
||||
|
||||
/* Now we manipulate the validity buffer for the deserialization */
|
||||
bitutil::bitClear(validityByte, 0);
|
||||
bitutil::bitSet(validityByte, 1);
|
||||
bitutil::bitClear(validityByte, 2);
|
||||
bitutil::clear(validityByte, 0);
|
||||
bitutil::set(validityByte, 1);
|
||||
bitutil::clear(validityByte, 2);
|
||||
/* Zero out everything except validity buffer */
|
||||
std::memset(buffer, 0, sizeof(buffer) - 1);
|
||||
sizeToDeserialize = maxSize;
|
||||
@ -239,8 +244,11 @@ TEST_CASE("DataSetTest" , "[DataSetTest]") {
|
||||
std::memcpy(validityBuffer.data(), buffer + 9 + sizeof(uint16_t) * 3, 2);
|
||||
/* The first 9 variables should be valid */
|
||||
CHECK(validityBuffer[0] == 0xff);
|
||||
CHECK(bitutil::bitGet(validityBuffer.data() + 1, 0) == true);
|
||||
CHECK(bitutil::bitGet(validityBuffer.data() + 1, 1) == false);
|
||||
bool bitSet = false;
|
||||
bitutil::get(validityBuffer.data() + 1, 0, bitSet);
|
||||
CHECK(bitSet == true);
|
||||
bitutil::get(validityBuffer.data() + 1, 1, bitSet);
|
||||
CHECK(bitSet == false);
|
||||
|
||||
/* Now we invert the validity */
|
||||
validityBuffer[0] = 0;
|
||||
|
@ -143,7 +143,7 @@ TEST_CASE("LocalPoolManagerTest" , "[LocManTest]") {
|
||||
CHECK(cdsShort.msDay_h == Catch::Approx(timeCdsNow.msDay_h).margin(1));
|
||||
CHECK(cdsShort.msDay_hh == Catch::Approx(timeCdsNow.msDay_hh).margin(1));
|
||||
CHECK(cdsShort.msDay_l == Catch::Approx(timeCdsNow.msDay_l).margin(1));
|
||||
CHECK(cdsShort.msDay_ll == Catch::Approx(timeCdsNow.msDay_ll).margin(1));
|
||||
CHECK(cdsShort.msDay_ll == Catch::Approx(timeCdsNow.msDay_ll).margin(5));
|
||||
}
|
||||
|
||||
SECTION("VariableSnapshotTest") {
|
||||
@ -205,7 +205,7 @@ TEST_CASE("LocalPoolManagerTest" , "[LocManTest]") {
|
||||
CHECK(cdsShort.msDay_h == Catch::Approx(timeCdsNow.msDay_h).margin(1));
|
||||
CHECK(cdsShort.msDay_hh == Catch::Approx(timeCdsNow.msDay_hh).margin(1));
|
||||
CHECK(cdsShort.msDay_l == Catch::Approx(timeCdsNow.msDay_l).margin(1));
|
||||
CHECK(cdsShort.msDay_ll == Catch::Approx(timeCdsNow.msDay_ll).margin(1));
|
||||
CHECK(cdsShort.msDay_ll == Catch::Approx(timeCdsNow.msDay_ll).margin(5));
|
||||
}
|
||||
|
||||
SECTION("VariableNotificationTest") {
|
||||
|
@ -1,3 +1,5 @@
|
||||
target_sources(${FSFW_TEST_TGT} PRIVATE
|
||||
testDleEncoder.cpp
|
||||
testOpDivider.cpp
|
||||
testBitutil.cpp
|
||||
)
|
||||
|
64
tests/src/fsfw_tests/unit/globalfunctions/testBitutil.cpp
Normal file
64
tests/src/fsfw_tests/unit/globalfunctions/testBitutil.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
#include "fsfw/globalfunctions/bitutility.h"
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
TEST_CASE("Bitutility" , "[Bitutility]") {
|
||||
uint8_t dummyByte = 0;
|
||||
bool bitSet = false;
|
||||
for(uint8_t pos = 0; pos < 8; pos++) {
|
||||
bitutil::set(&dummyByte, pos);
|
||||
REQUIRE(dummyByte == (1 << (7 - pos)));
|
||||
bitutil::get(&dummyByte, pos, bitSet);
|
||||
REQUIRE(bitSet == 1);
|
||||
dummyByte = 0;
|
||||
}
|
||||
|
||||
dummyByte = 0xff;
|
||||
for(uint8_t pos = 0; pos < 8; pos++) {
|
||||
bitutil::get(&dummyByte, pos, bitSet);
|
||||
REQUIRE(bitSet == 1);
|
||||
bitutil::clear(&dummyByte, pos);
|
||||
bitutil::get(&dummyByte, pos, bitSet);
|
||||
REQUIRE(bitSet == 0);
|
||||
dummyByte = 0xff;
|
||||
}
|
||||
|
||||
dummyByte = 0xf0;
|
||||
for(uint8_t pos = 0; pos < 8; pos++) {
|
||||
if(pos < 4) {
|
||||
bitutil::get(&dummyByte, pos, bitSet);
|
||||
REQUIRE(bitSet == 1);
|
||||
bitutil::toggle(&dummyByte, pos);
|
||||
bitutil::get(&dummyByte, pos, bitSet);
|
||||
REQUIRE(bitSet == 0);
|
||||
}
|
||||
else {
|
||||
bitutil::get(&dummyByte, pos, bitSet);
|
||||
REQUIRE(bitSet == false);
|
||||
bitutil::toggle(&dummyByte, pos);
|
||||
bitutil::get(&dummyByte, pos, bitSet);
|
||||
REQUIRE(bitSet == true);
|
||||
}
|
||||
}
|
||||
REQUIRE(dummyByte == 0x0f);
|
||||
|
||||
dummyByte = 0;
|
||||
bitutil::set(&dummyByte, 8);
|
||||
REQUIRE(dummyByte == 0);
|
||||
bitutil::set(&dummyByte, -1);
|
||||
REQUIRE(dummyByte == 0);
|
||||
dummyByte = 0xff;
|
||||
bitutil::clear(&dummyByte, 8);
|
||||
REQUIRE(dummyByte == 0xff);
|
||||
bitutil::clear(&dummyByte, -1);
|
||||
REQUIRE(dummyByte == 0xff);
|
||||
dummyByte = 0x00;
|
||||
bitutil::toggle(&dummyByte, 8);
|
||||
REQUIRE(dummyByte == 0x00);
|
||||
bitutil::toggle(&dummyByte, -1);
|
||||
REQUIRE(dummyByte == 0x00);
|
||||
|
||||
REQUIRE(bitutil::get(&dummyByte, 8, bitSet) == false);
|
||||
}
|
||||
|
||||
|
||||
|
64
tests/src/fsfw_tests/unit/globalfunctions/testOpDivider.cpp
Normal file
64
tests/src/fsfw_tests/unit/globalfunctions/testOpDivider.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
#include "fsfw/globalfunctions/PeriodicOperationDivider.h"
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
TEST_CASE("OpDivider" , "[OpDivider]") {
|
||||
auto opDivider = PeriodicOperationDivider(1);
|
||||
REQUIRE(opDivider.getDivider() == 1);
|
||||
REQUIRE(opDivider.getCounter() == 1);
|
||||
REQUIRE(opDivider.check() == true);
|
||||
REQUIRE(opDivider.checkAndIncrement() == true);
|
||||
REQUIRE(opDivider.getCounter() == 1);
|
||||
REQUIRE(opDivider.check() == true);
|
||||
REQUIRE(opDivider.checkAndIncrement() == true);
|
||||
REQUIRE(opDivider.checkAndIncrement() == true);
|
||||
|
||||
opDivider.setDivider(0);
|
||||
REQUIRE(opDivider.getCounter() == 1);
|
||||
REQUIRE(opDivider.checkAndIncrement() == true);
|
||||
REQUIRE(opDivider.getCounter() == 1);
|
||||
REQUIRE(opDivider.checkAndIncrement() == true);
|
||||
REQUIRE(opDivider.checkAndIncrement() == true);
|
||||
|
||||
opDivider.setDivider(2);
|
||||
opDivider.resetCounter();
|
||||
REQUIRE(opDivider.getDivider() == 2);
|
||||
REQUIRE(opDivider.getCounter() == 1);
|
||||
REQUIRE(opDivider.check() == false);
|
||||
REQUIRE(opDivider.checkAndIncrement() == false);
|
||||
REQUIRE(opDivider.getCounter() == 2);
|
||||
REQUIRE(opDivider.check() == true);
|
||||
REQUIRE(opDivider.checkAndIncrement() == true);
|
||||
REQUIRE(opDivider.getCounter() == 1);
|
||||
REQUIRE(opDivider.check() == false);
|
||||
REQUIRE(opDivider.checkAndIncrement() == false);
|
||||
REQUIRE(opDivider.getCounter() == 2);
|
||||
REQUIRE(opDivider.checkAndIncrement() == true);
|
||||
REQUIRE(opDivider.checkAndIncrement() == false);
|
||||
REQUIRE(opDivider.checkAndIncrement() == true);
|
||||
REQUIRE(opDivider.checkAndIncrement() == false);
|
||||
|
||||
opDivider.setDivider(3);
|
||||
opDivider.resetCounter();
|
||||
REQUIRE(opDivider.checkAndIncrement() == false);
|
||||
REQUIRE(opDivider.checkAndIncrement() == false);
|
||||
REQUIRE(opDivider.getCounter() == 3);
|
||||
REQUIRE(opDivider.checkAndIncrement() == true);
|
||||
REQUIRE(opDivider.getCounter() == 1);
|
||||
REQUIRE(opDivider.checkAndIncrement() == false);
|
||||
|
||||
auto opDividerNonResetting = PeriodicOperationDivider(2, false);
|
||||
REQUIRE(opDividerNonResetting.getCounter() == 1);
|
||||
REQUIRE(opDividerNonResetting.check() == false);
|
||||
REQUIRE(opDividerNonResetting.checkAndIncrement() == false);
|
||||
REQUIRE(opDividerNonResetting.getCounter() == 2);
|
||||
REQUIRE(opDividerNonResetting.check() == true);
|
||||
REQUIRE(opDividerNonResetting.checkAndIncrement() == true);
|
||||
REQUIRE(opDividerNonResetting.getCounter() == 3);
|
||||
REQUIRE(opDividerNonResetting.checkAndIncrement() == true);
|
||||
REQUIRE(opDividerNonResetting.getCounter() == 4);
|
||||
opDividerNonResetting.resetCounter();
|
||||
REQUIRE(opDividerNonResetting.getCounter() == 1);
|
||||
REQUIRE(opDividerNonResetting.check() == false);
|
||||
REQUIRE(opDividerNonResetting.checkAndIncrement() == false);
|
||||
REQUIRE(opDividerNonResetting.getCounter() == 2);
|
||||
}
|
@ -3,128 +3,213 @@
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/catch_approx.hpp>
|
||||
#include <fsfw/serialize/SerialBufferAdapter.h>
|
||||
|
||||
#include <array>
|
||||
|
||||
static bool test_value_bool = true;
|
||||
static uint8_t tv_uint8 {5};
|
||||
static uint16_t tv_uint16 {283};
|
||||
static uint32_t tv_uint32 {929221};
|
||||
static uint64_t tv_uint64 {2929329429};
|
||||
static bool testBool = true;
|
||||
static uint8_t tvUint8 {5};
|
||||
static uint16_t tvUint16 {283};
|
||||
static uint32_t tvUint32 {929221};
|
||||
static uint64_t tvUint64 {2929329429};
|
||||
|
||||
static int8_t tv_int8 {-16};
|
||||
static int16_t tv_int16 {-829};
|
||||
static int32_t tv_int32 {-2312};
|
||||
static int8_t tvInt8 {-16};
|
||||
static int16_t tvInt16 {-829};
|
||||
static int32_t tvInt32 {-2312};
|
||||
|
||||
static float tv_float {8.2149214};
|
||||
static float tv_sfloat = {-922.2321321};
|
||||
static double tv_double {9.2132142141e8};
|
||||
static double tv_sdouble {-2.2421e19};
|
||||
static float tvFloat {8.2149214};
|
||||
static float tvSfloat = {-922.2321321};
|
||||
static double tvDouble {9.2132142141e8};
|
||||
static double tvSdouble {-2.2421e19};
|
||||
|
||||
static std::array<uint8_t, 512> test_array;
|
||||
static std::array<uint8_t, 512> TEST_ARRAY;
|
||||
|
||||
TEST_CASE( "Serialization size tests", "[TestSerialization]") {
|
||||
TEST_CASE( "Serialization size tests", "[SerSizeTest]") {
|
||||
//REQUIRE(unitTestClass.test_autoserialization() == 0);
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&test_value_bool) ==
|
||||
sizeof(test_value_bool));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tv_uint8) ==
|
||||
sizeof(tv_uint8));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tv_uint16) ==
|
||||
sizeof(tv_uint16));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tv_uint32 ) ==
|
||||
sizeof(tv_uint32));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tv_uint64) ==
|
||||
sizeof(tv_uint64));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tv_int8) ==
|
||||
sizeof(tv_int8));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tv_int16) ==
|
||||
sizeof(tv_int16));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tv_int32) ==
|
||||
sizeof(tv_int32));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tv_float) ==
|
||||
sizeof(tv_float));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tv_sfloat) ==
|
||||
sizeof(tv_sfloat ));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tv_double) ==
|
||||
sizeof(tv_double));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tv_sdouble) ==
|
||||
sizeof(tv_sdouble));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&testBool) ==
|
||||
sizeof(testBool));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tvUint8) ==
|
||||
sizeof(tvUint8));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tvUint16) ==
|
||||
sizeof(tvUint16));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tvUint32 ) ==
|
||||
sizeof(tvUint32));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tvUint64) ==
|
||||
sizeof(tvUint64));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tvInt8) ==
|
||||
sizeof(tvInt8));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tvInt16) ==
|
||||
sizeof(tvInt16));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tvInt32) ==
|
||||
sizeof(tvInt32));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tvFloat) ==
|
||||
sizeof(tvFloat));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tvSfloat) ==
|
||||
sizeof(tvSfloat ));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tvDouble) ==
|
||||
sizeof(tvDouble));
|
||||
REQUIRE(SerializeAdapter::getSerializedSize(&tvSdouble) ==
|
||||
sizeof(tvSdouble));
|
||||
}
|
||||
|
||||
TEST_CASE("Auto Serialize Adapter", "[SerAdapter]") {
|
||||
size_t serializedSize = 0;
|
||||
uint8_t * pArray = TEST_ARRAY.data();
|
||||
|
||||
TEST_CASE("Auto Serialize Adapter testing", "[single-file]") {
|
||||
size_t serialized_size = 0;
|
||||
uint8_t * p_array = test_array.data();
|
||||
SECTION("SerDe") {
|
||||
size_t deserSize = 0;
|
||||
SerializeAdapter::serialize(&testBool, TEST_ARRAY.data(), &deserSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(deserSize == 1);
|
||||
REQUIRE(TEST_ARRAY[0] == true);
|
||||
bool readBack = false;
|
||||
SerializeAdapter::deSerialize(&readBack, TEST_ARRAY.data(), &deserSize,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(deserSize == 1);
|
||||
REQUIRE(readBack == true);
|
||||
SerializeAdapter::serialize(&tvUint8, TEST_ARRAY.data(), &deserSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(deserSize == 1);
|
||||
REQUIRE(TEST_ARRAY[0] == 5);
|
||||
uint8_t readBackUint8 = 0;
|
||||
uint8_t* const testPtr = TEST_ARRAY.data();
|
||||
uint8_t* const shouldStayConst = testPtr;
|
||||
SerializeAdapter::deSerialize(&readBackUint8, testPtr, &deserSize,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(testPtr == shouldStayConst);
|
||||
REQUIRE(deserSize == 1);
|
||||
REQUIRE(readBackUint8 == 5);
|
||||
SerializeAdapter::serialize(&tvUint16, TEST_ARRAY.data(), &deserSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(deserSize == 2);
|
||||
deserSize = 0;
|
||||
uint16_t readBackUint16 = 0;
|
||||
SerializeAdapter::deSerialize(&readBackUint16, TEST_ARRAY.data(), &deserSize,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(deserSize == 2);
|
||||
REQUIRE(readBackUint16 == 283);
|
||||
|
||||
SECTION("Serializing...") {
|
||||
SerializeAdapter::serialize(&test_value_bool, &p_array,
|
||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv_uint8, &p_array,
|
||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv_uint16, &p_array,
|
||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv_uint32, &p_array,
|
||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv_int8, &p_array,
|
||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv_int16, &p_array,
|
||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv_int32, &p_array,
|
||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv_uint64, &p_array,
|
||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv_float, &p_array,
|
||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv_double, &p_array,
|
||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv_sfloat, &p_array,
|
||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tv_sdouble, &p_array,
|
||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE (serialized_size == 47);
|
||||
SerializeAdapter::serialize(&tvUint32, TEST_ARRAY.data(), &deserSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(deserSize == 4);
|
||||
uint32_t readBackUint32 = 0;
|
||||
deserSize = 0;
|
||||
SerializeAdapter::deSerialize(&readBackUint32, TEST_ARRAY.data(), &deserSize,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(deserSize == 4);
|
||||
REQUIRE(readBackUint32 == 929221);
|
||||
|
||||
SerializeAdapter::serialize(&tvInt16, TEST_ARRAY.data(), &deserSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(deserSize == 2);
|
||||
int16_t readBackInt16 = 0;
|
||||
SerializeAdapter::deSerialize(&readBackInt16, TEST_ARRAY.data(), &deserSize,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(readBackInt16 == -829);
|
||||
REQUIRE(deserSize == 2);
|
||||
|
||||
SerializeAdapter::serialize(&tvFloat, TEST_ARRAY.data(), &deserSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
float readBackFloat = 0.0;
|
||||
SerializeAdapter::deSerialize(&readBackFloat, TEST_ARRAY.data(), &deserSize,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(readBackFloat == Catch::Approx(8.214921));
|
||||
|
||||
SerializeAdapter::serialize(&tvSdouble, TEST_ARRAY.data(), &deserSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
double readBackSignedDouble = 0.0;
|
||||
SerializeAdapter::deSerialize(&readBackSignedDouble, TEST_ARRAY.data(), &deserSize,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(readBackSignedDouble == Catch::Approx(-2.2421e19));
|
||||
|
||||
uint8_t testBuf[4] = {1, 2, 3, 4};
|
||||
SerialBufferAdapter<uint8_t> bufferAdapter(testBuf, sizeof(testBuf));
|
||||
SerializeAdapter::serialize(&bufferAdapter, TEST_ARRAY.data(), &deserSize,
|
||||
TEST_ARRAY.size(), SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(deserSize == 4);
|
||||
for(uint8_t idx = 0; idx < 4; idx++) {
|
||||
REQUIRE(TEST_ARRAY[idx] == idx + 1);
|
||||
}
|
||||
deserSize = 0;
|
||||
testBuf[0] = 0;
|
||||
testBuf[1] = 12;
|
||||
SerializeAdapter::deSerialize(&bufferAdapter, TEST_ARRAY.data(), &deserSize,
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(deserSize == 4);
|
||||
for(uint8_t idx = 0; idx < 4; idx++) {
|
||||
REQUIRE(testBuf[idx] == idx + 1);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Serialize incrementing") {
|
||||
SerializeAdapter::serialize(&testBool, &pArray, &serializedSize,
|
||||
TEST_ARRAY.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tvUint8, &pArray, &serializedSize,
|
||||
TEST_ARRAY.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tvUint16, &pArray, &serializedSize,
|
||||
TEST_ARRAY.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tvUint32, &pArray, &serializedSize,
|
||||
TEST_ARRAY.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tvInt8, &pArray, &serializedSize,
|
||||
TEST_ARRAY.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tvInt16, &pArray, &serializedSize,
|
||||
TEST_ARRAY.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tvInt32, &pArray, &serializedSize,
|
||||
TEST_ARRAY.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tvUint64, &pArray, &serializedSize,
|
||||
TEST_ARRAY.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tvFloat, &pArray, &serializedSize,
|
||||
TEST_ARRAY.size(), SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tvDouble, &pArray, &serializedSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tvSfloat, &pArray, &serializedSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::serialize(&tvSdouble, &pArray, &serializedSize, TEST_ARRAY.size(),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE (serializedSize == 47);
|
||||
}
|
||||
|
||||
SECTION("Deserializing") {
|
||||
p_array = test_array.data();
|
||||
size_t remaining_size = serialized_size;
|
||||
SerializeAdapter::deSerialize(&test_value_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);
|
||||
SECTION("Deserialize decrementing") {
|
||||
pArray = TEST_ARRAY.data();
|
||||
size_t remaining_size = serializedSize;
|
||||
SerializeAdapter::deSerialize(&testBool, const_cast<const uint8_t**>(&pArray),
|
||||
&remaining_size, SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tvUint8, const_cast<const uint8_t**>(&pArray),
|
||||
&remaining_size, SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tvUint16, const_cast<const uint8_t**>(&pArray),
|
||||
&remaining_size, SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tvUint32, const_cast<const uint8_t**>(&pArray),
|
||||
&remaining_size, SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tvInt8, const_cast<const uint8_t**>(&pArray),
|
||||
&remaining_size, SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tvInt16, const_cast<const uint8_t**>(&pArray),
|
||||
&remaining_size, SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tvInt32, const_cast<const uint8_t**>(&pArray),
|
||||
&remaining_size, SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tvUint64,
|
||||
const_cast<const uint8_t**>(&pArray), &remaining_size, SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tvFloat,
|
||||
const_cast<const uint8_t**>(&pArray), &remaining_size, SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tvDouble,
|
||||
const_cast<const uint8_t**>(&pArray), &remaining_size, SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tvSfloat,
|
||||
const_cast<const uint8_t**>(&pArray), &remaining_size, SerializeIF::Endianness::MACHINE);
|
||||
SerializeAdapter::deSerialize(&tvSdouble,
|
||||
const_cast<const uint8_t**>(&pArray), &remaining_size, SerializeIF::Endianness::MACHINE);
|
||||
|
||||
REQUIRE(test_value_bool == true);
|
||||
REQUIRE(tv_uint8 == 5);
|
||||
REQUIRE(tv_uint16 == 283);
|
||||
REQUIRE(tv_uint32 == 929221);
|
||||
REQUIRE(tv_uint64 == 2929329429);
|
||||
REQUIRE(tv_int8 == -16);
|
||||
REQUIRE(tv_int16 == -829);
|
||||
REQUIRE(tv_int32 == -2312);
|
||||
REQUIRE(testBool == true);
|
||||
REQUIRE(tvUint8 == 5);
|
||||
REQUIRE(tvUint16 == 283);
|
||||
REQUIRE(tvUint32 == 929221);
|
||||
REQUIRE(tvUint64 == 2929329429);
|
||||
REQUIRE(tvInt8 == -16);
|
||||
REQUIRE(tvInt16 == -829);
|
||||
REQUIRE(tvInt32 == -2312);
|
||||
|
||||
REQUIRE(tv_float == Catch::Approx(8.214921));
|
||||
REQUIRE(tv_double == Catch::Approx(9.2132142141e8));
|
||||
REQUIRE(tv_sfloat == Catch::Approx(-922.2321321));
|
||||
REQUIRE(tv_sdouble == Catch::Approx(-2.2421e19));
|
||||
REQUIRE(tvFloat == Catch::Approx(8.214921));
|
||||
REQUIRE(tvDouble == Catch::Approx(9.2132142141e8));
|
||||
REQUIRE(tvSfloat == Catch::Approx(-922.2321321));
|
||||
REQUIRE(tvSdouble == Catch::Approx(-2.2421e19));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
target_sources(${FSFW_TEST_TGT} PRIVATE
|
||||
PusTmTest.cpp
|
||||
testCcsds.cpp
|
||||
)
|
||||
|
11
tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp
Normal file
11
tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "fsfw/tmtcpacket/SpacePacket.h"
|
||||
|
||||
TEST_CASE( "CCSDS Test" , "[ccsds]") {
|
||||
REQUIRE(spacepacket::getTcSpacePacketIdFromApid(0x22) == 0x1822);
|
||||
REQUIRE(spacepacket::getTmSpacePacketIdFromApid(0x22) == 0x0822);
|
||||
|
||||
REQUIRE(spacepacket::getTcSpacePacketIdFromApid(0x7ff) == 0x1fff);
|
||||
REQUIRE(spacepacket::getTmSpacePacketIdFromApid(0x7ff) == 0xfff);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user