From ba3a36463c93fc5a16255c6b7aaa5bf1770aa654 Mon Sep 17 00:00:00 2001 From: Hongzhen Luo Date: Thu, 5 Dec 2024 18:32:22 +0800 Subject: [PATCH] [EROFS] test: add an interface for generating directory and file names To prepare for: 1. ontrol the overlap between the upper layer and lower layer 2. generate .wh.* Relevant tests will be added later. Signed-off-by: Hongzhen Luo --- src/overlaybd/tar/erofs/test/erofs_stress.cpp | 24 +++++++++++++++++++ .../tar/erofs/test/erofs_stress_base.cpp | 18 ++++++++------ .../tar/erofs/test/erofs_stress_base.h | 9 ++++++- 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/src/overlaybd/tar/erofs/test/erofs_stress.cpp b/src/overlaybd/tar/erofs/test/erofs_stress.cpp index f54c8bf8..c0d5ebbc 100644 --- a/src/overlaybd/tar/erofs/test/erofs_stress.cpp +++ b/src/overlaybd/tar/erofs/test/erofs_stress.cpp @@ -206,6 +206,10 @@ class StressCase001: public StressBase { EROFS_STRESS_UNIMPLEMENTED_FUNC(bool, verify_gen_xattrs(StressNode *node, photon::fs::IFile *erofs_file), true) EROFS_STRESS_UNIMPLEMENTED_FUNC(bool, verify_gen_content(StressNode *node, photon::fs::IFile *erofs_file), true) + /* simplely generate random dir and file names */ + EROFS_STRESS_UNIMPLEMENTED_FUNC(std::string, generate_name(int idx, int depth, std::string _prefix, NODE_TYPE type), \ + get_randomstr(type ? MAX_FILE_NAME : MAX_DIR_NAME, true)) + /* * each layer has two dirs: * dir one contains 50 files, @@ -248,6 +252,10 @@ class StressCase002: public StressBase, public StressInterImpl { return StressInterImpl::verify_gen_content(node, erofs_file); } + /* simplely generate random dir and file names */ + EROFS_STRESS_UNIMPLEMENTED_FUNC(std::string, generate_name(int idx, int depth, std::string _prefix, NODE_TYPE type), \ + get_randomstr(type ? MAX_FILE_NAME : MAX_DIR_NAME, true)) + /* * each layer has two dirs: * dir one contains 10 files, @@ -289,6 +297,10 @@ class StressCase003: public StressBase, public StressInterImpl { return StressInterImpl::verify_gen_xattrs(node, erofs_file); } + /* simplely generate random dir and file names */ + EROFS_STRESS_UNIMPLEMENTED_FUNC(std::string, generate_name(int idx, int depth, std::string _prefix, NODE_TYPE type), \ + get_randomstr(type ? MAX_FILE_NAME : MAX_DIR_NAME, true)) + std::vector layer_dirs(int idx) { std::vector ret; @@ -326,6 +338,10 @@ class StressCase004: public StressBase, public StressInterImpl { return StressInterImpl::verify_gen_mod(node, erofs_file); } + /* simplely generate random dir and file names */ + EROFS_STRESS_UNIMPLEMENTED_FUNC(std::string, generate_name(int idx, int depth, std::string _prefix, NODE_TYPE type), \ + get_randomstr(type ? MAX_FILE_NAME : MAX_DIR_NAME, true)) + std::vector layer_dirs(int idx) { std::vector ret; @@ -362,6 +378,10 @@ class StressCase005: public StressBase, public StressInterImpl { return StressInterImpl::verify_gen_own(node, erofs_file); } + /* simplely generate random dir and file names */ + EROFS_STRESS_UNIMPLEMENTED_FUNC(std::string, generate_name(int idx, int depth, std::string _prefix, NODE_TYPE type), \ + get_randomstr(type ? MAX_FILE_NAME : MAX_DIR_NAME, true)) + std::vector layer_dirs(int idx) { std::vector ret; @@ -410,6 +430,10 @@ class StressCase006: public StressBase, public StressInterImpl { return StressInterImpl::verify_gen_content(node, erofs_file); } + /* simplely generate random dir and file names */ + EROFS_STRESS_UNIMPLEMENTED_FUNC(std::string, generate_name(int idx, int depth, std::string _prefix, NODE_TYPE type), \ + get_randomstr(type ? MAX_FILE_NAME : MAX_DIR_NAME, true)) + std::vector layer_dirs(int idx) { std::vector ret; diff --git a/src/overlaybd/tar/erofs/test/erofs_stress_base.cpp b/src/overlaybd/tar/erofs/test/erofs_stress_base.cpp index f82eee86..bdb0298c 100644 --- a/src/overlaybd/tar/erofs/test/erofs_stress_base.cpp +++ b/src/overlaybd/tar/erofs/test/erofs_stress_base.cpp @@ -41,7 +41,7 @@ std::string get_randomstr(int max_length, bool range) struct LayerNode { std::string pwd; std::vector subdirs; - std::vector files; + int num_files, depth; }; static LayerNode *build_layer_tree(std::vector &dirs) { @@ -49,8 +49,8 @@ static LayerNode *build_layer_tree(std::vector &dirs) { for (int i = 0; i < (int)dirs.size(); i ++) { nodes.emplace_back(new LayerNode); - for (int j = 0; j < dirs[i]; j ++) - nodes[i]->files.emplace_back(get_randomstr(MAX_FILE_NAME, true)); + nodes[i]->depth = 0; + nodes[i]->num_files = dirs[i]; } while (nodes.size() > 1) { @@ -69,7 +69,7 @@ bool StressBase::create_layer(int idx) { std::vector dirs = layer_dirs(idx); LayerNode *layer_tree = build_layer_tree(dirs); std::vector q; - std::string root_dirname = get_randomstr(MAX_DIR_NAME, true); + std::string root_dirname = generate_name(idx, layer_tree->depth, "", NODE_DIR); std::string root_path = prefix + "/" + root_dirname; std::string clean_cmd = "rm -rf " + root_path; @@ -90,8 +90,10 @@ bool StressBase::create_layer(int idx) { LOG_ERROR_RETURN(-1, false, "fail to mkdir `", cur->pwd); tree->add_node(node); - for (int i = 0; i < (int)cur->files.size(); i ++) { - std::string filename = cur->pwd.substr(prefix.length()) + "/" + cur->files[i]; + for (int i = 0; i < (int)cur->num_files; i ++) { + std::string name_prefix = cur->pwd.substr(prefix.length()); + // generate filename for files in the current dir + std::string filename = name_prefix + "/" + generate_name(idx, cur->depth, name_prefix, NODE_REGULAR); StressNode *node = new StressNode(filename, NODE_REGULAR); StressHostFile *file_info = new StressHostFile(prefix + filename, host_fs); @@ -108,7 +110,9 @@ bool StressBase::create_layer(int idx) { for (int i = 0; i < (int)cur->subdirs.size(); i ++) { LayerNode *next = cur->subdirs[i]; - next->pwd = cur->pwd + "/" + get_randomstr(MAX_DIR_NAME, true); + next->depth = cur->depth + 1; + // generate subdir name in the current dir + next->pwd = cur->pwd + "/" + generate_name(idx, cur->depth, cur->pwd.substr(prefix.length()), NODE_DIR); q.emplace_back(next); } delete cur; diff --git a/src/overlaybd/tar/erofs/test/erofs_stress_base.h b/src/overlaybd/tar/erofs/test/erofs_stress_base.h index 512d5794..fed6cd60 100644 --- a/src/overlaybd/tar/erofs/test/erofs_stress_base.h +++ b/src/overlaybd/tar/erofs/test/erofs_stress_base.h @@ -34,8 +34,8 @@ /* in-mem node type */ enum NODE_TYPE { - NODE_REGULAR, NODE_DIR, + NODE_REGULAR, NODE_WHITEOUT, NODE_TYPE_MAX }; @@ -138,6 +138,13 @@ class StressGenInter { */ virtual std::vector layer_dirs(int idx) = 0; + /* + * generate the name for a dir or a file, to: + * 1. control the overlap between the upper layer and lower layer + * 2. generate .wh.* + */ + virtual std::string generate_name(int idx, int depth, std::string root_path, NODE_TYPE type) = 0; + virtual ~StressGenInter() {} };