Skip to content

Commit

Permalink
feat: make tools_test work without WITH_TOOLS
Browse files Browse the repository at this point in the history
  • Loading branch information
mhx committed Aug 12, 2024
1 parent 9c95ecb commit 941ca31
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 14 deletions.
21 changes: 16 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -464,11 +464,6 @@ if(WITH_TESTS)
list(APPEND TEST_TARGETS ${test})
endforeach()

set_source_files_properties(test/tools_test.cpp PROPERTIES
COMPILE_DEFINITIONS
$<$<BOOL:${WITH_UNIVERSAL_BINARY}>:DWARFS_HAVE_UNIVERSAL_BINARY>
)

if(TARGET tool_main_test)
target_link_libraries(tool_main_test PRIVATE mkdwarfs_main dwarfsck_main dwarfsextract_main)
endif()
Expand All @@ -484,6 +479,22 @@ if(WITH_TESTS)
endif()
endif()

if(TARGET tools_test)
if(NOT WITH_TOOLS)
find_program(MKDWARFS_EXE mkdwarfs mkdwarfs.exe)
find_program(DWARFSCK_EXE dwarfsck dwarfsck.exe)
find_program(DWARFSEXTRACT_EXE dwarfsextract dwarfsextract.exe)
endif()
target_compile_definitions(tools_test PRIVATE
$<$<AND:$<BOOL:${WITH_UNIVERSAL_BINARY}>,$<BOOL:${WITH_TOOLS}>>:DWARFS_HAVE_UNIVERSAL_BINARY>
$<$<BOOL:${WITH_TOOLS}>:DWARFS_WITH_TOOLS>
$<$<BOOL:${WITH_FUSE_DRIVER}>:DWARFS_WITH_FUSE_DRIVER>
$<$<BOOL:${MKDWARFS_EXE}>:MKDWARFS_BINARY=\"${MKDWARFS_EXE}\">
$<$<BOOL:${DWARFSCK_EXE}>:DWARFSCK_BINARY=\"${DWARFSCK_EXE}\">
$<$<BOOL:${DWARFSEXTRACT_EXE}>:DWARFSEXTRACT_BINARY=\"${DWARFSEXTRACT_EXE}\">
)
endif()

if(TARGET block_cache_test)
target_link_libraries(block_cache_test PRIVATE mkdwarfs_main)
endif()
Expand Down
54 changes: 45 additions & 9 deletions test/tools_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,24 @@ auto test_catdata_dwarfs = test_dir / "catdata.dwarfs";
#define EXE_EXT ""
#endif

#ifndef MKDWARFS_BINARY
#define MKDWARFS_BINARY tools_dir / "mkdwarfs" EXE_EXT
#endif

#ifndef DWARFSCK_BINARY
#define DWARFSCK_BINARY tools_dir / "dwarfsck" EXE_EXT
#endif

#ifndef DWARFSEXTRACT_BINARY
#define DWARFSEXTRACT_BINARY tools_dir / "dwarfsextract" EXE_EXT
#endif

auto tools_dir = fs::path(TOOLS_BIN_DIR).make_preferred();
auto mkdwarfs_bin = tools_dir / "mkdwarfs" EXE_EXT;
auto mkdwarfs_bin = fs::path{MKDWARFS_BINARY};
auto fuse3_bin = tools_dir / "dwarfs" EXE_EXT;
auto fuse2_bin = tools_dir / "dwarfs2" EXE_EXT;
auto dwarfsextract_bin = tools_dir / "dwarfsextract" EXE_EXT;
auto dwarfsck_bin = tools_dir / "dwarfsck" EXE_EXT;
auto dwarfsextract_bin = fs::path{DWARFSEXTRACT_BINARY};
auto dwarfsck_bin = fs::path{DWARFSCK_BINARY};
auto universal_bin = tools_dir / "universal" / "dwarfs-universal" EXE_EXT;

