rocksdb: initial util/testharness clean up

Summary: Deleted some redundant code. More comming.

Test Plan:
```lang=bash
% USE_CLANG=1 make check
```

Reviewers: meyering, sdong, igor

Reviewed By: igor

Subscribers: dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D35463
main
Igor Sugak 10 years ago
parent 836bcc2f00
commit 17ae3fcbca
  1. 62
      util/testharness.cc
  2. 9
      util/testharness.h

@ -9,72 +9,10 @@
#include "util/testharness.h" #include "util/testharness.h"
#include <string> #include <string>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "port/stack_trace.h"
namespace rocksdb { namespace rocksdb {
namespace test { namespace test {
namespace {
struct Test {
const char* base;
const char* name;
void (*func)();
};
std::vector<Test>* tests;
}
bool RegisterTest(const char* base, const char* name, void (*func)()) {
if (tests == nullptr) {
tests = new std::vector<Test>;
}
Test t;
t.base = base;
t.name = name;
t.func = func;
tests->push_back(t);
return true;
}
int RunAllTests() {
port::InstallStackTraceHandler();
const char* one_matcher = getenv("ROCKSDB_TESTS");
const char* from_matcher = getenv("ROCKSDB_TESTS_FROM");
int num = 0;
bool tests_on = (one_matcher == nullptr && from_matcher == nullptr);
if (tests != nullptr) {
for (unsigned int i = 0; i < tests->size(); i++) {
const Test& t = (*tests)[i];
if (tests_on == false) {
if (one_matcher != nullptr || from_matcher != nullptr) {
std::string name = t.base;
name.push_back('.');
name.append(t.name);
if (from_matcher != nullptr &&
strstr(name.c_str(), from_matcher) != nullptr) {
tests_on = true;
}
if (!tests_on) {
if (one_matcher == nullptr ||
strstr(name.c_str(), one_matcher) == nullptr) {
continue;
}
}
}
}
fprintf(stderr, "==== Test %s.%s\n", t.base, t.name);
(*t.func)();
++num;
}
}
fprintf(stderr, "==== PASSED %d tests\n", num);
return 0;
}
std::string TmpDir(Env* env) { std::string TmpDir(Env* env) {
std::string dir; std::string dir;
Status s = env->GetTestDirectory(&dir); Status s = env->GetTestDirectory(&dir);

@ -11,13 +11,8 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <stdio.h>
#include <stdlib.h>
#include <sstream>
#include <string> #include <string>
#include "port/stack_trace.h"
#include "rocksdb/env.h" #include "rocksdb/env.h"
#include "rocksdb/slice.h"
#include "util/random.h" #include "util/random.h"
#include "util/string_util.h" #include "util/string_util.h"
@ -25,12 +20,12 @@ namespace rocksdb {
namespace test { namespace test {
// Return the directory to use for temporary storage. // Return the directory to use for temporary storage.
extern std::string TmpDir(Env* env = Env::Default()); std::string TmpDir(Env* env = Env::Default());
// Return a randomization seed for this run. Typically returns the // Return a randomization seed for this run. Typically returns the
// same number on repeated invocations of this binary, but automated // same number on repeated invocations of this binary, but automated
// runs may be able to vary the seed. // runs may be able to vary the seed.
extern int RandomSeed(); int RandomSeed();
#define ASSERT_OK(s) ASSERT_TRUE(((s).ok())) #define ASSERT_OK(s) ASSERT_TRUE(((s).ok()))
#define ASSERT_NOK(s) ASSERT_FALSE(((s).ok())) #define ASSERT_NOK(s) ASSERT_FALSE(((s).ok()))

Loading…
Cancel
Save