diff --git a/CMakeLists.txt b/CMakeLists.txt index 573f0cea7..69ae7e6e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -464,11 +464,6 @@ if(WITH_TESTS) list(APPEND TEST_TARGETS ${test}) endforeach() - set_source_files_properties(test/tools_test.cpp PROPERTIES - COMPILE_DEFINITIONS - $<$:DWARFS_HAVE_UNIVERSAL_BINARY> - ) - if(TARGET tool_main_test) target_link_libraries(tool_main_test PRIVATE mkdwarfs_main dwarfsck_main dwarfsextract_main) endif() @@ -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 + $<$,$>:DWARFS_HAVE_UNIVERSAL_BINARY> + $<$:DWARFS_WITH_TOOLS> + $<$:DWARFS_WITH_FUSE_DRIVER> + $<$:MKDWARFS_BINARY=\"${MKDWARFS_EXE}\"> + $<$:DWARFSCK_BINARY=\"${DWARFSCK_EXE}\"> + $<$:DWARFSEXTRACT_BINARY=\"${DWARFSEXTRACT_EXE}\"> + ) + endif() + if(TARGET block_cache_test) target_link_libraries(block_cache_test PRIVATE mkdwarfs_main) endif() diff --git a/test/tools_test.cpp b/test/tools_test.cpp index 79c2ed207..e6d76c391 100644 --- a/test/tools_test.cpp +++ b/test/tools_test.cpp @@ -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 { @@ -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(dwarfs::getxattr(path, "user.dwarfs.driver.pid")); @@ -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()) { @@ -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 @@ -525,6 +541,8 @@ class process_guard { }; #endif +#ifdef DWARFS_WITH_FUSE_DRIVER + class driver_runner { public: struct foreground_t {}; @@ -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); @@ -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 drivers; switch (mode) { @@ -1133,6 +1154,7 @@ TEST_P(tools_test, end_to_end) { } } } +#endif auto meta_export = td / "test.meta"; @@ -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(); \ @@ -1403,6 +1427,8 @@ TEST_P(tools_test, mutating_and_error_ops) { } } +#endif + TEST_P(tools_test, categorize) { auto mode = GetParam(); @@ -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; @@ -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); @@ -1601,6 +1631,13 @@ INSTANTIATE_TEST_SUITE_P(dwarfs, tools_test, class manpage_test : public ::testing::TestWithParam> {}; +std::vector const manpage_test_tools{ +"mkdwarfs", "dwarfsck", "dwarfsextract", +#ifdef DWARFS_WITH_FUSE_DRIVER +"dwarfs", +#endif +}; + TEST_P(manpage_test, manpage) { auto [mode, tool] = GetParam(); @@ -1648,8 +1685,7 @@ std::vector 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) {