diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-05 22:01:20 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-05 22:01:20 +0000 |
commit | f5fd52e839ef091f27a3091fce46bbbfb38aa819 (patch) | |
tree | 4ad599b510485481ac8b20278e5f57cf4d8f71b9 /net/disk_cache/block_files_unittest.cc | |
parent | a5f99d12e5af6d1b4a60a9bf22b3bf3a1fa1ca24 (diff) | |
download | chromium_src-f5fd52e839ef091f27a3091fce46bbbfb38aa819.zip chromium_src-f5fd52e839ef091f27a3091fce46bbbfb38aa819.tar.gz chromium_src-f5fd52e839ef091f27a3091fce46bbbfb38aa819.tar.bz2 |
Disk Cache: Update the internal logic of a block file to make
sure that the number of entries on the file is not out of
sync.
* Check the counters on every session
* Make sure that num_entries is always >= number of used bits
(create/delete order)
* Make sure that the updating flag works for gcc & co.
* Fail initialization if we cannot fix the file.
BUG=108375
TEST=net_unittests
Review URL: http://codereview.chromium.org/9016033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116565 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/block_files_unittest.cc')
-rw-r--r-- | net/disk_cache/block_files_unittest.cc | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/net/disk_cache/block_files_unittest.cc b/net/disk_cache/block_files_unittest.cc index cabedf4..ebdae82 100644 --- a/net/disk_cache/block_files_unittest.cc +++ b/net/disk_cache/block_files_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -196,6 +196,61 @@ TEST_F(DiskCacheTest, BlockFiles_TruncatedFile) { ASSERT_FALSE(files.Init(false)); } +// Tests detection of out of sync counters. +TEST_F(DiskCacheTest, BlockFiles_Counters) { + ASSERT_TRUE(CleanupCacheDir()); + ASSERT_TRUE(file_util::CreateDirectory(cache_path_)); + + BlockFiles files(cache_path_); + ASSERT_TRUE(files.Init(true)); + + // Create a block of size 2. + Addr address(0); + EXPECT_TRUE(files.CreateBlock(RANKINGS, 2, &address)); + + MappedFile* file = files.GetFile(address); + ASSERT_TRUE(NULL != file); + + BlockFileHeader* header = reinterpret_cast<BlockFileHeader*>(file->buffer()); + ASSERT_TRUE(NULL != header); + ASSERT_EQ(0, header->updating); + + // Alter the counters so that the free space doesn't add up. + header->empty[2] = 50; // 50 free blocks of size 3. + files.CloseFiles(); + + ASSERT_TRUE(files.Init(false)); + file = files.GetFile(address); + ASSERT_TRUE(NULL != file); + header = reinterpret_cast<BlockFileHeader*>(file->buffer()); + ASSERT_TRUE(NULL != header); + + // The file must have been fixed. + ASSERT_EQ(0, header->empty[2]); + + // Change the number of entries. + header->num_entries = 3; + header->updating = 1; + files.CloseFiles(); + + ASSERT_TRUE(files.Init(false)); + file = files.GetFile(address); + ASSERT_TRUE(NULL != file); + header = reinterpret_cast<BlockFileHeader*>(file->buffer()); + ASSERT_TRUE(NULL != header); + + // The file must have been "fixed". + ASSERT_EQ(2, header->num_entries); + + // Change the number of entries. + header->num_entries = -1; + header->updating = 1; + files.CloseFiles(); + + // Detect the error. + ASSERT_FALSE(files.Init(false)); +} + // An invalid file can be detected after init. TEST_F(DiskCacheTest, BlockFiles_InvalidFile) { ASSERT_TRUE(CleanupCacheDir()); @@ -217,7 +272,7 @@ TEST_F(DiskCacheTest, BlockFiles_InvalidFile) { EXPECT_TRUE(NULL == files.GetFile(addr)); - // The file should not have been cached (it is still invalid). + // The file should not have been changed (it is still invalid). EXPECT_TRUE(NULL == files.GetFile(addr)); } |