]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/util/testharness.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / rocksdb / util / testharness.cc
CommitLineData
7c673cae 1// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
11fdf7f2
TL
2// This source code is licensed under both the GPLv2 (found in the
3// COPYING file in the root directory) and Apache 2.0 License
4// (found in the LICENSE.Apache file in the root directory).
7c673cae
FG
5//
6// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7// Use of this source code is governed by a BSD-style license that can be
8// found in the LICENSE file. See the AUTHORS file for names of contributors.
9
10#include "util/testharness.h"
11#include <string>
11fdf7f2 12#include <thread>
7c673cae
FG
13
14namespace rocksdb {
15namespace test {
16
17::testing::AssertionResult AssertStatus(const char* s_expr, const Status& s) {
18 if (s.ok()) {
19 return ::testing::AssertionSuccess();
20 } else {
21 return ::testing::AssertionFailure() << s_expr << std::endl
22 << s.ToString();
23 }
24}
25
26std::string TmpDir(Env* env) {
27 std::string dir;
28 Status s = env->GetTestDirectory(&dir);
29 EXPECT_TRUE(s.ok()) << s.ToString();
30 return dir;
31}
32
11fdf7f2
TL
33std::string PerThreadDBPath(std::string dir, std::string name) {
34 size_t tid = std::hash<std::thread::id>()(std::this_thread::get_id());
35 return dir + "/" + name + "_" + std::to_string(tid);
36}
37
38std::string PerThreadDBPath(std::string name) {
39 return PerThreadDBPath(test::TmpDir(), name);
40}
41
42std::string PerThreadDBPath(Env* env, std::string name) {
43 return PerThreadDBPath(test::TmpDir(env), name);
44}
45
7c673cae
FG
46int RandomSeed() {
47 const char* env = getenv("TEST_RANDOM_SEED");
48 int result = (env != nullptr ? atoi(env) : 301);
49 if (result <= 0) {
50 result = 301;
51 }
52 return result;
53}
54
55} // namespace test
56} // namespace rocksdb