mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-29 20:47:31 -03:00
cf44e4ca77
196962ff0 Add AcceleratedCRC32C to port_win.h 1bdf1c34c Merge upstream LevelDB v1.20 d31721eb0 Merge #17: Fixed file sharing errors fecd44902 Fixed file sharing error in Win32Env::GetFileSize(), Win32SequentialFile::_Init(), Win32RandomAccessFile::_Init() Fixed error checking in Win32SequentialFile::_Init() 5b7510f1b Merge #14: Merge upstream LevelDB 1.19 0d969fd57 Merge #16: [LevelDB] Do no crash if filesystem can't fsync c8c029b5b [LevelDB] Do no crash if filesystem can't fsync a53934a3a Increase leveldb version to 1.20. f3f139737 Separate Env tests from PosixEnv tests. eb4f0972f leveldb: Fix compilation warnings in port_posix_sse.cc on x86 (32-bit). d0883b600 Fixed path to doc file: index.md. 7fa20948d Convert documentation to markdown. ea175e28f Implement support for Intel crc32 instruction (SSE 4.2) 95cd743e5 Including <limits> for std::numeric_limits. 646c3588d Limit the number of read-only files the POSIX Env will have open. d40bc3fa5 Merge #13: Typo ebbd772d3 Typo a2fb086d0 Add option for max file size. The currend hard-coded value of 2M is inefficient in colossus. git-subtree-dir: src/leveldb git-subtree-split: 196962ff01c39b4705d8117df5c3f8c205349950
66 lines
2.1 KiB
C++
66 lines
2.1 KiB
C++
// Copyright (c) 2011 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 "leveldb/env.h"
|
|
|
|
#include "port/port.h"
|
|
#include "util/testharness.h"
|
|
#include "util/env_posix_test_helper.h"
|
|
|
|
namespace leveldb {
|
|
|
|
static const int kDelayMicros = 100000;
|
|
static const int kReadOnlyFileLimit = 4;
|
|
static const int kMMapLimit = 4;
|
|
|
|
class EnvPosixTest {
|
|
public:
|
|
Env* env_;
|
|
EnvPosixTest() : env_(Env::Default()) { }
|
|
|
|
static void SetFileLimits(int read_only_file_limit, int mmap_limit) {
|
|
EnvPosixTestHelper::SetReadOnlyFDLimit(read_only_file_limit);
|
|
EnvPosixTestHelper::SetReadOnlyMMapLimit(mmap_limit);
|
|
}
|
|
};
|
|
|
|
TEST(EnvPosixTest, TestOpenOnRead) {
|
|
// Write some test data to a single file that will be opened |n| times.
|
|
std::string test_dir;
|
|
ASSERT_OK(env_->GetTestDirectory(&test_dir));
|
|
std::string test_file = test_dir + "/open_on_read.txt";
|
|
|
|
FILE* f = fopen(test_file.c_str(), "w");
|
|
ASSERT_TRUE(f != NULL);
|
|
const char kFileData[] = "abcdefghijklmnopqrstuvwxyz";
|
|
fputs(kFileData, f);
|
|
fclose(f);
|
|
|
|
// Open test file some number above the sum of the two limits to force
|
|
// open-on-read behavior of POSIX Env leveldb::RandomAccessFile.
|
|
const int kNumFiles = kReadOnlyFileLimit + kMMapLimit + 5;
|
|
leveldb::RandomAccessFile* files[kNumFiles] = {0};
|
|
for (int i = 0; i < kNumFiles; i++) {
|
|
ASSERT_OK(env_->NewRandomAccessFile(test_file, &files[i]));
|
|
}
|
|
char scratch;
|
|
Slice read_result;
|
|
for (int i = 0; i < kNumFiles; i++) {
|
|
ASSERT_OK(files[i]->Read(i, 1, &read_result, &scratch));
|
|
ASSERT_EQ(kFileData[i], read_result[0]);
|
|
}
|
|
for (int i = 0; i < kNumFiles; i++) {
|
|
delete files[i];
|
|
}
|
|
ASSERT_OK(env_->DeleteFile(test_file));
|
|
}
|
|
|
|
} // namespace leveldb
|
|
|
|
int main(int argc, char** argv) {
|
|
// All tests currently run with the same read-only file limits.
|
|
leveldb::EnvPosixTest::SetFileLimits(leveldb::kReadOnlyFileLimit,
|
|
leveldb::kMMapLimit);
|
|
return leveldb::test::RunAllTests();
|
|
}
|