Skip to content

Commit

Permalink
[EROFS] test: add an interface for generating directory and file names
Browse files Browse the repository at this point in the history
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 <hongzhen@linux.alibaba.com>
  • Loading branch information
salvete committed Dec 16, 2024
1 parent 4a42002 commit ba3a364
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
24 changes: 24 additions & 0 deletions src/overlaybd/tar/erofs/test/erofs_stress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<int> layer_dirs(int idx) {
std::vector<int> ret;

Expand Down Expand Up @@ -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<int> layer_dirs(int idx) {
std::vector<int> ret;

Expand Down Expand Up @@ -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<int> layer_dirs(int idx) {
std::vector<int> ret;

Expand Down Expand Up @@ -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<int> layer_dirs(int idx) {
std::vector<int> ret;

Expand Down
18 changes: 11 additions & 7 deletions src/overlaybd/tar/erofs/test/erofs_stress_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ std::string get_randomstr(int max_length, bool range)
struct LayerNode {
std::string pwd;
std::vector<LayerNode*> subdirs;
std::vector<std::string> files;
int num_files, depth;
};

static LayerNode *build_layer_tree(std::vector<int> &dirs) {
std::vector<LayerNode*> nodes;

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) {
Expand All @@ -69,7 +69,7 @@ bool StressBase::create_layer(int idx) {
std::vector<int> dirs = layer_dirs(idx);
LayerNode *layer_tree = build_layer_tree(dirs);
std::vector<LayerNode*> 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;

Expand All @@ -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);

Expand All @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion src/overlaybd/tar/erofs/test/erofs_stress_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@

/* in-mem node type */
enum NODE_TYPE {
NODE_REGULAR,
NODE_DIR,
NODE_REGULAR,
NODE_WHITEOUT,
NODE_TYPE_MAX
};
Expand Down Expand Up @@ -138,6 +138,13 @@ class StressGenInter {
*/
virtual std::vector<int> 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() {}
};

Expand Down

0 comments on commit ba3a364

Please sign in to comment.