From ca70c8c61408df79bcc9aea8777a14447e625160 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 8 Mar 2022 10:05:18 +0100 Subject: [PATCH 1/9] function to get fsfw version --- src/fsfw/CMakeLists.txt | 4 ++++ src/fsfw/version.cpp | 8 ++++++++ src/fsfw/version.h | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 src/fsfw/version.cpp create mode 100644 src/fsfw/version.h diff --git a/src/fsfw/CMakeLists.txt b/src/fsfw/CMakeLists.txt index 12c673ed..efb9f6c7 100644 --- a/src/fsfw/CMakeLists.txt +++ b/src/fsfw/CMakeLists.txt @@ -1,3 +1,7 @@ +target_sources(${LIB_FSFW_NAME} PRIVATE + version.cpp +) + # Core add_subdirectory(action) diff --git a/src/fsfw/version.cpp b/src/fsfw/version.cpp new file mode 100644 index 00000000..1bdd6cc7 --- /dev/null +++ b/src/fsfw/version.cpp @@ -0,0 +1,8 @@ +#include "version.h" +#include "fsfw/FSFWVersion.h" + +void fsfw::getVersion(Version& v) { + v.major = FSFW_VERSION; + v.minor = FSFW_SUBVERSION; + v.revision = FSFW_REVISION; +} diff --git a/src/fsfw/version.h b/src/fsfw/version.h new file mode 100644 index 00000000..04b7e3ce --- /dev/null +++ b/src/fsfw/version.h @@ -0,0 +1,18 @@ +#ifndef FSFW_SRC_FSFW_VERSION_H_ +#define FSFW_SRC_FSFW_VERSION_H_ + +#include + +namespace fsfw { + +struct Version { + uint32_t major = 0; + uint32_t minor = 0; + uint32_t revision = 0; +}; + +void getVersion(Version& version); + +} + +#endif /* FSFW_SRC_FSFW_VERSION_H_ */ From 77e5fba7fdde8daf7d718a6841824c73e0a0b92c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 8 Mar 2022 10:08:53 +0100 Subject: [PATCH 2/9] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa59651f..6c3e4ce5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ 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 function to get FSFW version inside `fsfw/version.h` # [v4.0.0] From 345a799031560947445e404e79ce88c1f21fffb1 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 9 Mar 2022 19:05:07 +0100 Subject: [PATCH 3/9] improved version.h --- src/fsfw/FSFWVersion.h.in | 6 +++--- src/fsfw/version.cpp | 13 ++++++++----- src/fsfw/version.h | 25 +++++++++++++++++++++++-- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/fsfw/FSFWVersion.h.in b/src/fsfw/FSFWVersion.h.in index 7935b2f6..19a56214 100644 --- a/src/fsfw/FSFWVersion.h.in +++ b/src/fsfw/FSFWVersion.h.in @@ -2,8 +2,8 @@ #define FSFW_VERSION_H_ // Versioning is kept in project CMakeLists.txt file -#define FSFW_VERSION @FSFW_VERSION@ -#define FSFW_SUBVERSION @FSFW_SUBVERSION@ -#define FSFW_REVISION @FSFW_REVISION@ +#define FSFW_VERSION_MAJOR @FSFW_VERSION@ +#define FSFW_VERSION_MINOR @FSFW_SUBVERSION@ +#define FSFW_VERSION_REVISION @FSFW_REVISION@ #endif /* FSFW_VERSION_H_ */ diff --git a/src/fsfw/version.cpp b/src/fsfw/version.cpp index 1bdd6cc7..e1fc32c9 100644 --- a/src/fsfw/version.cpp +++ b/src/fsfw/version.cpp @@ -1,8 +1,11 @@ #include "version.h" + #include "fsfw/FSFWVersion.h" -void fsfw::getVersion(Version& v) { - v.major = FSFW_VERSION; - v.minor = FSFW_SUBVERSION; - v.revision = FSFW_REVISION; -} +const fsfw::Version fsfw::FSFW_VERSION = {FSFW_VERSION_MAJOR, FSFW_VERSION_MINOR, + FSFW_VERSION_REVISION}; + +fsfw::Version::Version(uint32_t major, uint32_t minor, uint32_t revision) + : major(major), minor(minor), revision(revision) {} + +void fsfw::getVersion(Version& version) {} diff --git a/src/fsfw/version.h b/src/fsfw/version.h index 04b7e3ce..8340fc9d 100644 --- a/src/fsfw/version.h +++ b/src/fsfw/version.h @@ -5,14 +5,35 @@ namespace fsfw { -struct Version { +class Version { + public: + Version(uint32_t major, uint32_t minor, uint32_t revision); uint32_t major = 0; uint32_t minor = 0; uint32_t revision = 0; + + friend bool operator==(const Version& v1, const Version& v2) { + return (v1.major == v2.major and v1.minor == v2.minor and v1.revision == v2.revision); + } + + friend bool operator!=(const Version& v1, const Version& v2) { return not(v1 == v2); } + + friend bool operator<(const Version& v1, const Version& v2) { + return ((v1.major < v2.major) or (v1.major == v2.major and v1.minor < v2.minor) or + (v1.major == v2.major and v1.minor == v2.minor and v1.revision < v2.revision)); + } + + friend bool operator>(const Version& v1, const Version& v2) { return not(v1 < v2); } + + 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)); } }; +extern const fsfw::Version FSFW_VERSION; + void getVersion(Version& version); -} +} // namespace fsfw #endif /* FSFW_SRC_FSFW_VERSION_H_ */ From ca508bfe61ac0f6e33232ca777b6078f972b0e68 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 9 Mar 2022 19:10:05 +0100 Subject: [PATCH 4/9] getter not required anymore --- src/fsfw/version.cpp | 2 -- src/fsfw/version.h | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/fsfw/version.cpp b/src/fsfw/version.cpp index e1fc32c9..133b9674 100644 --- a/src/fsfw/version.cpp +++ b/src/fsfw/version.cpp @@ -7,5 +7,3 @@ const fsfw::Version fsfw::FSFW_VERSION = {FSFW_VERSION_MAJOR, FSFW_VERSION_MINOR fsfw::Version::Version(uint32_t major, uint32_t minor, uint32_t revision) : major(major), minor(minor), revision(revision) {} - -void fsfw::getVersion(Version& version) {} diff --git a/src/fsfw/version.h b/src/fsfw/version.h index 8340fc9d..47860865 100644 --- a/src/fsfw/version.h +++ b/src/fsfw/version.h @@ -32,8 +32,6 @@ class Version { extern const fsfw::Version FSFW_VERSION; -void getVersion(Version& version); - } // namespace fsfw #endif /* FSFW_SRC_FSFW_VERSION_H_ */ From 7daa9812ff56657726b85c3304afdd852d84d951 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 10 Mar 2022 09:34:29 +0100 Subject: [PATCH 5/9] added tests --- src/fsfw/version.h | 28 ++++++++++++ tests/src/fsfw_tests/unit/CMakeLists.txt | 11 +++-- tests/src/fsfw_tests/unit/version.cpp | 55 ++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 tests/src/fsfw_tests/unit/version.cpp diff --git a/src/fsfw/version.h b/src/fsfw/version.h index 47860865..4ed748d1 100644 --- a/src/fsfw/version.h +++ b/src/fsfw/version.h @@ -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 +#endif #include +#include 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; diff --git a/tests/src/fsfw_tests/unit/CMakeLists.txt b/tests/src/fsfw_tests/unit/CMakeLists.txt index a83e2f7f..a8d31d88 100644 --- a/tests/src/fsfw_tests/unit/CMakeLists.txt +++ b/tests/src/fsfw_tests/unit/CMakeLists.txt @@ -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) diff --git a/tests/src/fsfw_tests/unit/version.cpp b/tests/src/fsfw_tests/unit/version.cpp new file mode 100644 index 00000000..6fcff215 --- /dev/null +++ b/tests/src/fsfw_tests/unit/version.cpp @@ -0,0 +1,55 @@ + +#include "fsfw/version.h" + +#include + +#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); + 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); + 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.minor -= 1; + v1.revision += 1; + REQUIRE(v1 != v2); + REQUIRE(v1 > v2); + REQUIRE(v1 >= v2); + v1.revision -= 1; + REQUIRE(v1 == v2); + sif::info << "v" << fsfw::FSFW_VERSION << std::endl; + char verString[10] = {}; + fsfw::FSFW_VERSION.getVersion(verString, sizeof(verString)); + sif::info << "v" << verString << std::endl; +} From 949549178a0a6826495c3be96179a1938a29a162 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 10 Mar 2022 09:36:36 +0100 Subject: [PATCH 6/9] update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c3e4ce5..e4afb8e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,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 function to get FSFW version inside `fsfw/version.h` +- Dedicated Version class and constant `fsfw::FSFW_VERSION` containing version information + inside `fsfw/version.h` # [v4.0.0] From 3779b44813e53cf0e9f4c59f67400e8a72500ee0 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 10 Mar 2022 09:37:57 +0100 Subject: [PATCH 7/9] added some more minor tests --- tests/src/fsfw_tests/unit/version.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/src/fsfw_tests/unit/version.cpp b/tests/src/fsfw_tests/unit/version.cpp index 6fcff215..7fffd986 100644 --- a/tests/src/fsfw_tests/unit/version.cpp +++ b/tests/src/fsfw_tests/unit/version.cpp @@ -16,6 +16,9 @@ TEST_CASE("Version API Tests", "[TestVersionAPI]") { 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); @@ -32,6 +35,8 @@ TEST_CASE("Version API Tests", "[TestVersionAPI]") { REQUIRE(v1 <= v2); v1.major += 1; REQUIRE(v1 == v2); + REQUIRE(v1 <= v2); + REQUIRE(v1 >= v2); v1.major += 1; REQUIRE(v1 != v2); REQUIRE(v1 > v2); @@ -48,6 +53,8 @@ TEST_CASE("Version API Tests", "[TestVersionAPI]") { REQUIRE(v1 >= v2); v1.revision -= 1; REQUIRE(v1 == v2); + REQUIRE(v1 <= v2); + REQUIRE(v1 >= v2); sif::info << "v" << fsfw::FSFW_VERSION << std::endl; char verString[10] = {}; fsfw::FSFW_VERSION.getVersion(verString, sizeof(verString)); From 6b1a81ee926accdae812db85eae4a0175d96eb29 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 10 Mar 2022 09:40:34 +0100 Subject: [PATCH 8/9] minor tweaks --- tests/src/fsfw_tests/unit/version.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/src/fsfw_tests/unit/version.cpp b/tests/src/fsfw_tests/unit/version.cpp index 7fffd986..d2a1f3ae 100644 --- a/tests/src/fsfw_tests/unit/version.cpp +++ b/tests/src/fsfw_tests/unit/version.cpp @@ -55,8 +55,12 @@ TEST_CASE("Version API Tests", "[TestVersionAPI]") { 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)); - sif::info << "v" << verString << std::endl; +#if FSFW_DISABLE_PRINTOUT == 0 + printf("v%s\n",verString); +#endif } From 14ac852b7e5885fcae2333ce5d5802241a84cb9d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 10 Mar 2022 09:44:06 +0100 Subject: [PATCH 9/9] this tests even a bit more --- tests/src/fsfw_tests/unit/version.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/src/fsfw_tests/unit/version.cpp b/tests/src/fsfw_tests/unit/version.cpp index d2a1f3ae..bca89692 100644 --- a/tests/src/fsfw_tests/unit/version.cpp +++ b/tests/src/fsfw_tests/unit/version.cpp @@ -38,16 +38,18 @@ TEST_CASE("Version API Tests", "[TestVersionAPI]") { 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 += 1; + v1.minor += 2; + v1.revision -= 1; REQUIRE(v1 != v2); REQUIRE(v1 > v2); REQUIRE(v1 >= v2); v1.minor -= 1; - v1.revision += 1; + v1.revision += 2; REQUIRE(v1 != v2); REQUIRE(v1 > v2); REQUIRE(v1 >= v2);