From bb496101b2202b862ac13be09ee08b8872f004b3 Mon Sep 17 00:00:00 2001 From: Radoslaw Wicik Date: Tue, 2 Feb 2021 23:08:04 +0100 Subject: [PATCH] [EGD-4763] Add check if all Unit Tests where run Catch2 doesn't report some errors in test, and some test are disabled on porpoise this commit adds set of scripts and changes to CI that will clearly mark what test haven't been run. --- .github/workflows/main.yml | 74 +++- enabled_unittests | 320 ++++++++++++++++++ .../application-calendar/data/dateCommon.hpp | 6 +- module-db/CMakeLists.txt | 5 +- module-db/tests/EventsRecord_tests.cpp | 3 +- module-db/tests/NotesTable_tests.cpp | 5 +- module-db/tests/QueryInterface.cpp | 4 +- .../test/test-catch-text/test-gui-Text.cpp | 21 +- module-gui/test/test-catch/CMakeLists.txt | 1 + .../test-catch/test-language-input-parser.cpp | 14 +- module-services/service-db/CMakeLists.txt | 3 +- .../agents/settings/SettingsAgent.cpp | 4 +- module-utils/test/CMakeLists.txt | 20 +- tools/check_unittests.sh | 121 +++++++ tools/get_unittests.sh | 61 ++++ tools/run_unittests.sh | 58 ++++ 16 files changed, 670 insertions(+), 50 deletions(-) create mode 100644 enabled_unittests create mode 100755 tools/check_unittests.sh create mode 100755 tools/get_unittests.sh create mode 100755 tools/run_unittests.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b903da1c61cd696d479a20dbeef6f21e3abecc8f..acfafb45e50ea73f541c39e62db3567a6dc9838e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -80,13 +80,19 @@ jobs: popd - name: Check for statics run: ./tools/find_global_data.py build-linux-Debug/PurePhone.elf - - name: run unit tests + - name: build unit tests run: | pushd build-linux-Debug && \ export JOBS=${JOBS:-`nproc`} && \ echo "JOBS=${JOBS}" && \ - make -j ${JOBS} check && \ + make -j ${JOBS} unittests && \ popd + - name: run unit tests + run: | + ./tools/run_unittests.sh enabled_unittests + - name: store build artefact + run: | + tar cf /artefacts/build-$(git rev-parse --short HEAD).tar build-linux-Debug - name: start emulator run: | ./run_emulator_on_filesystem_image.sh 2>&1 > emulator.log & @@ -103,16 +109,60 @@ jobs: run: cat emulator.log if: always() - emulator_on_off_test: - name: emulator on-off test - if: github.event.pull_request.draft == false - runs-on: self-hosted + #emulator_on_off_test: + #Enable this test in "Clean artefacts" + # name: emulator on-off test + # if: github.event.pull_request.draft == false + # runs-on: self-hosted + # needs: + # - build_linux_binary_and_run_tests + # steps: + # - name: clone repository + # uses: actions/checkout@v2 + # with: + # token: ${{ secrets.GitHub_PAT }} + # submodules: recursive + # - name: get artefacts + # run: | + # tar xf /artefacts/build-$(git rev-parse --short HEAD).tar + # - name: start emulator on-off test + # run: ./phone_on_off_test.sh + # working-directory: test + # - name: print emulator logs + # run: cat emulator.log + # if: always() + + check_run_unit_tests: + name: Check run unit tests needs: - build_linux_binary_and_run_tests + runs-on: self-hosted steps: - - name: start emulator on-off test - run: ./phone_on_off_test.sh - working-directory: test - - name: print emulator logs - run: cat emulator.log - if: always() + - name: clone repository + uses: actions/checkout@v2 + with: + token: ${{ secrets.GitHub_PAT }} + submodules: recursive + - name: get artefacts + run: | + tar xf /artefacts/build-$(git rev-parse --short HEAD).tar + - name: check if all Unit Tests where run + run: | + ./tools/check_unittests.sh enabled_unit_tests + + clean_artefacts: + name: Clean Artefacts + if: always() + #needs: [ build_linux_binary_and_run_tests, emulator_on_off_test, check_run_unit_tests ] + needs: [ build_linux_binary_and_run_tests, check_run_unit_tests ] + runs-on: self-hosted + steps: + - name: clone repository + uses: actions/checkout@v2 + with: + token: ${{ secrets.GitHub_PAT }} + submodules: recursive + - name: Delete Artefact + run: | + rm -f /artefacts/build-$(git rev-parse --short HEAD).tar + diff --git a/enabled_unittests b/enabled_unittests new file mode 100644 index 0000000000000000000000000000000000000000..514e73e1f98d2fe929c2aa5b5a80190d5624aa5c --- /dev/null +++ b/enabled_unittests @@ -0,0 +1,320 @@ +# Enabled test list +# test format +# TESTS_LIST["catch2-"]=" +# test 1; +# test 1; +# test 3; +#" +# +# each test is in separate line +# to disable test just rem it by putting # in front of it +# +declare -A TESTS_LIST + +TESTS_LIST["catch2-audio-test"]=" + Test audio tags; + Audio settings string creation; + Test AudioMux; +" +#--------- +TESTS_LIST["catch2-calculator"]=" + Calculator utilities; +" +#--------- +TESTS_LIST["catch2-callback-storage-test"]=" + CallbackStorageTests; +" +#--------- +TESTS_LIST["catch2-cellular-datatransfer"]=" + Quectel AT DataTransfer commands; +" +#--------- +TESTS_LIST["catch2-cellular-mmi"]=" + MMI requests; +" +#--------- +TESTS_LIST["catch2-cellular-response"]=" + Response COPS; + Response CLIR; + Response CLIP; + Response CLCK; + Response CCWA?; +" +#--------- +TESTS_LIST["catch2-cellular-simcard"]=" + SimCard functionality test; +" +#--------- +TESTS_LIST["catch2-cellular-URC"]=" + +Qind: csq; + +Qind: FOTA; + +Cusd; + +Ctze; + +Creg; + +Cmti; + +CLIP; + +CPIN; + POWERED DOWN; + Urc RESPONSE; + +Qind: SMS DONE; + +Qiurc: TCP Context and connection message; +" +#--------- +TESTS_LIST["catch2-commands-queue-tests"]=" + DrawCommandsQueueTests; +" +#--------- +TESTS_LIST["catch2-context-pool-tests"]=" + ContextPoolTests; +" +#--------- +TESTS_LIST["catch2-db"]=" + SMS Table tests; + Threads Table tests; + Contacts Table tests; + Contacts Name Table tests; + Contacts Number Table tests; + Contacts Ringtones Table tests; + Contacts address Table tests; + Contact Groups tests; + [Groups]; + Alarms Table tests; + SMS Templates Table tests; + Calllog Table tests; +# Notifications Table tests; +# Events Table tests; + Notes Record tests; + Notes Table tests; + Calllog Record tests; + Contact Record db tests; + Test contact name formatting; + Test converting contact data to string; + Contact record numbers update; + SMS Record tests; + Thread Record tests; + Alarms Record tests; + SMS templates Record tests; +# Notifications Record tests; + Events Record tests; + Query interface; +" +#--------- +TESTS_LIST["catch2-db-initializer"]=" + Create and destroy simple database; + Database initialization scripts; +" +#--------- +TESTS_LIST["catch2-gui"]=" + Test BoundingBox intersect; + Are fonts loaded; + Draw window with labels; + Draw window with box layouts; + test context size and position; + insertContextTest; + gui::Item on input flow test; + gui::Window on input flow test; + Set size tests; + Parsing English input language; + Parsing numeric keyboard; + Getting charKey after clicking button twice; +" +#--------- +TESTS_LIST["catch2-gui-text"]=" + Text ctor; + Text drawLines; + Text buildDrawList; + handle input mode ABC/abc/1234; + handle longpress for digit in ABC mode; + handle text expand; + handle newline; + handle text block - moved cursor to end; + Text backup and restore tests; + Text addition bounds - text sings count restricted; + Text addition bounds - text widget size restricted; + Text addition bounds - text widget line size restricted; + Text addition bounds - multiple limits tests; + TextBlock Ctor/Dtor ; + Text block - set/update/get text; + Text block - remove text; + Text block - get width; + Text BlockCursor Ctor/Dtor ; + TextDocument <-> BlockCursor fencing tests; + TextDocument <-> BlockCursor operators: +, ++, -, -- tests; + add Char to empty; + add Char; + remove Char in empty; + remove Char; + add newline; + add newline at the end; + atEOL(); + operator-> for Text block with text; + operator* for TextBlock; + TextDocument ctor; + TextDocument getBlockCursor; + TextLine - ctor; + TextLine - non fitting text; + TextLine - multiple styles text; + TextLine - elements sizes checkup; + TextParse; + Testo Font; + TextLineCursor - navigation without scroll; + TextLineCursor - navigation with scroll; + TextLineCursor - addition and deletion with scroll; +" +#--------- +TESTS_LIST["catch2-service-db"]=" + DB_API; + Settings Messages; +# FileIndexer; +" +#--------- +TESTS_LIST["catch2-service-db-settings"]=" + SettingsApi; +" +#--------- +TESTS_LIST["catch2-service-desktop"]=" + System Update Tests; + Parser Test; + DB Helpers test - json decoding; + DB Helpers test - json encoding (contacts); + DB Helpers test - json encoding (messages); + Context class test; + Endpoint Factory test; +" +#--------- +TESTS_LIST["catch2-service-evtmgr"]=" + ScreenLightControlFunctions; +" +#--------- +TESTS_LIST["catch2-unittest_parse_CSCA"]=" + CSCA parser test; + CSCA set data; +" +#--------- +TESTS_LIST["catch2-utils"]=" + Split tests; + toNumeric tests; + findAndReplaceAll tests; + Converts enum to string; + Get value from string; + Swap endianness; + Floating point to string; + Fill leading digit in string; + Read file length; +" +#--------- +TESTS_LIST["catch2-utils-clipboard"]=" + Clipboard; +" +#--------- +TESTS_LIST["catch2-utils-duration"]=" + Duration - creation; + Duration - arithemtics; + Duration - comparision; + Duration - display; +" +#--------- +TESTS_LIST["catch2-utils-loggerbuffer"]=" + LoggerBuffer tests; +" +#--------- +TESTS_LIST["catch2-utils-math"]=" + Math; +" +#--------- +TESTS_LIST["catch2-utils-phonenumber"]=" + PhoneNumber - parsing; + PhoneNumber - formatting; + PhoneNumber - views; + PhoneNumber - equality; + PhoneNumber - matching; + PhoneNumber - record validation; + Number matcher - basics; + Number matcher - match incoming (full list); + Number matcher - match incoming (loose); +" +#--------- +TESTS_LIST["catch2-utils-ucs2"]=" + UCS2 to UTF8 conversion; + UCS2 from UTF8 emoji 😁; + UCS2 from UTF8 emoji 🍣; + UTF8 to UCS2 conversion; + TEST special input characters from UTF8; + TEST special input characters from std::string; + UTF8 emoji 🍣 from UCS2 code; + UTF8 emoji 😁 and text ęą from UCS2 code; + UTF8 emoji 😁 and text abc from UCS2 code; + UCS2 to UTF8 long string conversion; + UTF8 to UCS2 long string conversion; +" +#--------- +TESTS_LIST["catch2-utils-utf8"]=" + UTF8: operator index returns value; + UTF8: operator index exceeds string size; + UTF8: operator== returns properly; + UTF8: substr returns empty string when zero length is passed; + UTF8: substr returns empty string when length is exceeded; + UTF8: substr returns proper begin char; + UTF8: substr returns proper string length; + UTF8: find returns npos if not found; + UTF8: find returns npos if pos exceeds string length; + UTF8: find returns position of passed string; + UTF8: find returns position of passed string when pos is passed; + UTF8: findLast returns npos if not found; + UTF8: findLast returns npos if pos exceeds string length; + UTF8: findLast returns position of passed string; + UTF8: findLast returns position of passed string when pos is passed; + UTF8: split returns empty object if idx exceeds string length; + UTF8: split returns propper string; + UTF8: split strings have propper length after split; + UTF8: split summary length is equal after split; + UTF8: getLine returns empty string if its not line; + UTF8: getLine returns proper string when line ends with n; + UTF8: getLine returns proper string when line ends with r; + UTF8: removeChar returns false when string to remove exceed; + UTF8: removeChar returns false when pos to remove exceed; + UTF8: removeChar returns propper string; + UTF8: getChar; + UTF8: encode / decode / how it works; + UTF8 bad case scenario - operator[] returns; + U8char && UTF8: encode; +" +#--------- +TESTS_LIST["catch2-vfs"]=" + Test vfs case 1; + VFS lseek check; + Simple file notifier init; + Simple file notifier write; +" +#--------- +TESTS_LIST["catch2-vfs-core-fs"]=" + Corefs: Registering and unregistering block device; + Corefs: Basic API test; + Corefs: Create new file, write, read from it; + Corefs: Register null filesystem; + Corefs: Mount empty strings; + Corefs: Write to not valid file descriptor; + Corefs: Directory operations; + Unititest integrated subsystem; +" +#--------- +TESTS_LIST["catch2-vfs-disk"]=" + Registering and unregistering device; + Parsing and checking partititons; + RW boundary checking; + Null pointer passed to disk manager functions; + Boundary checks for partitions; + Disk sectors out of range for partition; +" +#--------- +TESTS_LIST["catch2-vfs-littlefs"]=" + Littlefs: Basic mount and functionality; + littlefs: Basic API test; +" +#--------- +TESTS_LIST["catch2-utils-parserIcs"]=" +" +#--------- +TESTS_LIST["catch2-utils-time_display"]=" + Time display parser; +" diff --git a/module-apps/application-calendar/data/dateCommon.hpp b/module-apps/application-calendar/data/dateCommon.hpp index f598dabee864cdcc1b04f5826fb924dadd146b8b..9e39c336d303d0212c4f3c2f4bbcdebf84ec6ca6 100644 --- a/module-apps/application-calendar/data/dateCommon.hpp +++ b/module-apps/application-calendar/data/dateCommon.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #ifndef DATECOMMON_H @@ -176,7 +176,7 @@ inline std::string TimePointToString(const TimePoint &tp, date::months months) } } timePoint += tpHourMinuteSecond; - return date::format("%F %T", time_point_cast(timePoint)); + return date::format("%F %T", std::chrono::time_point_cast(timePoint)); } inline std::string TimePointToString(const TimePoint &tp, date::years years) @@ -187,7 +187,7 @@ inline std::string TimePointToString(const TimePoint &tp, date::years years) yearMonthDay += years; TimePoint timePoint = date::sys_days{yearMonthDay.year() / yearMonthDay.month() / yearMonthDay.day()}; timePoint += tpHourMinuteSecond; - return date::format("%F %T", time_point_cast(timePoint)); + return date::format("%F %T", std::chrono::time_point_cast(timePoint)); } inline std::string TimePointToLocalizedDateString(const TimePoint &tp, const std::string format = "") diff --git a/module-db/CMakeLists.txt b/module-db/CMakeLists.txt index 7f3bdebf38b5cc4e6fb56b54afdd6ed9861dd969..ccd53332fd91cee785a19a71ce79cfc2fdfd8a06 100644 --- a/module-db/CMakeLists.txt +++ b/module-db/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.12) project(module-db VERSION 1.0 DESCRIPTION "Database module library") @@ -175,8 +175,7 @@ target_link_libraries(${PROJECT_NAME} module-utils module-vfs ) # Host target configuration(mainly used for unit testing) if (${ENABLE_TESTS}) - message(WARNING "Unit tests for module-db are disabled until they're fixed (EGD-5583).") -# add_subdirectory(tests) + add_subdirectory(tests) endif () third_party_source_optimization(${SQLITE3_SOURCE}) diff --git a/module-db/tests/EventsRecord_tests.cpp b/module-db/tests/EventsRecord_tests.cpp index 555957d5f0901f144ef87235413990485471fa9b..d147b97af33e03aa87156e3776f05eab0198c4d0 100644 --- a/module-db/tests/EventsRecord_tests.cpp +++ b/module-db/tests/EventsRecord_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include @@ -130,7 +130,6 @@ TEST_CASE("Events Record tests") .provider_iCalUid = "test6"}; auto check_record = [](const EventsRecord &actual, const EventsRecord &expected) { - // CHECK(actual.ID == expected.ID); CHECK(actual.UID == expected.UID); CHECK(actual.title == expected.title); CHECK(TimePointToString(actual.date_from) == TimePointToString(expected.date_from)); diff --git a/module-db/tests/NotesTable_tests.cpp b/module-db/tests/NotesTable_tests.cpp index 00e665aa2f0773e20952f2f100a29264c470bfdc..09351cc5b915b63b36887fa94a68c25bb6698e5c 100644 --- a/module-db/tests/NotesTable_tests.cpp +++ b/module-db/tests/NotesTable_tests.cpp @@ -1,7 +1,6 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md -#include "vfs.hpp" #include #include @@ -75,4 +74,4 @@ TEST_CASE("Notes Table tests") } Database::deinitialize(); -} \ No newline at end of file +} diff --git a/module-db/tests/QueryInterface.cpp b/module-db/tests/QueryInterface.cpp index d1af4a132f2000f401083539e7a4eaf49e20a5e1..e189e907ad70659e7578c2c93b43ef3829d8119b 100644 --- a/module-db/tests/QueryInterface.cpp +++ b/module-db/tests/QueryInterface.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include @@ -19,6 +19,8 @@ #include #include +#include + namespace db { diff --git a/module-gui/test/test-catch-text/test-gui-Text.cpp b/module-gui/test/test-catch-text/test-gui-Text.cpp index 92f9d98e8fec98276fab08d2b23da25bdbbac9bd..7859be0f08658d7d28fcf5cf8897202310039828 100644 --- a/module-gui/test/test-catch-text/test-gui-Text.cpp +++ b/module-gui/test/test-catch-text/test-gui-Text.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "BoundingBox.hpp" @@ -201,16 +201,15 @@ TEST_CASE("handle input mode ABC/abc/1234") } } -// this test hangs - disabling -// TEST_CASE("handle longpress for digit in ABC mode") -//{ -// auto text = gui::TestText(); -// auto str = text.getText() + "1"; -// auto key_1 = gui::InputEvent({}, gui::InputEvent::State::keyReleasedLong, gui::KeyCode::KEY_1); -// text.setInputMode(new InputMode({InputMode::ABC})); -// text.onInput(key_1); -// REQUIRE(str == text.getText()); -//} +TEST_CASE("handle longpress for digit in ABC mode") +{ + auto text = gui::TestText(); + auto str = text.getText() + "1"; + auto key_1 = gui::InputEvent({}, gui::InputEvent::State::keyReleasedLong, gui::KeyCode::KEY_1); + text.setInputMode(new InputMode({InputMode::ABC})); + text.onInput(key_1); + REQUIRE(str == text.getText()); +} TEST_CASE("handle text expand") { diff --git a/module-gui/test/test-catch/CMakeLists.txt b/module-gui/test/test-catch/CMakeLists.txt index adbac305c8577d890e367f7e33db85cb09b1cb4d..d5b906e0e42fac9deb30241e0a36c8bd5222746f 100644 --- a/module-gui/test/test-catch/CMakeLists.txt +++ b/module-gui/test/test-catch/CMakeLists.txt @@ -14,6 +14,7 @@ add_catch2_executable( .. LIBS module-gui + module-vfs iosyscalls DEPS assets diff --git a/module-gui/test/test-catch/test-language-input-parser.cpp b/module-gui/test/test-catch/test-language-input-parser.cpp index 6f5f17ddcb2787c7692c348e8324d150936468a5..fd62daf58d0ee0b9df7e6d117d4e96984be2e8e8 100644 --- a/module-gui/test/test-catch/test-language-input-parser.cpp +++ b/module-gui/test/test-catch/test-language-input-parser.cpp @@ -1,9 +1,13 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include #include +#include + +extern class vfs vfs; + TEST_CASE("Parsing English input language") { @@ -12,6 +16,8 @@ TEST_CASE("Parsing English input language") SECTION("Getting charKey from lower letters") { + vfs.Init(); + key.key_code = bsp::KeyCodes::NumericKey1; REQUIRE(translator.handle(key, "English_lower") == 46); key.key_code = bsp::KeyCodes::NumericKey2; @@ -36,6 +42,8 @@ TEST_CASE("Parsing English input language") SECTION("Getting charKey from upper letters") { + vfs.Init(); + key.key_code = bsp::KeyCodes::NumericKey1; REQUIRE(translator.handle(key, "English_upper") == 46); key.key_code = bsp::KeyCodes::NumericKey2; @@ -61,6 +69,8 @@ TEST_CASE("Parsing English input language") TEST_CASE("Parsing numeric keyboard") { + vfs.Init(); + gui::KeyInputMappedTranslation translator; RawKey key; @@ -88,6 +98,8 @@ TEST_CASE("Parsing numeric keyboard") TEST_CASE("Getting charKey after clicking button twice") { + vfs.Init(); + gui::KeyInputMappedTranslation translator; gui::KeyBaseTranslation baseTranslation; RawKey key; diff --git a/module-services/service-db/CMakeLists.txt b/module-services/service-db/CMakeLists.txt index 5bff9ccf78ec06d279f6d0e6963cbcef649e6200..99c34a8a5dfb036b5cb81bd1ddb93377f3e7c87d 100644 --- a/module-services/service-db/CMakeLists.txt +++ b/module-services/service-db/CMakeLists.txt @@ -35,7 +35,6 @@ target_link_libraries(${PROJECT_NAME} ) if (${ENABLE_TESTS}) - message(WARNING "Unit tests for service-db are disabled until they're fixed (EGD-5583).") -# add_subdirectory(test) + add_subdirectory(test) endif () diff --git a/module-services/service-db/agents/settings/SettingsAgent.cpp b/module-services/service-db/agents/settings/SettingsAgent.cpp index a3de42eca38e386f55cdfb826a10222847d7c31f..ecbc45c73e8b94ceffe2cb97123d6689510f5d00 100644 --- a/module-services/service-db/agents/settings/SettingsAgent.cpp +++ b/module-services/service-db/agents/settings/SettingsAgent.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "SettingsAgent.hpp" @@ -231,7 +231,7 @@ auto SettingsAgent::handleRegisterOnVariableChange(sys::Message *req) -> sys::Me if (dbRegisterValueChange(path)) { auto it = variableChangeRecipents.find(path.variable); if (variableChangeRecipents.end() == it || it->second.end() == it->second.find(path)) { - variableChangeRecipents[path.variable] = {path.service}; + variableChangeRecipents[path.to_string()] = {path}; auto currentValue = dbGetValue(path).value_or(""); auto msgValue = std::make_shared<::settings::Messages::VariableChanged>(path, currentValue, ""); sys::Bus::SendUnicast(std::move(msgValue), msg->sender, parentService); diff --git a/module-utils/test/CMakeLists.txt b/module-utils/test/CMakeLists.txt index d72a34c6346eb00d7fac58df80450cd2489ae5df..0884e925432d9776804a24e8d54761d733022fbd 100644 --- a/module-utils/test/CMakeLists.txt +++ b/module-utils/test/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.12) # Phone number tests add_catch2_executable( @@ -102,15 +102,15 @@ add_catch2_executable( #) # time display tests -#add_catch2_executable( -# NAME -# utils-time_display -# SRCS -# unittest_TimeRangeParser.cpp -# LIBS -# module-utils -# module-db -#) +add_catch2_executable( + NAME + utils-time_display + SRCS + unittest_TimeRangeParser.cpp + LIBS + module-utils + module-db +) ########################################### # Log functional tests project diff --git a/tools/check_unittests.sh b/tools/check_unittests.sh new file mode 100755 index 0000000000000000000000000000000000000000..3d98f27ccf19a3a1640303806bfcdc326631477e --- /dev/null +++ b/tools/check_unittests.sh @@ -0,0 +1,121 @@ +#!/bin/bash +# Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +root_dir="$(realpath $(dirname $(realpath $0))/..)" +build_dir="${root_dir}/build-linux-Debug" + +ALL_TESTS_FILE=all_unittests +ALL_TESTS_PATH=${build_dir}/${ALL_TESTS_FILE} +ENABLED_TESTS_PATH=${root_dir}/enabled_unittests + +END=0 + +trim() { + local var="$*" + # remove leading whitespace characters + var="${var#"${var%%[![:space:]]*}"}" + # remove trailing whitespace characters + var="${var%"${var##*[![:space:]]}"}" + printf '%s' "$var" +} + + +# get all tests +${root_dir}/tools/get_unittests.sh ${ALL_TESTS_FILE} CHECK_OUT > /dev/null +TEMP_SOURCE=$(mktemp) +sed -e '/^[[:space:]]*#.*/d' ${ALL_TESTS_PATH} > $TEMP_SOURCE +source ${TEMP_SOURCE} + +# get enabled tests +sed -e '/^[[:space:]]*#.*/d' ${ENABLED_TESTS_PATH} > $TEMP_SOURCE +source ${TEMP_SOURCE} + +declare -a BINARY_NOT_RUN +declare -A TESTS_NOT_RUN +echo "--tests--" +for BINARY in ${!CHECK_OUT[@]} +do + #echo BINARY:$BINARY + #echo "TESTS_LIST[${BINARY}]: ${TESTS_LIST[${BINARY}]}" + if [[ -n "${TESTS_LIST[${BINARY}]}" ]]; then + #echo "" + readarray -d\; -t TESTS_FROM_ALL < <(echo ${CHECK_OUT["${BINARY}"]} | tr "\n" " ") + #declare -p TESTS_FROM_ALL + #echo "NO: ${#TESTS_FROM_ALL[@]}" + I=0 + declare -a TEST_NOT_RUN + while [[ ${I} -lt ${#TESTS_FROM_ALL[@]} ]]; + do + CURRENT_TEST=$(trim ${TESTS_FROM_ALL[${I}]}) + if [[ -n "$CURRENT_TEST" ]]; then + #if [[ ${BINARY} == "catch2-gui-text" ]]; then + # echo "--- CURRENT_TEST: ${CURRENT_TEST}" + #fi + CHK=$(echo ${TESTS_LIST["${BINARY}"]} | grep -F "${CURRENT_TEST}") + #echo "#@#@#@# $CHK #@#@##" + if [[ -z "${CHK}" ]]; then + #echo "!!!!!!!!!!${CURRENT_TEST}!!!!!!!!!" + TEST_NOT_RUN+=("${CURRENT_TEST}") + fi + fi + I=$(( $I + 1 )) + done + if [[ "${#TEST_NOT_RUN[@]}" -gt 0 ]]; then + #echo "!@@!@!@!@!@! ${#TEST_NOT_RUN[@]} @!#!@#!@#!" + #declare -p TEST_NOT_RUN + I=0 + TEST_NOT_RUN_STR="" + while [[ $I -lt ${#TEST_NOT_RUN[@]} ]] + do + #TEST_NOT_RUN_STR="${TEST_NOT_RUN[${I}]};${TEST_NOT_RUN_STR}" + TEST_NOT_RUN_STR="${TEST_NOT_RUN_STR};${TEST_NOT_RUN[${I}]}" + I=$(( I + 1 )) + done + TESTS_NOT_RUN["${BINARY}"]="${TEST_NOT_RUN_STR}" + unset TEST_NOT_RUN + fi + else + #echo "######## $BINARY ########" + BINARY_NOT_RUN+=($BINARY) + fi +done + +if [[ -n "${BINARY_NOT_RUN}" ]]; then + END=1 + I=0 + echo "binaries not run:" + while [[ $I -lt ${#BINARY_NOT_RUN[@]} ]] + do + echo " - ${BINARY_NOT_RUN[$I]}" + I=$(( $I + 1 )) + done +fi +pushd ${build_dir} > /dev/null +BINARIES_IN_BUILD=( `ls -1 catch2*` ) +popd > /dev/null +BINARIES_IN_DECLARED=( ${!TESTS_LIST[@]} ) + +if [[ ${#BINARIES_IN_BUILD[@]} -ne ${#BINARIES_IN_DECLARED[@]} ]]; then + END=1 + echo "not all binaries were build:" + printf '\t- %s\n' ${BINARIES_IN_BUILD[@]} ${BINARIES_IN_DECLARED[@]} | sort | uniq -u +fi +#declare -p TESTS_NOT_RUN +#echo ${#TESTS_NOT_RUN[@]} +if [[ "${#TESTS_NOT_RUN[@]}" -gt 0 ]]; then + END=1 + echo "Tests not run:" + for BINARY in ${!TESTS_NOT_RUN[@]} + do + echo -n " - Binary: ${BINARY}" + echo "${TESTS_NOT_RUN[${BINARY}]}" | sed 's/;/\n\t- /g' + done +fi + +case $END in + "0") echo "OK";; + "*") echo "ERROR";; +esac + +exit $END diff --git a/tools/get_unittests.sh b/tools/get_unittests.sh new file mode 100755 index 0000000000000000000000000000000000000000..2cb8d91e8cba9b2eefcbb9e2ed658c8437f43bff --- /dev/null +++ b/tools/get_unittests.sh @@ -0,0 +1,61 @@ +#!/bin/bash +# Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +root_dir="$(realpath $(dirname $(realpath $0))/..)" +build_dir="${root_dir}/build-linux-Debug" + +function help() { + cat <<- EOF + Usage: $0 tests_list [VAR_NAME] + EOF +} + + +if [[ $# -lt 1 ]]; then + help + exit 1 +fi + +TESTS_FILE=$1 + +TESTS_LIST_VAR=${2:-TESTS_LIST} + +function addHeader() { +cat <<- EOF + # Enabled test list + # test format + # TESTS_LIST["catch2-"]=" + # test 1; + # test 1; + # test 3; + #" + # + # each test is in separate line + # to disable test just rem it by putting # in front of it + # + declare -A ${TESTS_LIST_VAR} + +EOF +} + +pushd ${build_dir} +addHeader > ${TESTS_FILE} + +for TEST_BINARY in catch2-* +do + echo "${TEST_BINARY}" + echo "${TESTS_LIST_VAR}[\"${TEST_BINARY}\"]=\"" >> ${TESTS_FILE} + + readarray -t TESTS_LIST < <(./${TEST_BINARY} -l | grep -e "^ " | xargs -i{} echo {} ) + I=0 + while [[ $I -lt ${#TESTS_LIST[@]} ]] + do + echo -e " ${TESTS_LIST[$I]};" >> ${TESTS_FILE} + I=$(( $I + 1 )) + done + echo "\"" >> ${TESTS_FILE} + echo "#---------" >> ${TESTS_FILE} +done +popd + diff --git a/tools/run_unittests.sh b/tools/run_unittests.sh new file mode 100755 index 0000000000000000000000000000000000000000..7f3ce5cbd4331e86d26c7aed611be13c971c1cec --- /dev/null +++ b/tools/run_unittests.sh @@ -0,0 +1,58 @@ +#!/bin/bash -e +# Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +root_dir="$(realpath $(dirname $(realpath $0))/..)" +build_dir="${root_dir}/build-linux-Debug" + + +function help() { + cat <<- EOF + Usage: $0 tests_list + EOF +} + +trim() { + local var="$*" + # remove leading whitespace characters + var="${var#"${var%%[![:space:]]*}"}" + # remove trailing whitespace characters + var="${var%"${var##*[![:space:]]}"}" + printf '%s' "$var" +} + +if [[ $# -ne 1 ]]; then + help + exit 1 +fi + +TESTS_FILE=$1 + +if [[ ! -r ${TESTS_FILE} ]]; then + echo "Cannot read: \"${TESTS_FILE}\"" + exit 2 +fi + +TEMP_SOURCE=$(mktemp) + +sed -e '/^[[:space:]]*#.*/d' ${TESTS_FILE} > $TEMP_SOURCE + +source ${TEMP_SOURCE} + +pushd ${build_dir} +for TEST_BINARY in catch2-* +do + echo "= ${TEST_BINARY} =" + readarray -d\; -t TESTS < <(echo ${TESTS_LIST["${TEST_BINARY}"]} | tr "\n" " " ) + I=0 + while [[ $I -lt ${#TESTS[@]} ]] + do + CUR_TEST=$( trim ${TESTS[$I]}) + if [[ -n "${CUR_TEST}" ]]; then + echo ${TEST_BINARY} \"${CUR_TEST}\" + ./${TEST_BINARY} "${CUR_TEST}" + fi + I=$(( $I + 1 )) + done +done +popd