Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No public description #1228

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion centipede/test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ std::filesystem::path GetTestTempDir(std::string_view subdir) {
if (!std::filesystem::exists(dir)) {
std::error_code error;
std::filesystem::create_directories(dir, error);
CHECK(!error) << "Failed to create dir: " VV(dir) << error.message();
CHECK(!error) << "Failed to create dir: " VV(dir) << VV(error);
} else {
std::error_code error;
std::filesystem::remove_all(dir, error);
CHECK(!error) << "Failed to clear dir: " VV(dir) << VV(error);
}
return std::filesystem::canonical(dir);
}
Expand Down
32 changes: 2 additions & 30 deletions centipede/test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,32 +65,6 @@ std::string GetObjDumpPath();
// Resets the PATH envvar to "`dir`:$PATH".
void PrependDirToPathEnvvar(std::string_view dir);

// Creates or clears a tmp dir in CTOR. The dir will end with `leaf` subdir.
class TempDir {
public:
explicit TempDir(std::string_view leaf1, std::string_view leaf2 = "")
: path_{GetTestTempDir(leaf1) / leaf2} {
std::filesystem::remove_all(path_);
std::filesystem::create_directories(path_);
}

const std::filesystem::path& path() const { return path_; }

std::string GetFilePath(std::string_view file_name) const {
return path_ / file_name;
}

std::string CreateSubdir(std::string_view name) const {
std::string path = GetFilePath(name);
std::filesystem::remove_all(path);
std::filesystem::create_directories(path);
return path;
}

private:
std::filesystem::path path_;
};

class TempCorpusDir : public TempDir {
public:
// Reuse the parent's ctor.
Expand All @@ -99,8 +73,7 @@ class TempCorpusDir : public TempDir {
// Loads the corpus from the file `name_prefix``shard_index`
// and returns it as a vector<ByteArray>.
// Returns an empty vector if the file cannot be opened.
std::vector<ByteArray> GetCorpus(size_t shard_index,
std::string_view name_prefix = "corpus.") {
std::vector<ByteArray> GetCorpus(size_t shard_index) {
// NOTE: The "6" in the "%06d" comes from kDigitsInShardIndex in
// environment.cc.
if (!reader_
Expand All @@ -119,8 +92,7 @@ class TempCorpusDir : public TempDir {
}

// Returns the count of elements in the corpus file `path`/`file_name`.
size_t CountElementsInCorpusFile(size_t shard_index,
std::string_view name_prefix = "corpus.") {
size_t CountElementsInCorpusFile(size_t shard_index) {
return GetCorpus(shard_index, name_prefix).size();
}

Expand Down
Loading