Merge branch 'mueller/version-getter' into mueller/master

This commit is contained in:
Robin Müller 2022-03-10 09:47:32 +01:00
commit 60639f56dc
4 changed files with 103 additions and 6 deletions

View File

@ -26,6 +26,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## Additions
- Linux HAL: Add wiretapping option for I2C. Enabled with `FSFW_HAL_I2C_WIRETAPPING` defined to 1
- Dedicated Version class and constant `fsfw::FSFW_VERSION` containing version information
inside `fsfw/version.h`
# [v4.0.0]

View File

@ -1,7 +1,13 @@
#ifndef FSFW_SRC_FSFW_VERSION_H_
#define FSFW_SRC_FSFW_VERSION_H_
#include "fsfw/FSFW.h"
#if FSFW_CPP_OSTREAM_ENABLED == 1
#include <iostream>
#endif
#include <cstdint>
#include <cstdio>
namespace fsfw {
@ -28,6 +34,28 @@ class Version {
friend bool operator<=(const Version& v1, const Version& v2) { return ((v1 == v2) or (v1 < v2)); }
friend bool operator>=(const Version& v1, const Version& v2) { return ((v1 == v2) or (v1 > v2)); }
#if FSFW_CPP_OSTREAM_ENABLED == 1
/**
* Print format to given ostream using format "major.minor.revision"
* @param os
* @param v
* @return
*/
friend std::ostream& operator<<(std::ostream& os, const Version& v) {
os << v.major << "." << v.minor << "." << v.revision;
return os;
}
#endif
/**
* Get version as format "major.minor.revision"
* @param str
* @param maxLen
*/
void getVersion(char* str, size_t maxLen) const {
snprintf(str, maxLen, "%d.%d.%d", major, minor, revision);
}
};
extern const fsfw::Version FSFW_VERSION;

View File

@ -2,14 +2,13 @@ target_sources(${FSFW_TEST_TGT} PRIVATE
CatchDefinitions.cpp
CatchFactory.cpp
printChar.cpp
version.cpp
)
# if(FSFW_CUSTOM_UNITTEST_RUNNER)
target_sources(${FSFW_TEST_TGT} PRIVATE
CatchRunner.cpp
CatchSetup.cpp
)
# endif()
target_sources(${FSFW_TEST_TGT} PRIVATE
CatchRunner.cpp
CatchSetup.cpp
)
add_subdirectory(testcfg)
add_subdirectory(action)

View File

@ -0,0 +1,68 @@
#include "fsfw/version.h"
#include <catch2/catch_test_macros.hpp>
#include "fsfw/serviceinterface.h"
#include "fsfw_tests/unit/CatchDefinitions.h"
TEST_CASE("Version API Tests", "[TestVersionAPI]") {
// Check that major version is non-zero
REQUIRE(fsfw::FSFW_VERSION.major > 0);
uint32_t fsfwMajor = fsfw::FSFW_VERSION.major;
REQUIRE(fsfw::Version(255, 0, 0) > fsfw::FSFW_VERSION);
REQUIRE(fsfw::Version(255, 0, 0) >= fsfw::FSFW_VERSION);
REQUIRE(fsfw::Version(0, 0, 0) < fsfw::FSFW_VERSION);
REQUIRE(fsfw::Version(0, 0, 0) <= fsfw::FSFW_VERSION);
fsfw::Version v1 = fsfw::Version(1, 1, 1);
fsfw::Version v2 = fsfw::Version(1, 1, 1);
REQUIRE(v1 == v2);
REQUIRE(v1 <= v2);
REQUIRE(v1 >= v2);
v1.revision -= 1;
REQUIRE(v1 != v2);
REQUIRE(v1 < v2);
REQUIRE(v1 <= v2);
v1.revision += 1;
v1.minor -= 1;
REQUIRE(v1 != v2);
REQUIRE(v1 < v2);
REQUIRE(v1 <= v2);
v1.minor += 1;
v1.major -= 1;
REQUIRE(v1 != v2);
REQUIRE(v1 < v2);
REQUIRE(v1 <= v2);
v1.major += 1;
REQUIRE(v1 == v2);
REQUIRE(v1 <= v2);
REQUIRE(v1 >= v2);
v1.major += 1;
v1.minor -= 1;
REQUIRE(v1 != v2);
REQUIRE(v1 > v2);
REQUIRE(v1 >= v2);
v1.major -= 1;
v1.minor += 2;
v1.revision -= 1;
REQUIRE(v1 != v2);
REQUIRE(v1 > v2);
REQUIRE(v1 >= v2);
v1.minor -= 1;
v1.revision += 2;
REQUIRE(v1 != v2);
REQUIRE(v1 > v2);
REQUIRE(v1 >= v2);
v1.revision -= 1;
REQUIRE(v1 == v2);
REQUIRE(v1 <= v2);
REQUIRE(v1 >= v2);
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "v" << fsfw::FSFW_VERSION << std::endl;
#endif
char verString[10] = {};
fsfw::FSFW_VERSION.getVersion(verString, sizeof(verString));
#if FSFW_DISABLE_PRINTOUT == 0
printf("v%s\n",verString);
#endif
}