From 74ae1a6589caaf2f822bec932476bbd4b4c12a94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Smoczy=C5=84ski?= Date: Mon, 28 Jun 2021 11:55:56 +0200 Subject: [PATCH] [EGD-7031] Remove UT deps to the production image MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove dependency to the production image by creating separate sysroot for test assets alongside with a test image Test.img. Signed-off-by: Marcin Smoczyński --- CMakeLists.txt | 4 +- board/CMakeLists.txt | 2 + board/linux/CMakeLists.txt | 1 + board/linux/libiosyscalls/CMakeLists.txt | 30 +++--- .../linux/libiosyscalls/include/iosyscalls.h | 7 ++ .../libiosyscalls/include/iosyscalls.hpp | 57 +---------- board/linux/libiosyscalls/src/interface.cpp | 19 ++++ .../libiosyscalls/src/iosyscalls-internal.hpp | 58 +++++++++++ board/linux/libiosyscalls/src/iosyscalls.cpp | 95 +++++++++++++------ .../libiosyscalls/src/syscalls_posix.cpp | 20 ++-- .../src/syscalls_posix_dirent.cpp | 2 +- .../src/syscalls_scan_family.cpp | 10 +- .../libiosyscalls/src/syscalls_stdio.cpp | 2 +- board/linux/libiosyscalls/version.txt | 4 + board/rt1051/CMakeLists.txt | 0 cmake/modules/AddBootBin.cmake | 1 - cmake/modules/Assets.cmake | 27 ++++++ cmake/modules/DiskImage.cmake | 65 +++++++++---- generate_image.sh | 21 ++-- image/CMakeLists.txt | 25 +---- .../tests/CMakeLists.txt | 11 +-- module-db/tests/CMakeLists.txt | 9 +- .../tests/test-initializer/CMakeLists.txt | 10 +- .../test/test-catch-text/CMakeLists.txt | 5 +- module-gui/test/test-catch/CMakeLists.txt | 9 +- module-gui/test/test-google/CMakeLists.txt | 1 + module-platform/CMakeLists.txt | 7 ++ module-platform/linux/CMakeLists.txt | 1 + module-platform/linux/src/LinuxPlatform.cpp | 3 + module-platform/linux/tests/CMakeLists.txt | 17 ++-- module-platform/linux/tests/genlfstestimg.sh | 15 +-- module-platform/linux/tests/test-setup.hpp | 9 ++ .../linux/tests/unittest_disk_manager.cpp | 13 ++- .../linux/tests/unittest_filesystem_core.cpp | 33 +++---- .../tests/unittest_filesystem_dualmount.cpp | 10 +- .../linux/tests/unittest_iosys.cpp | 2 +- .../service-db/test/CMakeLists.txt | 4 +- .../test/test-settings/CMakeLists.txt | 1 - .../service-desktop/tests/CMakeLists.txt | 27 ++++-- module-utils/board/CMakeLists.txt | 2 - module-utils/i18n/tests/CMakeLists.txt | 1 + module-utils/test/CMakeLists.txt | 13 --- module-utils/time/test/CMakeLists.txt | 4 +- module-vfs/CMakeLists.txt | 2 +- products/BellHybrid/CMakeLists.txt | 8 +- products/PurePhone/CMakeLists.txt | 6 +- test/CMakeLists.txt | 42 ++++++-- test/filesystem.cpp | 17 ++++ 48 files changed, 447 insertions(+), 285 deletions(-) create mode 100644 board/CMakeLists.txt create mode 100644 board/linux/CMakeLists.txt create mode 100644 board/linux/libiosyscalls/include/iosyscalls.h create mode 100644 board/linux/libiosyscalls/src/interface.cpp create mode 100644 board/linux/libiosyscalls/src/iosyscalls-internal.hpp create mode 100644 board/rt1051/CMakeLists.txt create mode 100644 cmake/modules/Assets.cmake create mode 100644 module-platform/linux/tests/test-setup.hpp create mode 100644 test/filesystem.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 38ae1fb16159ec6b2302c8db755ecad169b5f8b6..030dad4d2679cd7ea75b9c92fc1565222bee0a8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -111,9 +111,7 @@ endif () add_subdirectory(third-party) -if (${PROJECT_TARGET} STREQUAL "TARGET_Linux") - add_subdirectory(board/linux/libiosyscalls) -endif() +add_subdirectory(board) add_subdirectory(source) add_subdirectory(module-platform) diff --git a/board/CMakeLists.txt b/board/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..032d480419b22ffd017150339aa71a2866ca0e5a --- /dev/null +++ b/board/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(board STATIC) +add_subdirectory(${PROJECT_TARGET_NAME}) diff --git a/board/linux/CMakeLists.txt b/board/linux/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..aba4005523827196f58ba65854427ac16846fac3 --- /dev/null +++ b/board/linux/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(libiosyscalls) diff --git a/board/linux/libiosyscalls/CMakeLists.txt b/board/linux/libiosyscalls/CMakeLists.txt index f2d96d2186fa0c5911d92a9d49a0631b4af30056..32ba5b88cba3603cf1a6a5894634b63e90840877 100644 --- a/board/linux/libiosyscalls/CMakeLists.txt +++ b/board/linux/libiosyscalls/CMakeLists.txt @@ -3,16 +3,6 @@ project(iosyscalls VERSION 1.0 DESCRIPTION "linux syscalls wrapper to our VFS" ) - -set(SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/src/syscalls_stdio.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/syscalls_scan_family.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/syscalls_posix.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/syscalls_posix_dirent.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/iosyscalls.cpp -) - - set(INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_SOURCE_DIR}/module-os/board/linux" @@ -22,8 +12,26 @@ set(INCLUDES "${CMAKE_SOURCE_DIR}/module-vfs/include/internal" ) +add_library(${PROJECT_NAME} SHARED) + +target_sources( + ${PROJECT_NAME} -add_library(${PROJECT_NAME} SHARED ${SOURCES}) + PRIVATE + src/interface.cpp + src/iosyscalls-internal.hpp + src/iosyscalls.cpp + src/syscalls_posix_dirent.cpp + src/syscalls_posix.cpp + src/syscalls_real.hpp + src/syscalls_scan_family.cpp + src/syscalls_stdio.cpp + + PUBLIC + include/debug.hpp + include/iosyscalls.h + include/iosyscalls.hpp +) target_compile_options( ${PROJECT_NAME} PRIVATE "-Wno-nonnull-compare" ) get_target_property( target_options ${PROJECT_NAME} COMPILE_OPTIONS) diff --git a/board/linux/libiosyscalls/include/iosyscalls.h b/board/linux/libiosyscalls/include/iosyscalls.h new file mode 100644 index 0000000000000000000000000000000000000000..b730af61b0a1f456ca16441b4f86ca77c56707f9 --- /dev/null +++ b/board/linux/libiosyscalls/include/iosyscalls.h @@ -0,0 +1,7 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +void iosyscalls_set_image_name(const char *newImageName); +void iosyscalls_set_sysroot(const char *newSysroot); diff --git a/board/linux/libiosyscalls/include/iosyscalls.hpp b/board/linux/libiosyscalls/include/iosyscalls.hpp index c6e5b2f2b155d3bee718fbe7f81f1a0ed8863a86..c0ac3775f2217812e26f590e191a5e77293e9b83 100644 --- a/board/linux/libiosyscalls/include/iosyscalls.hpp +++ b/board/linux/libiosyscalls/include/iosyscalls.hpp @@ -1,56 +1,5 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - #pragma once -#include -#include -#include - -struct __dirstream; - -namespace vfsn::linux::internal +extern "C" { - bool redirect_to_image(); - bool is_image_handle(const FILE *fil); - bool is_image_fd(int fd); - bool redirect_to_image(const char *inpath); - const char *npath_translate(const char *inpath, char *buffer); - - struct FILEX - { - int fd{0}; - int error{0}; - int ungetchar{-1}; - }; - - int to_native_fd(int fd); - int to_image_fd(int fd); - - FILEX *allocate_filex(int fd); - bool is_filex(const void *fd); - void remove_filex(FILEX *fil); - - void add_DIR_to_image_list(__dirstream *indir); - void remove_DIR_from_image_list(__dirstream *indir); - bool is_image_DIR(__dirstream *indir); - - template - auto invoke_fs(T Base::*lfs_fun, Args &&... args) - -> decltype((static_cast(nullptr)->*lfs_fun)(std::forward(args)...)) - { - auto vfs = purefs::subsystem::vfs_core(); - if (!vfs) { - errno = EIO; - return -1; - } - auto ret = (vfs.get()->*lfs_fun)(std::forward(args)...); - if (ret < 0) { - errno = -ret; - ret = -1; - } - else { - errno = 0; - } - return ret; - } -} // namespace vfsn::linux::internal +#include "iosyscalls.h" +} diff --git a/board/linux/libiosyscalls/src/interface.cpp b/board/linux/libiosyscalls/src/interface.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8abc163cbad178afc5f67466f938776fec391556 --- /dev/null +++ b/board/linux/libiosyscalls/src/interface.cpp @@ -0,0 +1,19 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "iosyscalls-internal.hpp" + +extern "C" +{ + namespace vfs = vfsn::linux::internal; + + void iosyscalls_set_sysroot(const char *newSysroot) + { + vfs::set_sysroot(newSysroot); + } + + void iosyscalls_set_image_name(const char *newImageName) + { + vfs::set_image_path(newImageName); + } +} diff --git a/board/linux/libiosyscalls/src/iosyscalls-internal.hpp b/board/linux/libiosyscalls/src/iosyscalls-internal.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f10e7ac3b98a98f678cc932e21ef9b87f13f68a6 --- /dev/null +++ b/board/linux/libiosyscalls/src/iosyscalls-internal.hpp @@ -0,0 +1,58 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once +#include +#include +#include + +struct __dirstream; + +namespace vfsn::linux::internal +{ + void set_image_path(const char *newImageName); + void set_sysroot(const char *newSysroot); + bool redirect_to_image(); + bool is_image_handle(const FILE *fil); + bool is_image_fd(int fd); + bool redirect_to_image(const char *inpath); + const char *npath_translate(const char *inpath, char *buffer); + + struct FILEX + { + int fd{0}; + int error{0}; + int ungetchar{-1}; + }; + + int to_native_fd(int fd); + int to_image_fd(int fd); + + FILEX *allocate_filex(int fd); + bool is_filex(const void *fd); + void remove_filex(FILEX *fil); + + void add_DIR_to_image_list(__dirstream *indir); + void remove_DIR_from_image_list(__dirstream *indir); + bool is_image_DIR(__dirstream *indir); + + template + auto invoke_fs(T Base::*lfs_fun, Args &&... args) + -> decltype((static_cast(nullptr)->*lfs_fun)(std::forward(args)...)) + { + auto vfs = purefs::subsystem::vfs_core(); + if (!vfs) { + errno = EIO; + return -1; + } + auto ret = (vfs.get()->*lfs_fun)(std::forward(args)...); + if (ret < 0) { + errno = -ret; + ret = -1; + } + else { + errno = 0; + } + return ret; + } +} // namespace vfsn::linux::internal diff --git a/board/linux/libiosyscalls/src/iosyscalls.cpp b/board/linux/libiosyscalls/src/iosyscalls.cpp index 447259aeff0475207a20e55e06743dbfd73794c2..31d5a3cf4a827bf8b118a64613c2f346f1f7df9e 100644 --- a/board/linux/libiosyscalls/src/iosyscalls.cpp +++ b/board/linux/libiosyscalls/src/iosyscalls.cpp @@ -1,45 +1,55 @@ // 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 -#include -#include -#include -#include -#include +#include "iosyscalls-internal.hpp" + #include +#include + #include +#include +#include + +#include + +#include +#include +#include +#include +#include namespace { constexpr auto ENV_NAME = "IOSYSCALLS_REDIRECT_TO_IMAGE"; constexpr auto FIRST_FILEDESC = 64'566'756; + constexpr auto SYSROOT = "sysroot"; bool g_evaluated = false; bool g_redirect = false; - constexpr const char *LINUX_PATHS[]{"/dev/", - "/etc/", - "/lib", - "/usr/share", - "/run/user", - "/home", - "/proc", - "PurePhone.img", - "MuditaOS.log", - "/tmp", - nullptr}; + constexpr const char *LINUX_PATHS[]{ + "/dev/", "/etc/", "/lib", "/usr/share", "/run/user", "/home", "/proc", "/tmp", "MuditaOS.log", nullptr}; - constexpr const char *IMAGE_PATHS[]{"/sys", "/mfgconf", "assets", "country-codes.db", "Luts.bin", nullptr}; + constexpr const char *IMAGE_PATHS[]{"/sys", "/mfgconf", "sys", "assets", "country-codes.db", "Luts.bin", nullptr}; pthread_mutex_t g_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; phmap::flat_hash_set g_fdlist; phmap::flat_hash_set g_dirlist; + std::string imageFileName; + std::string sysroot = SYSROOT; } // namespace namespace vfsn::linux::internal { + void set_sysroot(const char *newSysroot) + { + sysroot = newSysroot; + } + + void set_image_path(const char *newImageName) + { + imageFileName = std::string(newImageName); + } + bool redirect_to_image() { if (!g_evaluated) { @@ -52,33 +62,58 @@ namespace vfsn::linux::internal bool redirect_to_image(const char *inpath) { - if (!redirect_to_image()) + if (!redirect_to_image()) { return false; + } - for (auto path = LINUX_PATHS; *path; ++path) - if (std::strstr(inpath, *path) == inpath) + if (std::strstr(inpath, imageFileName.c_str()) == inpath) { + return false; + } + + for (auto path = LINUX_PATHS; *path; ++path) { + if (std::strstr(inpath, *path) == inpath) { return false; + } + } return true; } const char *npath_translate(const char *inpath, char *buffer) { - for (auto path = IMAGE_PATHS; *path; ++path) + auto inputPath = std::string(inpath); + + for (auto path = IMAGE_PATHS; *path != 0; ++path) { if (std::strstr(inpath, *path) == inpath) { - if (!std::strcmp(*path, "/mfgconf")) { - std::strncpy(buffer, "sys/", PATH_MAX); - std::strncpy(buffer + 3, inpath + 8, PATH_MAX - 3); + std::string outpath; + + if (std::strcmp(*path, "/mfgconf") == 0) { + outpath = sysroot; + outpath += "/sys/"; + outpath += inputPath; + } + else if (std::strcmp(*path, "sys") == 0) { + outpath = sysroot; + outpath += "/"; + outpath += inputPath; } else if (*inpath == '/') { - std::strncpy(buffer, inpath + 1, PATH_MAX); + outpath = sysroot + inputPath; } else { - std::strncpy(buffer, "sys/current/", PATH_MAX); - std::strncpy(buffer + 12, inpath, PATH_MAX - 12); + outpath = sysroot; + outpath += "/sys/current/"; + outpath += inputPath; } + + assert(outpath.size() < PATH_MAX); + std::copy_n(std::begin(outpath), outpath.size(), buffer); + buffer[outpath.size()] = '\0'; + return buffer; } + } + return inpath; } diff --git a/board/linux/libiosyscalls/src/syscalls_posix.cpp b/board/linux/libiosyscalls/src/syscalls_posix.cpp index a3d550252e30125c4f163d845760f21fa0453936..b2b90281cf19bd577bf645ffdc74bbbbbc5dcca0 100644 --- a/board/linux/libiosyscalls/src/syscalls_posix.cpp +++ b/board/linux/libiosyscalls/src/syscalls_posix.cpp @@ -1,19 +1,19 @@ // Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md -#include +#include "iosyscalls-internal.hpp" -#include -#include -#include -#include -#include -#include -#include -#include #include -#include // for va_* +#include #include // for PATH_MAX +#include +#include // for va_* +#include +#include +#include +#include +#include +#include #include "syscalls_real.hpp" diff --git a/board/linux/libiosyscalls/src/syscalls_posix_dirent.cpp b/board/linux/libiosyscalls/src/syscalls_posix_dirent.cpp index e497abf6a9a8993c3809e3ea9657142b9cc5ece4..a9ef2f7f78ea9467de7e7d8165a2a252c24b869c 100644 --- a/board/linux/libiosyscalls/src/syscalls_posix_dirent.cpp +++ b/board/linux/libiosyscalls/src/syscalls_posix_dirent.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md -#include +#include "iosyscalls-internal.hpp" #include #include diff --git a/board/linux/libiosyscalls/src/syscalls_scan_family.cpp b/board/linux/libiosyscalls/src/syscalls_scan_family.cpp index 315ad46ecf8597c24de876fd345798e5c3a96768..c1087ef764f436683f3a520ead7df94e4dafc816 100644 --- a/board/linux/libiosyscalls/src/syscalls_scan_family.cpp +++ b/board/linux/libiosyscalls/src/syscalls_scan_family.cpp @@ -1,15 +1,15 @@ // Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md +#include "iosyscalls-internal.hpp" + +#include "debug.hpp" +#include "syscalls_real.hpp" + #include #include #include #include -#include - -#include "syscalls_real.hpp" - -#include "debug.hpp" namespace { diff --git a/board/linux/libiosyscalls/src/syscalls_stdio.cpp b/board/linux/libiosyscalls/src/syscalls_stdio.cpp index 2b3814ff9f1805e57627dea5951781b0854ec708..bae13e9eb3daae4bdfc5c0d4fc4336dae3b3d458 100644 --- a/board/linux/libiosyscalls/src/syscalls_stdio.cpp +++ b/board/linux/libiosyscalls/src/syscalls_stdio.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md -#include +#include "iosyscalls-internal.hpp" #include #include diff --git a/board/linux/libiosyscalls/version.txt b/board/linux/libiosyscalls/version.txt index 71cb276b2a3e74fb9513d6f0712274ea6e116db7..ffca0d4e420059003f3faef6a10b10f9dfd169a1 100644 --- a/board/linux/libiosyscalls/version.txt +++ b/board/linux/libiosyscalls/version.txt @@ -94,3 +94,7 @@ GLIBC_2.33 { lstat64; fstat64; }; +IOSYSCALLS_1.0 { + global: + iosyscalls_*; +}; diff --git a/board/rt1051/CMakeLists.txt b/board/rt1051/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/cmake/modules/AddBootBin.cmake b/cmake/modules/AddBootBin.cmake index 1ee70f41409305107ef15b5c28f5d923042e5d29..40fe69c34ebe6d02a9c3cdb69b6ac438c1cb861d 100644 --- a/cmake/modules/AddBootBin.cmake +++ b/cmake/modules/AddBootBin.cmake @@ -35,5 +35,4 @@ function(add_boot_bin SOURCE_TARGET) message("Adding '${SOURCE_TARGET}-boot.bin' target") add_custom_target(${SOURCE_TARGET}-boot.bin DEPENDS ${BIN_FILE}) - set_target_properties(${SOURCE_TARGET}-boot.bin PROPERTIES BIN_FILE ${BIN_FILE}) endfunction() diff --git a/cmake/modules/Assets.cmake b/cmake/modules/Assets.cmake new file mode 100644 index 0000000000000000000000000000000000000000..0ca4b3c04fad310dfe7cf39a12b855f95f6d8b01 --- /dev/null +++ b/cmake/modules/Assets.cmake @@ -0,0 +1,27 @@ +set(ASSETS_SOURCE_DIR ${CMAKE_SOURCE_DIR}/image) + +macro(add_assets_target) + + set(_ASSETS_TARGET ${ARGV0}) + set(_ASSETS_SOURCE_DIR ${ARGV1}) + set(_ASSETS_DEST_DIR ${ARGV2}) + + add_custom_target( + ${_ASSETS_TARGET} + COMMAND mkdir -p ${_ASSETS_DEST_DIR} + COMMAND rsync -qravu --delete + ${_ASSETS_SOURCE_DIR}/.boot.json* + ${_ASSETS_SOURCE_DIR}/personalization.json + ${_ASSETS_DEST_DIR} + COMMAND rsync -qravu --delete + ${_ASSETS_SOURCE_DIR}/assets + ${_ASSETS_SOURCE_DIR}/Luts.bin + ${_ASSETS_SOURCE_DIR}/country-codes.db + ${_ASSETS_DEST_DIR}/current + COMMAND rsync -qravu --delete + ${_ASSETS_SOURCE_DIR}/user + ${_ASSETS_DEST_DIR} + COMMENT + "Copying assets.. (${_ASSETS_TARGET})" + ) +endmacro() diff --git a/cmake/modules/DiskImage.cmake b/cmake/modules/DiskImage.cmake index 1e8c160626d0de3e382edd506b6a694ecdb78ed8..663e5e733d0fa6bedfee573223f07d3af8c9d71a 100644 --- a/cmake/modules/DiskImage.cmake +++ b/cmake/modules/DiskImage.cmake @@ -1,32 +1,57 @@ -function(add_image SOURCE_TARGET) - set(DISK_IMAGE_NAME ${SOURCE_TARGET}.img) - set(DISK_IMAGE ${CMAKE_BINARY_DIR}/${DISK_IMAGE_NAME}) - set(BIN_FILE_TARGET ${SOURCE_TARGET}-boot.bin) - get_target_property(BIN_FILE ${BIN_FILE_TARGET} BIN_FILE) - - if (${PROJECT_TARGET} STREQUAL "TARGET_RT1051") - SET(TARGET_DEP ${BIN_FILE} pureflash) +function(add_image) + cmake_parse_arguments( + _ARG + "" + "PRODUCT;SYSROOT;ASSETS" + "" + ${ARGN} + ) + + if(NOT ${PROJECT_TARGET_NAME} STREQUAL "linux") + set(HAS_BOOTFILE YES) + set(RUNS_ON_HARDWARE YES) + endif() + + set(SCRIPT_PATH ${CMAKE_SOURCE_DIR}/generate_image.sh) + + set(DISK_IMAGE_NAME ${_ARG_PRODUCT}.img) + set(DISK_IMAGE_PATH ${CMAKE_BINARY_DIR}/${DISK_IMAGE_NAME}) + + if(HAS_BOOTFILE) + set(BIN_FILE_TARGET ${_ARG_PRODUCT}-boot.bin) + set(BIN_FILE_PATH ${CMAKE_BINARY_DIR}/sys/current/${_ARG_PRODUCT}-boot.bin) else() - SET(TARGET_DEP ${SOURCE_TARGET}) + set(BIN_FILE_PATH "") + endif() + + set(COMMAND_DEPENDS "genlittlefs") + list(APPEND COMMNDS_DEPENDS ${SCRIPT_PATH}) + if(_ARG_ASSETS) + list(APPEND COMMAND_DEPENDS ${_ARG_ASSETS}) + endif() + if(RUNS_ON_HARDWARE) + list(APPEND COMMAND_DEPENDS pureflash) + endif() + if(HAS_BOOTFILE) + list(APPEND COMMAND_DEPENDS ${BIN_FILE_TARGET}) endif() add_custom_command( OUTPUT ${DISK_IMAGE_NAME} - DEPENDS genlittlefs - DEPENDS assets - DEPENDS ${BIN_FILE_TARGET} - DEPENDS ${TARGET_DEP} - DEPENDS ${CMAKE_SOURCE_DIR}/generate_image.sh - COMMAND ${CMAKE_SOURCE_DIR}/generate_image.sh - ${DISK_IMAGE} - ${CMAKE_BINARY_DIR} - "$<$:${BIN_FILE}>" + DEPENDS ${COMMAND_DEPENDS} + COMMAND + ${SCRIPT_PATH} + ${DISK_IMAGE_NAME} + ${CMAKE_BINARY_DIR}/${_ARG_SYSROOT} + "${BIN_FILE_PATH}" WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMENT "Generate ${DISK_IMAGE_NAME}" - ) + ) message("Adding disk image target: ${DISK_IMAGE_NAME}") - add_custom_target(${SOURCE_TARGET}-disk-img + + add_custom_target(${_ARG_PRODUCT}-disk-img DEPENDS ${DISK_IMAGE_NAME}) endfunction() + diff --git a/generate_image.sh b/generate_image.sh index ba648ae560806de24493bec7bfdeee394bc4ac5c..70555062a001f8e59cc3d8abeda6480deaac4b55 100755 --- a/generate_image.sh +++ b/generate_image.sh @@ -5,8 +5,8 @@ usage() { cat << ==usage Usage: $(basename $0) image_path build_dir [boot.bin_file] - image_path - Destination image path name e.g. PurePhone.img - build_dir - PurePhone build dir e.g. build-rt1051-RelWithDebInfo + image_path - Destination image path name e.g., PurePhone.img + sysroot - product's system root e.g., build-rt1051-RelWithDebInfo/sysroot boot.bin_file - optional for linux image - name of the boot.bin file (for different targets) ==usage } @@ -18,11 +18,11 @@ if [[ ( $# -ne 2 ) && ( $# -ne 3 ) ]]; then fi IMAGE_NAME=$(realpath $1) -BUILDDIR=$(realpath $2) +SYSROOT=$(realpath $2) BIN_FILE=$3 -if [ ! -d "$BUILDDIR" ]; then - echo "Error! \${build_dir} (${BUILDDIR}) is not a directory" +if [ ! -d "$SYSROOT" ]; then + echo "Error! ${SYSROOT} is not a directory" usage exit -1 fi @@ -49,7 +49,7 @@ if [ ! $MTOOLS_OK ]; then exit -1 fi -GENLFS=$(find $BUILDDIR -type f -iname genlittlefs -executable -print -quit) +GENLFS=$(realpath $(find $BUILDDIR -type f -iname genlittlefs -executable -print -quit)) if [ -z ${GENLFS} ]; then echo "Error: Unable to find genlilttlefs..." exit -1 @@ -82,11 +82,11 @@ unit: sectors PART1="$IMAGE_NAME@@$(($PART1_START * $DEVICE_BLK_SIZE))" mformat -i "$PART1" -F -T $PART1_SIZE -M $DEVICE_BLK_SIZE -v MUDITAOS -if [ ! -d "$BUILDDIR/sys" ]; then +if [ ! -d "${SYSROOT}/sys" ]; then echo "Fatal! Image folder sys/ missing in build. Check build system." exit -1 fi -cd "$BUILDDIR"/sys +cd "${SYSROOT}/sys" #Copy FAT data CURRENT_DATA="assets country-codes.db Luts.bin" @@ -97,7 +97,7 @@ mmd -i "$PART1" ::/updates for i in $CURRENT_DATA; do f="current/$i" - if [ -f "$f" -o -d "$f" ]; then + if [ -f "$f" -o -d "$f" ]; then mcopy -s -i "$PART1" $f ::/current/ else echo "Error! Unable to copy item: $f" @@ -106,7 +106,7 @@ for i in $CURRENT_DATA; do done if [[ -n "${BIN_FILE}" && -f "${BIN_FILE}" ]]; then - mcopy -v -s -i "$PART1" ${BIN_FILE} ::/current/boot.bin + mcopy -v -s -i "$PART1" ${BIN_FILE} ::/current/boot.bin else echo "Warning! Missing boot.bin" echo "(it's fine for a Linux build)" @@ -116,6 +116,7 @@ mcopy -s -i "$PART1" .boot.json :: mcopy -s -i "$PART1" .boot.json.crc32 :: #Littlefs generate image +echo $(pwd) $GENLFS --image=$IMAGE_NAME --block_size=32768 --overwrite --partition_num=3 -- user/* $GENLFS --image=$IMAGE_NAME --block_size=4096 --overwrite --partition_num=2 diff --git a/image/CMakeLists.txt b/image/CMakeLists.txt index 3e58b891c10f943a9e4e5536de8bb811d6614300..4a66fa4807f0b69419082c23c6cbf749970f905a 100644 --- a/image/CMakeLists.txt +++ b/image/CMakeLists.txt @@ -1,25 +1,10 @@ -include(Utils) +include(Assets) +include(Utils) -set(ASSETS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") -set(ASSETS_DEST_DIR "${CMAKE_BINARY_DIR}/sys") +set(SYSROOT ${CMAKE_BINARY_DIR}/sysroot) +set(ASSETS_DEST_DIR ${SYSROOT}/sys) -add_custom_target( - assets - COMMAND rsync -ravu --delete - ${ASSETS_SOURCE_DIR}/.boot.json* - ${ASSETS_SOURCE_DIR}/personalization.json - ${ASSETS_DEST_DIR} - COMMAND rsync -ravu --delete - ${ASSETS_SOURCE_DIR}/assets - ${ASSETS_SOURCE_DIR}/Luts.bin - ${ASSETS_SOURCE_DIR}/country-codes.db - ${ASSETS_DEST_DIR}/current - COMMAND rsync -ravu --delete - ${ASSETS_SOURCE_DIR}/user - ${ASSETS_DEST_DIR} - COMMENT - "Copying assets.." - ) +add_assets_target(assets ${ASSETS_SOURCE_DIR} ${ASSETS_DEST_DIR}) multicomp_install( FILES diff --git a/module-apps/application-calculator/tests/CMakeLists.txt b/module-apps/application-calculator/tests/CMakeLists.txt index 35a0b9ab002a8187f308ccc17178cfb048ecbc36..2f8932c47fd9ae4d53309648d6db7b983d030268 100644 --- a/module-apps/application-calculator/tests/CMakeLists.txt +++ b/module-apps/application-calculator/tests/CMakeLists.txt @@ -1,8 +1,4 @@ -if (NOT IS_SYMLINK "${CMAKE_BINARY_DIR}/sys/user") - file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/sys/user") -endif() - -add_catch2_executable( +add_catch2_executable( NAME calculator SRCS @@ -11,11 +7,8 @@ add_catch2_executable( CalculatorUtility_tests.cpp LIBS application-calculator - iosyscalls - module-gui module-sys - DEPS - assets + USE_FS ) target_include_directories(catch2-calculator PRIVATE $) diff --git a/module-db/tests/CMakeLists.txt b/module-db/tests/CMakeLists.txt index 244b26eceec201bacd4ceb298f8c8d9d84053943..aea5bb0122ed438ec1d98aa9118796a44edd2020 100644 --- a/module-db/tests/CMakeLists.txt +++ b/module-db/tests/CMakeLists.txt @@ -1,7 +1,3 @@ -if (NOT IS_SYMLINK "${CMAKE_BINARY_DIR}/sys/user") - file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/sys/user") -endif() - add_catch2_executable( NAME db @@ -34,11 +30,8 @@ add_catch2_executable( LIBS module-sys - iosyscalls module-db json::json - DEPS - assets - PurePhone-disk-img + USE_FS ) add_subdirectory(test-initializer) diff --git a/module-db/tests/test-initializer/CMakeLists.txt b/module-db/tests/test-initializer/CMakeLists.txt index 7a408d4c7ea437feae9f22aaa6f60657c62b86fa..39e95e8a3c9cfde9388bf293080639b230fbb6b7 100644 --- a/module-db/tests/test-initializer/CMakeLists.txt +++ b/module-db/tests/test-initializer/CMakeLists.txt @@ -1,7 +1,3 @@ -if (NOT IS_SYMLINK "${CMAKE_BINARY_DIR}/sys/user") - file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/sys/user") -endif() - add_catch2_executable( NAME db-initializer @@ -11,9 +7,7 @@ add_catch2_executable( LIBS module-sys - iosyscalls module-db - DEPS - assets - PurePhone-disk-img + + USE_FS ) diff --git a/module-gui/test/test-catch-text/CMakeLists.txt b/module-gui/test/test-catch-text/CMakeLists.txt index 30681ad107be57b40c9675d4551af7d0b04d527f..98073ccdbfe54dc15d33c19e14f0ab5652a49d69 100644 --- a/module-gui/test/test-catch-text/CMakeLists.txt +++ b/module-gui/test/test-catch-text/CMakeLists.txt @@ -21,9 +21,6 @@ add_catch2_executable( ../mock/ LIBS module-sys - iosyscalls module-gui - DEPS - assets - PurePhone-disk-img + USE_FS ) diff --git a/module-gui/test/test-catch/CMakeLists.txt b/module-gui/test/test-catch/CMakeLists.txt index f0bee7e44b38dc66ba0d97bcbf3f05480f0b2845..5d7d51b6b32a54488fcf73a0812d49184a81912e 100644 --- a/module-gui/test/test-catch/CMakeLists.txt +++ b/module-gui/test/test-catch/CMakeLists.txt @@ -10,15 +10,12 @@ add_catch2_executable( test-gui-image.cpp ../mock/TestWindow.cpp ../mock/InitializedFontManager.cpp - test-language-input-parser.cpp - test-key-translator.cpp + test-language-input-parser.cpp + test-key-translator.cpp INCLUDE .. LIBS module-sys - iosyscalls module-gui - DEPS - assets - PurePhone-disk-img + USE_FS ) diff --git a/module-gui/test/test-google/CMakeLists.txt b/module-gui/test/test-google/CMakeLists.txt index 25aa104da58a0e26a3b4e5b95047c7d5ff9c02e9..135c5ec3f9ec0d154c3da03e8c337102e4ee2e86 100644 --- a/module-gui/test/test-google/CMakeLists.txt +++ b/module-gui/test/test-google/CMakeLists.txt @@ -12,4 +12,5 @@ add_gtest_executable( LIBS module-utils module-gui + USE_FS ) diff --git a/module-platform/CMakeLists.txt b/module-platform/CMakeLists.txt index c488f4d90f632478511bc124ce3c364fd7de2fe1..666a4fa1f48bf1d59fc8b2c122e025745b017208 100644 --- a/module-platform/CMakeLists.txt +++ b/module-platform/CMakeLists.txt @@ -16,4 +16,11 @@ target_sources( include/Platform.hpp ) +target_link_libraries( + platform + + PRIVATE + module-bsp +) + add_subdirectory(${PROJECT_TARGET_NAME}) diff --git a/module-platform/linux/CMakeLists.txt b/module-platform/linux/CMakeLists.txt index 8dc1386083b3891ccde28f5736e2c18c827684cd..9111909cf7d9b844f292016220c8e92344503715 100644 --- a/module-platform/linux/CMakeLists.txt +++ b/module-platform/linux/CMakeLists.txt @@ -21,6 +21,7 @@ target_include_directories( target_link_libraries( platform PRIVATE + iosyscalls module-vfs ) diff --git a/module-platform/linux/src/LinuxPlatform.cpp b/module-platform/linux/src/LinuxPlatform.cpp index 46fcc78e33b7504ab45270c4e8fdc8ba5f165372..4cb470c6f67ae38346999c262fde04d6e6bf54f2 100644 --- a/module-platform/linux/src/LinuxPlatform.cpp +++ b/module-platform/linux/src/LinuxPlatform.cpp @@ -6,6 +6,7 @@ #include "BlockDeviceFactory.hpp" #include +#include #include #include @@ -36,6 +37,8 @@ void LinuxPlatform::initFilesystem() throw std::runtime_error("Filesystem already initialized"); } + iosyscalls_set_image_name(imageName.c_str()); + auto blockDeviceFactory = std::make_unique(imageName); vfs = purefs::subsystem::initialize(std::move(blockDeviceFactory)); diff --git a/module-platform/linux/tests/CMakeLists.txt b/module-platform/linux/tests/CMakeLists.txt index da24a75446ff6496324a234c94433e84133b85f4..1890ff4066b7051628c2012ab5d91d57d876990a 100644 --- a/module-platform/linux/tests/CMakeLists.txt +++ b/module-platform/linux/tests/CMakeLists.txt @@ -1,3 +1,5 @@ + +set(TEST_SYSROOT ${CMAKE_BINARY_DIR}/test-sysroot) add_custom_target("test_disk_image") add_custom_command( PRE_BUILD @@ -12,9 +14,9 @@ add_catch2_executable( ${CMAKE_CURRENT_LIST_DIR}/unittest_disk_manager.cpp LIBS platform - module-vfs DEPS test_disk_image + USE_FS ) add_catch2_executable( @@ -24,14 +26,15 @@ add_catch2_executable( LIBS platform module-vfs + USE_FS ) set(LITTLEFS_IMAGE "lfstest.img") add_custom_target( ${LITTLEFS_IMAGE} - COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/genlfstestimg.sh 1G ${LITTLEFS_IMAGE} + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/genlfstestimg.sh 1G ${LITTLEFS_IMAGE} ${TEST_SYSROOT} WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - DEPENDS genlittlefs assets + DEPENDS genlittlefs test-assets ) add_catch2_executable( @@ -40,9 +43,9 @@ add_catch2_executable( ${CMAKE_CURRENT_LIST_DIR}/unittest_filesystem_littlefs.cpp LIBS platform - module-vfs DEPS ${LITTLEFS_IMAGE} + USE_FS ) add_catch2_executable( @@ -51,9 +54,9 @@ add_catch2_executable( ${CMAKE_CURRENT_LIST_DIR}/unittest_filesystem_dualmount.cpp LIBS platform - module-vfs DEPS ${LITTLEFS_IMAGE} + USE_FS ) # iosyscalls tests @@ -65,10 +68,8 @@ add_catch2_executable( LIBS module-sys module-vfs - iosyscalls platform - DEPS - PurePhone-disk-img + USE_FS ) # prepare test assets diff --git a/module-platform/linux/tests/genlfstestimg.sh b/module-platform/linux/tests/genlfstestimg.sh index f0f7282ad6dfea870c6f75754747cf3b918ae3a0..e515dfa9359ff8a2d948a17d0e4a65bcc20e4c75 100755 --- a/module-platform/linux/tests/genlfstestimg.sh +++ b/module-platform/linux/tests/genlfstestimg.sh @@ -4,7 +4,7 @@ usage() { cat << ==usage -Usage: $(basename $0) [image_size] [image_file] [files]... +Usage: $(basename $0) [image_size] [image_file] [sysroot] [files]... image_size Target disk image size image_file Target image name files Files to include in the image @@ -19,7 +19,13 @@ if [ $# -lt 2 ]; then fi IMAGE_SIZE="$1" IMAGE_FILE="$2" -shift 2 +SYSROOT="$3" +shift 3 + +if [ ! -d "${SYSROOT}/sys" ]; then + echo "Invalid sysroot: ${SYSROOT}" + exit -1 +fi _REQ_CMDS="sfdisk truncate" for cmd in $_REQ_CMDS; do @@ -33,8 +39,6 @@ truncate -s $IMAGE_SIZE $IMAGE_FILE SECTOR_START=2048 SECTOR_END=$(( $(stat -c "%s" $IMAGE_FILE)/512 - $SECTOR_START)) - - sfdisk $IMAGE_FILE << ==sfdisk label: dos unit: sectors @@ -42,5 +46,4 @@ unit: sectors /dev/sdz1 : start=$SECTOR_START, size=$SECTOR_END, type=9e ==sfdisk pwd -./genlittlefs --image $IMAGE_FILE --block_size=32768 --overwrite --partition_num 1 -- sys/.boot.json sys/current/assets/* module-platform/test_dir/* - +./genlittlefs --image $IMAGE_FILE --block_size=32768 --overwrite --partition_num 1 -- ${SYSROOT}/sys/.boot.json ${SYSROOT}/sys/current/assets/* module-platform/test_dir/* diff --git a/module-platform/linux/tests/test-setup.hpp b/module-platform/linux/tests/test-setup.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f3c2ddea69560d571b36746965646804d6b81ada --- /dev/null +++ b/module-platform/linux/tests/test-setup.hpp @@ -0,0 +1,9 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +namespace testing::vfs +{ + constexpr auto disk_image = "Test.img"; +} diff --git a/module-platform/linux/tests/unittest_disk_manager.cpp b/module-platform/linux/tests/unittest_disk_manager.cpp index 93070f31554e91646c21675f9b4d55a18d33818c..5c706e80a113c54a6980de1bf1878a0556a71eba 100644 --- a/module-platform/linux/tests/unittest_disk_manager.cpp +++ b/module-platform/linux/tests/unittest_disk_manager.cpp @@ -3,12 +3,15 @@ #define CATCH_CONFIG_MAIN #include #include + #include + +#include "test-setup.hpp" + #include namespace { - constexpr auto disk_image = "PurePhone.img"; constexpr auto part_disk_image = "test_disk.img"; constexpr auto part_disk_image_ext = "test_disk_ext.img"; constexpr auto part_disk_image_bad = "test_disk_bad.img"; @@ -19,7 +22,7 @@ TEST_CASE("Registering and unregistering device") { using namespace purefs; blkdev::disk_manager dm; - auto disk = std::make_shared(disk_image); + auto disk = std::make_shared(::testing::vfs::disk_image); REQUIRE(disk); REQUIRE(dm.register_device(disk, "emmc0") == 0); REQUIRE(dm.register_device(disk, "emmc0") == -EEXIST); @@ -93,7 +96,7 @@ TEST_CASE("RW boundary checking") { using namespace purefs; blkdev::disk_manager dm; - auto disk = std::make_shared(disk_image); + auto disk = std::make_shared(::testing::vfs::disk_image); REQUIRE(disk); REQUIRE(dm.register_device(disk, "emmc0") == 0); const auto parts = dm.partitions("emmc0"); @@ -112,7 +115,7 @@ TEST_CASE("Alternative partitions in the disk manager") { using namespace purefs; blkdev::disk_manager dm; - auto disk = std::make_shared(disk_image); + auto disk = std::make_shared(::testing::vfs::disk_image); REQUIRE(disk); REQUIRE(dm.register_device(disk, "emmc0") == 0); const auto sect_size = dm.get_info("emmc0", blkdev::info_type::sector_size); @@ -291,7 +294,7 @@ TEST_CASE("Disk sectors out of range for partition") { using namespace purefs; blkdev::disk_manager dm; - auto disk = std::make_shared(disk_image); + auto disk = std::make_shared(::testing::vfs::disk_image); REQUIRE(disk); REQUIRE(dm.register_device(disk, "emmc1") == 0); const auto parts = dm.partitions("emmc1"); diff --git a/module-platform/linux/tests/unittest_filesystem_core.cpp b/module-platform/linux/tests/unittest_filesystem_core.cpp index d0451805236ce9155d5419f8f63eea9a4c0f7487..fe25864f5ee0cdc2b4e9a7408fa991aa901ac3d6 100644 --- a/module-platform/linux/tests/unittest_filesystem_core.cpp +++ b/module-platform/linux/tests/unittest_filesystem_core.cpp @@ -10,21 +10,22 @@ #include #include #include + +#include + +#include "test-setup.hpp" + +#include + #include #include #include -#include - -namespace -{ - constexpr auto disk_image = "PurePhone.img"; -} TEST_CASE("Corefs: Registering and unregistering block device") { using namespace purefs; auto dm = std::make_shared(); - auto disk = std::make_shared(disk_image); + auto disk = std::make_shared(::testing::vfs::disk_image); REQUIRE(disk); REQUIRE(dm->register_device(disk, "emmc0") == 0); purefs::fs::filesystem fscore(dm); @@ -58,7 +59,7 @@ TEST_CASE("Corefs: Basic API test") { using namespace purefs; auto dm = std::make_shared(); - auto disk = std::make_shared(disk_image); + auto disk = std::make_shared(::testing::vfs::disk_image); REQUIRE(disk); REQUIRE(dm->register_device(disk, "emmc0") == 0); purefs::fs::filesystem fscore(dm); @@ -117,7 +118,7 @@ TEST_CASE("Corefs: Create new file, write, read from it") { using namespace purefs; auto dm = std::make_shared(); - auto disk = std::make_shared(disk_image); + auto disk = std::make_shared(::testing::vfs::disk_image); REQUIRE(disk); REQUIRE(dm->register_device(disk, "emmc0") == 0); purefs::fs::filesystem fscore(dm); @@ -162,7 +163,7 @@ TEST_CASE("Corefs: Register null filesystem") { using namespace purefs; auto dm = std::make_shared(); - auto disk = std::make_shared(disk_image); + auto disk = std::make_shared(::testing::vfs::disk_image); REQUIRE(disk); REQUIRE(dm->register_device(disk, "emmc0") == 0); purefs::fs::filesystem fscore(dm); @@ -173,7 +174,7 @@ TEST_CASE("Corefs: Mount empty strings") { using namespace purefs; auto dm = std::make_shared(); - auto disk = std::make_shared(disk_image); + auto disk = std::make_shared(::testing::vfs::disk_image); REQUIRE(disk); REQUIRE(dm->register_device(disk, "emmc0") == 0); purefs::fs::filesystem fscore(dm); @@ -189,7 +190,7 @@ TEST_CASE("Corefs: Write to not valid file descriptor") { using namespace purefs; auto dm = std::make_shared(); - auto disk = std::make_shared(disk_image); + auto disk = std::make_shared(::testing::vfs::disk_image); REQUIRE(disk); REQUIRE(dm->register_device(disk, "emmc0") == 0); purefs::fs::filesystem fscore(dm); @@ -211,7 +212,7 @@ TEST_CASE("Corefs: Directory operations") { using namespace purefs; auto dm = std::make_shared(); - auto disk = std::make_shared(disk_image); + auto disk = std::make_shared(::testing::vfs::disk_image); REQUIRE(disk); REQUIRE(dm->register_device(disk, "emmc0") == 0); purefs::fs::filesystem fscore(dm); @@ -277,7 +278,7 @@ TEST_CASE("Corefs: Read only filesystem") { using namespace purefs; auto dm = std::make_shared(); - auto disk = std::make_shared(disk_image); + auto disk = std::make_shared(::testing::vfs::disk_image); REQUIRE(disk); REQUIRE(dm->register_device(disk, "emmc0") == 0); purefs::fs::filesystem fscore(dm); @@ -314,7 +315,7 @@ TEST_CASE("Corefs: Remount filesystem from RO to RW and to RO") { using namespace purefs; auto dm = std::make_shared(); - auto disk = std::make_shared(disk_image); + auto disk = std::make_shared(::testing::vfs::disk_image); REQUIRE(disk); REQUIRE(dm->register_device(disk, "emmc0") == 0); auto fscore = std::make_shared(dm); @@ -350,7 +351,7 @@ TEST_CASE("Corefs: Autodetect filesystems") { using namespace purefs; auto dm = std::make_shared(); - auto disk = std::make_shared(disk_image); + auto disk = std::make_shared(::testing::vfs::disk_image); REQUIRE(disk); REQUIRE(dm->register_device(disk, "emmc0") == 0); auto fscore = std::make_shared(dm); diff --git a/module-platform/linux/tests/unittest_filesystem_dualmount.cpp b/module-platform/linux/tests/unittest_filesystem_dualmount.cpp index 1646871b0c0daa603078931f748afc76789b564a..e5baec1e6688636b88325eb002da36d1eb325379 100644 --- a/module-platform/linux/tests/unittest_filesystem_dualmount.cpp +++ b/module-platform/linux/tests/unittest_filesystem_dualmount.cpp @@ -10,14 +10,16 @@ #include #include #include + +#include "test-setup.hpp" + #include #include #include namespace { - constexpr auto vfat_disk_image = "PurePhone.img"; - constexpr auto lfs_disk_image = "lfstest.img"; + constexpr auto lfs_disk_image = "lfstest.img"; auto prepare_filesystem(std::string_view vfat_dev_name, std::string_view lfs_dev_name) -> std::pair, std::shared_ptr> @@ -25,7 +27,7 @@ namespace using namespace purefs; auto dm = std::make_shared(); - auto vfat_disk = std::make_shared(vfat_disk_image); + auto vfat_disk = std::make_shared(::testing::vfs::disk_image); auto lfs_disk = std::make_shared(lfs_disk_image); if (dm->register_device(vfat_disk, vfat_dev_name) != 0) { @@ -55,7 +57,7 @@ TEST_CASE("dualmount: Basic mount") using namespace purefs; auto dm = std::make_shared(); - auto vfat_disk = std::make_shared(vfat_disk_image); + auto vfat_disk = std::make_shared(::testing::vfs::disk_image); auto lfs_disk = std::make_shared(lfs_disk_image); REQUIRE(vfat_disk); REQUIRE(lfs_disk); diff --git a/module-platform/linux/tests/unittest_iosys.cpp b/module-platform/linux/tests/unittest_iosys.cpp index 77e62d5856cd54b1dad0b0d1b881531a5e663f3a..2bacaf74b2abb7d2c2523688a31567100173e78a 100644 --- a/module-platform/linux/tests/unittest_iosys.cpp +++ b/module-platform/linux/tests/unittest_iosys.cpp @@ -10,7 +10,7 @@ TEST_CASE("VFS linux support") { - auto platform = platform::linux::LinuxPlatform("PurePhone.img"); + auto platform = platform::linux::LinuxPlatform("Test.img"); REQUIRE_NOTHROW(platform.init()); diff --git a/module-services/service-db/test/CMakeLists.txt b/module-services/service-db/test/CMakeLists.txt index aa70e8e3381b5952b6f1c4b1bc6d6ec623e66a7f..5ee518393c215be8fe6b52fe39dd3fccbb23690d 100644 --- a/module-services/service-db/test/CMakeLists.txt +++ b/module-services/service-db/test/CMakeLists.txt @@ -6,7 +6,6 @@ add_catch2_executable( main.cpp test-service-db-api.cpp test-service-db-settings-messages.cpp - #test-service-db-file_indexer.cpp test-service-db-quotes.cpp test-factory-settings.cpp LIBS @@ -18,8 +17,7 @@ add_catch2_executable( module-vfs service-audio service-cellular - DEPS - PurePhone-disk-img + USE_FS ) add_catch2_executable( diff --git a/module-services/service-db/test/test-settings/CMakeLists.txt b/module-services/service-db/test/test-settings/CMakeLists.txt index f614ff52b3689e74b160ad084697b5081669a5ac..c649baefbd905baf13d4ed936a53bd93ae0b5f2b 100644 --- a/module-services/service-db/test/test-settings/CMakeLists.txt +++ b/module-services/service-db/test/test-settings/CMakeLists.txt @@ -13,5 +13,4 @@ add_catch2_executable( module-cellular DEPS module-sys - PurePhone-disk-img ) diff --git a/module-services/service-desktop/tests/CMakeLists.txt b/module-services/service-desktop/tests/CMakeLists.txt index e1615be1972afbc3bf43d729a7f1a356fa79edf8..7117f655ccaf8d13254105aa7eac861220eef2e6 100644 --- a/module-services/service-desktop/tests/CMakeLists.txt +++ b/module-services/service-desktop/tests/CMakeLists.txt @@ -1,5 +1,16 @@ -file (COPY "${CMAKE_CURRENT_LIST_DIR}/muditaos-unittest.tar" DESTINATION "${CMAKE_BINARY_DIR}/sys/updates") -file (COPY "${CMAKE_CURRENT_LIST_DIR}/factory-test" DESTINATION "${CMAKE_BINARY_DIR}/sys") +file( + COPY + muditaos-unittest.tar + DESTINATION + ${TEST_ASSETS_DEST_DIR}/updates +) + +file( + COPY + factory-test + DESTINATION + ${TEST_ASSETS_DEST_DIR} +) add_catch2_executable( NAME @@ -11,9 +22,7 @@ add_catch2_executable( service-desktop module-utils module-apps - iosyscalls - DEPS - PurePhone-disk-img + USE_FS ) add_catch2_executable( @@ -26,8 +35,7 @@ add_catch2_executable( service-desktop module-utils module-apps - module-vfs - iosyscalls + USE_FS ) add_catch2_executable( @@ -40,6 +48,5 @@ add_catch2_executable( service-desktop module-utils module-apps - module-vfs - iosyscalls -) \ No newline at end of file + USE_FS +) diff --git a/module-utils/board/CMakeLists.txt b/module-utils/board/CMakeLists.txt index 56a5335aa3c658819172bf2bc3a244d39fb11fb0..bfe44b39a50cc3e6fe5d248e28e519f2ca6703af 100644 --- a/module-utils/board/CMakeLists.txt +++ b/module-utils/board/CMakeLists.txt @@ -1,5 +1,3 @@ -add_library(board STATIC) - if(${PROJECT_TARGET} STREQUAL "TARGET_Linux") target_sources(board PRIVATE diff --git a/module-utils/i18n/tests/CMakeLists.txt b/module-utils/i18n/tests/CMakeLists.txt index b8290c266d67c7f8514c0e8f7d9a42353e7bcbce..4faf6de58ccc3dee84799b84bc45810e797e4f3d 100644 --- a/module-utils/i18n/tests/CMakeLists.txt +++ b/module-utils/i18n/tests/CMakeLists.txt @@ -5,4 +5,5 @@ add_catch2_executable( test_i18n.cpp LIBS i18n + USE_FS ) diff --git a/module-utils/test/CMakeLists.txt b/module-utils/test/CMakeLists.txt index f4fed5ee5da1f8ee92d38e4a2f2655bad7762791..3185318ac7f016e750a8f1c63acb4a2efa47c701 100644 --- a/module-utils/test/CMakeLists.txt +++ b/module-utils/test/CMakeLists.txt @@ -26,9 +26,6 @@ add_catch2_executable( unittest_utils.cpp LIBS module-utils - iosyscalls - DEPS - PurePhone-disk-img ) # Log tests @@ -50,13 +47,3 @@ add_catch2_executable( LIBS module-utils ) - -# ParserICS tests -#add_catch2_executable( -# NAME -# utils-parserIcs -# SRCS -# test_ParserICS.cpp -# LIBS -# module-utils -#) diff --git a/module-utils/time/test/CMakeLists.txt b/module-utils/time/test/CMakeLists.txt index e943fd1dd19e3622884a4fb7dff448e200085d3a..e3285d9d6b19370f6efe9c94086d9ddccb9ee6ec 100644 --- a/module-utils/time/test/CMakeLists.txt +++ b/module-utils/time/test/CMakeLists.txt @@ -25,7 +25,5 @@ add_catch2_executable( LIBS time utf8 - iosyscalls - DEPS - PurePhone-disk-img + USE_FS ) diff --git a/module-vfs/CMakeLists.txt b/module-vfs/CMakeLists.txt index f989c2f279fcb6c2fb3bea1101c1852d2e9a36f2..8b5af09d9a5ee61a6d0a5db9ce377877a36138ae 100644 --- a/module-vfs/CMakeLists.txt +++ b/module-vfs/CMakeLists.txt @@ -96,7 +96,7 @@ target_include_directories(module-vfs ) target_link_libraries(module-vfs - PRIVATE + PRIVATE fatfs::fatfs json::json littlefs::littlefs diff --git a/products/BellHybrid/CMakeLists.txt b/products/BellHybrid/CMakeLists.txt index 606a90f014a3cfc255f8e9bae9c175256ec01153..73babbf7ca8e8ae99a66e378553fd7f21c1769ea 100644 --- a/products/BellHybrid/CMakeLists.txt +++ b/products/BellHybrid/CMakeLists.txt @@ -73,15 +73,17 @@ endif() set_source_files_properties(BellHybridMain.cpp PROPERTIES COMPILE_DEFINITIONS "${ENABLED_APPS_DEFINES}") - strip_executable(BellHybrid) - add_dependencies(BellHybrid version) include(AddBootBin) add_boot_bin(BellHybrid) -add_image(BellHybrid) +add_image( + PRODUCT BellHybrid + SYSROOT sysroot + ASSETS assets +) include(AddHexTarget) add_hex_target(BellHybrid) diff --git a/products/PurePhone/CMakeLists.txt b/products/PurePhone/CMakeLists.txt index 882224f7c194039b3e761efdf4d036896c81975b..4f6c4b311aba4ba1a4b73cfa645bc672a3fea2e2 100644 --- a/products/PurePhone/CMakeLists.txt +++ b/products/PurePhone/CMakeLists.txt @@ -91,7 +91,11 @@ add_dependencies(PurePhone version) include(AddBootBin) add_boot_bin(PurePhone) -add_image(PurePhone) +add_image( + PRODUCT PurePhone + SYSROOT sysroot + ASSETS assets +) include(AddHexTarget) add_hex_target(PurePhone) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 218546b628d45de7ba7b8d48e836883425aa527d..5154dc08e54c7d4692bc58ad966dc5771ade2f9f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -12,18 +12,37 @@ define_property( FULL_DOCS "Add directory to a test entity to group tests defined in the directory and its subdirectories" ) +include(Assets) +include(Catch) include(CMakeParseArguments) +include(DiskImage) include(GoogleTest) -include(Catch) add_custom_target(unittests) set(ROOT_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE) +set(TEST_ASSETS_DEST_DIR ${CMAKE_BINARY_DIR}/test-sysroot/sys) +set(TEST_ASSETS_DEST_DIR ${TEST_ASSETS_DEST_DIR} PARENT_SCOPE) + +add_assets_target(test-assets ${ASSETS_SOURCE_DIR} ${TEST_ASSETS_DEST_DIR}) +add_image( + PRODUCT Test + SYSROOT test-sysroot + ASSETS test-assets +) + +macro(enable_test_filesystem) + target_sources(${_TESTNAME} PRIVATE ${ROOT_TEST_DIR}/filesystem.cpp) + list(APPEND _TEST_ARGS_LIBS iosyscalls) + list(APPEND _TEST_ARGS_LIBS board) + list(APPEND _TEST_ARGS_INCLUDE ${CMAKE_SOURCE_DIR}/module-vfs/include/user) + list(APPEND _TEST_ARGS_DEPS Test-disk-img) +endmacro() function(add_gtest_executable) cmake_parse_arguments( _TEST_ARGS - "" + "USE_FS" "NAME" "SRCS;INCLUDE;LIBS;DEFS;DEPS" ${ARGN} @@ -51,6 +70,11 @@ function(add_gtest_executable) target_sources(${_TESTNAME} PRIVATE ${ROOT_TEST_DIR}/mock-freertos-tls.cpp) endif (NOT ${ENABLE_TEST_LOGS}) + set(_TEST_LABELS "") + if(_TEST_ARGS_USE_FS) + enable_test_filesystem() + endif() + target_link_libraries(${_TESTNAME} PRIVATE gtest_main gmock log) foreach(lib ${_TEST_ARGS_LIBS}) target_link_libraries(${_TESTNAME} PRIVATE ${lib}) @@ -74,7 +98,6 @@ function(add_gtest_executable) add_dependencies(unittests ${_TESTNAME}) add_dependencies(check ${_TESTNAME}) - set(_TEST_LABELS "") if(_TEST_ENTITY) add_dependencies(unittests-${_TEST_ENTITY} ${_TESTNAME}) list(APPEND _TEST_LABELS ${_TEST_ENTITY}) @@ -86,13 +109,13 @@ function(add_gtest_executable) TEST_LIST _TEST_LIST ) - set_tests_properties(${_TEST_LIST} PROPERTIES LABELS ${_TEST_ENTITY}) + set_tests_properties(${_TEST_LIST} PROPERTIES LABELS ${_TEST_LABELS}) endfunction() function(add_catch2_executable) cmake_parse_arguments( _TEST_ARGS - "" + "USE_FS" "NAME" "SRCS;INCLUDE;LIBS;DEFS;DEPS" ${ARGN} @@ -120,11 +143,15 @@ function(add_catch2_executable) target_sources(${_TESTNAME} PRIVATE ${ROOT_TEST_DIR}/mock-freertos-tls.cpp) endif (NOT ${ENABLE_TEST_LOGS} AND NOT ${_TESTNAME} STREQUAL "catch2-utils-log") + set(_TEST_LABELS "") + if(_TEST_ARGS_USE_FS) + enable_test_filesystem() + endif() + target_link_libraries(${_TESTNAME} PRIVATE Catch2::Catch2 log) foreach(lib ${_TEST_ARGS_LIBS}) target_link_libraries(${_TESTNAME} PRIVATE ${lib}) endforeach(lib) - foreach(include ${_TEST_ARGS_INCLUDE}) target_include_directories(${_TESTNAME} PRIVATE ${include}) endforeach(include) @@ -142,11 +169,12 @@ function(add_catch2_executable) if(_TEST_ENTITY) add_dependencies(unittests-${_TEST_ENTITY} ${_TESTNAME}) + list(APPEND _TEST_LABELS ${_TEST_ENTITY}) endif() catch_discover_tests(${_TESTNAME} WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - PROPERTIES LABELS ${_TEST_ENTITY} + PROPERTIES LABELS ${_TEST_LABELS} ) endfunction() diff --git a/test/filesystem.cpp b/test/filesystem.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d8fcc7e91105129e9dca90a227a8a608c58247d8 --- /dev/null +++ b/test/filesystem.cpp @@ -0,0 +1,17 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include + +auto constexpr TESTS_SYSROOT = "test-sysroot"; +auto constexpr IMAGE_NAME = "Test.img"; + +void __attribute__((constructor)) setup_sysroot() +{ + iosyscalls_set_sysroot(TESTS_SYSROOT); +} + +void __attribute__((constructor)) setup_disk_image() +{ + iosyscalls_set_image_name(IMAGE_NAME); +}