Skip to content

Commit

Permalink
[EROFS] test: add stat check
Browse files Browse the repository at this point in the history
Signed-off-by: Hongzhen Luo <hongzhen@linux.alibaba.com>
  • Loading branch information
salvete committed Dec 21, 2024
1 parent c43d8f1 commit 8a99dd2
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 102 deletions.
186 changes: 101 additions & 85 deletions src/overlaybd/tar/erofs/test/erofs_stress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,6 @@ class StressInterImpl: public StressGenInter {
mode = std::stoi(str_mode, nullptr, 8);
if (file->file->fchmod(mode))
LOG_ERROR_RETURN(-1, false, "fail to set mode ` for file `", str_mode, file->path);
node->mod = str_mode;
return true;
}

/* mode in verify phase */
bool verify_gen_mod(StressNode *node, photon::fs::IFile *erofs_file) override {
struct stat st;
std::ostringstream oss;

if (erofs_file->fstat(&st))
LOG_ERROR_RETURN(-1, false, "fail to stat erofs file");
oss << std::oct << std::setfill('0') << std::setw(3) << (st.st_mode & 0777);
node->mod = oss.str();
return true;
}

Expand All @@ -169,17 +156,6 @@ class StressInterImpl: public StressGenInter {

if (file->file->fchown(uid, gid))
LOG_ERROR_RETURN(-1,false, "failt to chown of file `", file->path);
node->own = std::to_string(uid) + std::to_string(gid);
return true;
}

/* own in verify phase */
bool verify_gen_own(StressNode *node, photon::fs::IFile *erofs_file) override {
struct stat st;

if (erofs_file->fstat(&st))
LOG_ERROR_RETURN(-1, false, "fail to stat erofs file");
node->own = std::to_string(st.st_uid) + std::to_string(st.st_gid);
return true;
}

Expand Down Expand Up @@ -209,7 +185,6 @@ class StressInterImpl: public StressGenInter {
mode = std::stoi(str_mode, nullptr, 8);
if (host_fs->chmod(path, mode))
LOG_ERROR_RETURN(-1, false, "fail to set mode ` for dir `", str_mode, path);
node->mod = str_mode;
return true;
}

Expand All @@ -219,7 +194,6 @@ class StressInterImpl: public StressGenInter {

if (host_fs->chown(path, uid, gid))
LOG_ERROR_RETURN(-1,false, "failt to chown of dir `", path);
node->own = std::to_string(uid) + std::to_string(gid);
return true;
}

Expand All @@ -238,6 +212,24 @@ class StressInterImpl: public StressGenInter {
}
return true;
}

bool build_stat_file(StressNode *node, StressHostFile *file_info) override {
if (file_info->file->fstat(&node->node_stat))
LOG_ERRNO_RETURN(-1, false, "fail to stat file `", file_info->path);
return true;
}

bool build_stat_dir(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
if (host_fs->stat(path, &node->node_stat))
LOG_ERROR_RETURN(-1, false, "fail to stat dir `", path);
return true;
}

bool verify_stat(StressNode *node, photon::fs::IFile *erofs_file) override {
if (erofs_file->fstat(&node->node_stat))
LOG_ERRNO_RETURN(-1, false, "fail to stat erofs_file");
return true;
}
};

