Files
MuditaOS/module-vfs/tests/unittest_filesystem_core.cpp
T
Lucjan Bryndza 55ab66e55a [EGD-4499] Create drivers for the VFS (#1128)
* GId modules updated

* Remove module

* Gitmodules update

* [EGD-4499] Global module VFS

* [EGD-4499] vfat driver in progress + fsfat

* [EGD-4499] fffat glue to our implementation.

Signed-off-by: Lucjan Bryndza <lucjan.bryndza@mudita.com>

* [EGD-4498] Glue logic between ff_fat and disk mgr.

* [EGD-4499] Mount and unmount fat_fs.

* [EGD-4499] Filesystem mount seams to be working

* [EGD-4499] Missing umount volume removal

* [EGD-4499] Code review vol 1

* [EGD-4499] Missing erase element from map

* [EGD-4499] Missing mount umount

* [EGD-4261] Mount and unmount tests

Signed-off-by: Lucjan Bryndza <lucjan.bryndza@mudita.com>

* [EGD-4499] Initial filesystem implementation

Iterate over directories are not completed yet

* [EGD-4261] unit test fix

Signed-off-by: Lucjan Bryndza <lucjan.bryndza@mudita.com>

* [EGD-4499] Stat vfs for RT1051

* [EGD-4499] Small fix in the seek

* [EGD-4499] Directory handle fix

* [EGD4499] Completed ffat implementation

It is already completed vfat driver for vfs core
but it is not tested yet.

Signed-off-by: Lucjan Bryndza <lucjan.bryndza@mudita.com>

* [EGD4499] Code review part #1

Signed-off-by: Lucjan Bryndza <lucjan.bryndza@mudita.com>

* [EGD4499] Remove double dynamic allocation of mount point

Signed-off-by: Lucjan Bryndza <lucjan.bryndza@mudita.com>

* [EGD4499] Partition out of range fix

Signed-off-by: Lucjan Bryndza <lucjan.bryndza@mudita.com>

* [EGD-4499] Handle leak fix

Signed-off-by: Lucjan Bryndza <lucjan.bryndza@mudita.com>

* [EGD-4499] VFS vfat completed.

Signed-off-by: Lucjan Bryndza <lucjan.bryndza@mudita.com>

* [EGD-4499] File descriptors from 3 according to POSIX std

0,1,2 fds are reserved for stdin,stdout,stderr

Signed-off-by: Lucjan Bryndza <lucjan.bryndza@mudita.com>
2020-12-07 14:18:03 +01:00

108 lines
3.7 KiB
C++

// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include <purefs/fs/filesystem.hpp>
#include <purefs/blkdev/disk_manager.hpp>
#include <purefs/blkdev/disk_image.hpp>
#include <purefs/fs/drivers/filesystem_vfat.hpp>
#include <sys/statvfs.h>
#include <sys/stat.h>
namespace
{
constexpr auto disk_image = "PurePhone.img";
}
TEST_CASE("Corefs: Registering and unregistering block device")
{
using namespace purefs;
auto dm = std::make_shared<blkdev::disk_manager>();
auto disk = std::make_shared<blkdev::disk_image>(disk_image);
REQUIRE(disk);
REQUIRE(dm->register_device(disk, "emmc0") == 0);
purefs::fs::filesystem fscore(dm);
/* Requested filesystem is not registered */
REQUIRE(fscore.mount("emmc0", "/sys", "vfat") == -ENODEV);
const auto vfs_vfat = std::make_shared<fs::drivers::filesystem_vfat>();
REQUIRE(vfs_vfat->mount_count() == 0);
auto ret = fscore.register_filesystem("vfat", vfs_vfat);
REQUIRE(ret == 0);
ret = fscore.mount("emmc0part1", "/sys", "vfat");
REQUIRE(ret == 0);
REQUIRE(vfs_vfat->mount_count() == 1);
REQUIRE(fscore.umount("/ala") == -ENOENT);
ret = fscore.mount("emmc0part1", "/sys", "vfat");
REQUIRE(ret == -EBUSY);
ret = fscore.mount("emmc0part1", "/path", "vfat");
REQUIRE(ret == -EBUSY);
ret = fscore.mount("emmc0part2", "/path", "nonexisting_fs");
REQUIRE(ret == -ENODEV);
ret = fscore.umount("/sys");
REQUIRE(ret == 0);
REQUIRE(vfs_vfat->mount_count() == 0);
ret = fscore.mount("emmc0part1", "/path", "vfat");
REQUIRE(ret == 0);
REQUIRE(vfs_vfat->mount_count() == 1);
ret = fscore.umount("/path");
REQUIRE(ret == 0);
}
TEST_CASE("Corefs: Basic API test")
{
using namespace purefs;
auto dm = std::make_shared<blkdev::disk_manager>();
auto disk = std::make_shared<blkdev::disk_image>(disk_image);
REQUIRE(disk);
REQUIRE(dm->register_device(disk, "emmc0") == 0);
purefs::fs::filesystem fscore(dm);
const auto vfs_vfat = std::make_shared<fs::drivers::filesystem_vfat>();
REQUIRE(vfs_vfat->mount_count() == 0);
auto ret = fscore.register_filesystem("vfat", vfs_vfat);
REQUIRE(ret == 0);
// List partitions
for (const auto &part : dm->partitions("emmc0")) {
std::cout << part.name << " " << part.bootable << std::endl;
}
ret = fscore.mount("emmc0part0", "/sys", "vfat");
REQUIRE(ret == 0);
{
struct statvfs ssv;
ret = fscore.stat_vfs("/sys/", ssv);
REQUIRE(ret == 0);
}
{
ret = fscore.open("/sys/ala/ma/kota/", 0, 0);
REQUIRE(ret == -ENOENT);
// Simple file test
int hwnd = fscore.open("/sys/.boot.json", 0, 0);
REQUIRE(hwnd >= 3);
std::cout << "File open handle " << hwnd << std::endl;
struct stat st;
ret = fscore.fstat(hwnd, st);
REQUIRE(ret == 0);
std::cout << "File size " << st.st_size << std::endl;
char buf[4096]{};
ret = fscore.read(hwnd, buf, sizeof buf);
REQUIRE(ret > 0);
ret = fscore.close(hwnd);
REQUIRE(ret == 0);
{
// Simple directory test
auto dirhandle = fscore.diropen("/sys");
REQUIRE(dirhandle);
REQUIRE(dirhandle->error() == 0);
for (std::string fnm;;) {
if (fscore.dirnext(dirhandle, fnm, st) != 0) {
break;
}
else {
std::cout << "name " << fnm << " size " << st.st_size << std::endl;
}
}
fscore.dirclose(dirhandle);
dirhandle = nullptr;
}
}
}