Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(390)

Side by Side Diff: net/disk_cache/entry_unittest.cc

Issue 132031: Disk cache: First pass to add support for sparse entries.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/entry_impl.cc ('k') | net/disk_cache/sparse_control.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/platform_thread.h" 6 #include "base/platform_thread.h"
7 #include "base/timer.h" 7 #include "base/timer.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "net/base/io_buffer.h" 9 #include "net/base/io_buffer.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 17 matching lines...) Expand all
28 void ExternalAsyncIO(); 28 void ExternalAsyncIO();
29 void StreamAccess(); 29 void StreamAccess();
30 void GetKey(); 30 void GetKey();
31 void GrowData(); 31 void GrowData();
32 void TruncateData(); 32 void TruncateData();
33 void ZeroLengthIO(); 33 void ZeroLengthIO();
34 void ReuseEntry(int size); 34 void ReuseEntry(int size);
35 void InvalidData(); 35 void InvalidData();
36 void DoomEntry(); 36 void DoomEntry();
37 void DoomedEntry(); 37 void DoomedEntry();
38 void BasicSparseIO(bool async);
39 void HugeSparseIO(bool async);
38 }; 40 };
39 41
40 void DiskCacheEntryTest::InternalSyncIO() { 42 void DiskCacheEntryTest::InternalSyncIO() {
41 disk_cache::Entry *entry1 = NULL; 43 disk_cache::Entry *entry1 = NULL;
42 ASSERT_TRUE(cache_->CreateEntry("the first key", &entry1)); 44 ASSERT_TRUE(cache_->CreateEntry("the first key", &entry1));
43 ASSERT_TRUE(NULL != entry1); 45 ASSERT_TRUE(NULL != entry1);
44 46
45 const int kSize1 = 10; 47 const int kSize1 = 10;
46 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize1); 48 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize1);
47 CacheTestFillBuffer(buffer1->data(), kSize1, false); 49 CacheTestFillBuffer(buffer1->data(), kSize1, false);
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 EXPECT_TRUE(mem_entry == parent_entry); 858 EXPECT_TRUE(mem_entry == parent_entry);
857 mem_entry->Close(); 859 mem_entry->Close();
858 ++count; 860 ++count;
859 } 861 }
860 EXPECT_EQ(1, count); 862 EXPECT_EQ(1, count);
861 863
862 // TODO(hclam): remove this when parent entry can doom child entries 864 // TODO(hclam): remove this when parent entry can doom child entries
863 // internally. Now we have to doom this child entry manually. 865 // internally. Now we have to doom this child entry manually.
864 child_entry->Doom(); 866 child_entry->Doom();
865 } 867 }
868
869 // Writes |buf_1| to offset and reads it back as |buf_2|.
870 void VerifySparseIO(disk_cache::Entry* entry, int64 offset,
871 net::IOBuffer* buf_1, int size, bool async,
872 net::IOBuffer* buf_2) {
873 SimpleCallbackTest callback;
874 SimpleCallbackTest* cb = async ? &callback : NULL;
875
876 memset(buf_2->data(), 0, size);
877 int ret = entry->ReadSparseData(offset, buf_2, size, cb);
878 ret = callback.GetResult(ret);
879 EXPECT_EQ(0, ret);
880
881 ret = entry->WriteSparseData(offset, buf_1, size, cb);
882 ret = callback.GetResult(ret);
883 EXPECT_EQ(size, ret);
884
885 ret = entry->ReadSparseData(offset, buf_2, size, cb);
886 ret = callback.GetResult(ret);
887 EXPECT_EQ(size, ret);
888
889 EXPECT_EQ(0, memcmp(buf_1->data(), buf_2->data(), size));
890 }
891
892 // Reads |size| bytes from |entry| at |offset| and verifies that they are the
893 // same as the content of the provided |buffer|.
894 void VerifyContentSparseIO(disk_cache::Entry* entry, int64 offset, char* buffer,
895 int size, bool async) {
896 SimpleCallbackTest callback;
897 SimpleCallbackTest* cb = async ? &callback : NULL;
898
899 scoped_refptr<net::IOBuffer> buf_1 = new net::IOBuffer(size);
900 memset(buf_1->data(), 0, size);
901 int ret = entry->ReadSparseData(offset, buf_1, size, cb);
902 ret = callback.GetResult(ret);
903 EXPECT_EQ(size, ret);
904
905 EXPECT_EQ(0, memcmp(buf_1->data(), buffer, size));
906 }
907
908 void DiskCacheEntryTest::BasicSparseIO(bool async) {
909 std::string key("the first key");
910 disk_cache::Entry* entry;
911 ASSERT_TRUE(cache_->CreateEntry(key, &entry));
912
913 const int kSize = 2048;
914 scoped_refptr<net::IOBuffer> buf_1 = new net::IOBuffer(kSize);
915 scoped_refptr<net::IOBuffer> buf_2 = new net::IOBuffer(kSize);
916 CacheTestFillBuffer(buf_1->data(), kSize, false);
917
918 // Write at offset 0.
919 VerifySparseIO(entry, 0, buf_1, kSize, async, buf_2);
920
921 // Write at offset 0x400000 (4 MB).
922 VerifySparseIO(entry, 0x400000, buf_1, kSize, async, buf_2);
923
924 // Write at offset 0x800000000 (32 GB).
925 VerifySparseIO(entry, 0x800000000LL, buf_1, kSize, async, buf_2);
926
927 entry->Close();
928
929 // Check everything again.
930 ASSERT_TRUE(cache_->OpenEntry(key, &entry));
931 VerifyContentSparseIO(entry, 0, buf_1->data(), kSize, async);
932 VerifyContentSparseIO(entry, 0x400000, buf_1->data(), kSize, async);
933 VerifyContentSparseIO(entry, 0x800000000LL, buf_1->data(), kSize, async);
934 entry->Close();
935 }
936
937 TEST_F(DiskCacheEntryTest, BasicSparseSyncIO) {
938 InitCache();
939 BasicSparseIO(false);
940 }
941
942 TEST_F(DiskCacheEntryTest, DISABLED_MemoryOnlyBasicSparseSyncIO) {
943 SetMemoryOnlyMode();
944 InitCache();
945 BasicSparseIO(false);
946 }
947
948 TEST_F(DiskCacheEntryTest, BasicSparseAsyncIO) {
949 InitCache();
950 BasicSparseIO(true);
951 }
952
953 TEST_F(DiskCacheEntryTest, DISABLED_MemoryOnlyBasicSparseAsyncIO) {
954 SetMemoryOnlyMode();
955 InitCache();
956 BasicSparseIO(true);
957 }
958
959 void DiskCacheEntryTest::HugeSparseIO(bool async) {
960 std::string key("the first key");
961 disk_cache::Entry* entry;
962 ASSERT_TRUE(cache_->CreateEntry(key, &entry));
963
964 // Write 1.2 MB so that we cover multiple entries.
965 const int kSize = 1200 * 1024;
966 scoped_refptr<net::IOBuffer> buf_1 = new net::IOBuffer(kSize);
967 scoped_refptr<net::IOBuffer> buf_2 = new net::IOBuffer(kSize);
968 CacheTestFillBuffer(buf_1->data(), kSize, false);
969
970 // Write at offset 0x20F0000 (20 MB - 64 KB).
971 VerifySparseIO(entry, 0x20F0000, buf_1, kSize, async, buf_2);
972 entry->Close();
973
974 // Check it again.
975 ASSERT_TRUE(cache_->OpenEntry(key, &entry));
976 VerifyContentSparseIO(entry, 0x20F0000, buf_1->data(), kSize, async);
977 entry->Close();
978 }
979
980 TEST_F(DiskCacheEntryTest, HugeSparseSyncIO) {
981 InitCache();
982 HugeSparseIO(false);
983 }
984
985 TEST_F(DiskCacheEntryTest, DISABLED_MemoryOnlyHugeSparseSyncIO) {
986 SetMemoryOnlyMode();
987 InitCache();
988 HugeSparseIO(false);
989 }
990
991 TEST_F(DiskCacheEntryTest, HugeSparseAsyncIO) {
992 InitCache();
993 HugeSparseIO(true);
994 }
995
996 TEST_F(DiskCacheEntryTest, DISABLED_MemoryOnlyHugeSparseAsyncIO) {
997 SetMemoryOnlyMode();
998 InitCache();
999 HugeSparseIO(true);
1000 }
OLDNEW
« no previous file with comments | « net/disk_cache/entry_impl.cc ('k') | net/disk_cache/sparse_control.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698