Skip to content

Commit

Permalink
tests second fs
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Oct 21, 2024
1 parent 2e05c39 commit 18e868f
Show file tree
Hide file tree
Showing 29 changed files with 864 additions and 277 deletions.
1 change: 1 addition & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ jobs:
path: |
${{github.workspace}}/build/wr-bin
${{github.workspace}}/build/wr-tests
${{github.workspace}}/build/fs2.bin
test-on-macos-13-and-14:
# The run on MacOS 14 is the amd64 on arm64 test
Expand Down
53 changes: 33 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -813,10 +813,10 @@ add_library(dwarfs-wr STATIC
"src/tebako-io-helpers.cpp"
"src/tebako-io-root.cpp"
"src/tebako-kfd.cpp"
"src/tebako-mnt.cpp"
"src/tebako-mount-table.cpp"
"src/tebako-mfs.cpp"
"src/tebako-dfs.cpp"
"src/tebako-dft.cpp"
"src/tebako-memfs.cpp"
"src/tebako-memfs-table.cpp"
"src/tebako-fd.cpp"
"src/tebako-dirent.cpp"
"include/tebako-cmdline-helpers.h"
Expand All @@ -829,9 +829,9 @@ add_library(dwarfs-wr STATIC
"include/tebako-io-inner.h"
"include/tebako-io-root.h"
"include/tebako-kfd.h"
"include/tebako-dfs.h"
"include/tebako-dft.h"
"include/tebako-mnt.h"
"include/tebako-memfs.h"
"include/tebako-memfs-table.h"
"include/tebako-mount-table.h"
"include/tebako-mfs.h"
"include/tebako-pch.h"
"include/tebako-pch-pp.h"
Expand Down Expand Up @@ -938,11 +938,21 @@ if(WITH_TESTS)
BYPRODUCTS ${DATA_BIN_FILE_2}
)

add_dependencies(PACKAGED_FILESYSTEM_STEP_1 empty)
add_dependencies(PACKAGED_FILESYSTEM_STEP_1 empty ${DWARFS_PRJ})
add_dependencies(dwarfs-wr PACKAGED_FILESYSTEM_STEP_1)

set(TESTS_OUTSIDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_files")

set(TESTS_THE_OTHER_MEMFS_IMAGE "${CMAKE_CURRENT_BINARY_DIR}/fs2.bin")

# feat: exectable application stub
# add_executable(wr-mount "tests/tebako-fs2.cpp")
# if(WIN32)
# set(TESTS_THE_OTHER_MEMFS_IMAGE "${CMAKE_CURRENT_BINARY_DIR}/wr-mount.exe")
# else()
# set(TESTS_THE_OTHER_MEMFS_IMAGE "${CMAKE_CURRENT_BINARY_DIR}/wr-mount")
# endif()

if (WITH_LINK_TESTS)
add_custom_target(PACKAGED_FILESYSTEM_STEP_2 ALL
COMMAND ${CMAKE_COMMAND} -E chdir ${DATA_TEST_DIR} rm -rf h-link-to-file-2 s-link-to-file-1 s-link-to-dir-1 s-link-outside-of-memfs s-dir-outside-of-memfs
Expand Down Expand Up @@ -1001,23 +1011,25 @@ if(WITH_TESTS)
@ONLY
)

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/tests/resources/tebako-fs2.cpp.in
${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs2.cpp
@ONLY
)
# feat: exectable application stub
# configure_file(
# ${CMAKE_CURRENT_SOURCE_DIR}/tests/resources/tebako-fs2.cpp.in
# ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs2.cpp
# @ONLY
# )

if(IS_WINDOWS)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs0.c
COMMAND ${DEPS}/bin/incbin.exe ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs.cpp -o ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs0.c
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs.cpp ${DATA_BIN_FILE} ${INCBIN_PRJ}
)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs02.c
COMMAND ${DEPS}/bin/incbin.exe ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs2.cpp -o ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs02.c
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs2.cpp ${DATA_BIN_FILE_2} ${INCBIN_PRJ}
)
# feat: exectable application stub
# add_custom_command(
# OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs02.c
# COMMAND ${DEPS}/bin/incbin.exe ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs2.cpp -o ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs02.c
# DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/tebako-fs2.cpp ${DATA_BIN_FILE_2} ${INCBIN_PRJ}
# )
endif(IS_WINDOWS)

function(ADD_DWARFS_LIBRARY NAME PRJ APP_NM)
Expand Down Expand Up @@ -1150,13 +1162,14 @@ else(IS_WINDOWS)
)
add_dependencies(wr-tests PACKAGED_FILESYSTEM_STEP_3)

add_executable(wr-mount "tests/tebako-fs2.cpp")
add_dependencies(wr-mount PACKAGED_FILESYSTEM_STEP_1)
# feat: exectable application stub
# add_dependencies(wr-mount PACKAGED_FILESYSTEM_STEP_1)

if(IS_WINDOWS)
target_sources(wr-bin PUBLIC "tests/tebako-fs0.c" )
target_sources(wr-tests PUBLIC "tests/tebako-fs0.c")
target_sources(wr-mount PUBLIC "tests/tebako-fs02.c")
# feat: exectable application stub
# target_sources(wr-mount PUBLIC "tests/tebako-fs02.c")
endif(IS_WINDOWS)

if(RB_W32)
Expand Down
8 changes: 8 additions & 0 deletions include/tebako-io-root.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ int mount_root_memfs(const void* data,
const char* decompress_ratio,
const char* image_offset);

