summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt102
-rw-r--r--benchmarks/db_bench_log.cc92
-rw-r--r--db/autocompact_test.cc5
-rw-r--r--db/corruption_test.cc5
-rw-r--r--db/db_test.cc69
-rw-r--r--db/dbformat_test.cc5
-rw-r--r--db/fault_injection_test.cc5
-rw-r--r--db/filename_test.cc5
-rw-r--r--db/log_test.cc5
-rw-r--r--db/recovery_test.cc5
-rw-r--r--db/skiplist.h2
-rw-r--r--db/skiplist_test.cc5
-rw-r--r--db/snapshot.h2
-rw-r--r--db/table_cache.h4
-rw-r--r--db/version_edit_test.cc5
-rw-r--r--db/version_set.cc2
-rw-r--r--db/version_set_test.cc5
-rw-r--r--db/write_batch_test.cc5
-rw-r--r--helpers/memenv/memenv_test.cc5
-rw-r--r--include/leveldb/cache.h8
-rw-r--r--issues/issue178_test.cc5
-rw-r--r--issues/issue200_test.cc5
-rw-r--r--issues/issue320_test.cc5
-rw-r--r--table/filter_block_test.cc5
-rw-r--r--table/table_test.cc5
-rw-r--r--util/arena_test.cc5
-rw-r--r--util/bloom_test.cc5
-rw-r--r--util/cache_test.cc5
-rw-r--r--util/coding_test.cc5
-rw-r--r--util/crc32c_test.cc5
-rw-r--r--util/env_posix.cc41
-rw-r--r--util/env_test.cc5
-rw-r--r--util/env_windows.cc30
-rw-r--r--util/hash_test.cc5
-rw-r--r--util/logging_test.cc5
-rw-r--r--util/no_destructor_test.cc5
-rw-r--r--util/status_test.cc5
37 files changed, 219 insertions, 268 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f8285b8..b829c94 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -298,11 +298,6 @@ if(LEVELDB_BUILD_TESTS)
# This project is tested using GoogleTest.
add_subdirectory("third_party/googletest")
- # This project uses Google benchmark for benchmarking.
- set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
- set(BENCHMARK_ENABLE_EXCEPTIONS OFF CACHE BOOL "" FORCE)
- add_subdirectory("third_party/benchmark")
-
# GoogleTest triggers a missing field initializers warning.
if(LEVELDB_HAVE_NO_MISSING_FIELD_INITIALIZERS)
set_property(TARGET gtest
@@ -311,6 +306,60 @@ if(LEVELDB_BUILD_TESTS)
APPEND PROPERTY COMPILE_OPTIONS -Wno-missing-field-initializers)
endif(LEVELDB_HAVE_NO_MISSING_FIELD_INITIALIZERS)
+ add_executable(leveldb_tests "")
+ target_sources(leveldb_tests
+ PRIVATE
+ # "db/fault_injection_test.cc"
+ # "issues/issue178_test.cc"
+ # "issues/issue200_test.cc"
+ # "issues/issue320_test.cc"
+ "${PROJECT_BINARY_DIR}/${LEVELDB_PORT_CONFIG_DIR}/port_config.h"
+ # "util/env_test.cc"
+ "util/status_test.cc"
+ "util/no_destructor_test.cc"
+ "util/testutil.cc"
+ "util/testutil.h"
+ )
+ if(NOT BUILD_SHARED_LIBS)
+ target_sources(leveldb_tests
+ PRIVATE
+ "db/autocompact_test.cc"
+ "db/corruption_test.cc"
+ "db/db_test.cc"
+ "db/dbformat_test.cc"
+ "db/filename_test.cc"
+ "db/log_test.cc"
+ "db/recovery_test.cc"
+ "db/skiplist_test.cc"
+ "db/version_edit_test.cc"
+ "db/version_set_test.cc"
+ "db/write_batch_test.cc"
+ "helpers/memenv/memenv_test.cc"
+ "table/filter_block_test.cc"
+ "table/table_test.cc"
+ "util/arena_test.cc"
+ "util/bloom_test.cc"
+ "util/cache_test.cc"
+ "util/coding_test.cc"
+ "util/crc32c_test.cc"
+ "util/hash_test.cc"
+ "util/logging_test.cc"
+ )
+ endif(NOT BUILD_SHARED_LIBS)
+ target_link_libraries(leveldb_tests leveldb gmock gtest gtest_main)
+ target_compile_definitions(leveldb_tests
+ PRIVATE
+ ${LEVELDB_PLATFORM_NAME}=1
+ )
+ if (NOT HAVE_CXX17_HAS_INCLUDE)
+ target_compile_definitions(leveldb_tests
+ PRIVATE
+ LEVELDB_HAS_PORT_CONFIG_H=1
+ )
+ endif(NOT HAVE_CXX17_HAS_INCLUDE)
+
+ add_test(NAME "leveldb_tests" COMMAND "leveldb_tests")
+
function(leveldb_test test_file)
get_filename_component(test_target_name "${test_file}" NAME_WE)
@@ -323,7 +372,7 @@ if(LEVELDB_BUILD_TESTS)
"${test_file}"
)
- target_link_libraries("${test_target_name}" leveldb gmock gtest benchmark)
+ target_link_libraries("${test_target_name}" leveldb gmock gtest)
target_compile_definitions("${test_target_name}"
PRIVATE
${LEVELDB_PLATFORM_NAME}=1
@@ -339,42 +388,8 @@ if(LEVELDB_BUILD_TESTS)
endfunction(leveldb_test)
leveldb_test("db/c_test.c")
- leveldb_test("db/fault_injection_test.cc")
-
- leveldb_test("issues/issue178_test.cc")
- leveldb_test("issues/issue200_test.cc")
- leveldb_test("issues/issue320_test.cc")
-
- leveldb_test("util/env_test.cc")
- leveldb_test("util/status_test.cc")
- leveldb_test("util/no_destructor_test.cc")
if(NOT BUILD_SHARED_LIBS)
- leveldb_test("db/autocompact_test.cc")
- leveldb_test("db/corruption_test.cc")
- leveldb_test("db/db_test.cc")
- leveldb_test("db/dbformat_test.cc")
- leveldb_test("db/filename_test.cc")
- leveldb_test("db/log_test.cc")
- leveldb_test("db/recovery_test.cc")
- leveldb_test("db/skiplist_test.cc")
- leveldb_test("db/version_edit_test.cc")
- leveldb_test("db/version_set_test.cc")
- leveldb_test("db/write_batch_test.cc")
-
- leveldb_test("helpers/memenv/memenv_test.cc")
-
- leveldb_test("table/filter_block_test.cc")
- leveldb_test("table/table_test.cc")
-
- leveldb_test("util/arena_test.cc")
- leveldb_test("util/bloom_test.cc")
- leveldb_test("util/cache_test.cc")
- leveldb_test("util/coding_test.cc")
- leveldb_test("util/crc32c_test.cc")
- leveldb_test("util/hash_test.cc")
- leveldb_test("util/logging_test.cc")
-
# TODO(costan): This test also uses
# "util/env_{posix|windows}_test_helper.h"
if (WIN32)
@@ -386,6 +401,11 @@ if(LEVELDB_BUILD_TESTS)
endif(LEVELDB_BUILD_TESTS)
if(LEVELDB_BUILD_BENCHMARKS)
+ # This project uses Google benchmark for benchmarking.
+ set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
+ set(BENCHMARK_ENABLE_EXCEPTIONS OFF CACHE BOOL "" FORCE)
+ add_subdirectory("third_party/benchmark")
+
function(leveldb_benchmark bench_file)
get_filename_component(bench_target_name "${bench_file}" NAME_WE)
@@ -400,7 +420,7 @@ if(LEVELDB_BUILD_BENCHMARKS)
"${bench_file}"
)
- target_link_libraries("${bench_target_name}" leveldb gmock gtest)
+ target_link_libraries("${bench_target_name}" leveldb gmock gtest benchmark)
target_compile_definitions("${bench_target_name}"
PRIVATE
${LEVELDB_PLATFORM_NAME}=1
diff --git a/benchmarks/db_bench_log.cc b/benchmarks/db_bench_log.cc
new file mode 100644
index 0000000..a1845bf
--- /dev/null
+++ b/benchmarks/db_bench_log.cc
@@ -0,0 +1,92 @@
+// Copyright (c) 2019 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.
+
+#include <cinttypes>
+#include <cstdio>
+#include <string>
+
+#include "gtest/gtest.h"
+#include "benchmark/benchmark.h"
+#include "db/version_set.h"
+#include "leveldb/comparator.h"
+#include "leveldb/db.h"
+#include "leveldb/env.h"
+#include "leveldb/options.h"
+#include "port/port.h"
+#include "util/mutexlock.h"
+#include "util/testutil.h"
+
+namespace leveldb {
+
+namespace {
+
+std::string MakeKey(unsigned int num) {
+ char buf[30];
+ std::snprintf(buf, sizeof(buf), "%016u", num);
+ return std::string(buf);
+}
+
+void BM_LogAndApply(benchmark::State& state) {
+ const int num_base_files = state.range(0);
+
+ std::string dbname = testing::TempDir() + "leveldb_test_benchmark";
+ DestroyDB(dbname, Options());
+
+ DB* db = nullptr;
+ Options opts;
+ opts.create_if_missing = true;
+ Status s = DB::Open(opts, dbname, &db);
+ ASSERT_LEVELDB_OK(s);
+ ASSERT_TRUE(db != nullptr);
+
+ delete db;
+ db = nullptr;
+
+ Env* env = Env::Default();
+
+ port::Mutex mu;
+ MutexLock l(&mu);
+
+ InternalKeyComparator cmp(BytewiseComparator());
+ Options options;
+ VersionSet vset(dbname, &options, nullptr, &cmp);
+ bool save_manifest;
+ ASSERT_LEVELDB_OK(vset.Recover(&save_manifest));
+ VersionEdit vbase;
+ uint64_t fnum = 1;
+ for (int i = 0; i < num_base_files; i++) {
+ InternalKey start(MakeKey(2 * fnum), 1, kTypeValue);
+ InternalKey limit(MakeKey(2 * fnum + 1), 1, kTypeDeletion);
+ vbase.AddFile(2, fnum++, 1 /* file size */, start, limit);
+ }
+ ASSERT_LEVELDB_OK(vset.LogAndApply(&vbase, &mu));
+
+ uint64_t start_micros = env->NowMicros();
+
+ for (auto st : state) {
+ VersionEdit vedit;
+ vedit.RemoveFile(2, fnum);
+ InternalKey start(MakeKey(2 * fnum), 1, kTypeValue);
+ InternalKey limit(MakeKey(2 * fnum + 1), 1, kTypeDeletion);
+ vedit.AddFile(2, fnum++, 1 /* file size */, start, limit);
+ vset.LogAndApply(&vedit, &mu);
+ }
+
+ uint64_t stop_micros = env->NowMicros();
+ unsigned int us = stop_micros - start_micros;
+ char buf[16];
+ std::snprintf(buf, sizeof(buf), "%d", num_base_files);
+ std::fprintf(stderr,
+ "BM_LogAndApply/%-6s %8" PRIu64
+ " iters : %9u us (%7.0f us / iter)\n",
+ buf, state.iterations(), us, ((float)us) / state.iterations());
+}
+
+BENCHMARK(BM_LogAndApply)->Arg(1)->Arg(100)->Arg(10000)->Arg(100000);
+
+} // namespace
+
+} // namespace leveldb
+
+BENCHMARK_MAIN();
diff --git a/db/autocompact_test.cc b/db/autocompact_test.cc
index 3b7241b..69341e3 100644
--- a/db/autocompact_test.cc
+++ b/db/autocompact_test.cc
@@ -108,8 +108,3 @@ TEST_F(AutoCompactTest, ReadAll) { DoReads(kCount); }
TEST_F(AutoCompactTest, ReadHalf) { DoReads(kCount / 2); }
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/db/corruption_test.cc b/db/corruption_test.cc
index a31f448..dc7da76 100644
--- a/db/corruption_test.cc
+++ b/db/corruption_test.cc
@@ -360,8 +360,3 @@ TEST_F(CorruptionTest, UnrelatedKeys) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/db/db_test.cc b/db/db_test.cc
index 908b41d..9bd6e14 100644
--- a/db/db_test.cc
+++ b/db/db_test.cc
@@ -9,7 +9,6 @@
#include <string>
#include "gtest/gtest.h"
-#include "benchmark/benchmark.h"
#include "db/db_impl.h"
#include "db/filename.h"
#include "db/version_set.h"
@@ -2295,72 +2294,4 @@ TEST_F(DBTest, Randomized) {
} while (ChangeOptions());
}
-std::string MakeKey(unsigned int num) {
- char buf[30];
- std::snprintf(buf, sizeof(buf), "%016u", num);
- return std::string(buf);
-}
-
-static void BM_LogAndApply(benchmark::State& state) {
- const int num_base_files = state.range(0);
-
- std::string dbname = testing::TempDir() + "leveldb_test_benchmark";
- DestroyDB(dbname, Options());
-
- DB* db = nullptr;
- Options opts;
- opts.create_if_missing = true;
- Status s = DB::Open(opts, dbname, &db);
- ASSERT_LEVELDB_OK(s);
- ASSERT_TRUE(db != nullptr);
-
- delete db;
- db = nullptr;
-
- Env* env = Env::Default();
-
- port::Mutex mu;
- MutexLock l(&mu);
-
- InternalKeyComparator cmp(BytewiseComparator());
- Options options;
- VersionSet vset(dbname, &options, nullptr, &cmp);
- bool save_manifest;
- ASSERT_LEVELDB_OK(vset.Recover(&save_manifest));
- VersionEdit vbase;
- uint64_t fnum = 1;
- for (int i = 0; i < num_base_files; i++) {
- InternalKey start(MakeKey(2 * fnum), 1, kTypeValue);
- InternalKey limit(MakeKey(2 * fnum + 1), 1, kTypeDeletion);
- vbase.AddFile(2, fnum++, 1 /* file size */, start, limit);
- }
- ASSERT_LEVELDB_OK(vset.LogAndApply(&vbase, &mu));
-
- uint64_t start_micros = env->NowMicros();
-
- for (auto st : state) {
- VersionEdit vedit;
- vedit.RemoveFile(2, fnum);
- InternalKey start(MakeKey(2 * fnum), 1, kTypeValue);
- InternalKey limit(MakeKey(2 * fnum + 1), 1, kTypeDeletion);
- vedit.AddFile(2, fnum++, 1 /* file size */, start, limit);
- vset.LogAndApply(&vedit, &mu);
- }
- uint64_t stop_micros = env->NowMicros();
- unsigned int us = stop_micros - start_micros;
- char buf[16];
- std::snprintf(buf, sizeof(buf), "%d", num_base_files);
- std::fprintf(stderr,
- "BM_LogAndApply/%-6s %8" PRIu64
- " iters : %9u us (%7.0f us / iter)\n",
- buf, state.iterations(), us, ((float)us) / state.iterations());
-}
-
-BENCHMARK(BM_LogAndApply)->Arg(1)->Arg(100)->Arg(10000)->Arg(100000);
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- benchmark::RunSpecifiedBenchmarks();
- return RUN_ALL_TESTS();
-}
diff --git a/db/dbformat_test.cc b/db/dbformat_test.cc
index 4a11c4a..7f3f81a 100644
--- a/db/dbformat_test.cc
+++ b/db/dbformat_test.cc
@@ -126,8 +126,3 @@ TEST(FormatTest, InternalKeyDebugString) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/db/fault_injection_test.cc b/db/fault_injection_test.cc
index 6eebafa..ef864a4 100644
--- a/db/fault_injection_test.cc
+++ b/db/fault_injection_test.cc
@@ -548,8 +548,3 @@ TEST_F(FaultInjectionTest, FaultTestWithLogReuse) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/db/filename_test.cc b/db/filename_test.cc
index f291d72..9ac0111 100644
--- a/db/filename_test.cc
+++ b/db/filename_test.cc
@@ -125,8 +125,3 @@ TEST(FileNameTest, Construction) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/db/log_test.cc b/db/log_test.cc
index 346b19c..d55d4dd 100644
--- a/db/log_test.cc
+++ b/db/log_test.cc
@@ -556,8 +556,3 @@ TEST_F(LogTest, ReadPastEnd) { CheckOffsetPastEndReturnsNoRecords(5); }
} // namespace log
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/db/recovery_test.cc b/db/recovery_test.cc
index 6c5d42e..1d9f621 100644
--- a/db/recovery_test.cc
+++ b/db/recovery_test.cc
@@ -332,8 +332,3 @@ TEST_F(RecoveryTest, ManifestMissing) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/db/skiplist.h b/db/skiplist.h
index a59b45b..f716834 100644
--- a/db/skiplist.h
+++ b/db/skiplist.h
@@ -243,7 +243,7 @@ int SkipList<Key, Comparator>::RandomHeight() {
// Increase height with probability 1 in kBranching
static const unsigned int kBranching = 4;
int height = 1;
- while (height < kMaxHeight && ((rnd_.Next() % kBranching) == 0)) {
+ while (height < kMaxHeight && rnd_.OneIn(kBranching)) {
height++;
}
assert(height > 0);
diff --git a/db/skiplist_test.cc b/db/skiplist_test.cc
index 79a5b86..1d355cb 100644
--- a/db/skiplist_test.cc
+++ b/db/skiplist_test.cc
@@ -366,8 +366,3 @@ TEST(SkipTest, Concurrent4) { RunConcurrent(4); }
TEST(SkipTest, Concurrent5) { RunConcurrent(5); }
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/db/snapshot.h b/db/snapshot.h
index 9f1d664..817bb7b 100644
--- a/db/snapshot.h
+++ b/db/snapshot.h
@@ -25,7 +25,7 @@ class SnapshotImpl : public Snapshot {
friend class SnapshotList;
// SnapshotImpl is kept in a doubly-linked circular list. The SnapshotList
- // implementation operates on the next/previous fields direcly.
+ // implementation operates on the next/previous fields directly.
SnapshotImpl* prev_;
SnapshotImpl* next_;
diff --git a/db/table_cache.h b/db/table_cache.h
index aac9bfc..db8a123 100644
--- a/db/table_cache.h
+++ b/db/table_cache.h
@@ -22,6 +22,10 @@ class Env;
class TableCache {
public:
TableCache(const std::string& dbname, const Options& options, int entries);
+
+ TableCache(const TableCache&) = delete;
+ TableCache& operator=(const TableCache&) = delete;
+
~TableCache();
// Return an iterator for the specified file number (the corresponding
diff --git a/db/version_edit_test.cc b/db/version_edit_test.cc
index acafab0..a108c15 100644
--- a/db/version_edit_test.cc
+++ b/db/version_edit_test.cc
@@ -39,8 +39,3 @@ TEST(VersionEditTest, EncodeDecode) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/db/version_set.cc b/db/version_set.cc
index f457e26..18c5f23 100644
--- a/db/version_set.cc
+++ b/db/version_set.cc
@@ -626,7 +626,7 @@ class VersionSet::Builder {
}
// Apply all of the edits in *edit to the current state.
- void Apply(VersionEdit* edit) {
+ void Apply(const VersionEdit* edit) {
// Update compaction pointers
for (size_t i = 0; i < edit->compact_pointers_.size(); i++) {
const int level = edit->compact_pointers_[i].first;
diff --git a/db/version_set_test.cc b/db/version_set_test.cc
index dee6b4c..64bb983 100644
--- a/db/version_set_test.cc
+++ b/db/version_set_test.cc
@@ -329,8 +329,3 @@ TEST_F(AddBoundaryInputsTest, TestDisjoinFilePointers) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/db/write_batch_test.cc b/db/write_batch_test.cc
index 64df9b8..1a3ea8f 100644
--- a/db/write_batch_test.cc
+++ b/db/write_batch_test.cc
@@ -130,8 +130,3 @@ TEST(WriteBatchTest, ApproximateSize) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/helpers/memenv/memenv_test.cc b/helpers/memenv/memenv_test.cc
index 3f03cb6..909a0ca 100644
--- a/helpers/memenv/memenv_test.cc
+++ b/helpers/memenv/memenv_test.cc
@@ -257,8 +257,3 @@ TEST_F(MemEnvTest, DBTest) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/include/leveldb/cache.h b/include/leveldb/cache.h
index 98c95ac..a94c683 100644
--- a/include/leveldb/cache.h
+++ b/include/leveldb/cache.h
@@ -96,14 +96,6 @@ class LEVELDB_EXPORT Cache {
// Return an estimate of the combined charges of all elements stored in the
// cache.
virtual size_t TotalCharge() const = 0;
-
- private:
- void LRU_Remove(Handle* e);
- void LRU_Append(Handle* e);
- void Unref(Handle* e);
-
- struct Rep;
- Rep* rep_;
};
} // namespace leveldb
diff --git a/issues/issue178_test.cc b/issues/issue178_test.cc
index 8fa5bb9..5cd5862 100644
--- a/issues/issue178_test.cc
+++ b/issues/issue178_test.cc
@@ -83,8 +83,3 @@ TEST(Issue178, Test) {
}
} // anonymous namespace
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/issues/issue200_test.cc b/issues/issue200_test.cc
index 4eba23a..959b371 100644
--- a/issues/issue200_test.cc
+++ b/issues/issue200_test.cc
@@ -52,8 +52,3 @@ TEST(Issue200, Test) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/issues/issue320_test.cc b/issues/issue320_test.cc
index c08296a..9d7fa7b 100644
--- a/issues/issue320_test.cc
+++ b/issues/issue320_test.cc
@@ -124,8 +124,3 @@ TEST(Issue320, Test) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/table/filter_block_test.cc b/table/filter_block_test.cc
index 91a6be2..3ee41cf 100644
--- a/table/filter_block_test.cc
+++ b/table/filter_block_test.cc
@@ -120,8 +120,3 @@ TEST_F(FilterBlockTest, MultiChunk) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/table/table_test.cc b/table/table_test.cc
index 190dd0f..7f0f998 100644
--- a/table/table_test.cc
+++ b/table/table_test.cc
@@ -827,8 +827,3 @@ TEST(TableTest, ApproximateOffsetOfCompressed) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/arena_test.cc b/util/arena_test.cc
index 90226fe..3e2011e 100644
--- a/util/arena_test.cc
+++ b/util/arena_test.cc
@@ -59,8 +59,3 @@ TEST(ArenaTest, Simple) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/bloom_test.cc b/util/bloom_test.cc
index 520473e..9f11108 100644
--- a/util/bloom_test.cc
+++ b/util/bloom_test.cc
@@ -152,8 +152,3 @@ TEST_F(BloomTest, VaryingLengths) {
// Different bits-per-byte
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/cache_test.cc b/util/cache_test.cc
index 79cfc27..e68da34 100644
--- a/util/cache_test.cc
+++ b/util/cache_test.cc
@@ -222,8 +222,3 @@ TEST_F(CacheTest, ZeroSizeCache) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/coding_test.cc b/util/coding_test.cc
index aa6c748..cceda14 100644
--- a/util/coding_test.cc
+++ b/util/coding_test.cc
@@ -191,8 +191,3 @@ TEST(Coding, Strings) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/crc32c_test.cc b/util/crc32c_test.cc
index 647e561..2fe1c41 100644
--- a/util/crc32c_test.cc
+++ b/util/crc32c_test.cc
@@ -54,8 +54,3 @@ TEST(CRC, Mask) {
} // namespace crc32c
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/env_posix.cc b/util/env_posix.cc
index 9ac03f8..936d43d 100644
--- a/util/env_posix.cc
+++ b/util/env_posix.cc
@@ -73,7 +73,14 @@ Status PosixError(const std::string& context, int error_number) {
class Limiter {
public:
// Limit maximum number of resources to |max_acquires|.
- Limiter(int max_acquires) : acquires_allowed_(max_acquires) {}
+ Limiter(int max_acquires)
+ :
+#if !defined(NDEBUG)
+ max_acquires_(max_acquires),
+#endif // !defined(NDEBUG)
+ acquires_allowed_(max_acquires) {
+ assert(max_acquires >= 0);
+ }
Limiter(const Limiter&) = delete;
Limiter operator=(const Limiter&) = delete;
@@ -86,15 +93,35 @@ class Limiter {
if (old_acquires_allowed > 0) return true;
- acquires_allowed_.fetch_add(1, std::memory_order_relaxed);
+ int pre_increment_acquires_allowed =
+ acquires_allowed_.fetch_add(1, std::memory_order_relaxed);
+
+ // Silence compiler warnings about unused arguments when NDEBUG is defined.
+ (void)pre_increment_acquires_allowed;
+ // If the check below fails, Release() was called more times than acquire.
+ assert(pre_increment_acquires_allowed < max_acquires_);
+
return false;
}
// Release a resource acquired by a previous call to Acquire() that returned
// true.
- void Release() { acquires_allowed_.fetch_add(1, std::memory_order_relaxed); }
+ void Release() {
+ int old_acquires_allowed =
+ acquires_allowed_.fetch_add(1, std::memory_order_relaxed);
+
+ // Silence compiler warnings about unused arguments when NDEBUG is defined.
+ (void)old_acquires_allowed;
+ // If the check below fails, Release() was called more times than acquire.
+ assert(old_acquires_allowed < max_acquires_);
+ }
private:
+#if !defined(NDEBUG)
+ // Catches an excessive number of Release() calls.
+ const int max_acquires_;
+#endif // !defined(NDEBUG)
+
// The number of available resources.
//
// This is a counter and is not tied to the invariants of any other class, so
@@ -215,7 +242,7 @@ class PosixMmapReadableFile final : public RandomAccessFile {
// over the ownership of the region.
//
// |mmap_limiter| must outlive this instance. The caller must have already
- // aquired the right to use one mmap region, which will be released when this
+ // acquired the right to use one mmap region, which will be released when this
// instance is destroyed.
PosixMmapReadableFile(std::string filename, char* mmap_base, size_t length,
Limiter* mmap_limiter)
@@ -729,7 +756,7 @@ class PosixEnv : public Env {
// Instances are constructed on the thread calling Schedule() and used on the
// background thread.
//
- // This structure is thread-safe beacuse it is immutable.
+ // This structure is thread-safe because it is immutable.
struct BackgroundWorkItem {
explicit BackgroundWorkItem(void (*function)(void* arg), void* arg)
: function(function), arg(arg) {}
@@ -843,7 +870,7 @@ class SingletonEnv {
public:
SingletonEnv() {
#if !defined(NDEBUG)
- env_initialized_.store(true, std::memory_order::memory_order_relaxed);
+ env_initialized_.store(true, std::memory_order_relaxed);
#endif // !defined(NDEBUG)
static_assert(sizeof(env_storage_) >= sizeof(EnvType),
"env_storage_ will not fit the Env");
@@ -860,7 +887,7 @@ class SingletonEnv {
static void AssertEnvNotInitialized() {
#if !defined(NDEBUG)
- assert(!env_initialized_.load(std::memory_order::memory_order_relaxed));
+ assert(!env_initialized_.load(std::memory_order_relaxed));
#endif // !defined(NDEBUG)
}
diff --git a/util/env_test.cc b/util/env_test.cc
index 491ef43..fc69d71 100644
--- a/util/env_test.cc
+++ b/util/env_test.cc
@@ -233,8 +233,3 @@ TEST_F(EnvTest, ReopenAppendableFile) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/env_windows.cc b/util/env_windows.cc
index 84905df..1c74b02 100644
--- a/util/env_windows.cc
+++ b/util/env_windows.cc
@@ -114,7 +114,14 @@ class ScopedHandle {
class Limiter {
public:
// Limit maximum number of resources to |max_acquires|.
- Limiter(int max_acquires) : acquires_allowed_(max_acquires) {}
+ Limiter(int max_acquires)
+ :
+#if !defined(NDEBUG)
+ max_acquires_(max_acquires),
+#endif // !defined(NDEBUG)
+ acquires_allowed_(max_acquires) {
+ assert(max_acquires >= 0);
+ }
Limiter(const Limiter&) = delete;
Limiter operator=(const Limiter&) = delete;
@@ -133,9 +140,22 @@ class Limiter {
// Release a resource acquired by a previous call to Acquire() that returned
// true.
- void Release() { acquires_allowed_.fetch_add(1, std::memory_order_relaxed); }
+ void Release() {
+ int old_acquires_allowed =
+ acquires_allowed_.fetch_add(1, std::memory_order_relaxed);
+
+ // Silence compiler warnings about unused arguments when NDEBUG is defined.
+ (void)old_acquires_allowed;
+ // If the check below fails, Release() was called more times than acquire.
+ assert(old_acquires_allowed < max_acquires_);
+ }
private:
+#if !defined(NDEBUG)
+ // Catches an excessive number of Release() calls.
+ const int max_acquires_;
+#endif // !defined(NDEBUG)
+
// The number of available resources.
//
// This is a counter and is not tied to the invariants of any other class, so
@@ -661,7 +681,7 @@ class WindowsEnv : public Env {
// Instances are constructed on the thread calling Schedule() and used on the
// background thread.
//
- // This structure is thread-safe beacuse it is immutable.
+ // This structure is thread-safe because it is immutable.
struct BackgroundWorkItem {
explicit BackgroundWorkItem(void (*function)(void* arg), void* arg)
: function(function), arg(arg) {}
@@ -745,7 +765,7 @@ class SingletonEnv {
public:
SingletonEnv() {
#if !defined(NDEBUG)
- env_initialized_.store(true, std::memory_order::memory_order_relaxed);
+ env_initialized_.store(true, std::memory_order_relaxed);
#endif // !defined(NDEBUG)
static_assert(sizeof(env_storage_) >= sizeof(EnvType),
"env_storage_ will not fit the Env");
@@ -762,7 +782,7 @@ class SingletonEnv {
static void AssertEnvNotInitialized() {
#if !defined(NDEBUG)
- assert(!env_initialized_.load(std::memory_order::memory_order_relaxed));
+ assert(!env_initialized_.load(std::memory_order_relaxed));
#endif // !defined(NDEBUG)
}
diff --git a/util/hash_test.cc b/util/hash_test.cc
index 6d6771f..0ea5977 100644
--- a/util/hash_test.cc
+++ b/util/hash_test.cc
@@ -39,8 +39,3 @@ TEST(HASH, SignedUnsignedIssue) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/logging_test.cc b/util/logging_test.cc
index 24e1fe9..1746c57 100644
--- a/util/logging_test.cc
+++ b/util/logging_test.cc
@@ -138,8 +138,3 @@ TEST(Logging, ConsumeDecimalNumberNoDigits) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/no_destructor_test.cc b/util/no_destructor_test.cc
index 68fdfee..e3602cc 100644
--- a/util/no_destructor_test.cc
+++ b/util/no_destructor_test.cc
@@ -42,8 +42,3 @@ TEST(NoDestructorTest, StaticInstance) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/util/status_test.cc b/util/status_test.cc
index 914b386..dbf5faa 100644
--- a/util/status_test.cc
+++ b/util/status_test.cc
@@ -37,8 +37,3 @@ TEST(Status, MoveConstructor) {
}
} // namespace leveldb
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}