~aleteoryx/muditaos

18198ffa8053b5a033d9165d481547cc2f66aa2f — Wiktor S. Ovalle Correa 5 years ago 25d1831
[EGD-5737] Fix filesystem unit tests

Remove old VFS and utils::filesystem calls
Update unittest lists
M enabled_unittests => enabled_unittests +21 -11
@@ 250,7 250,6 @@ TESTS_LIST["catch2-utils"]="
    Swap endianness;
    Floating point to string;
    Fill leading digit in string;
    Read file length;
    Hex to bytes;
    Bytes to hex;
"


@@ 350,13 349,6 @@ TESTS_LIST["catch2-utils-utf8"]="
    UTF8: Not ASCII combination;
"
#---------
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;


@@ 365,12 357,17 @@ TESTS_LIST["catch2-vfs-core-fs"]="
    Corefs: Mount empty strings;
    Corefs: Write to not valid file descriptor;
    Corefs: Directory operations;
    Unititest integrated subsystem;
    Corefs: Read only filesystem;
    Corefs: Remount filesystem from RO to RW and to RO;
    Corefs: Autodetect filesystems;
    Corefs: Unittest integrated subsystem;
"
#---------
TESTS_LIST["catch2-vfs-disk"]="
    Registering and unregistering device;
    Parsing and checking partititons;
    Parsing and checking extended partititons;
    Parsing and checking invalid partititons;
    RW boundary checking;
    Null pointer passed to disk manager functions;
    Boundary checks for partitions;


@@ 378,7 375,20 @@ TESTS_LIST["catch2-vfs-disk"]="
"
#---------
TESTS_LIST["catch2-vfs-littlefs"]="
    Littlefs: Basic mount and functionality;
    littlefs: Basic API test;
    littlefs: Basic mount and functionality;
    littlefs: Read tests;
    littlefs: Write tests;
    littlefs: Read-only filesystem tests;
    littlefs: Directory tests;
    littlefs: Remount RO->RW->RW;
"
#---------
TESTS_LIST["catch2-vfs-dualmount"]="
    dualmount: Basic mount;
    dualmount: API tests;
"
#---------
TESTS_LIST["catch2-iosyscalls"]="
    VFS linux support;
"
#---------

M module-services/service-db/test/CMakeLists.txt => module-services/service-db/test/CMakeLists.txt +1 -0
@@ 17,4 17,5 @@ add_catch2_executable(
        DEPS
            PurePhone.img-target
)

add_subdirectory(test-settings)

M module-services/service-db/test/test-settings/Database.cpp => module-services/service-db/test/test-settings/Database.cpp +1 -1
@@ 123,7 123,7 @@ std::unique_ptr<QueryResult> stubQuery(const std::string &format, const std::str
    return queryResult;
}

Database::Database(const char *name)
Database::Database(const char *name, bool)
    : dbName(name), queryStatementBuffer{nullptr}, isInitialized_(false),
      initializer(std::make_unique<DatabaseInitializer>(this))
{

M module-services/service-desktop/tests/test-contacts.cpp => module-services/service-desktop/tests/test-contacts.cpp +0 -3
@@ 8,7 8,6 @@
#include <json/json11.hpp>
#include <purefs/filesystem_paths.hpp>
#include <utf8/UTF8.hpp>
#include <vfs.hpp>

#include <memory>
#include <filesystem>


@@ 18,7 17,6 @@
#include <module-db/Interface/ContactRecord.hpp>
#include <module-db/Databases/ContactsDB.hpp>

class vfs vfs;
std::unique_ptr<ContactsDB> contactsDb = nullptr;
std::vector<std::string> messageStrings;



@@ 154,7 152,6 @@ void parserFSM::MessageHandler::putToSendQueue(const std::string &msg)

TEST_CASE("Endpoint Contacts Test")
{
    vfs.Init();
    Database::initialize();

    const auto contactsPath = purefs::dir::getUserDiskPath() / "contacts.db";

M module-utils/test/unittest_utils.cpp => module-utils/test/unittest_utils.cpp +0 -33
@@ 271,39 271,6 @@ TEST_CASE("Fill leading digit in string")
    REQUIRE(utils::addLeadingZeros(test, 4) == "0045");
}

class ScopedDir
{
  public:
    ScopedDir(const std::filesystem::path &dirPath) : dirPath{dirPath}
    {
        REQUIRE(std::filesystem::create_directory(dirPath));
    }

    ~ScopedDir()
    {
        REQUIRE(std::filesystem::remove(dirPath));
    }

    auto operator()(std::string file = "") -> std::filesystem::path
    {
        return dirPath.c_str() + file;
    }

  private:
    std::filesystem::path dirPath;
};

TEST_CASE("Read file length")
{
    ScopedDir dir("test");
    auto *file = std::fopen(dir("test.txt").c_str(), "w");
    REQUIRE(file != nullptr);
    std::array<int, 3> v = {42, -1, 7};
    std::fwrite(v.data(), sizeof(v[0]), v.size(), file);
    REQUIRE(utils::filesystem::filelength(file) == static_cast<long>(sizeof(v[0]) * v.size()));
    REQUIRE(std::fclose(file) == 0);
}

TEST_CASE("Hex to bytes")
{
    SECTION("One byte as two hex digits")

M module-vfs/tests/unittest_filesystem_core.cpp => module-vfs/tests/unittest_filesystem_core.cpp +4 -4
@@ 272,7 272,7 @@ TEST_CASE("Corefs: Directory operations")
    }
}

TEST_CASE("Read only filesystem")
TEST_CASE("Corefs: Read only filesystem")
{
    using namespace purefs;
    auto dm   = std::make_shared<blkdev::disk_manager>();


@@ 309,7 309,7 @@ TEST_CASE("Read only filesystem")
    REQUIRE(fscore.umount("/sys") == 0);
}

TEST_CASE("Remount filesystem from RO to RW and to RO")
TEST_CASE("Corefs: Remount filesystem from RO to RW and to RO")
{
    using namespace purefs;
    auto dm   = std::make_shared<blkdev::disk_manager>();


@@ 345,7 345,7 @@ TEST_CASE("Remount filesystem from RO to RW and to RO")
    REQUIRE(fscore->umount("/sys") == 0);
}

TEST_CASE("Autodetect filesystems")
TEST_CASE("Corefs: Autodetect filesystems")
{
    using namespace purefs;
    auto dm   = std::make_shared<blkdev::disk_manager>();


@@ 361,7 361,7 @@ TEST_CASE("Autodetect filesystems")
    REQUIRE(fscore->umount("/sys") == 0);
}

TEST_CASE("Unititest integrated subsystem")
TEST_CASE("Corefs: Unittest integrated subsystem")
{
    auto [disk, vfs] = purefs::subsystem::initialize();
    REQUIRE(purefs::subsystem::mount_defaults() == 0);

M module-vfs/tests/unittest_filesystem_dualmount.cpp => module-vfs/tests/unittest_filesystem_dualmount.cpp +1 -1
@@ 133,4 133,4 @@ TEST_CASE("dualmount: API tests")

    REQUIRE(fs_core->umount("/vfat") == 0);
    REQUIRE(fs_core->umount("/lfs") == 0);
}
\ No newline at end of file
}