class scoped_no_leak_check {
Expand Down Expand Up @@ -125,6 +137,12 @@ class scoped_no_leak_check {
#endif
};

#ifdef DWARFS_WITH_FUSE_DRIVER

bool skip_fuse_tests() {
return dwarfs::getenv_is_enabled("DWARFS_SKIP_FUSE_TESTS");
}

#if !(defined(_WIN32) || defined(__APPLE__))
pid_t get_dwarfs_pid(fs::path const& path) {
return dwarfs::to<pid_t>(dwarfs::getxattr(path, "user.dwarfs.driver.pid"));
Expand All @@ -151,6 +169,8 @@ bool wait_until_file_ready(fs::path const& path,
return true;
}

#endif

bool read_file(fs::path const& path, std::string& out) {
std::ifstream ifs(path, std::ios::binary);
if (!ifs.is_open()) {
Expand Down Expand Up @@ -300,10 +320,6 @@ bool compare_directories(fs::path const& p1, fs::path const& p2,
return rv;
}

bool skip_fuse_tests() {
return dwarfs::getenv_is_enabled("DWARFS_SKIP_FUSE_TESTS");
}

#ifdef _WIN32
struct new_process_group : public ::boost::process::detail::handler_base {
template <class WindowsExecutor>
Expand Down Expand Up @@ -525,6 +541,8 @@ class process_guard {
};
#endif

#ifdef DWARFS_WITH_FUSE_DRIVER

class driver_runner {
public:
struct foreground_t {};
Expand Down Expand Up @@ -742,6 +760,8 @@ bool check_readonly(fs::path const& p, bool readonly) {
return true;
}

#endif

size_t num_hardlinks(fs::path const& p) {
#ifdef _WIN32
dwarfs::file_stat stat(p);
Expand Down Expand Up @@ -889,6 +909,7 @@ TEST_P(tools_test, end_to_end) {
auto extracted = td / "extracted";
auto untared = td / "untared";

#ifdef DWARFS_WITH_FUSE_DRIVER
std::vector<fs::path> drivers;

switch (mode) {
Expand Down Expand Up @@ -1133,6 +1154,7 @@ TEST_P(tools_test, end_to_end) {
}
}
}
#endif

auto meta_export = td / "test.meta";

Expand Down Expand Up @@ -1173,6 +1195,8 @@ TEST_P(tools_test, end_to_end) {
EXPECT_EQ(cdr.symlinks.size(), 2) << cdr;
}

#ifdef DWARFS_WITH_FUSE_DRIVER

#define EXPECT_EC_IMPL(ec, cat, val) \
EXPECT_TRUE(ec) << runner.cmdline(); \
EXPECT_EQ(cat, (ec).category()) << runner.cmdline(); \
Expand Down Expand Up @@ -1403,6 +1427,8 @@ TEST_P(tools_test, mutating_and_error_ops) {
}
}

#endif

TEST_P(tools_test, categorize) {
auto mode = GetParam();

Expand Down Expand Up @@ -1492,6 +1518,8 @@ TEST_P(tools_test, categorize) {
EXPECT_LT(image_size_recompressed, image_size);
}

#ifdef DWARFS_WITH_FUSE_DRIVER

if (!skip_fuse_tests()) {
auto mountpoint = td / "mnt";
fs::path driver;
Expand Down Expand Up @@ -1526,6 +1554,8 @@ TEST_P(tools_test, categorize) {
EXPECT_TRUE(runner.unmount()) << runner.cmdline();
}

#endif

auto json_info = subprocess::check_run(*dwarfsck_test_bin, dwarfsck_tool_arg,
image_recompressed, "--json");
ASSERT_TRUE(json_info);
Expand Down Expand Up @@ -1601,6 +1631,13 @@ INSTANTIATE_TEST_SUITE_P(dwarfs, tools_test,
class manpage_test
: public ::testing::TestWithParam<std::tuple<binary_mode, std::string>> {};

std::vector<std::string> const manpage_test_tools{
"mkdwarfs", "dwarfsck", "dwarfsextract",
#ifdef DWARFS_WITH_FUSE_DRIVER
"dwarfs",
#endif
};

TEST_P(manpage_test, manpage) {
auto [mode, tool] = GetParam();

Expand Down Expand Up @@ -1648,8 +1685,7 @@ std::vector<binary_mode> manpage_test_modes{
INSTANTIATE_TEST_SUITE_P(
dwarfs, manpage_test,
::testing::Combine(::testing::ValuesIn(manpage_test_modes),
::testing::Values("dwarfs", "mkdwarfs", "dwarfsck",
"dwarfsextract")));
::testing::ValuesIn(manpage_test_tools)));
#endif

TEST(tools_test, dwarfsextract_progress) {
Expand Down

0 comments on commit 941ca31

Please sign in to comment.