testharness.cc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
  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).
  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. #include "test_util/testharness.h"
  10. #include <string>
  11. #include <thread>
  12. namespace ROCKSDB_NAMESPACE {
  13. namespace test {
  14. ::testing::AssertionResult AssertStatus(const char* s_expr, const Status& s) {
  15. if (s.ok()) {
  16. return ::testing::AssertionSuccess();
  17. } else {
  18. return ::testing::AssertionFailure() << s_expr << std::endl
  19. << s.ToString();
  20. }
  21. }
  22. std::string TmpDir(Env* env) {
  23. std::string dir;
  24. Status s = env->GetTestDirectory(&dir);
  25. EXPECT_TRUE(s.ok()) << s.ToString();
  26. return dir;
  27. }
  28. std::string PerThreadDBPath(std::string dir, std::string name) {
  29. size_t tid = std::hash<std::thread::id>()(std::this_thread::get_id());
  30. return dir + "/" + name + "_" + std::to_string(tid);
  31. }
  32. std::string PerThreadDBPath(std::string name) {
  33. return PerThreadDBPath(test::TmpDir(), name);
  34. }
  35. std::string PerThreadDBPath(Env* env, std::string name) {
  36. return PerThreadDBPath(test::TmpDir(env), name);
  37. }
  38. int RandomSeed() {
  39. const char* env = getenv("TEST_RANDOM_SEED");
  40. int result = (env != nullptr ? atoi(env) : 301);
  41. if (result <= 0) {
  42. result = 301;
  43. }
  44. return result;
  45. }
  46. } // namespace test
  47. } // namespace ROCKSDB_NAMESPACE