From ea49b27d062c4bc998616cef7944f7f9088a327d Mon Sep 17 00:00:00 2001 From: cmumford Date: Tue, 19 Mar 2019 17:30:42 -0700 Subject: 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 --- util/env_windows.cc | 20 -------------------- util/env_windows_test_helper.h | 5 ----- util/testutil.h | 6 +++++- 3 files changed, 5 insertions(+), 26 deletions(-) (limited to 'util') 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) { -- cgit v1.2.1