From 13269271e607be8f2df2b0480098d7e29879c064 Mon Sep 17 00:00:00 2001 From: Lefucjusz Date: Tue, 20 Jun 2023 15:05:13 +0200 Subject: [PATCH] [MOS-998] Provide additional info in crashdump filename Added info about product, OS version and commit hash to crashdump filename to simplify analysis of the crashdumps without corresponding logs available. --- board/linux/CMakeLists.txt | 1 - .../crashdump-serial-number/CMakeLists.txt | 13 ---- .../crashdump_serial_number.cpp | 23 ------ .../crashdump_serial_number.hpp | 14 ---- board/rt1051/CMakeLists.txt | 3 +- .../crashdump-serial-number/CMakeLists.txt | 13 ---- .../crashdump_serial_number.cpp | 22 ------ .../crashdump_serial_number.hpp | 18 ----- board/rt1051/crashdump/crashcatcher_impl.cpp | 12 +-- .../rt1051/crashdump/crashdumpwriter_vfs.cpp | 66 ++++++++-------- .../rt1051/crashdump/crashdumpwriter_vfs.hpp | 2 +- harmony_changelog.md | 1 + module-bsp/board/rt1051/os/_exit.cpp | 3 +- module-utils/CMakeLists.txt | 1 + .../Clipboard/test/unittest_clipboard.cpp | 3 +- .../CrashdumpMetadataStore/CMakeLists.txt | 15 ++++ .../CrashdumpMetadataStore.cpp | 74 ++++++++++++++++++ .../CrashdumpMetadataStore.hpp | 40 ++++++++++ .../tests/CMakeLists.txt | 8 ++ .../tests/unittest_crashdumpmetadatastore.cpp | 76 +++++++++++++++++++ .../BellHybrid/services/db/CMakeLists.txt | 2 +- products/BellHybrid/services/db/ServiceDB.cpp | 12 ++- products/PurePhone/services/db/CMakeLists.txt | 2 +- products/PurePhone/services/db/ServiceDB.cpp | 11 ++- .../services/evtmgr/EventManager.cpp | 15 ++-- pure_changelog.md | 1 + 26 files changed, 281 insertions(+), 170 deletions(-) delete mode 100644 board/linux/crashdump-serial-number/CMakeLists.txt delete mode 100644 board/linux/crashdump-serial-number/crashdump_serial_number.cpp delete mode 100644 board/linux/crashdump-serial-number/include/crashdump-serial-number/crashdump_serial_number.hpp delete mode 100644 board/rt1051/crashdump-serial-number/CMakeLists.txt delete mode 100644 board/rt1051/crashdump-serial-number/crashdump_serial_number.cpp delete mode 100644 board/rt1051/crashdump-serial-number/include/crashdump-serial-number/crashdump_serial_number.hpp create mode 100644 module-utils/CrashdumpMetadataStore/CMakeLists.txt create mode 100644 module-utils/CrashdumpMetadataStore/CrashdumpMetadataStore.cpp create mode 100644 module-utils/CrashdumpMetadataStore/CrashdumpMetadataStore.hpp create mode 100644 module-utils/CrashdumpMetadataStore/tests/CMakeLists.txt create mode 100644 module-utils/CrashdumpMetadataStore/tests/unittest_crashdumpmetadatastore.cpp diff --git a/board/linux/CMakeLists.txt b/board/linux/CMakeLists.txt index 645592d4146f69210fb8d54812ea7075c2722f02..fd75e9a8e466821ed44739e16dac2d8b8aa1d50c 100644 --- a/board/linux/CMakeLists.txt +++ b/board/linux/CMakeLists.txt @@ -1,4 +1,3 @@ add_library(board INTERFACE) add_subdirectory(libiosyscalls) -add_subdirectory(crashdump-serial-number) target_compile_definitions(board-config INTERFACE PROJECT_CONFIG_USER_DYNMEM_SIZE=0) diff --git a/board/linux/crashdump-serial-number/CMakeLists.txt b/board/linux/crashdump-serial-number/CMakeLists.txt deleted file mode 100644 index 29b825a11d0383aecbebb6cbbeac73ac1800cc38..0000000000000000000000000000000000000000 --- a/board/linux/crashdump-serial-number/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -add_library(crashdump-serial-number STATIC) - -target_include_directories(crashdump-serial-number - PUBLIC - $/include -) - -target_sources(crashdump-serial-number - PUBLIC - crashdump_serial_number.cpp -) - - diff --git a/board/linux/crashdump-serial-number/crashdump_serial_number.cpp b/board/linux/crashdump-serial-number/crashdump_serial_number.cpp deleted file mode 100644 index 11e0c9d3b7320765713123c29ef63cc1fbe665ad..0000000000000000000000000000000000000000 --- a/board/linux/crashdump-serial-number/crashdump_serial_number.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#include - -namespace crashdump -{ - namespace - { - std::string serialNumber{}; - } - - void setSerialNumber(const std::string &sn) - { - serialNumber = sn; - } - - const std::string &getSerialNumber() - { - return serialNumber; - } - -} // namespace crashdump diff --git a/board/linux/crashdump-serial-number/include/crashdump-serial-number/crashdump_serial_number.hpp b/board/linux/crashdump-serial-number/include/crashdump-serial-number/crashdump_serial_number.hpp deleted file mode 100644 index c18ec8d6a84373535d80b5d723ff2f73a593b3dc..0000000000000000000000000000000000000000 --- a/board/linux/crashdump-serial-number/include/crashdump-serial-number/crashdump_serial_number.hpp +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -// Dummy file to keep linux variant compiling. - -#pragma once - -#include - -namespace crashdump -{ - void setSerialNumber(const std::string &sn); - const std::string &getSerialNumber(); -} // namespace crashdump diff --git a/board/rt1051/CMakeLists.txt b/board/rt1051/CMakeLists.txt index 565f1208df51c0d264480f3d380361ad797c9427..ddfae5f9ccf7dfa68e63d01b95bb7fba0ac7daaf 100644 --- a/board/rt1051/CMakeLists.txt +++ b/board/rt1051/CMakeLists.txt @@ -2,7 +2,6 @@ add_library(board STATIC) add_subdirectory(cmsis) add_subdirectory(${BOARD}) -add_subdirectory(crashdump-serial-number) if (${MEMORY_LINKER_FILE_PATH} STREQUAL "") message(FATAL_ERROR "Linker RAM layout not provided") @@ -43,7 +42,7 @@ target_include_directories(board target_link_libraries(board PRIVATE utils-rotator - crashdump-serial-number + crashdump-metadata-store PUBLIC fsl module-vfs diff --git a/board/rt1051/crashdump-serial-number/CMakeLists.txt b/board/rt1051/crashdump-serial-number/CMakeLists.txt deleted file mode 100644 index 29b825a11d0383aecbebb6cbbeac73ac1800cc38..0000000000000000000000000000000000000000 --- a/board/rt1051/crashdump-serial-number/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -add_library(crashdump-serial-number STATIC) - -target_include_directories(crashdump-serial-number - PUBLIC - $/include -) - -target_sources(crashdump-serial-number - PUBLIC - crashdump_serial_number.cpp -) - - diff --git a/board/rt1051/crashdump-serial-number/crashdump_serial_number.cpp b/board/rt1051/crashdump-serial-number/crashdump_serial_number.cpp deleted file mode 100644 index 792e62a89d4257f89472249ced0b065006a5ae10..0000000000000000000000000000000000000000 --- a/board/rt1051/crashdump-serial-number/crashdump_serial_number.cpp +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#include - -namespace crashdump -{ - namespace - { - std::string serialNumber{}; - } - - void setSerialNumber(const std::string &sn) - { - serialNumber = sn; - } - - const std::string &getSerialNumber() - { - return serialNumber; - } -} // namespace crashdump diff --git a/board/rt1051/crashdump-serial-number/include/crashdump-serial-number/crashdump_serial_number.hpp b/board/rt1051/crashdump-serial-number/include/crashdump-serial-number/crashdump_serial_number.hpp deleted file mode 100644 index 2d8d67cfe278805b22f0a0f36e940b3267ea4bf6..0000000000000000000000000000000000000000 --- a/board/rt1051/crashdump-serial-number/include/crashdump-serial-number/crashdump_serial_number.hpp +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -// The purpose of this file is to keep the devices serial number in the memory. -// In case of any crash, the serial number could be easily added to a crash dump filename. -// It will allow to identify the crash even after it is moved or copied from the device. -// setSerialNumber() should be called during system initialization. -// getSerialNumber() is called by the crash dump writer during file creation. - -#pragma once - -#include - -namespace crashdump -{ - void setSerialNumber(const std::string &sn); - const std::string &getSerialNumber(); -} // namespace crashdump diff --git a/board/rt1051/crashdump/crashcatcher_impl.cpp b/board/rt1051/crashdump/crashcatcher_impl.cpp index 1e16700bd381b5fcf28dafbedd860bd77806be44..3153f39bbfa7e382a234221d3f224185135632d5 100644 --- a/board/rt1051/crashdump/crashcatcher_impl.cpp +++ b/board/rt1051/crashdump/crashcatcher_impl.cpp @@ -16,17 +16,17 @@ namespace crashdump::CrashDumpWriterVFS cwrite; } -const CrashCatcherMemoryRegion *CrashCatcher_GetMemoryRegions(void) +const CrashCatcherMemoryRegion *CrashCatcher_GetMemoryRegions() { /* board/rt1051/ldscripts/memory.ld - * NOTE: Text section and stacks sections are intentionally ommited - * because can cause throubles in the running system + * NOTE: Text section and stacks sections are intentionally omitted + * because can cause troubles in the running system */ static const CrashCatcherMemoryRegion regions[] = { // SRAM_OC - {0x20200000, 0x20210000, CRASH_CATCHER_WORD}, + {0x20200000, 0x20200000 + 0x10000, CRASH_CATCHER_WORD}, // SRAM_DTC - {0x20000000, 0x20070000, CRASH_CATCHER_WORD}, + {0x20000000, 0x20000000 + 0x70000, CRASH_CATCHER_WORD}, // intentionally skip text section // intentionally skip the heap section // end tag @@ -57,7 +57,7 @@ void CrashCatcher_DumpMemory(const void *pvMemory, CrashCatcherElementSizes elem } } -CrashCatcherReturnCodes CrashCatcher_DumpEnd(void) +CrashCatcherReturnCodes CrashCatcher_DumpEnd() { cwrite.saveDump(); _exit_backtrace(-1, false); diff --git a/board/rt1051/crashdump/crashdumpwriter_vfs.cpp b/board/rt1051/crashdump/crashdumpwriter_vfs.cpp index d4f1c83e7e057b660b62b0f6708357e7d49f22df..5d21cbdf3e67bddcfcc2b26203494cbd0a66eb50 100644 --- a/board/rt1051/crashdump/crashdumpwriter_vfs.cpp +++ b/board/rt1051/crashdump/crashdumpwriter_vfs.cpp @@ -2,90 +2,86 @@ // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "crashdumpwriter_vfs.hpp" -#include #include #include -#include "purefs/vfs_subsystem.hpp" #include #include +#include #include #include -#include #include -#include -#include + +/* Crashdump filename pattern: + * crashdump_[os-metadata]_[timestamp-in-seconds].hex.[index] + * where [os-metadata] is in [product]_[os-version]_[commit-hash]-[serial-number] form. + * [index] was added to ensure resistance to the device date retraction. + */ namespace { - constexpr inline auto suffix = "_crashdump.hex"; - constexpr inline auto file_index = ".1"; - - // Crashdump filename pattern: - // [serial-number]_[timestamp-in-seconds]_crashdump.hex.[index] - // [index] was added to ensure resistance to the device date retraction + inline constexpr auto prefix = "crashdump"; + inline constexpr auto extension = ".hex"; + inline constexpr auto file_index = ".1"; + inline constexpr auto separator = "_"; - inline std::string generate_crashdump_filename() + inline std::string generateCrashdumpFilename() { - const auto crash_time = - std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()) - .count(); - auto filename = - std::string("/") + crashdump::getSerialNumber() + "_" + std::to_string(crash_time) + suffix + file_index; - return filename; + const auto crashTime = std::time(nullptr); + const auto &osMetadata = Store::CrashdumpMetadata::getInstance().getMetadataString(); + return (std::string(prefix) + separator + osMetadata + separator + std::to_string(crashTime) + extension + + file_index); } - } // namespace namespace crashdump { - void CrashDumpWriterVFS::openDump() { - const auto crashDumpFilePath = purefs::dir::getCrashDumpsPath().string() + generate_crashdump_filename(); + const auto crashdumpFilePath = purefs::dir::getCrashDumpsPath() / generateCrashdumpFilename(); - LOG_INFO("Crash dump %s preparing ...", crashDumpFilePath.c_str()); + LOG_INFO("Preparing crashdump '%s'...", crashdumpFilePath.c_str()); if (!rotator.rotateFiles(purefs::dir::getCrashDumpsPath())) { - LOG_FATAL("Failed to rotate crash dumps errno: %i", errno); + LOG_FATAL("Failed to rotate crashdump, errno: %d", errno); _exit_backtrace(-1, false); } - file = std::fopen(crashDumpFilePath.c_str(), "w"); - if (!file) { - LOG_FATAL("Failed to open crash dump file errno %i", errno); + + file = std::fopen(crashdumpFilePath.c_str(), "w"); + if (file == nullptr) { + LOG_FATAL("Failed to open crashdump file '%s', errno: %d", crashdumpFilePath.c_str(), errno); _exit_backtrace(-1, false); } } void CrashDumpWriterVFS::saveDump() { - LOG_INFO("Crash dump create finished."); - fflush(file); + LOG_INFO("Crashdump created successfully!"); + std::fflush(file); fsync(fileno(file)); std::fclose(file); } - void CrashDumpWriterVFS::writeBytes(const uint8_t *buff, std::size_t size) + void CrashDumpWriterVFS::writeBytes(const std::uint8_t *buff, std::size_t size) { if (std::fwrite(buff, sizeof(*buff), size, file) != size) { - LOG_FATAL("Unable to write crash dump errno: %i", errno); + LOG_FATAL("Unable to write crashdump, errno: %d", errno); _exit_backtrace(-1, false); } } - void CrashDumpWriterVFS::writeHalfWords(const uint16_t *buff, std::size_t size) + void CrashDumpWriterVFS::writeHalfWords(const std::uint16_t *buff, std::size_t size) { if (std::fwrite(buff, sizeof(*buff), size, file) != size) { - LOG_FATAL("Unable to write crash dump errno: %i", errno); + LOG_FATAL("Unable to write crashdump, errno: %d", errno); _exit_backtrace(-1, false); } } - void CrashDumpWriterVFS::writeWords(const uint32_t *buff, std::size_t size) + void CrashDumpWriterVFS::writeWords(const std::uint32_t *buff, std::size_t size) { if (std::fwrite(buff, sizeof(*buff), size, file) != size) { - LOG_FATAL("Unable to write crash dump errno: %i", errno); + LOG_FATAL("Unable to write crashdump, errno: %d", errno); _exit_backtrace(-1, false); } } - } // namespace crashdump diff --git a/board/rt1051/crashdump/crashdumpwriter_vfs.hpp b/board/rt1051/crashdump/crashdumpwriter_vfs.hpp index f6c9ac774bdf13b929d237cc0146de88bc642df7..17a243c7917d9459c4686ccd09f7f6b4ef665b1d 100644 --- a/board/rt1051/crashdump/crashdumpwriter_vfs.hpp +++ b/board/rt1051/crashdump/crashdumpwriter_vfs.hpp @@ -16,7 +16,6 @@ namespace purefs::fs namespace crashdump { - constexpr inline auto maxRotationFilesCount = 5; class CrashDumpWriterVFS { public: @@ -30,6 +29,7 @@ namespace crashdump void writeWords(const std::uint32_t *buff, std::size_t size); private: + static constexpr auto maxRotationFilesCount = 5; utils::Rotator rotator; std::FILE *file{}; }; diff --git a/harmony_changelog.md b/harmony_changelog.md index 1d0d89db7b0942eb0d64d6b365d0563e8fe2e3c5..21009977ad1e95f45539c79653f963fd3d2f2e03 100644 --- a/harmony_changelog.md +++ b/harmony_changelog.md @@ -34,6 +34,7 @@ * Added label informing about PC connection. * Added serial number to About section * Added possibility to detect device's case colour +* Added extended information to crashdump filename ### Changed / Improved diff --git a/module-bsp/board/rt1051/os/_exit.cpp b/module-bsp/board/rt1051/os/_exit.cpp index d74c548fafb63ee82aa7b03ba8be329d79f02e42..0e47bc1d036d330a2ecb93e0cc0316095b17074d 100644 --- a/module-bsp/board/rt1051/os/_exit.cpp +++ b/module-bsp/board/rt1051/os/_exit.cpp @@ -36,7 +36,6 @@ #include #include #include -#include #include #include #include @@ -60,7 +59,7 @@ static void __attribute__((noreturn)) stop_system(void) LOG_INFO("Restarting the system..."); NVIC_SystemReset(); // waiting for system reset - while (1) { + while (true) { #ifndef DEBUG __asm volatile("wfi\n"); #endif diff --git a/module-utils/CMakeLists.txt b/module-utils/CMakeLists.txt index 190de84fdc8ae4b996dae75af6fa8f7c4379543c..93e1582fd3933f8c27e1073534eee8502adcd025 100644 --- a/module-utils/CMakeLists.txt +++ b/module-utils/CMakeLists.txt @@ -4,6 +4,7 @@ add_library(module-utils INTERFACE) add_subdirectory(tar) add_subdirectory(Clipboard) +add_subdirectory(CrashdumpMetadataStore) add_subdirectory(EventStore) add_subdirectory(i18n) add_subdirectory(locale) diff --git a/module-utils/Clipboard/test/unittest_clipboard.cpp b/module-utils/Clipboard/test/unittest_clipboard.cpp index 04f017f19473a8dcf119d1e72b9533e7435edbe1..174819b45801d6154e15ae843562235a9050e6ef 100644 --- a/module-utils/Clipboard/test/unittest_clipboard.cpp +++ b/module-utils/Clipboard/test/unittest_clipboard.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include @@ -16,7 +16,6 @@ TEST_CASE("Clipboard") SECTION("Single copy") { const std::string test1 = "test1"; - const std::string test2 = "test2"; Clipboard::getInstance().copy(test1); REQUIRE(Clipboard::getInstance().gotData() == true); REQUIRE(Clipboard::getInstance().paste() == test1); diff --git a/module-utils/CrashdumpMetadataStore/CMakeLists.txt b/module-utils/CrashdumpMetadataStore/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..9ecaad915b7a8a8d6aa793140b27355de68d0605 --- /dev/null +++ b/module-utils/CrashdumpMetadataStore/CMakeLists.txt @@ -0,0 +1,15 @@ +add_library(crashdump-metadata-store STATIC) + +target_include_directories(crashdump-metadata-store + PUBLIC + $ + ) + +target_sources(crashdump-metadata-store + PUBLIC + CrashdumpMetadataStore.cpp + ) + +if (${ENABLE_TESTS}) + add_subdirectory(tests) +endif() diff --git a/module-utils/CrashdumpMetadataStore/CrashdumpMetadataStore.cpp b/module-utils/CrashdumpMetadataStore/CrashdumpMetadataStore.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d84357df91c93e68bb38e42c886b535835872410 --- /dev/null +++ b/module-utils/CrashdumpMetadataStore/CrashdumpMetadataStore.cpp @@ -0,0 +1,74 @@ +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "CrashdumpMetadataStore.hpp" + +namespace +{ + inline constexpr auto separator = "_"; + inline constexpr auto defaultSerialNumberLength = 13; + inline constexpr auto defaultCommitHashLength = 8; + inline constexpr auto defaultProductName = "unknown"; + inline constexpr auto defaultOsVersion = "0.0.0"; + inline constexpr auto defaultFillValue = '0'; +} // namespace + +namespace Store +{ + CrashdumpMetadata::CrashdumpMetadata() : productName(defaultProductName), osVersion(defaultOsVersion) + { + serialNumber.insert(0, defaultSerialNumberLength, defaultFillValue); + commitHash.insert(0, defaultCommitHashLength, defaultFillValue); + } + + CrashdumpMetadata &CrashdumpMetadata::getInstance() + { + static CrashdumpMetadata instance; + return instance; + } + + void CrashdumpMetadata::setSerialNumber(const std::string &sn) + { + serialNumber = sn; + } + + const std::string &CrashdumpMetadata::getSerialNumber() + { + return serialNumber; + } + + void CrashdumpMetadata::setProductName(const std::string &name) + { + productName = name; + } + + const std::string &CrashdumpMetadata::getProductName() + { + return productName; + } + + void CrashdumpMetadata::setOsVersion(const std::string &version) + { + osVersion = version; + } + + const std::string &CrashdumpMetadata::getOsVersion() + { + return osVersion; + } + + void CrashdumpMetadata::setCommitHash(const std::string &hash) + { + commitHash = hash; + } + + const std::string &CrashdumpMetadata::getCommitHash() + { + return commitHash; + } + + std::string CrashdumpMetadata::getMetadataString() + { + return productName + separator + osVersion + separator + commitHash + separator + serialNumber; + } +} // namespace Store diff --git a/module-utils/CrashdumpMetadataStore/CrashdumpMetadataStore.hpp b/module-utils/CrashdumpMetadataStore/CrashdumpMetadataStore.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b264b184c726214d239633b7c4122f34e2dd4a4f --- /dev/null +++ b/module-utils/CrashdumpMetadataStore/CrashdumpMetadataStore.hpp @@ -0,0 +1,40 @@ +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include + +namespace Store +{ + struct CrashdumpMetadata + { + public: + CrashdumpMetadata(const CrashdumpMetadata &) = delete; + CrashdumpMetadata &operator=(const CrashdumpMetadata &) = delete; + + static CrashdumpMetadata &getInstance(); + + void setSerialNumber(const std::string &serialNumber); + const std::string &getSerialNumber(); + + void setProductName(const std::string &product); + const std::string &getProductName(); + + void setOsVersion(const std::string &osVersion); + const std::string &getOsVersion(); + + void setCommitHash(const std::string &hash); + const std::string &getCommitHash(); + + std::string getMetadataString(); + + private: + CrashdumpMetadata(); + + std::string serialNumber; + std::string productName; + std::string osVersion; + std::string commitHash; + }; +} // namespace Store diff --git a/module-utils/CrashdumpMetadataStore/tests/CMakeLists.txt b/module-utils/CrashdumpMetadataStore/tests/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..21c86b6b01b9779ce52c71f81bbbe06e3eb89613 --- /dev/null +++ b/module-utils/CrashdumpMetadataStore/tests/CMakeLists.txt @@ -0,0 +1,8 @@ +add_catch2_executable( + NAME + utils-crashdump-metadata-store + SRCS + unittest_crashdumpmetadatastore.cpp + LIBS + crashdump-metadata-store +) diff --git a/module-utils/CrashdumpMetadataStore/tests/unittest_crashdumpmetadatastore.cpp b/module-utils/CrashdumpMetadataStore/tests/unittest_crashdumpmetadatastore.cpp new file mode 100644 index 0000000000000000000000000000000000000000..25c058ba4262f2de75c63db8c4f3d44f4b4f9d17 --- /dev/null +++ b/module-utils/CrashdumpMetadataStore/tests/unittest_crashdumpmetadatastore.cpp @@ -0,0 +1,76 @@ +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include +#include + +using namespace Store; + +/* This has to be the first test case! */ +TEST_CASE("Crashdump metadata store defaults") +{ + static constexpr auto defaultSerialNumber = "0000000000000"; + static constexpr auto defaultOsVersion = "0.0.0"; + static constexpr auto defaultCommitHash = "00000000"; + static constexpr auto defaultProductName = "unknown"; + + REQUIRE(CrashdumpMetadata::getInstance().getSerialNumber() == defaultSerialNumber); + REQUIRE(CrashdumpMetadata::getInstance().getOsVersion() == defaultOsVersion); + REQUIRE(CrashdumpMetadata::getInstance().getCommitHash() == defaultCommitHash); + REQUIRE(CrashdumpMetadata::getInstance().getProductName() == defaultProductName); +} + +TEST_CASE("Crashdump metadata store operations") +{ + static constexpr auto serialNumber1 = "1234567892137"; + static constexpr auto serialNumber2 = "2010307060900"; + + static constexpr auto osVersion1 = "6.6.6"; + static constexpr auto osVersion2 = "9.9.9"; + + static constexpr auto commitHash1 = "baadcafe"; + static constexpr auto commitHash2 = "c00lbabe"; + + static constexpr auto productName1 = "pure"; + static constexpr auto productName2 = "bell"; + + static constexpr auto separator = "_"; + + SECTION("Setting values") + { + CrashdumpMetadata::getInstance().setSerialNumber(serialNumber1); + REQUIRE(CrashdumpMetadata::getInstance().getSerialNumber() == serialNumber1); + + CrashdumpMetadata::getInstance().setOsVersion(osVersion1); + REQUIRE(CrashdumpMetadata::getInstance().getOsVersion() == osVersion1); + + CrashdumpMetadata::getInstance().setCommitHash(commitHash1); + REQUIRE(CrashdumpMetadata::getInstance().getCommitHash() == commitHash1); + + CrashdumpMetadata::getInstance().setProductName(productName1); + REQUIRE(CrashdumpMetadata::getInstance().getProductName() == productName1); + } + + SECTION("Updating values") + { + CrashdumpMetadata::getInstance().setSerialNumber(serialNumber2); + REQUIRE(CrashdumpMetadata::getInstance().getSerialNumber() == serialNumber2); + + CrashdumpMetadata::getInstance().setOsVersion(osVersion2); + REQUIRE(CrashdumpMetadata::getInstance().getOsVersion() == osVersion2); + + CrashdumpMetadata::getInstance().setCommitHash(commitHash2); + REQUIRE(CrashdumpMetadata::getInstance().getCommitHash() == commitHash2); + + CrashdumpMetadata::getInstance().setProductName(productName2); + REQUIRE(CrashdumpMetadata::getInstance().getProductName() == productName2); + } + + SECTION("Stringifying values") + { + const auto realMetadataStringified = CrashdumpMetadata::getInstance().getMetadataString(); + const auto referenceMetadataStringified = + std::string(productName2) + separator + osVersion2 + separator + commitHash2 + separator + serialNumber2; + REQUIRE(realMetadataStringified == referenceMetadataStringified); + } +} diff --git a/products/BellHybrid/services/db/CMakeLists.txt b/products/BellHybrid/services/db/CMakeLists.txt index f5e34a67937f21d9826c69caebe323fb26fbc097..b3d17a091ed0b636940aadf547f4943e53eaa49c 100644 --- a/products/BellHybrid/services/db/CMakeLists.txt +++ b/products/BellHybrid/services/db/CMakeLists.txt @@ -24,7 +24,7 @@ target_link_libraries(databases bell::db::meditation_stats service-db serial-number-parser - crashdump-serial-number + crashdump-metadata-store ) if (${ENABLE_TESTS}) diff --git a/products/BellHybrid/services/db/ServiceDB.cpp b/products/BellHybrid/services/db/ServiceDB.cpp index 73bae3fa9ad23363f011b6c433f8a7d388213bde..6887ff7c4462612a71ff4aaf0ff828d0ce184f1a 100644 --- a/products/BellHybrid/services/db/ServiceDB.cpp +++ b/products/BellHybrid/services/db/ServiceDB.cpp @@ -18,8 +18,8 @@ #include