/*
Expand All @@ -257,6 +249,9 @@ class StressCase001: public StressBase, public StressInterImpl {
EROFS_STRESS_UNIMPLEMENTED_FUNC(bool, build_gen_own(StressNode *node, StressHostFile *file), true)
EROFS_STRESS_UNIMPLEMENTED_FUNC(bool, build_gen_xattrs(StressNode *node, StressHostFile *file), true)
EROFS_STRESS_UNIMPLEMENTED_FUNC(bool, build_gen_content(StressNode *node, StressHostFile *file), true)
bool build_stat_file(StressNode *node, StressHostFile *file) override {
return StressInterImpl::build_stat_file(node, file);
}

bool build_dir_mod(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_mod(node, path, host_fs);
Expand All @@ -267,17 +262,16 @@ class StressCase001: public StressBase, public StressInterImpl {
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
}

/* create empty nodes in verify phase */
bool verify_gen_mod(StressNode *node, photon::fs::IFile *erofs_file) override {
return node->type ==NODE_DIR ? StressInterImpl::verify_gen_mod(node, erofs_file) : true;
}
bool verify_gen_own(StressNode *node, photon::fs::IFile *erofs_file) override {
return node->type == NODE_DIR ? StressInterImpl::verify_gen_own(node, erofs_file) : true;
bool build_stat_dir(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_stat_dir(node, path, host_fs);
}

bool verify_gen_xattrs(StressNode *node, photon::fs::IFile *erofs_file) override {
return node->type == NODE_DIR ? StressInterImpl::verify_gen_xattrs(node, erofs_file): true;
}
bool verify_stat(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_stat(node, erofs_file);
}

EROFS_STRESS_UNIMPLEMENTED_FUNC(bool, verify_gen_content(StressNode *node, photon::fs::IFile *erofs_file), true)

Expand Down Expand Up @@ -319,6 +313,9 @@ class StressCase002: public StressBase, public StressInterImpl {
bool build_gen_content(StressNode *node, StressHostFile *file) override {
return StressInterImpl::build_gen_content(node, file);
}
bool build_stat_file(StressNode *node, StressHostFile *file) override {
return StressInterImpl::build_stat_file(node, file);
}

bool build_dir_mod(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_mod(node, path, host_fs);
Expand All @@ -329,20 +326,19 @@ class StressCase002: public StressBase, public StressInterImpl {
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
}

/* leave mod/own/xattr empty */
bool verify_gen_mod(StressNode *node, photon::fs::IFile *erofs_file) override {
return node->type ==NODE_DIR ? StressInterImpl::verify_gen_mod(node, erofs_file) : true;
}
bool verify_gen_own(StressNode *node, photon::fs::IFile *erofs_file) override {
return node->type == NODE_DIR ? StressInterImpl::verify_gen_own(node, erofs_file) : true;
bool build_stat_dir(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_stat_dir(node, path, host_fs);
}

bool verify_gen_xattrs(StressNode *node, photon::fs::IFile *erofs_file) override {
return node->type == NODE_DIR ? StressInterImpl::verify_gen_xattrs(node, erofs_file): true;
}
bool verify_gen_content(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_gen_content(node, erofs_file);
}
bool verify_stat(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_stat(node, erofs_file);
}

/* simplely generate random dir and file names */
std::string generate_name(int idx, int depth, std::string root_path, NODE_TYPE type) override {
Expand Down Expand Up @@ -381,6 +377,9 @@ class StressCase003: public StressBase, public StressInterImpl {
bool build_gen_xattrs(StressNode *node, StressHostFile *file) override {
return StressInterImpl::build_gen_xattrs(node, file);
}
bool build_stat_file(StressNode *node, StressHostFile *file) override {
return StressInterImpl::build_stat_file(node, file);
}

bool build_dir_mod(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_mod(node, path, host_fs);
Expand All @@ -391,18 +390,17 @@ class StressCase003: public StressBase, public StressInterImpl {
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
}

/* leave mod/own/content empty */
bool verify_gen_mod(StressNode *node, photon::fs::IFile *erofs_file) override {
return node->type ==NODE_DIR ? StressInterImpl::verify_gen_mod(node, erofs_file) : true;
}
bool verify_gen_own(StressNode *node, photon::fs::IFile *erofs_file) override {
return node->type == NODE_DIR ? StressInterImpl::verify_gen_own(node, erofs_file) : true;
bool build_stat_dir(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_stat_dir(node, path, host_fs);
}
EROFS_STRESS_UNIMPLEMENTED_FUNC(bool, verify_gen_content(StressNode *node, photon::fs::IFile *erofs_file), true)

bool verify_gen_xattrs(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_gen_xattrs(node, erofs_file);
}
bool verify_stat(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_stat(node, erofs_file);
}
EROFS_STRESS_UNIMPLEMENTED_FUNC(bool, verify_gen_content(StressNode *node, photon::fs::IFile *erofs_file), true)

/* simplely generate random dir and file names */
std::string generate_name(int idx, int depth, std::string root_path, NODE_TYPE type) override {
Expand Down Expand Up @@ -438,6 +436,9 @@ class StressCase004: public StressBase, public StressInterImpl {
bool build_gen_mod(StressNode *node, StressHostFile *file) override {
return StressInterImpl::build_gen_mod(node, file);
}
bool build_stat_file(StressNode *node, StressHostFile *file) override {
return StressInterImpl::build_stat_file(node, file);
}

bool build_dir_mod(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_mod(node, path, host_fs);
Expand All @@ -448,17 +449,17 @@ class StressCase004: public StressBase, public StressInterImpl {
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
}
bool build_stat_dir(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_stat_dir(node, path, host_fs);
}

EROFS_STRESS_UNIMPLEMENTED_FUNC(bool, verify_gen_content(StressNode *node, photon::fs::IFile *erofs_file), true)
bool verify_gen_mod(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_gen_mod(node, erofs_file);
}
bool verify_gen_own(StressNode *node, photon::fs::IFile *erofs_file) override {
return node->type == NODE_DIR ? StressInterImpl::verify_gen_own(node, erofs_file) : true;
}
bool verify_gen_xattrs(StressNode *node, photon::fs::IFile *erofs_file) override {
return node->type == NODE_DIR ? StressInterImpl::verify_gen_xattrs(node, erofs_file): true;
}
bool verify_stat(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_stat(node, erofs_file);
}

/* simplely generate random dir and file names */
std::string generate_name(int idx, int depth, std::string root_path, NODE_TYPE type) override {
Expand Down Expand Up @@ -493,6 +494,9 @@ class StressCase005: public StressBase, public StressInterImpl {
bool build_gen_own(StressNode *node, StressHostFile *file) override {
return StressInterImpl::build_gen_own(node, file);
}
bool build_stat_file(StressNode *node, StressHostFile *file) override {
return StressInterImpl::build_stat_file(node, file);
}

bool build_dir_mod(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_mod(node, path, host_fs);
Expand All @@ -503,17 +507,17 @@ class StressCase005: public StressBase, public StressInterImpl {
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
}

bool verify_gen_mod(StressNode *node, photon::fs::IFile *erofs_file) override {
return node->type ==NODE_DIR ? StressInterImpl::verify_gen_mod(node, erofs_file) : true;
}
EROFS_STRESS_UNIMPLEMENTED_FUNC(bool, verify_gen_content(StressNode *node, photon::fs::IFile *erofs_file), true)
bool verify_gen_own(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_gen_own(node, erofs_file);
bool build_stat_dir(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_stat_dir(node, path, host_fs);
}

bool verify_gen_xattrs(StressNode *node, photon::fs::IFile *erofs_file) override {
return node->type == NODE_DIR ? StressInterImpl::verify_gen_xattrs(node, erofs_file): true;
}
bool verify_stat(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_stat(node, erofs_file);
}
EROFS_STRESS_UNIMPLEMENTED_FUNC(bool, verify_gen_content(StressNode *node, photon::fs::IFile *erofs_file), true)

/* simplely generate random dir and file names */
std::string generate_name(int idx, int depth, std::string root_path, NODE_TYPE type) override {
Expand Down Expand Up @@ -554,6 +558,9 @@ class StressCase006: public StressBase, public StressInterImpl {
bool build_gen_content(StressNode *node, StressHostFile *file) override {
return StressInterImpl::build_gen_content(node, file);
}
bool build_stat_file(StressNode *node, StressHostFile *file) override {
return StressInterImpl::build_stat_file(node, file);
}

bool build_dir_mod(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_mod(node, path, host_fs);
Expand All @@ -564,19 +571,19 @@ class StressCase006: public StressBase, public StressInterImpl {
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
}

bool verify_gen_mod(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_gen_mod(node, erofs_file);
}
bool verify_gen_own(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_gen_own(node, erofs_file);
bool build_stat_dir(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_stat_dir(node, path, host_fs);
}

bool verify_gen_xattrs(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_gen_xattrs(node, erofs_file);
}
bool verify_gen_content(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_gen_content(node, erofs_file);
}
bool verify_stat(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_stat(node, erofs_file);
}

/* simplely generate random dir and file names */
std::string generate_name(int idx, int depth, std::string root_path, NODE_TYPE type) override {
Expand Down Expand Up @@ -619,6 +626,9 @@ class StressCase007: public StressBase, public StressInterImpl {
bool build_gen_content(StressNode *node, StressHostFile *file) override {
return StressInterImpl::build_gen_content(node, file);
}
bool build_stat_file(StressNode *node, StressHostFile *file) override {
return StressInterImpl::build_stat_file(node, file);
}

bool build_dir_mod(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_mod(node, path, host_fs);
Expand All @@ -629,19 +639,19 @@ class StressCase007: public StressBase, public StressInterImpl {
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
}

bool verify_gen_mod(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_gen_mod(node, erofs_file);
}
bool verify_gen_own(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_gen_own(node, erofs_file);
bool build_stat_dir(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_stat_dir(node, path, host_fs);
}

bool verify_gen_xattrs(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_gen_xattrs(node, erofs_file);
}
bool verify_gen_content(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_gen_content(node, erofs_file);
}
bool verify_stat(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_stat(node, erofs_file);
}

std::string generate_name(int idx, int depth, std::string root_path, NODE_TYPE type) override {
std::string res;
Expand Down Expand Up @@ -704,6 +714,9 @@ class StressCase008: public StressBase, public StressInterImpl {
bool build_gen_content(StressNode *node, StressHostFile *file) override {
return StressInterImpl::build_gen_content(node, file);
}
bool build_stat_file(StressNode *node, StressHostFile *file) override {
return StressInterImpl::build_stat_file(node, file);
}

bool build_dir_mod(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_mod(node, path, host_fs);
Expand All @@ -714,19 +727,19 @@ class StressCase008: public StressBase, public StressInterImpl {
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
}

bool verify_gen_mod(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_gen_mod(node, erofs_file);
}
bool verify_gen_own(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_gen_own(node, erofs_file);
bool build_stat_dir(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_stat_dir(node, path, host_fs);
}

bool verify_gen_xattrs(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_gen_xattrs(node, erofs_file);
}
bool verify_gen_content(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_gen_content(node, erofs_file);
}
bool verify_stat(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_stat(node, erofs_file);
}

std::string generate_name(int idx, int depth, std::string root_path, NODE_TYPE type) override {
std::string res;
Expand Down Expand Up @@ -798,6 +811,9 @@ class StressCase009: public StressBase, public StressInterImpl {
bool build_gen_content(StressNode *node, StressHostFile *file) override {
return StressInterImpl::build_gen_content(node, file);
}
bool build_stat_file(StressNode *node, StressHostFile *file) override {
return StressInterImpl::build_stat_file(node, file);
}

bool build_dir_mod(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_mod(node, path, host_fs);
Expand All @@ -808,19 +824,19 @@ class StressCase009: public StressBase, public StressInterImpl {
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
}

bool verify_gen_mod(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_gen_mod(node, erofs_file);
}
bool verify_gen_own(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_gen_own(node, erofs_file);
bool build_stat_dir(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_stat_dir(node, path, host_fs);
}

bool verify_gen_xattrs(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_gen_xattrs(node, erofs_file);
}
bool verify_gen_content(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_gen_content(node, erofs_file);
}
bool verify_stat(StressNode *node, photon::fs::IFile *erofs_file) override {
return StressInterImpl::verify_stat(node, erofs_file);
}

std::string generate_name(int idx, int depth, std::string root_path, NODE_TYPE type) override {
std::string res;
Expand Down
Loading

0 comments on commit 8a99dd2

Please sign in to comment.