summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorcmumford <cmumford@google.com>2019-03-19 17:30:42 -0700
committerVictor Costan <pwnall@chromium.org>2019-03-20 13:57:03 -0700
commitea49b27d062c4bc998616cef7944f7f9088a327d (patch)
tree3616eb24ed7f65461ccc7c5675bad4028836c650 /util
parentce399ac28af7023b1aff0ede4986cb6d89b3c0b5 (diff)
downloadleveldb-ea49b27d062c4bc998616cef7944f7f9088a327d.tar.gz
Switch corruption_test to use InMemEnv.
This change switches corruption_test, which previously used direct file I/O to corrupt table files for open databases, to use InMemEnv. Using an Env eliminates some platform dependencies thus simplifying the tests. Also removed EnvWindowsTestHelper::RelaxFilePermissions(). This was only added because the Windows Env opens files for exclusive access. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=239305329
Diffstat (limited to 'util')
-rw-r--r--util/env_windows.cc20
-rw-r--r--util/env_windows_test_helper.h5
-rw-r--r--util/testutil.h6
3 files changed, 5 insertions, 26 deletions
diff --git a/util/env_windows.cc b/util/env_windows.cc
index 3b4496b..93555a8 100644
--- a/util/env_windows.cc
+++ b/util/env_windows.cc
@@ -43,9 +43,6 @@ constexpr int kDefaultMmapLimit = sizeof(void*) >= 8 ? 1000 : 0;
// Modified by EnvWindowsTestHelper::SetReadOnlyMMapLimit().
int g_mmap_limit = kDefaultMmapLimit;
-// Relax some file access permissions for testing.
-bool g_relax_permissions = false;
-
std::string GetWindowsErrorMessage(DWORD error_code) {
std::string message;
char* error_text = nullptr;
@@ -366,10 +363,6 @@ class WindowsEnv : public Env {
*result = nullptr;
DWORD desired_access = GENERIC_READ;
DWORD share_mode = FILE_SHARE_READ;
- if (g_relax_permissions) {
- desired_access |= GENERIC_WRITE;
- share_mode |= FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
- }
ScopedHandle handle =
::CreateFileA(fname.c_str(), desired_access, share_mode, nullptr,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
@@ -385,10 +378,6 @@ class WindowsEnv : public Env {
*result = nullptr;
DWORD desired_access = GENERIC_READ;
DWORD share_mode = FILE_SHARE_READ;
- if (g_relax_permissions) {
- // desired_access |= GENERIC_WRITE;
- share_mode |= FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
- }
DWORD file_flags = FILE_ATTRIBUTE_READONLY;
ScopedHandle handle =
@@ -433,10 +422,6 @@ class WindowsEnv : public Env {
WritableFile** result) override {
DWORD desired_access = GENERIC_WRITE;
DWORD share_mode = 0;
- if (g_relax_permissions) {
- desired_access |= GENERIC_READ;
- share_mode |= FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
- }
ScopedHandle handle =
::CreateFileA(fname.c_str(), desired_access, share_mode, nullptr,
@@ -721,11 +706,6 @@ void EnvWindowsTestHelper::SetReadOnlyMMapLimit(int limit) {
g_mmap_limit = limit;
}
-void EnvWindowsTestHelper::RelaxFilePermissions() {
- assert(default_env == nullptr);
- g_relax_permissions = true;
-}
-
Env* Env::Default() {
std::call_once(once, InitDefaultEnv);
return default_env;
diff --git a/util/env_windows_test_helper.h b/util/env_windows_test_helper.h
index 5ffbe44..e6f6020 100644
--- a/util/env_windows_test_helper.h
+++ b/util/env_windows_test_helper.h
@@ -18,11 +18,6 @@ class EnvWindowsTestHelper {
// Set the maximum number of read-only files that will be mapped via mmap.
// Must be called before creating an Env.
static void SetReadOnlyMMapLimit(int limit);
-
- // Relax file permissions for tests. This results in most files being opened
- // with read-write permissions. This is helpful for corruption tests that
- // need to corrupt the database files for open databases.
- static void RelaxFilePermissions();
};
} // namespace leveldb
diff --git a/util/testutil.h b/util/testutil.h
index dc77ac3..3934242 100644
--- a/util/testutil.h
+++ b/util/testutil.h
@@ -5,6 +5,7 @@
#ifndef STORAGE_LEVELDB_UTIL_TESTUTIL_H_
#define STORAGE_LEVELDB_UTIL_TESTUTIL_H_
+#include "helpers/memenv/memenv.h"
#include "leveldb/env.h"
#include "leveldb/slice.h"
#include "util/random.h"
@@ -32,9 +33,12 @@ class ErrorEnv : public EnvWrapper {
bool writable_file_error_;
int num_writable_file_errors_;
- ErrorEnv() : EnvWrapper(Env::Default()),
+ ErrorEnv() : EnvWrapper(NewMemEnv(Env::Default())),
writable_file_error_(false),
num_writable_file_errors_(0) { }
+ ~ErrorEnv() override {
+ delete target();
+ }
virtual Status NewWritableFile(const std::string& fname,
WritableFile** result) {