2016-02-09 23:12:00 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-15 23:03:42 +00:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2013-10-16 21:59:46 +00:00
|
|
|
//
|
2011-03-18 22:37:00 +00:00
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
|
2019-05-30 18:21:38 +00:00
|
|
|
#include "test_util/testharness.h"
|
2011-08-16 01:21:01 +00:00
|
|
|
#include <string>
|
2018-07-14 00:18:39 +00:00
|
|
|
#include <thread>
|
2011-03-18 22:37:00 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2011-03-18 22:37:00 +00:00
|
|
|
namespace test {
|
|
|
|
|
2015-03-20 00:32:43 +00:00
|
|
|
::testing::AssertionResult AssertStatus(const char* s_expr, const Status& s) {
|
|
|
|
if (s.ok()) {
|
|
|
|
return ::testing::AssertionSuccess();
|
|
|
|
} else {
|
|
|
|
return ::testing::AssertionFailure() << s_expr << std::endl
|
|
|
|
<< s.ToString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-31 22:08:10 +00:00
|
|
|
std::string TmpDir(Env* env) {
|
2011-03-18 22:37:00 +00:00
|
|
|
std::string dir;
|
2014-10-31 22:08:10 +00:00
|
|
|
Status s = env->GetTestDirectory(&dir);
|
2020-07-29 05:58:28 +00:00
|
|
|
EXPECT_OK(s);
|
2011-03-18 22:37:00 +00:00
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
2018-07-14 00:18:39 +00:00
|
|
|
std::string PerThreadDBPath(std::string dir, std::string name) {
|
|
|
|
size_t tid = std::hash<std::thread::id>()(std::this_thread::get_id());
|
|
|
|
return dir + "/" + name + "_" + std::to_string(tid);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string PerThreadDBPath(std::string name) {
|
|
|
|
return PerThreadDBPath(test::TmpDir(), name);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string PerThreadDBPath(Env* env, std::string name) {
|
|
|
|
return PerThreadDBPath(test::TmpDir(env), name);
|
|
|
|
}
|
|
|
|
|
2011-03-18 22:37:00 +00:00
|
|
|
int RandomSeed() {
|
|
|
|
const char* env = getenv("TEST_RANDOM_SEED");
|
2013-03-01 02:04:58 +00:00
|
|
|
int result = (env != nullptr ? atoi(env) : 301);
|
2011-03-18 22:37:00 +00:00
|
|
|
if (result <= 0) {
|
|
|
|
result = 301;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-10-31 17:22:06 +00:00
|
|
|
} // namespace test
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|