2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02: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 23:59:46 +02:00
|
|
|
//
|
2011-03-18 23:37:00 +01: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 20:21:38 +02:00
|
|
|
#include "test_util/testharness.h"
|
2011-08-16 03:21:01 +02:00
|
|
|
#include <string>
|
2018-07-14 02:18:39 +02:00
|
|
|
#include <thread>
|
2011-03-18 23:37:00 +01:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2011-03-18 23:37:00 +01:00
|
|
|
namespace test {
|
|
|
|
|
2021-03-31 01:50:17 +02:00
|
|
|
#ifdef OS_WIN
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
std::string GetPidStr() { return std::to_string(GetCurrentProcessId()); }
|
|
|
|
#else
|
|
|
|
std::string GetPidStr() { return std::to_string(getpid()); }
|
|
|
|
#endif
|
|
|
|
|
2015-03-20 01:32:43 +01: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 23:08:10 +01:00
|
|
|
std::string TmpDir(Env* env) {
|
2011-03-18 23:37:00 +01:00
|
|
|
std::string dir;
|
2014-10-31 23:08:10 +01:00
|
|
|
Status s = env->GetTestDirectory(&dir);
|
2020-07-29 07:58:28 +02:00
|
|
|
EXPECT_OK(s);
|
2011-03-18 23:37:00 +01:00
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
2018-07-14 02:18:39 +02:00
|
|
|
std::string PerThreadDBPath(std::string dir, std::string name) {
|
|
|
|
size_t tid = std::hash<std::thread::id>()(std::this_thread::get_id());
|
2021-03-31 01:50:17 +02:00
|
|
|
return dir + "/" + name + "_" + GetPidStr() + "_" + std::to_string(tid);
|
2018-07-14 02:18:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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 23:37:00 +01:00
|
|
|
int RandomSeed() {
|
|
|
|
const char* env = getenv("TEST_RANDOM_SEED");
|
2013-03-01 03:04:58 +01:00
|
|
|
int result = (env != nullptr ? atoi(env) : 301);
|
2011-03-18 23:37:00 +01:00
|
|
|
if (result <= 0) {
|
|
|
|
result = 301;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-10-31 18:22:06 +01:00
|
|
|
} // namespace test
|
2020-02-20 21:07:53 +01:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|