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

Use the Test Name for the dbname when running unit tests #353

Merged
merged 2 commits into from
Feb 7, 2023
Merged
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
2 changes: 1 addition & 1 deletion db/db_test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ DBTestBase::DBTestBase(const std::string path, bool env_do_fsync)
env_->SetBackgroundThreads(1, Env::LOW);
env_->SetBackgroundThreads(1, Env::HIGH);
env_->skip_fsync_ = !env_do_fsync;
dbname_ = test::PerThreadDBPath(env_, path);
dbname_ = test::PerThreadDBPath(env_, test::GetTestNameForDB(path));
alternative_wal_dir_ = dbname_ + "/wal";
alternative_db_log_dir_ = dbname_ + "/db_log_dir";
auto options = CurrentOptions();
Expand Down
24 changes: 24 additions & 0 deletions test_util/testharness.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,30 @@ ::testing::AssertionResult AssertStatus(const char* s_expr, const Status& s) {
}
}

// If suggested is empty, the name will be <test case>-<test name>
// Replaces all of the "/" in the test case/name with "_", so that they will not
// appear as directories
std::string GetTestNameForDB(const std::string& suggested) {
const testing::TestInfo* const test_info =
testing::UnitTest::GetInstance()->current_test_info();
std::string test_name = test_info->name();
std::string test_case = test_info->test_case_name();
auto pos = test_case.find("/");
if (pos != test_case.npos && !suggested.empty()) {
test_case = suggested;
} else {
while (pos != test_case.npos) {
test_case[pos] = '_';
pos = test_case.find("/", pos);
}
}
for (pos = test_name.find("/"); pos != test_name.npos;
pos = test_name.find("/", pos)) {
test_name[pos] = '_';
}
return test_case + "-" + test_name;
}

std::string TmpDir(Env* env) {
std::string dir;
Status s = env->GetTestDirectory(&dir);
Expand Down
3 changes: 3 additions & 0 deletions test_util/testharness.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
namespace ROCKSDB_NAMESPACE {
namespace test {

// Return a name of the DB for this test, based on the test case/name
std::string GetTestNameForDB(const std::string& suggested = "");

// Return the directory to use for temporary storage.
std::string TmpDir(Env* env = Env::Default());

Expand Down