Skip to content

Commit

Permalink
[EROFS] test: add test for mtime
Browse files Browse the repository at this point in the history
Signed-off-by: Hongzhen Luo <[email protected]>
  • Loading branch information
salvete committed Dec 22, 2024
1 parent f4969c1 commit 115be8d
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 3 deletions.
76 changes: 74 additions & 2 deletions src/overlaybd/tar/erofs/test/erofs_stress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ class StressInterImpl: public StressGenInter {
return true;
}

bool build_gen_mtime(StressNode *node, struct in_mem_meta *meta) override {
size_t now = time(nullptr);
time_t time_sec = get_randomint(now, now + 24 * 60 * 60);
struct tm *time_info = localtime(&time_sec);
char buffer[256];
strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", time_info);
std::ostringstream oss;
oss << buffer;
meta->mtime_date = oss.str();
meta->mtime = time_sec;
return true;
}
/* generate a random dir or file name in the current layer */
std::string generate_name(int idx, int depth, std::string root_path, NODE_TYPE type) override {
std::string res;
Expand Down Expand Up @@ -198,6 +210,10 @@ class StressInterImpl: public StressGenInter {
return true;
}

bool build_dir_mtime(StressNode *node, struct in_mem_meta *meta) override {
return build_gen_mtime(node, meta);
}

bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
photon::fs::IFileSystemXAttr *xattr_ops = dynamic_cast<photon::fs::IFileSystemXAttr*>(host_fs);
if (xattr_ops == nullptr)
Expand All @@ -219,6 +235,7 @@ class StressInterImpl: public StressGenInter {
LOG_ERRNO_RETURN(-1, false, "fail to stat file `", file_info->path);
node->node_stat.st_uid = meta->uid;
node->node_stat.st_gid = meta->gid;
node->node_stat.st_mtime = meta->mtime;

return true;
}
Expand All @@ -228,6 +245,7 @@ class StressInterImpl: public StressGenInter {
LOG_ERROR_RETURN(-1, false, "fail to stat dir `", path);
node->node_stat.st_uid = meta->uid;
node->node_stat.st_gid = meta->gid;
node->node_stat.st_mtime = meta->mtime;
return true;
}

Expand Down Expand Up @@ -257,6 +275,9 @@ class StressCase001: public StressBase, public StressInterImpl {
bool build_gen_own(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_gen_own(node, meta);
}
bool build_gen_mtime(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_gen_mtime(node, meta);
}
bool build_stat_file(StressNode *node, StressHostFile *file, struct in_mem_meta *meta) override {
return StressInterImpl::build_stat_file(node, file, meta);
}
Expand All @@ -267,6 +288,9 @@ class StressCase001: public StressBase, public StressInterImpl {
bool build_dir_own(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_dir_own(node, meta);
}
bool build_dir_mtime(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_dir_mtime(node, meta);
}
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
}
Expand Down Expand Up @@ -296,8 +320,8 @@ class StressCase001: public StressBase, public StressInterImpl {
std::vector<int> layer_dirs(int idx) {
std::vector<int> ret;

ret.emplace_back(50);
ret.emplace_back(50);
ret.emplace_back(3);
ret.emplace_back(3);
return ret;
}
};
Expand All @@ -320,6 +344,9 @@ class StressCase002: public StressBase, public StressInterImpl {
bool build_gen_own(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_gen_own(node, meta);
}
bool build_gen_mtime(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_gen_mtime(node, meta);
}
bool build_gen_content(StressNode *node, StressHostFile *file) override {
return StressInterImpl::build_gen_content(node, file);
}
Expand All @@ -333,6 +360,9 @@ class StressCase002: public StressBase, public StressInterImpl {
bool build_dir_own(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_dir_own(node, meta);
}
bool build_dir_mtime(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_dir_mtime(node, meta);
}
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
}
Expand Down Expand Up @@ -388,6 +418,9 @@ class StressCase003: public StressBase, public StressInterImpl {
bool build_gen_own(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_gen_own(node, meta);
}
bool build_gen_mtime(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_gen_mtime(node, meta);
}
bool build_gen_xattrs(StressNode *node, StressHostFile *file) override {
return StressInterImpl::build_gen_xattrs(node, file);
}
Expand All @@ -401,6 +434,9 @@ class StressCase003: public StressBase, public StressInterImpl {
bool build_dir_own(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_dir_own(node, meta);
}
bool build_dir_mtime(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_dir_mtime(node, meta);
}
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
}
Expand Down Expand Up @@ -449,6 +485,9 @@ class StressCase004: public StressBase, public StressInterImpl {
bool build_gen_own(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_gen_own(node, meta);
}
bool build_gen_mtime(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_gen_mtime(node, meta);
}
bool build_gen_mod(StressNode *node, StressHostFile *file) override {
return StressInterImpl::build_gen_mod(node, file);
}
Expand All @@ -462,6 +501,9 @@ class StressCase004: public StressBase, public StressInterImpl {
bool build_dir_own(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_dir_own(node, meta);
}
bool build_dir_mtime(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_dir_mtime(node, meta);
}
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
}
Expand Down Expand Up @@ -510,6 +552,9 @@ class StressCase005: public StressBase, public StressInterImpl {
bool build_gen_own(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_gen_own(node, meta);
}
bool build_gen_mtime(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_gen_mtime(node, meta);
}
bool build_stat_file(StressNode *node, StressHostFile *file, struct in_mem_meta *meta) override {
return StressInterImpl::build_stat_file(node, file, meta);
}
Expand All @@ -520,6 +565,9 @@ class StressCase005: public StressBase, public StressInterImpl {
bool build_dir_own(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_dir_own(node, meta);
}
bool build_dir_mtime(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_dir_mtime(node, meta);
}
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
}
Expand Down Expand Up @@ -568,6 +616,9 @@ class StressCase006: public StressBase, public StressInterImpl {
bool build_gen_own(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_gen_own(node, meta);
}
bool build_gen_mtime(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_gen_mtime(node, meta);
}
bool build_gen_xattrs(StressNode *node, StressHostFile *file) override {
return StressInterImpl::build_gen_xattrs(node, file);
}
Expand All @@ -584,6 +635,9 @@ class StressCase006: public StressBase, public StressInterImpl {
bool build_dir_own(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_dir_own(node, meta);
}
bool build_dir_mtime(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_dir_mtime(node, meta);
}
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
}
Expand Down Expand Up @@ -636,6 +690,9 @@ class StressCase007: public StressBase, public StressInterImpl {
bool build_gen_own(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_gen_own(node, meta);
}
bool build_gen_mtime(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_gen_mtime(node, meta);
}
bool build_gen_xattrs(StressNode *node, StressHostFile *file) override {
return StressInterImpl::build_gen_xattrs(node, file);
}
Expand All @@ -652,6 +709,9 @@ class StressCase007: public StressBase, public StressInterImpl {
bool build_dir_own(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_dir_own(node, meta);
}
bool build_dir_mtime(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_dir_mtime(node, meta);
}
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
}
Expand Down Expand Up @@ -724,6 +784,9 @@ class StressCase008: public StressBase, public StressInterImpl {
bool build_gen_own(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_gen_own(node, meta);
}
bool build_gen_mtime(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_gen_mtime(node, meta);
}
bool build_gen_xattrs(StressNode *node, StressHostFile *file) override {
return StressInterImpl::build_gen_xattrs(node, file);
}
Expand All @@ -740,6 +803,9 @@ class StressCase008: public StressBase, public StressInterImpl {
bool build_dir_own(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_dir_own(node, meta);
}
bool build_dir_mtime(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_dir_mtime(node, meta);
}
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
}
Expand Down Expand Up @@ -821,6 +887,9 @@ class StressCase009: public StressBase, public StressInterImpl {
bool build_gen_own(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_gen_own(node, meta);
}
bool build_gen_mtime(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_gen_mtime(node, meta);
}
bool build_gen_xattrs(StressNode *node, StressHostFile *file) override {
return StressInterImpl::build_gen_xattrs(node, file);
}
Expand All @@ -837,6 +906,9 @@ class StressCase009: public StressBase, public StressInterImpl {
bool build_dir_own(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_dir_own(node, meta);
}
bool build_dir_mtime(StressNode *node, struct in_mem_meta *meta) override {
return StressInterImpl::build_dir_mtime(node, meta);
}
bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) override {
return StressInterImpl::build_dir_xattrs(node, path, host_fs);
}
Expand Down
5 changes: 4 additions & 1 deletion src/overlaybd/tar/erofs/test/erofs_stress_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ static bool append_tar(bool first, std::string tar_name, std::string tmp_tar, st
{
std::string cmd = std::string("tar --create --file=") + (first ? tar_name : tmp_tar) + " --xattrs --xattrs-include='*'";
if (meta)
cmd = cmd + " --owner=" + std::to_string(meta->uid) + " --group=" + std::to_string(meta->gid);
cmd = cmd + " --owner=" + std::to_string(meta->uid) + " --group=" + std::to_string(meta->gid) + " --mtime=\"" + meta->mtime_date + "\"";
cmd = cmd + " -C " + prefix + " " + file_name;

if (system(cmd.c_str()))
Expand Down Expand Up @@ -205,6 +205,7 @@ bool StressBase::create_layer(int idx) {
meta_maps[layer_tree->pwd] = new struct in_mem_meta();
res = build_dir_mod(node, layer_tree->pwd.c_str(), host_fs) &&
build_dir_own(node, meta_maps[layer_tree->pwd]) &&
build_dir_mtime(node, meta_maps[layer_tree->pwd]) &&
build_dir_xattrs(node, layer_tree->pwd.c_str(), host_fs) &&
build_stat_dir(node, layer_tree->pwd.c_str(), host_fs, meta_maps[layer_tree->pwd]);
if (!res)
Expand Down Expand Up @@ -250,6 +251,7 @@ bool StressBase::create_layer(int idx) {
meta_maps[prefix + filename] = new struct in_mem_meta();
res = build_gen_mod(node, file_info) &&
build_gen_own(node, meta_maps[prefix + filename]) &&
build_gen_mtime(node, meta_maps[prefix + filename]) &&
build_gen_xattrs(node, file_info) &&
build_gen_content(node, file_info) &&
build_stat_file(node, file_info, meta_maps[prefix + filename]);
Expand Down Expand Up @@ -297,6 +299,7 @@ bool StressBase::create_layer(int idx) {
meta_maps[next->pwd] = new struct in_mem_meta();
res = build_dir_mod(dir_node, next->pwd.c_str(), host_fs) &&
build_dir_own(dir_node, meta_maps[next->pwd]) &&
build_dir_mtime(dir_node, meta_maps[next->pwd]) &&
build_dir_xattrs(dir_node, next->pwd.c_str(), host_fs) &&
build_stat_dir(dir_node, next->pwd.c_str(), host_fs, meta_maps[next->pwd]);
if (!res)
Expand Down
9 changes: 9 additions & 0 deletions src/overlaybd/tar/erofs/test/erofs_stress_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ class StressNode {
*/
if (type != NODE_DIR && node_stat.st_size != ano->node_stat.st_size)
LOG_ERROR_RETURN(-1, false, "file size ` not equal to ` (`)", node_stat.st_size, ano->node_stat.st_size, path);

if (node_stat.st_mtime != ano->node_stat.st_mtime)
LOG_ERRNO_RETURN(-1, false, "mtime ` not equal to ` (`)", node_stat.st_mtime,
ano->node_stat.st_mtime,
path);
return true;
}
};
Expand Down Expand Up @@ -139,6 +144,8 @@ class StressHostFile {
struct in_mem_meta{
uid_t uid;
gid_t gid;
std::string mtime_date;
time_t mtime;
};

/* interface to generate corresponding values for in-mem nodes and host-fs files */
Expand All @@ -148,13 +155,15 @@ class StressGenInter {
/* generate content for in-memory inodes and host files (prepare layers phase) */
virtual bool build_gen_mod(StressNode *node /* out */, StressHostFile *file_info /* out */) = 0;
virtual bool build_gen_own(StressNode *node /* out */, struct in_mem_meta *meta /* out */) = 0;
virtual bool build_gen_mtime(StressNode *node, struct in_mem_meta *meta) = 0;
virtual bool build_gen_xattrs(StressNode *node /* out */, StressHostFile *file_info /* out */) = 0;
virtual bool build_gen_content(StressNode *node /* out */, StressHostFile *file_info /* out */) = 0;
virtual bool build_stat_file(StressNode *node /* out */, StressHostFile *file_info /* out */, struct in_mem_meta *meta) = 0;

/* for a single dir (node) */
virtual bool build_dir_mod(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) = 0;
virtual bool build_dir_own(StressNode *node, struct in_mem_meta *meta) = 0;
virtual bool build_dir_mtime(StressNode *node, struct in_mem_meta *meta) = 0;
virtual bool build_dir_xattrs(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs) = 0;
virtual bool build_stat_dir(StressNode *node, const char *path, photon::fs::IFileSystem *host_fs, struct in_mem_meta *meta) = 0;

Expand Down

0 comments on commit 115be8d

Please sign in to comment.