Skip to content

Commit

Permalink
test: add xattr tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mhx committed Dec 22, 2023
1 parent ceec2e1 commit 71c5d42
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/dwarfs_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ namespace {
namespace bp = boost::process;
namespace fs = std::filesystem;

using namespace std::literals::string_view_literals;

auto test_dir = fs::path(TEST_DATA_DIR).make_preferred();
auto test_data_dwarfs = test_dir / "data.dwarfs";
auto test_catdata_dwarfs = test_dir / "catdata.dwarfs";
Expand Down Expand Up @@ -768,6 +770,46 @@ TEST_P(tools_test, end_to_end) {
ASSERT_EQ(0, ::statfs(mountpoint.c_str(), &stfs)) << runner.cmdline();
EXPECT_EQ(stfs.f_files, 44) << runner.cmdline();
}

{
static constexpr auto kInodeInfoXattr{"user.dwarfs.inodeinfo"};
std::vector<std::pair<fs::path, std::string_view>> xattr_tests{
{mountpoint,
"user.dwarfs.driver.pid\0user.dwarfs.driver.perfmon\0user.dwarfs.inodeinfo\0"sv},
{mountpoint / "format.sh", "user.dwarfs.inodeinfo\0"sv},
{mountpoint / "empty", "user.dwarfs.inodeinfo\0"sv},
};

for (auto const& [path, ref] : xattr_tests) {
std::string buf;
buf.resize(1);

auto r = ::listxattr(path.c_str(), buf.data(), buf.size());
EXPECT_LT(r, 0) << runner.cmdline();
EXPECT_EQ(ERANGE, errno) << runner.cmdline();
r = ::listxattr(path.c_str(), buf.data(), 0);
EXPECT_GT(r, 0) << runner.cmdline();
buf.resize(r);
r = ::listxattr(path.c_str(), buf.data(), buf.size());
EXPECT_GT(r, 0) << runner.cmdline();
EXPECT_EQ(ref, buf) << runner.cmdline();

buf.resize(1);
r = ::getxattr(path.c_str(), kInodeInfoXattr, buf.data(), buf.size());
EXPECT_LT(r, 0) << runner.cmdline();
EXPECT_EQ(ERANGE, errno) << runner.cmdline();
r = ::getxattr(path.c_str(), kInodeInfoXattr, buf.data(), 0);
EXPECT_GT(r, 0) << runner.cmdline();
buf.resize(r);
r = ::getxattr(path.c_str(), kInodeInfoXattr, buf.data(), buf.size());
EXPECT_GT(r, 0) << runner.cmdline();

auto info = folly::parseJson(buf);
EXPECT_TRUE(info.count("uid"));
EXPECT_TRUE(info.count("gid"));
EXPECT_TRUE(info.count("mode"));
}
}
#endif

EXPECT_TRUE(runner.unmount()) << runner.cmdline();
Expand Down

0 comments on commit 71c5d42

Please sign in to comment.