From 7797a2eaf0ca3d9e1132e9e957273b85750faf35 Mon Sep 17 00:00:00 2001 From: Jakub Pyszczak Date: Mon, 18 Jan 2021 10:53:43 +0100 Subject: [PATCH] [EGD-5266] Fix test harness Covers harness issues that occures on experimental branch due to the new filesystem implementation. --- board/linux/libiosyscalls/src/iosyscalls.cpp | 2 +- module-db/tests/EventsTable_tests.cpp | 78 +++++++++---------- .../endpoints/backup/BackupRestore.cpp | 10 ++- .../deviceInfo/DeviceInfoEndpoint.cpp | 2 +- .../endpoints/factoryReset/FactoryReset.cpp | 10 ++- test/pytest/service-desktop/test_backup.py | 2 +- 6 files changed, 58 insertions(+), 46 deletions(-) diff --git a/board/linux/libiosyscalls/src/iosyscalls.cpp b/board/linux/libiosyscalls/src/iosyscalls.cpp index 0906ac5a8797fc1f53dacaac1adebd8686e844b0..c8a2dd9de6aaede7420475b43982ab23b54a716a 100644 --- a/board/linux/libiosyscalls/src/iosyscalls.cpp +++ b/board/linux/libiosyscalls/src/iosyscalls.cpp @@ -26,9 +26,9 @@ namespace "/run/user", "/home", "/proc", - "/dev/shm", "PurePhone.img", "MuditaOS.log", + "/tmp", nullptr}; constexpr const char *IMAGE_PATHS[]{"/sys", nullptr}; diff --git a/module-db/tests/EventsTable_tests.cpp b/module-db/tests/EventsTable_tests.cpp index caec86d9f73373b38020ebab5c207ad6673c1104..c66df79ab22f766458c123c4a2d8ae40a6113d28 100644 --- a/module-db/tests/EventsTable_tests.cpp +++ b/module-db/tests/EventsTable_tests.cpp @@ -165,11 +165,11 @@ TEST_CASE("Events Table tests") } CHECK(eventsTbl.count() == 0); - uint32_t numberOfEvents = 7; - TimePoint startDate = TimePointFromString("2019-10-20 14:30:00"); - TimePoint endDate = TimePointFromString("2019-10-20 15:30:00"); - testRow1.date_from = startDate; - testRow1.date_till = endDate; + uint32_t numberOfEvents = 7; + TimePoint startDate = TimePointFromString("2019-10-20 14:30:00"); + TimePoint endDate = TimePointFromString("2019-10-20 15:30:00"); + testRow1.date_from = startDate; + testRow1.date_till = endDate; CHECK(eventsTbl.addDaily(testRow1)); CHECK(eventsTbl.count() == numberOfEvents); @@ -200,11 +200,11 @@ TEST_CASE("Events Table tests") } CHECK(eventsTbl.count() == 0); - uint32_t numberOfEvents = 4; - TimePoint startDate = TimePointFromString("2019-10-20 14:30:00"); - TimePoint endDate = TimePointFromString("2019-10-20 15:30:00"); - testRow1.date_from = startDate; - testRow1.date_till = endDate; + uint32_t numberOfEvents = 4; + TimePoint startDate = TimePointFromString("2019-10-20 14:30:00"); + TimePoint endDate = TimePointFromString("2019-10-20 15:30:00"); + testRow1.date_from = startDate; + testRow1.date_till = endDate; CHECK(eventsTbl.addWeekly(testRow1)); CHECK(eventsTbl.count() == numberOfEvents); @@ -235,11 +235,11 @@ TEST_CASE("Events Table tests") } CHECK(eventsTbl.count() == 0); - uint32_t numberOfEvents = 4; - TimePoint startDate = TimePointFromString("2019-10-20 14:30:00"); - TimePoint endDate = TimePointFromString("2019-10-20 15:30:00"); - testRow1.date_from = startDate; - testRow1.date_till = endDate; + uint32_t numberOfEvents = 4; + TimePoint startDate = TimePointFromString("2019-10-20 14:30:00"); + TimePoint endDate = TimePointFromString("2019-10-20 15:30:00"); + testRow1.date_from = startDate; + testRow1.date_till = endDate; CHECK(eventsTbl.addTwoWeeks(testRow1)); CHECK(eventsTbl.count() == numberOfEvents); @@ -438,9 +438,9 @@ TEST_CASE("Events Table tests") { uint32_t customRepeatOption = static_cast(weekDayOption::monday) + static_cast(weekDayOption::wednesday); - uint32_t numberOfEvents = 9; - TimePoint originalStartDate = TimePointFromString("2020-12-10 14:30:00"); // thursday - TimePoint originalEndDate = TimePointFromString("2020-12-10 15:30:00"); // thursday + uint32_t numberOfEvents = 9; + TimePoint originalStartDate = TimePointFromString("2020-12-10 14:30:00"); // thursday + TimePoint originalEndDate = TimePointFromString("2020-12-10 15:30:00"); // thursday check_custom_repeat(customRepeatOption, numberOfEvents, originalStartDate, originalEndDate); } @@ -450,19 +450,19 @@ TEST_CASE("Events Table tests") uint32_t customRepeatOption = static_cast(weekDayOption::monday) + static_cast(weekDayOption::wednesday) + static_cast(weekDayOption::tuesday) + static_cast(weekDayOption::sunday); - uint32_t numberOfEvents = 17; - TimePoint originalStartDate = TimePointFromString("2020-12-10 14:30:00"); // thursday - TimePoint originalEndDate = TimePointFromString("2020-12-10 15:30:00"); // thursday + uint32_t numberOfEvents = 17; + TimePoint originalStartDate = TimePointFromString("2020-12-10 14:30:00"); // thursday + TimePoint originalEndDate = TimePointFromString("2020-12-10 15:30:00"); // thursday check_custom_repeat(customRepeatOption, numberOfEvents, originalStartDate, originalEndDate); } SECTION("Repeat Saturdays (original thursday)") { - uint32_t customRepeatOption = static_cast(weekDayOption::saturday); - uint32_t numberOfEvents = 5; - TimePoint originalStartDate = TimePointFromString("2020-12-10 14:30:00"); // thursday - TimePoint originalEndDate = TimePointFromString("2020-12-10 15:30:00"); // thursday + uint32_t customRepeatOption = static_cast(weekDayOption::saturday); + uint32_t numberOfEvents = 5; + TimePoint originalStartDate = TimePointFromString("2020-12-10 14:30:00"); // thursday + TimePoint originalEndDate = TimePointFromString("2020-12-10 15:30:00"); // thursday check_custom_repeat(customRepeatOption, numberOfEvents, originalStartDate, originalEndDate); } @@ -516,10 +516,10 @@ TEST_CASE("Events Table tests") CHECK(eventsTbl.count() == 6); std::string newTitle = "Updated Title", newProviderID = "PurePhoneUpdated"; - TimePoint newDateFrom = TimePointFromString("2020-10-20 15:00:00"), - newDateTill = TimePointFromString("2020-10-20 16:00:00"); - uint32_t newReminder = static_cast(Reminder::one_week_before); - uint32_t newRepeatOption = static_cast(Repeat::biweekly); + TimePoint newDateFrom = TimePointFromString("2020-10-20 15:00:00"), + newDateTill = TimePointFromString("2020-10-20 16:00:00"); + uint32_t newReminder = static_cast(Reminder::one_week_before); + uint32_t newRepeatOption = static_cast(Repeat::biweekly); /// check title and provider id update auto entryToUpdate = eventsTbl.getById(testRow6.ID); @@ -571,11 +571,11 @@ TEST_CASE("Events Table tests") CHECK(eventsTbl.count() == 6); std::string newTitle = "Updated Title", newProviderType = "PurePhoneUpdate", newProviderID = "newID", - newProvideriCalUid = "new iCalUid"; - TimePoint newDateFrom = TimePointFromString("2020-10-20 15:00:00"), - newDateTill = TimePointFromString("2020-10-20 16:00:00"); - uint32_t newReminder = static_cast(Reminder::one_week_before); - uint32_t newRepeatOption = static_cast(Repeat::biweekly); + newProvideriCalUid = "new iCalUid"; + TimePoint newDateFrom = TimePointFromString("2020-10-20 15:00:00"), + newDateTill = TimePointFromString("2020-10-20 16:00:00"); + uint32_t newReminder = static_cast(Reminder::one_week_before); + uint32_t newRepeatOption = static_cast(Repeat::biweekly); /// check title and provider id update auto entryToUpdate = eventsTbl.getById(testRow6.ID); @@ -629,11 +629,11 @@ TEST_CASE("Events Table tests") CHECK(eventsTbl.count() == 6); std::string newTitle = "Updated Title", newProviderType = "PurePhoneUpdate", newProviderID = "newID", - newProvideriCalUid = "new iCalUid"; - TimePoint newDateFrom = TimePointFromString("2020-10-20 15:00:00"), - newDateTill = TimePointFromString("2020-10-20 16:00:00"); - uint32_t newReminder = static_cast(Reminder::one_week_before); - uint32_t newRepeatOption = static_cast(Repeat::biweekly); + newProvideriCalUid = "new iCalUid"; + TimePoint newDateFrom = TimePointFromString("2020-10-20 15:00:00"), + newDateTill = TimePointFromString("2020-10-20 16:00:00"); + uint32_t newReminder = static_cast(Reminder::one_week_before); + uint32_t newRepeatOption = static_cast(Repeat::biweekly); /// check title and provider id update auto entryToUpdate = eventsTbl.getByUID(testRow6.UID); diff --git a/module-services/service-desktop/endpoints/backup/BackupRestore.cpp b/module-services/service-desktop/endpoints/backup/BackupRestore.cpp index 3b782788bd996c1c06f46cc09cfeed7015322ec2..28b3e9f08bac862360e213e93fb2c0dbc45c7d16 100644 --- a/module-services/service-desktop/endpoints/backup/BackupRestore.cpp +++ b/module-services/service-desktop/endpoints/backup/BackupRestore.cpp @@ -105,8 +105,14 @@ bool BackupRestore::CreateBackupDir() LOG_INFO("CreateBackupDir: creating backup directory %s...", backupOSPath.c_str()); if (!std::filesystem::is_directory(backupOSPath.c_str())) { - if (!std::filesystem::create_directory(backupOSPath.c_str())) { - LOG_ERROR("CreateBackupDir: creating backup directory %s failed.", backupOSPath.c_str()); + try { + if (!std::filesystem::create_directory(backupOSPath.c_str())) { + LOG_ERROR("CreateBackupDir: creating backup directory %s failed.", backupOSPath.c_str()); + return false; + } + } + catch (const std::filesystem::filesystem_error &err) { + LOG_FATAL("Exception while creating dir %s", backupOSPath.c_str()); return false; } } diff --git a/module-services/service-desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp b/module-services/service-desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp index 813a2c8fc31f8614dfb6586a782da8ee2e944d88..62879f61e4765c00de5a50b60e487e2e6c47d1db 100644 --- a/module-services/service-desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp +++ b/module-services/service-desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp @@ -40,7 +40,7 @@ auto DeviceInfoEndpoint::getDeviceInfo(Context &context) -> bool return false; } auto totalMbytes = (vfstat.f_frsize * vfstat.f_blocks) / 1024LLU / 1024LLU; - auto freeMbytes = (vfstat.f_ffree * vfstat.f_bsize) / 1024LLU / 1024LLU; + auto freeMbytes = (vfstat.f_bfree * vfstat.f_bsize) / 1024LLU / 1024LLU; auto freePercent = (freeMbytes * 100) / totalMbytes; context.setResponseBody(json11::Json::object( diff --git a/module-services/service-desktop/endpoints/factoryReset/FactoryReset.cpp b/module-services/service-desktop/endpoints/factoryReset/FactoryReset.cpp index 3b961c5e7ed58dea1e1534b4b29b140ee92e20c0..242927582f5a0d351e94377dc1e413794f68f37b 100644 --- a/module-services/service-desktop/endpoints/factoryReset/FactoryReset.cpp +++ b/module-services/service-desktop/endpoints/factoryReset/FactoryReset.cpp @@ -144,8 +144,14 @@ namespace FactoryReset LOG_INFO("FactoryReset: restoring dir %s into %s...", sourcepath.c_str(), targetpath.c_str()); - if (std::filesystem::create_directory(targetpath.c_str())) { - LOG_ERROR("FactoryReset: create dir %s failed", targetpath.c_str()); + try { + if (std::filesystem::create_directory(targetpath.c_str())) { + LOG_ERROR("FactoryReset: create dir %s failed", targetpath.c_str()); + return false; + } + } + catch (const std::filesystem::filesystem_error &err) { + LOG_FATAL("Exception while creating dir %s", targetpath.c_str()); return false; } diff --git a/test/pytest/service-desktop/test_backup.py b/test/pytest/service-desktop/test_backup.py index 82cc528acab4b087819de7b486a15c80dbb3b814..719fef1f10fd2122b62ff78c67199821ff8d5f74 100644 --- a/test/pytest/service-desktop/test_backup.py +++ b/test/pytest/service-desktop/test_backup.py @@ -29,5 +29,5 @@ def test_backup(harness): body = {"backupUpload": True} ret = harness.endpoint_request("backup", "post", body) assert ret["status"] == status["OK"] - assert ret["body"]["backupUpload"] is False + assert ret["body"]["backupUpload"] is True