Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 646262391
  • Loading branch information
ussuri authored and copybara-github committed Jun 24, 2024
1 parent 63a1ba0 commit 43eec9b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 31 deletions.
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

0 comments on commit 43eec9b

Please sign in to comment.