int mount_memfs(const void* data, const unsigned int size, const char* image_offset, const char* path);

int mount_memfs(const void* data,
const unsigned int size,
const char* image_offset,
uint32_t parent_inode,
const char* path);

void unmount_root_memfs(void);

int dwarfs_access(const std::string&, int amode, uid_t uid, gid_t gid, std::string& lnk) noexcept;
Expand Down
8 changes: 8 additions & 0 deletions include/tebako-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ int mount_root_memfs(const void* data,
const char* decompress_ratio,
const char* image_offset);

int mount_memfs_at_root(const void* data, const unsigned int size, const char* image_offset, const char* path);

int mount_memfs(const void* data,
const unsigned int size,
const char* image_offset,
uint32_t parent_inode,
const char* path);

void unmount_root_memfs(void);

char* tebako_getcwd(char* buf, size_t size);
Expand Down
8 changes: 4 additions & 4 deletions include/tebako-dft.h → include/tebako-memfs-table.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

namespace tebako {

typedef std::map<uint32_t, memfs*> tebako_memfs_table;
typedef std::map<uint32_t, std::shared_ptr<memfs>> tebako_memfs_table;

class sync_tebako_memfs_table {
private:
Expand All @@ -43,9 +43,9 @@ class sync_tebako_memfs_table {
bool check(uint32_t index);
void clear(void);
void erase(uint32_t index);
memfs* get(uint32_t index);
bool insert(uint32_t index, memfs* fs);
std::shared_ptr<memfs> get(uint32_t index);
bool insert(uint32_t index, std::shared_ptr<memfs> fs);
uint32_t insert_auto(std::shared_ptr<memfs> fs);
};


} // namespace tebako
8 changes: 5 additions & 3 deletions include/tebako-dfs.h → include/tebako-memfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ class memfs {
private:
const void* data;
const unsigned int size;
uint32_t dwarfs_root;
uint32_t dwarfs_root_inode;

dwarfs::filesystem_options fsopts;
dwarfs::filesystem_v2 fs;

// std::shared_ptr<dwarfs::performance_monitor> perfmon;
// std::shared_ptr<dwarfs::performance_monitor> perfmon;

public:
static void set_cachesize(const char* cachesize);
Expand All @@ -79,6 +79,8 @@ class memfs {

int load(const char* image_offset = "auto");
void set_image_offset_str(const char* image_offset = "auto");
uint32_t get_root_inode(void) { return dwarfs_root_inode; }
void set_root_inode(uint32_t df_root_inode) { dwarfs_root_inode = df_root_inode; }

int access(const std::string& path, int amode, uid_t uid, gid_t gid, std::string& lnk) noexcept;
int inode_access(uint32_t inode, int amode, uid_t uid, gid_t gid) noexcept;
Expand All @@ -105,7 +107,7 @@ class memfs {
}
int relative_stat(const std::string& path, struct stat* st, std::string& lnk, bool follow) noexcept
{
return find_inode_abs(dwarfs_root, path, follow, lnk, st);
return find_inode_abs(dwarfs_root_inode, path, follow, lnk, st);
}

#if defined(TEBAKO_HAS_LSTAT) || defined(RB_W32) || defined(_WIN32)
Expand Down
1 change: 0 additions & 1 deletion include/tebako-mnt.h → include/tebako-mount-table.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class sync_tebako_mount_table {
{
return insert(std::make_pair(ino, mount_path), mount_target);
};

};

} // namespace tebako
1 change: 1 addition & 0 deletions include/tebako-pch-pp.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#include <algorithm>
#include <array>
#include <cassert>
#include <cstddef>
#include <cstdlib>
#include <cstring>
Expand Down
10 changes: 6 additions & 4 deletions src/tebako-cmdline-helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <tebako-common.h>
#include <tebako-io-inner.h>
#include <tebako-io-root.h>
#include <tebako-mnt.h>
#include <tebako-mount-table.h>

#include <tebako-cmdline-helpers.h>

Expand Down Expand Up @@ -120,12 +120,13 @@ std::pair<std::vector<std::string>, std::vector<std::string>> parse_arguments(in

// Handle "--tebako-mount=value" case
if (arg.rfind("--tebako-mount=", 0) == 0) { // Check if it starts with "--tebako-mount="
std::string value = arg.substr(15); // Extract the part after "--tebako-mount="
std::string value = arg.substr(15); // Extract the part after "--tebako-mount="

if (!value.empty()) {
tebako_mount_args.push_back(value); // Add the value part to tebako_mount_args
continue;
} else {
}
else {
throw std::invalid_argument(error_msg); // Handle case where value is empty
}
}
Expand All @@ -141,7 +142,8 @@ std::pair<std::vector<std::string>, std::vector<std::string>> parse_arguments(in
tebako_mount_args.push_back(next_arg);
i += 1; // Skip the next argument as it is the rule
continue;
} else {
}
else {
throw std::invalid_argument(error_msg);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tebako-dirent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <tebako-io-root.h>
#include <tebako-fd.h>
#include <tebako-dirent.h>
#include <tebako-dfs.h>
#include <tebako-memfs.h>

using namespace std;

Expand Down
2 changes: 1 addition & 1 deletion src/tebako-fd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <tebako-io-inner.h>
#include <tebako-io-root.h>
#include <tebako-fd.h>
#include <tebako-dfs.h>
#include <tebako-memfs.h>

using namespace std;

Expand Down
Loading

0 comments on commit 18e868f

Please sign in to comment.