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
|
#tzdata is a dependency, won't install otherwise
|
||||||
ARG DEBIAN_FRONTEND=noninteractive
|
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];
|
uint8_t cmmValue = packet[1];
|
||||||
// We clear the seventh bit in any case
|
// We clear the seventh bit in any case
|
||||||
// because this one is zero sometimes for some reason
|
// 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) {
|
if(cmmValue == cmmRegValue and internalState == InternalState::READ_CMM) {
|
||||||
commandExecuted = true;
|
commandExecuted = true;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import platform
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import argparse
|
import argparse
|
||||||
|
import webbrowser
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
@ -18,6 +19,10 @@ information how to set up the build folder.
|
|||||||
def main():
|
def main():
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Processing arguments for LCOV helper script.")
|
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 = []
|
build_dir_list = []
|
||||||
if not os.path.isfile('README.md'):
|
if not os.path.isfile('README.md'):
|
||||||
@ -41,6 +46,8 @@ def main():
|
|||||||
print("Multiple build directories found!")
|
print("Multiple build directories found!")
|
||||||
build_directory = determine_build_dir(build_dir_list)
|
build_directory = determine_build_dir(build_dir_list)
|
||||||
perform_lcov_operation(build_directory)
|
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):
|
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++) {
|
for (uint16_t count = 0; count < fillCount; count++) {
|
||||||
if(registeredVariables[count]->isValid()) {
|
if(registeredVariables[count]->isValid()) {
|
||||||
/* Set bit at correct position */
|
/* Set bit at correct position */
|
||||||
bitutil::bitSet(validityPtr + validBufferIndex, validBufferIndexBit);
|
bitutil::set(validityPtr + validBufferIndex, validBufferIndexBit);
|
||||||
}
|
}
|
||||||
if(validBufferIndexBit == 7) {
|
if(validBufferIndexBit == 7) {
|
||||||
validBufferIndex ++;
|
validBufferIndex ++;
|
||||||
@ -156,8 +156,8 @@ ReturnValue_t LocalPoolDataSetBase::deSerializeWithValidityBuffer(
|
|||||||
uint8_t validBufferIndexBit = 0;
|
uint8_t validBufferIndexBit = 0;
|
||||||
for (uint16_t count = 0; count < fillCount; count++) {
|
for (uint16_t count = 0; count < fillCount; count++) {
|
||||||
// set validity buffer here.
|
// set validity buffer here.
|
||||||
bool nextVarValid = bitutil::bitGet(*buffer +
|
bool nextVarValid = false;
|
||||||
validBufferIndex, validBufferIndexBit);
|
bitutil::get(*buffer + validBufferIndex, validBufferIndexBit, nextVarValid);
|
||||||
registeredVariables[count]->setValid(nextVarValid);
|
registeredVariables[count]->setValid(nextVarValid);
|
||||||
|
|
||||||
if(validBufferIndexBit == 7) {
|
if(validBufferIndexBit == 7) {
|
||||||
|
@ -2,43 +2,40 @@
|
|||||||
|
|
||||||
|
|
||||||
PeriodicOperationDivider::PeriodicOperationDivider(uint32_t divider,
|
PeriodicOperationDivider::PeriodicOperationDivider(uint32_t divider,
|
||||||
bool resetAutomatically): resetAutomatically(resetAutomatically),
|
bool resetAutomatically): resetAutomatically(resetAutomatically),
|
||||||
counter(divider), divider(divider) {
|
divider(divider) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PeriodicOperationDivider::checkAndIncrement() {
|
bool PeriodicOperationDivider::checkAndIncrement() {
|
||||||
bool opNecessary = check();
|
bool opNecessary = check();
|
||||||
if(opNecessary) {
|
if(opNecessary and resetAutomatically) {
|
||||||
if(resetAutomatically) {
|
resetCounter();
|
||||||
counter = 0;
|
}
|
||||||
}
|
else {
|
||||||
return opNecessary;
|
counter++;
|
||||||
}
|
}
|
||||||
counter ++;
|
return opNecessary;
|
||||||
return opNecessary;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PeriodicOperationDivider::check() {
|
bool PeriodicOperationDivider::check() {
|
||||||
if(counter >= divider) {
|
if(counter >= divider) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PeriodicOperationDivider::resetCounter() {
|
void PeriodicOperationDivider::resetCounter() {
|
||||||
counter = 0;
|
counter = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeriodicOperationDivider::setDivider(uint32_t newDivider) {
|
void PeriodicOperationDivider::setDivider(uint32_t newDivider) {
|
||||||
divider = newDivider;
|
divider = newDivider;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t PeriodicOperationDivider::getCounter() const {
|
uint32_t PeriodicOperationDivider::getCounter() const {
|
||||||
return counter;
|
return counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t PeriodicOperationDivider::getDivider() const {
|
uint32_t PeriodicOperationDivider::getDivider() const {
|
||||||
return divider;
|
return divider;
|
||||||
}
|
}
|
||||||
|
@ -13,51 +13,50 @@
|
|||||||
*/
|
*/
|
||||||
class PeriodicOperationDivider {
|
class PeriodicOperationDivider {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Initialize with the desired divider and specify whether the internal
|
* Initialize with the desired divider and specify whether the internal
|
||||||
* counter will be reset automatically.
|
* counter will be reset automatically.
|
||||||
* @param divider
|
* @param divider Value of 0 or 1 will cause #check and #checkAndIncrement to always return
|
||||||
* @param resetAutomatically
|
* true
|
||||||
*/
|
* @param resetAutomatically
|
||||||
PeriodicOperationDivider(uint32_t divider, bool resetAutomatically = true);
|
*/
|
||||||
|
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.
|
* Checks whether an operation is necessary. This function will not increment the counter.
|
||||||
* If an operation is necessary and the class has been
|
* @return
|
||||||
* configured to be reset automatically, the counter will be reset.
|
* -@c true if the counter is larger or equal to the divider
|
||||||
*
|
* -@c false otherwise
|
||||||
* @return
|
*/
|
||||||
* -@c true if the counter is larger or equal to the divider
|
bool check();
|
||||||
* -@c false otherwise
|
|
||||||
*/
|
|
||||||
bool checkAndIncrement();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether an operation is necessary.
|
* Can be used to reset the counter to 1 manually
|
||||||
* This function will not increment the counter!
|
*/
|
||||||
* @return
|
void resetCounter();
|
||||||
* -@c true if the counter is larger or equal to the divider
|
uint32_t getCounter() const;
|
||||||
* -@c false otherwise
|
|
||||||
*/
|
|
||||||
bool check();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can be used to reset the counter to 0 manually.
|
* Can be used to set a new divider value.
|
||||||
*/
|
* @param newDivider
|
||||||
void resetCounter();
|
*/
|
||||||
uint32_t getCounter() const;
|
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:
|
private:
|
||||||
bool resetAutomatically = true;
|
bool resetAutomatically = true;
|
||||||
uint32_t counter = 0;
|
uint32_t counter = 1;
|
||||||
uint32_t divider = 0;
|
uint32_t divider = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "fsfw/globalfunctions/bitutility.h"
|
#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) {
|
if(position > 7) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -8,7 +8,7 @@ void bitutil::bitSet(uint8_t *byte, uint8_t position) {
|
|||||||
*byte |= 1 << shiftNumber;
|
*byte |= 1 << shiftNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bitutil::bitToggle(uint8_t *byte, uint8_t position) {
|
void bitutil::toggle(uint8_t *byte, uint8_t position) {
|
||||||
if(position > 7) {
|
if(position > 7) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -16,7 +16,7 @@ void bitutil::bitToggle(uint8_t *byte, uint8_t position) {
|
|||||||
*byte ^= 1 << shiftNumber;
|
*byte ^= 1 << shiftNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bitutil::bitClear(uint8_t *byte, uint8_t position) {
|
void bitutil::clear(uint8_t *byte, uint8_t position) {
|
||||||
if(position > 7) {
|
if(position > 7) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -24,10 +24,11 @@ void bitutil::bitClear(uint8_t *byte, uint8_t position) {
|
|||||||
*byte &= ~(1 << shiftNumber);
|
*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) {
|
if(position > 7) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
uint8_t shiftNumber = position + (7 - 2 * position);
|
uint8_t shiftNumber = position + (7 - 2 * position);
|
||||||
return *byte & (1 << shiftNumber);
|
bit = *byte & (1 << shiftNumber);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -5,13 +5,36 @@
|
|||||||
|
|
||||||
namespace bitutil {
|
namespace bitutil {
|
||||||
|
|
||||||
/* Helper functions for manipulating the individual bits of a byte.
|
// 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
|
// Position refers to n-th bit of a byte, going from 0 (most significant bit) to
|
||||||
7 (least significant bit) */
|
// 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);
|
* @brief Set the bit in a given byte
|
||||||
bool bitGet(const uint8_t* byte, uint8_t position);
|
* @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 <cstddef>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief These adapters provides an interface to use the SerializeIF functions
|
* @brief These adapters provides an interface to use the SerializeIF functions
|
||||||
* with arbitrary template objects to facilitate and simplify the
|
* with arbitrary template objects to facilitate and simplify the
|
||||||
* serialization of classes with different multiple different data types
|
* serialization of classes with different multiple different data types
|
||||||
@ -20,174 +20,250 @@
|
|||||||
*/
|
*/
|
||||||
class SerializeAdapter {
|
class SerializeAdapter {
|
||||||
public:
|
public:
|
||||||
/***
|
/***
|
||||||
* This function can be used to serialize a trivial copy-able type or a
|
* @brief Serialize a trivial copy-able type or a child of SerializeIF.
|
||||||
* child of SerializeIF.
|
* @details
|
||||||
* The right template to be called is determined in the function itself.
|
* 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
|
* For objects of non trivial copy-able type this function is almost never
|
||||||
* called by the user directly. Instead helpers for specific types like
|
* called by the user directly. Instead helpers for specific types like
|
||||||
* SerialArrayListAdapter or SerialLinkedListAdapter is the right choice here.
|
* SerialArrayListAdapter or SerialLinkedListAdapter are the right choice here.
|
||||||
*
|
*
|
||||||
* @param[in] object Object to serialize, the used type is deduced from this pointer
|
* @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] buffer: Pointer to the buffer to serialize into. Buffer position will be
|
||||||
* @param[in/out] size Size of current written buffer. Will be incremented by the function.
|
* incremented by the function.
|
||||||
* @param[in] maxSize Max size of Buffer
|
* @param[in/out] size: Pointer to size of current written buffer.
|
||||||
* @param[in] streamEndianness Endianness of serialized element as in according to SerializeIF::Endianness
|
* SIze will be incremented by the function.
|
||||||
* @return
|
* @param[in] maxSize: Max size of Buffer
|
||||||
* - @c BUFFER_TOO_SHORT The given buffer in is too short
|
* @param[in] streamEndianness: Endianness of serialized element as in according to
|
||||||
* - @c RETURN_FAILED Generic Error
|
* SerializeIF::Endianness
|
||||||
* - @c RETURN_OK Successful serialization
|
* @return
|
||||||
*/
|
* - @c BUFFER_TOO_SHORT The given buffer in is too short
|
||||||
template<typename T>
|
* - @c RETURN_FAILED Generic Error
|
||||||
static ReturnValue_t serialize(const T *object, uint8_t **buffer,
|
* - @c RETURN_OK Successful serialization
|
||||||
size_t *size, size_t maxSize,
|
*/
|
||||||
SerializeIF::Endianness streamEndianness) {
|
template<typename T>
|
||||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
static ReturnValue_t serialize(const T *object, uint8_t **buffer,
|
||||||
return adapter.serialize(object, buffer, size, maxSize,
|
size_t *size, size_t maxSize,
|
||||||
streamEndianness);
|
SerializeIF::Endianness streamEndianness) {
|
||||||
}
|
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||||
/**
|
return adapter.serialize(object, buffer, size, maxSize,
|
||||||
* Function to return the serialized size of the object in the pointer.
|
streamEndianness);
|
||||||
* May be a trivially copy-able object or a Child of SerializeIF
|
}
|
||||||
*
|
|
||||||
* @param object Pointer to Object
|
/***
|
||||||
* @return Serialized size of object
|
* 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.
|
||||||
template<typename T>
|
* For objects of non trivial copy-able type this function is almost never
|
||||||
static size_t getSerializedSize(const T *object){
|
* called by the user directly. Instead helpers for specific types like
|
||||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
* SerialArrayListAdapter or SerialLinkedListAdapter are the right choice here.
|
||||||
return adapter.getSerializedSize(object);
|
*
|
||||||
}
|
* @param[in] object: Object to serialize, the used type is deduced from this pointer
|
||||||
/**
|
* @param[in/out] buffer: Buffer to serialize into.
|
||||||
* @brief
|
* @param[out] serSize: Serialized size
|
||||||
* Deserializes a object from a given buffer of given size.
|
* @param[in] maxSize: Max size of buffer
|
||||||
* Object Must be trivially copy-able or a child of SerializeIF.
|
* @param[in] streamEndianness: Endianness of serialized element as in according to
|
||||||
*
|
* SerializeIF::Endianness
|
||||||
* @details
|
* @return
|
||||||
* Buffer will be moved to the current read location. Size will be decreased by the function.
|
* - @c BUFFER_TOO_SHORT The given buffer in is too short
|
||||||
*
|
* - @c RETURN_FAILED Generic Error
|
||||||
* @param[in/out] buffer Buffer to deSerialize from. Will be moved by the function.
|
* - @c RETURN_OK Successful serialization
|
||||||
* @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
|
template<typename T>
|
||||||
* @return
|
static ReturnValue_t serialize(const T *object, uint8_t* const buffer, size_t* serSize,
|
||||||
* - @c STREAM_TOO_SHORT The input stream is too short to deSerialize the object
|
size_t maxSize, SerializeIF::Endianness streamEndianness) {
|
||||||
* - @c TOO_MANY_ELEMENTS The buffer has more inputs than expected
|
if(object == nullptr or buffer == nullptr) {
|
||||||
* - @c RETURN_FAILED Generic Error
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
* - @c RETURN_OK Successful deserialization
|
}
|
||||||
*/
|
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||||
template<typename T>
|
uint8_t** tempPtr = const_cast<uint8_t**>(&buffer);
|
||||||
static ReturnValue_t deSerialize(T *object, const uint8_t **buffer,
|
size_t tmpSize = 0;
|
||||||
size_t *size, SerializeIF::Endianness streamEndianness) {
|
ReturnValue_t result = adapter.serialize(object, tempPtr, &tmpSize, maxSize,
|
||||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
streamEndianness);
|
||||||
return adapter.deSerialize(object, buffer, size, 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:
|
private:
|
||||||
/**
|
/**
|
||||||
* Internal template to deduce the right function calls at compile time
|
* Internal template to deduce the right function calls at compile time
|
||||||
*/
|
*/
|
||||||
template<typename T, bool> class InternalSerializeAdapter;
|
template<typename T, bool> class InternalSerializeAdapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Template to be used if T is not a child of SerializeIF
|
* Template to be used if T is not a child of SerializeIF
|
||||||
*
|
*
|
||||||
* @tparam T T must be trivially_copyable
|
* @tparam T T must be trivially_copyable
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class InternalSerializeAdapter<T, false> {
|
class InternalSerializeAdapter<T, false> {
|
||||||
static_assert (std::is_trivially_copyable<T>::value,
|
static_assert (std::is_trivially_copyable<T>::value,
|
||||||
"If a type needs to be serialized it must be a child of "
|
"If a type needs to be serialized it must be a child of "
|
||||||
"SerializeIF or trivially copy-able");
|
"SerializeIF or trivially copy-able");
|
||||||
public:
|
public:
|
||||||
static ReturnValue_t serialize(const T *object, uint8_t **buffer,
|
static ReturnValue_t serialize(const T *object, uint8_t **buffer,
|
||||||
size_t *size, size_t max_size,
|
size_t *size, size_t max_size,
|
||||||
SerializeIF::Endianness streamEndianness) {
|
SerializeIF::Endianness streamEndianness) {
|
||||||
size_t ignoredSize = 0;
|
size_t ignoredSize = 0;
|
||||||
if (size == nullptr) {
|
if (size == nullptr) {
|
||||||
size = &ignoredSize;
|
size = &ignoredSize;
|
||||||
}
|
}
|
||||||
// Check remaining size is large enough and check integer
|
// Check remaining size is large enough and check integer
|
||||||
// overflow of *size
|
// overflow of *size
|
||||||
size_t newSize = sizeof(T) + *size;
|
size_t newSize = sizeof(T) + *size;
|
||||||
if ((newSize <= max_size) and (newSize > *size)) {
|
if ((newSize <= max_size) and (newSize > *size)) {
|
||||||
T tmp;
|
T tmp;
|
||||||
switch (streamEndianness) {
|
switch (streamEndianness) {
|
||||||
case SerializeIF::Endianness::BIG:
|
case SerializeIF::Endianness::BIG:
|
||||||
tmp = EndianConverter::convertBigEndian<T>(*object);
|
tmp = EndianConverter::convertBigEndian<T>(*object);
|
||||||
break;
|
break;
|
||||||
case SerializeIF::Endianness::LITTLE:
|
case SerializeIF::Endianness::LITTLE:
|
||||||
tmp = EndianConverter::convertLittleEndian<T>(*object);
|
tmp = EndianConverter::convertLittleEndian<T>(*object);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
case SerializeIF::Endianness::MACHINE:
|
case SerializeIF::Endianness::MACHINE:
|
||||||
tmp = *object;
|
tmp = *object;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
std::memcpy(*buffer, &tmp, sizeof(T));
|
std::memcpy(*buffer, &tmp, sizeof(T));
|
||||||
*size += sizeof(T);
|
*size += sizeof(T);
|
||||||
(*buffer) += sizeof(T);
|
(*buffer) += sizeof(T);
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
} else {
|
} else {
|
||||||
return SerializeIF::BUFFER_TOO_SHORT;
|
return SerializeIF::BUFFER_TOO_SHORT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t deSerialize(T *object, const uint8_t **buffer,
|
ReturnValue_t deSerialize(T *object, const uint8_t **buffer,
|
||||||
size_t *size, SerializeIF::Endianness streamEndianness) {
|
size_t *size, SerializeIF::Endianness streamEndianness) {
|
||||||
T tmp;
|
T tmp;
|
||||||
if (*size >= sizeof(T)) {
|
if (*size >= sizeof(T)) {
|
||||||
*size -= sizeof(T);
|
*size -= sizeof(T);
|
||||||
std::memcpy(&tmp, *buffer, sizeof(T));
|
std::memcpy(&tmp, *buffer, sizeof(T));
|
||||||
switch (streamEndianness) {
|
switch (streamEndianness) {
|
||||||
case SerializeIF::Endianness::BIG:
|
case SerializeIF::Endianness::BIG:
|
||||||
*object = EndianConverter::convertBigEndian<T>(tmp);
|
*object = EndianConverter::convertBigEndian<T>(tmp);
|
||||||
break;
|
break;
|
||||||
case SerializeIF::Endianness::LITTLE:
|
case SerializeIF::Endianness::LITTLE:
|
||||||
*object = EndianConverter::convertLittleEndian<T>(tmp);
|
*object = EndianConverter::convertLittleEndian<T>(tmp);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
case SerializeIF::Endianness::MACHINE:
|
case SerializeIF::Endianness::MACHINE:
|
||||||
*object = tmp;
|
*object = tmp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
*buffer += sizeof(T);
|
*buffer += sizeof(T);
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
} else {
|
} else {
|
||||||
return SerializeIF::STREAM_TOO_SHORT;
|
return SerializeIF::STREAM_TOO_SHORT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t getSerializedSize(const T *object) {
|
uint32_t getSerializedSize(const T *object) {
|
||||||
return sizeof(T);
|
return sizeof(T);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Template for objects that inherit from SerializeIF
|
* Template for objects that inherit from SerializeIF
|
||||||
*
|
*
|
||||||
* @tparam T A child of SerializeIF
|
* @tparam T A child of SerializeIF
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class InternalSerializeAdapter<T, true> {
|
class InternalSerializeAdapter<T, true> {
|
||||||
public:
|
public:
|
||||||
ReturnValue_t serialize(const T *object, uint8_t **buffer, size_t *size,
|
ReturnValue_t serialize(const T *object, uint8_t **buffer, size_t *size,
|
||||||
size_t max_size,
|
size_t max_size,
|
||||||
SerializeIF::Endianness streamEndianness) const {
|
SerializeIF::Endianness streamEndianness) const {
|
||||||
size_t ignoredSize = 0;
|
size_t ignoredSize = 0;
|
||||||
if (size == nullptr) {
|
if (size == nullptr) {
|
||||||
size = &ignoredSize;
|
size = &ignoredSize;
|
||||||
}
|
}
|
||||||
return object->serialize(buffer, size, max_size, streamEndianness);
|
return object->serialize(buffer, size, max_size, streamEndianness);
|
||||||
}
|
}
|
||||||
size_t getSerializedSize(const T *object) const {
|
size_t getSerializedSize(const T *object) const {
|
||||||
return object->getSerializedSize();
|
return object->getSerializedSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t deSerialize(T *object, const uint8_t **buffer,
|
ReturnValue_t deSerialize(T *object, const uint8_t **buffer,
|
||||||
size_t *size, SerializeIF::Endianness streamEndianness) {
|
size_t *size, SerializeIF::Endianness streamEndianness) {
|
||||||
return object->deSerialize(buffer, size, streamEndianness);
|
return object->deSerialize(buffer, size, streamEndianness);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _FSFW_SERIALIZE_SERIALIZEADAPTER_H_ */
|
#endif /* _FSFW_SERIALIZE_SERIALIZEADAPTER_H_ */
|
||||||
|
@ -73,7 +73,7 @@ namespace spacepacket {
|
|||||||
|
|
||||||
constexpr uint16_t getSpacePacketIdFromApid(bool isTc, uint16_t apid,
|
constexpr uint16_t getSpacePacketIdFromApid(bool isTc, uint16_t apid,
|
||||||
bool secondaryHeaderFlag = true) {
|
bool secondaryHeaderFlag = true) {
|
||||||
return (((isTc << 5) & 0x10) | ((secondaryHeaderFlag << 4) & 0x08) |
|
return ((isTc << 4) | (secondaryHeaderFlag << 3) |
|
||||||
((apid >> 8) & 0x07)) << 8 | (apid & 0x00ff);
|
((apid >> 8) & 0x07)) << 8 | (apid & 0x00ff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ TEST_CASE("Ring Buffer Test" , "[RingBufferTest]") {
|
|||||||
TEST_CASE("Ring Buffer Test2" , "[RingBufferTest2]") {
|
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 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 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);
|
SimpleRingBuffer ringBuffer(newBuffer, 10, true, 5);
|
||||||
|
|
||||||
SECTION("Simple Test") {
|
SECTION("Simple Test") {
|
||||||
@ -168,7 +168,7 @@ TEST_CASE("Ring Buffer Test2" , "[RingBufferTest2]") {
|
|||||||
TEST_CASE("Ring Buffer Test3" , "[RingBufferTest3]") {
|
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 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 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);
|
SimpleRingBuffer ringBuffer(newBuffer, 10, true, 15);
|
||||||
|
|
||||||
SECTION("Simple Test") {
|
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
|
/* We can do it like this because the buffer only has one byte for
|
||||||
less than 8 variables */
|
less than 8 variables */
|
||||||
uint8_t* validityByte = buffer + sizeof(buffer) - 1;
|
uint8_t* validityByte = buffer + sizeof(buffer) - 1;
|
||||||
CHECK(bitutil::bitGet(validityByte, 0) == true);
|
bool bitSet = false;
|
||||||
CHECK(bitutil::bitGet(validityByte, 1) == false);
|
bitutil::get(validityByte, 0, bitSet);
|
||||||
CHECK(bitutil::bitGet(validityByte, 2) == true);
|
|
||||||
|
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 */
|
/* Now we manipulate the validity buffer for the deserialization */
|
||||||
bitutil::bitClear(validityByte, 0);
|
bitutil::clear(validityByte, 0);
|
||||||
bitutil::bitSet(validityByte, 1);
|
bitutil::set(validityByte, 1);
|
||||||
bitutil::bitClear(validityByte, 2);
|
bitutil::clear(validityByte, 2);
|
||||||
/* Zero out everything except validity buffer */
|
/* Zero out everything except validity buffer */
|
||||||
std::memset(buffer, 0, sizeof(buffer) - 1);
|
std::memset(buffer, 0, sizeof(buffer) - 1);
|
||||||
sizeToDeserialize = maxSize;
|
sizeToDeserialize = maxSize;
|
||||||
@ -239,8 +244,11 @@ TEST_CASE("DataSetTest" , "[DataSetTest]") {
|
|||||||
std::memcpy(validityBuffer.data(), buffer + 9 + sizeof(uint16_t) * 3, 2);
|
std::memcpy(validityBuffer.data(), buffer + 9 + sizeof(uint16_t) * 3, 2);
|
||||||
/* The first 9 variables should be valid */
|
/* The first 9 variables should be valid */
|
||||||
CHECK(validityBuffer[0] == 0xff);
|
CHECK(validityBuffer[0] == 0xff);
|
||||||
CHECK(bitutil::bitGet(validityBuffer.data() + 1, 0) == true);
|
bool bitSet = false;
|
||||||
CHECK(bitutil::bitGet(validityBuffer.data() + 1, 1) == 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 */
|
/* Now we invert the validity */
|
||||||
validityBuffer[0] = 0;
|
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_h == Catch::Approx(timeCdsNow.msDay_h).margin(1));
|
||||||
CHECK(cdsShort.msDay_hh == Catch::Approx(timeCdsNow.msDay_hh).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_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") {
|
SECTION("VariableSnapshotTest") {
|
||||||
@ -205,7 +205,7 @@ TEST_CASE("LocalPoolManagerTest" , "[LocManTest]") {
|
|||||||
CHECK(cdsShort.msDay_h == Catch::Approx(timeCdsNow.msDay_h).margin(1));
|
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_hh == Catch::Approx(timeCdsNow.msDay_hh).margin(1));
|
||||||
CHECK(cdsShort.msDay_l == Catch::Approx(timeCdsNow.msDay_l).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") {
|
SECTION("VariableNotificationTest") {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
target_sources(${FSFW_TEST_TGT} PRIVATE
|
target_sources(${FSFW_TEST_TGT} PRIVATE
|
||||||
testDleEncoder.cpp
|
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_test_macros.hpp>
|
||||||
#include <catch2/catch_approx.hpp>
|
#include <catch2/catch_approx.hpp>
|
||||||
|
#include <fsfw/serialize/SerialBufferAdapter.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
static bool test_value_bool = true;
|
static bool testBool = true;
|
||||||
static uint8_t tv_uint8 {5};
|
static uint8_t tvUint8 {5};
|
||||||
static uint16_t tv_uint16 {283};
|
static uint16_t tvUint16 {283};
|
||||||
static uint32_t tv_uint32 {929221};
|
static uint32_t tvUint32 {929221};
|
||||||
static uint64_t tv_uint64 {2929329429};
|
static uint64_t tvUint64 {2929329429};
|
||||||
|
|
||||||
static int8_t tv_int8 {-16};
|
static int8_t tvInt8 {-16};
|
||||||
static int16_t tv_int16 {-829};
|
static int16_t tvInt16 {-829};
|
||||||
static int32_t tv_int32 {-2312};
|
static int32_t tvInt32 {-2312};
|
||||||
|
|
||||||
static float tv_float {8.2149214};
|
static float tvFloat {8.2149214};
|
||||||
static float tv_sfloat = {-922.2321321};
|
static float tvSfloat = {-922.2321321};
|
||||||
static double tv_double {9.2132142141e8};
|
static double tvDouble {9.2132142141e8};
|
||||||
static double tv_sdouble {-2.2421e19};
|
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(unitTestClass.test_autoserialization() == 0);
|
||||||
REQUIRE(SerializeAdapter::getSerializedSize(&test_value_bool) ==
|
REQUIRE(SerializeAdapter::getSerializedSize(&testBool) ==
|
||||||
sizeof(test_value_bool));
|
sizeof(testBool));
|
||||||
REQUIRE(SerializeAdapter::getSerializedSize(&tv_uint8) ==
|
REQUIRE(SerializeAdapter::getSerializedSize(&tvUint8) ==
|
||||||
sizeof(tv_uint8));
|
sizeof(tvUint8));
|
||||||
REQUIRE(SerializeAdapter::getSerializedSize(&tv_uint16) ==
|
REQUIRE(SerializeAdapter::getSerializedSize(&tvUint16) ==
|
||||||
sizeof(tv_uint16));
|
sizeof(tvUint16));
|
||||||
REQUIRE(SerializeAdapter::getSerializedSize(&tv_uint32 ) ==
|
REQUIRE(SerializeAdapter::getSerializedSize(&tvUint32 ) ==
|
||||||
sizeof(tv_uint32));
|
sizeof(tvUint32));
|
||||||
REQUIRE(SerializeAdapter::getSerializedSize(&tv_uint64) ==
|
REQUIRE(SerializeAdapter::getSerializedSize(&tvUint64) ==
|
||||||
sizeof(tv_uint64));
|
sizeof(tvUint64));
|
||||||
REQUIRE(SerializeAdapter::getSerializedSize(&tv_int8) ==
|
REQUIRE(SerializeAdapter::getSerializedSize(&tvInt8) ==
|
||||||
sizeof(tv_int8));
|
sizeof(tvInt8));
|
||||||
REQUIRE(SerializeAdapter::getSerializedSize(&tv_int16) ==
|
REQUIRE(SerializeAdapter::getSerializedSize(&tvInt16) ==
|
||||||
sizeof(tv_int16));
|
sizeof(tvInt16));
|
||||||
REQUIRE(SerializeAdapter::getSerializedSize(&tv_int32) ==
|
REQUIRE(SerializeAdapter::getSerializedSize(&tvInt32) ==
|
||||||
sizeof(tv_int32));
|
sizeof(tvInt32));
|
||||||
REQUIRE(SerializeAdapter::getSerializedSize(&tv_float) ==
|
REQUIRE(SerializeAdapter::getSerializedSize(&tvFloat) ==
|
||||||
sizeof(tv_float));
|
sizeof(tvFloat));
|
||||||
REQUIRE(SerializeAdapter::getSerializedSize(&tv_sfloat) ==
|
REQUIRE(SerializeAdapter::getSerializedSize(&tvSfloat) ==
|
||||||
sizeof(tv_sfloat ));
|
sizeof(tvSfloat ));
|
||||||
REQUIRE(SerializeAdapter::getSerializedSize(&tv_double) ==
|
REQUIRE(SerializeAdapter::getSerializedSize(&tvDouble) ==
|
||||||
sizeof(tv_double));
|
sizeof(tvDouble));
|
||||||
REQUIRE(SerializeAdapter::getSerializedSize(&tv_sdouble) ==
|
REQUIRE(SerializeAdapter::getSerializedSize(&tvSdouble) ==
|
||||||
sizeof(tv_sdouble));
|
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]") {
|
SECTION("SerDe") {
|
||||||
size_t serialized_size = 0;
|
size_t deserSize = 0;
|
||||||
uint8_t * p_array = test_array.data();
|
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(&tvUint32, TEST_ARRAY.data(), &deserSize, TEST_ARRAY.size(),
|
||||||
SerializeAdapter::serialize(&test_value_bool, &p_array,
|
SerializeIF::Endianness::MACHINE);
|
||||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
REQUIRE(deserSize == 4);
|
||||||
SerializeAdapter::serialize(&tv_uint8, &p_array,
|
uint32_t readBackUint32 = 0;
|
||||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
deserSize = 0;
|
||||||
SerializeAdapter::serialize(&tv_uint16, &p_array,
|
SerializeAdapter::deSerialize(&readBackUint32, TEST_ARRAY.data(), &deserSize,
|
||||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
SerializeIF::Endianness::MACHINE);
|
||||||
SerializeAdapter::serialize(&tv_uint32, &p_array,
|
REQUIRE(deserSize == 4);
|
||||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
REQUIRE(readBackUint32 == 929221);
|
||||||
SerializeAdapter::serialize(&tv_int8, &p_array,
|
|
||||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
SerializeAdapter::serialize(&tvInt16, TEST_ARRAY.data(), &deserSize, TEST_ARRAY.size(),
|
||||||
SerializeAdapter::serialize(&tv_int16, &p_array,
|
SerializeIF::Endianness::MACHINE);
|
||||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
REQUIRE(deserSize == 2);
|
||||||
SerializeAdapter::serialize(&tv_int32, &p_array,
|
int16_t readBackInt16 = 0;
|
||||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
SerializeAdapter::deSerialize(&readBackInt16, TEST_ARRAY.data(), &deserSize,
|
||||||
SerializeAdapter::serialize(&tv_uint64, &p_array,
|
SerializeIF::Endianness::MACHINE);
|
||||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
REQUIRE(readBackInt16 == -829);
|
||||||
SerializeAdapter::serialize(&tv_float, &p_array,
|
REQUIRE(deserSize == 2);
|
||||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
|
||||||
SerializeAdapter::serialize(&tv_double, &p_array,
|
SerializeAdapter::serialize(&tvFloat, TEST_ARRAY.data(), &deserSize, TEST_ARRAY.size(),
|
||||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
SerializeIF::Endianness::MACHINE);
|
||||||
SerializeAdapter::serialize(&tv_sfloat, &p_array,
|
float readBackFloat = 0.0;
|
||||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
SerializeAdapter::deSerialize(&readBackFloat, TEST_ARRAY.data(), &deserSize,
|
||||||
SerializeAdapter::serialize(&tv_sdouble, &p_array,
|
SerializeIF::Endianness::MACHINE);
|
||||||
&serialized_size, test_array.size(), SerializeIF::Endianness::MACHINE);
|
REQUIRE(readBackFloat == Catch::Approx(8.214921));
|
||||||
REQUIRE (serialized_size == 47);
|
|
||||||
|
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") {
|
SECTION("Deserialize decrementing") {
|
||||||
p_array = test_array.data();
|
pArray = TEST_ARRAY.data();
|
||||||
size_t remaining_size = serialized_size;
|
size_t remaining_size = serializedSize;
|
||||||
SerializeAdapter::deSerialize(&test_value_bool,
|
SerializeAdapter::deSerialize(&testBool, const_cast<const uint8_t**>(&pArray),
|
||||||
const_cast<const uint8_t**>(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE);
|
&remaining_size, SerializeIF::Endianness::MACHINE);
|
||||||
SerializeAdapter::deSerialize(&tv_uint8,
|
SerializeAdapter::deSerialize(&tvUint8, const_cast<const uint8_t**>(&pArray),
|
||||||
const_cast<const uint8_t**>(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE);
|
&remaining_size, SerializeIF::Endianness::MACHINE);
|
||||||
SerializeAdapter::deSerialize(&tv_uint16,
|
SerializeAdapter::deSerialize(&tvUint16, const_cast<const uint8_t**>(&pArray),
|
||||||
const_cast<const uint8_t**>(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE);
|
&remaining_size, SerializeIF::Endianness::MACHINE);
|
||||||
SerializeAdapter::deSerialize(&tv_uint32,
|
SerializeAdapter::deSerialize(&tvUint32, const_cast<const uint8_t**>(&pArray),
|
||||||
const_cast<const uint8_t**>(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE);
|
&remaining_size, SerializeIF::Endianness::MACHINE);
|
||||||
SerializeAdapter::deSerialize(&tv_int8,
|
SerializeAdapter::deSerialize(&tvInt8, const_cast<const uint8_t**>(&pArray),
|
||||||
const_cast<const uint8_t**>(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE);
|
&remaining_size, SerializeIF::Endianness::MACHINE);
|
||||||
SerializeAdapter::deSerialize(&tv_int16,
|
SerializeAdapter::deSerialize(&tvInt16, const_cast<const uint8_t**>(&pArray),
|
||||||
const_cast<const uint8_t**>(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE);
|
&remaining_size, SerializeIF::Endianness::MACHINE);
|
||||||
SerializeAdapter::deSerialize(&tv_int32,
|
SerializeAdapter::deSerialize(&tvInt32, const_cast<const uint8_t**>(&pArray),
|
||||||
const_cast<const uint8_t**>(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE);
|
&remaining_size, SerializeIF::Endianness::MACHINE);
|
||||||
SerializeAdapter::deSerialize(&tv_uint64,
|
SerializeAdapter::deSerialize(&tvUint64,
|
||||||
const_cast<const uint8_t**>(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE);
|
const_cast<const uint8_t**>(&pArray), &remaining_size, SerializeIF::Endianness::MACHINE);
|
||||||
SerializeAdapter::deSerialize(&tv_float,
|
SerializeAdapter::deSerialize(&tvFloat,
|
||||||
const_cast<const uint8_t**>(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE);
|
const_cast<const uint8_t**>(&pArray), &remaining_size, SerializeIF::Endianness::MACHINE);
|
||||||
SerializeAdapter::deSerialize(&tv_double,
|
SerializeAdapter::deSerialize(&tvDouble,
|
||||||
const_cast<const uint8_t**>(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE);
|
const_cast<const uint8_t**>(&pArray), &remaining_size, SerializeIF::Endianness::MACHINE);
|
||||||
SerializeAdapter::deSerialize(&tv_sfloat,
|
SerializeAdapter::deSerialize(&tvSfloat,
|
||||||
const_cast<const uint8_t**>(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE);
|
const_cast<const uint8_t**>(&pArray), &remaining_size, SerializeIF::Endianness::MACHINE);
|
||||||
SerializeAdapter::deSerialize(&tv_sdouble,
|
SerializeAdapter::deSerialize(&tvSdouble,
|
||||||
const_cast<const uint8_t**>(&p_array), &remaining_size, SerializeIF::Endianness::MACHINE);
|
const_cast<const uint8_t**>(&pArray), &remaining_size, SerializeIF::Endianness::MACHINE);
|
||||||
|
|
||||||
REQUIRE(test_value_bool == true);
|
REQUIRE(testBool == true);
|
||||||
REQUIRE(tv_uint8 == 5);
|
REQUIRE(tvUint8 == 5);
|
||||||
REQUIRE(tv_uint16 == 283);
|
REQUIRE(tvUint16 == 283);
|
||||||
REQUIRE(tv_uint32 == 929221);
|
REQUIRE(tvUint32 == 929221);
|
||||||
REQUIRE(tv_uint64 == 2929329429);
|
REQUIRE(tvUint64 == 2929329429);
|
||||||
REQUIRE(tv_int8 == -16);
|
REQUIRE(tvInt8 == -16);
|
||||||
REQUIRE(tv_int16 == -829);
|
REQUIRE(tvInt16 == -829);
|
||||||
REQUIRE(tv_int32 == -2312);
|
REQUIRE(tvInt32 == -2312);
|
||||||
|
|
||||||
REQUIRE(tv_float == Catch::Approx(8.214921));
|
REQUIRE(tvFloat == Catch::Approx(8.214921));
|
||||||
REQUIRE(tv_double == Catch::Approx(9.2132142141e8));
|
REQUIRE(tvDouble == Catch::Approx(9.2132142141e8));
|
||||||
REQUIRE(tv_sfloat == Catch::Approx(-922.2321321));
|
REQUIRE(tvSfloat == Catch::Approx(-922.2321321));
|
||||||
REQUIRE(tv_sdouble == Catch::Approx(-2.2421e19));
|
REQUIRE(tvSdouble == Catch::Approx(-2.2421e19));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
target_sources(${FSFW_TEST_TGT} PRIVATE
|
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