diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-22 11:47:29 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-22 11:47:29 +0000 |
commit | 3cc5922dbc5f1668bc1cd4f691286c5a7218c167 (patch) | |
tree | 4acd9b73dc5f6ab0c0a6aa2da482d2fd6948816f | |
parent | c86d350e584b00bd5df71e82b5774ef245a14bef (diff) | |
download | chromium_src-3cc5922dbc5f1668bc1cd4f691286c5a7218c167.zip chromium_src-3cc5922dbc5f1668bc1cd4f691286c5a7218c167.tar.gz chromium_src-3cc5922dbc5f1668bc1cd4f691286c5a7218c167.tar.bz2 |
Revert 60165 - GTTF: Make net_unittests run successfully with parallel test launcher
by using a unique directory for disk cache tests.
BUG=54098
TEST=run net_unittests using tools/parallel_launcher/parallel_launcher.py
Review URL: http://codereview.chromium.org/3410008
TBR=phajdan.jr@chromium.org
Review URL: http://codereview.chromium.org/3387012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60166 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | net/disk_cache/backend_unittest.cc | 103 | ||||
-rw-r--r-- | net/disk_cache/block_files_unittest.cc | 49 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_test_base.cc | 17 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_test_base.h | 7 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_test_util.cc | 37 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_test_util.h | 14 | ||||
-rw-r--r-- | net/disk_cache/mapped_file_unittest.cc | 8 | ||||
-rw-r--r-- | net/disk_cache/storage_block_unittest.cc | 12 | ||||
-rw-r--r-- | net/disk_cache/stress_cache.cc | 13 |
9 files changed, 139 insertions, 121 deletions
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc index 7794e51..3f0018c 100644 --- a/net/disk_cache/backend_unittest.cc +++ b/net/disk_cache/backend_unittest.cc @@ -180,10 +180,11 @@ TEST_F(DiskCacheBackendTest, AppCacheKeying) { } TEST_F(DiskCacheTest, CreateBackend) { - ScopedTestCache test_cache; TestCompletionCallback cb; { + FilePath path = GetCacheFilePath(); + ASSERT_TRUE(DeleteCache(path)); base::Thread cache_thread("CacheThread"); ASSERT_TRUE(cache_thread.StartWithOptions( base::Thread::Options(MessageLoop::TYPE_IO, 0))); @@ -191,8 +192,8 @@ TEST_F(DiskCacheTest, CreateBackend) { // Test the private factory methods. disk_cache::Backend* cache = NULL; int rv = disk_cache::BackendImpl::CreateBackend( - test_cache.path(), false, 0, net::DISK_CACHE, disk_cache::kNoRandom, - cache_thread.message_loop_proxy(), &cache, &cb); + path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, + cache_thread.message_loop_proxy(), &cache, &cb); ASSERT_EQ(net::OK, cb.GetResult(rv)); ASSERT_TRUE(cache); delete cache; @@ -203,8 +204,7 @@ TEST_F(DiskCacheTest, CreateBackend) { cache = NULL; // Now test the public API. - rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, test_cache.path(), - 0, false, + rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, path, 0, false, cache_thread.message_loop_proxy(), &cache, &cb); ASSERT_EQ(net::OK, cb.GetResult(rv)); @@ -225,7 +225,7 @@ TEST_F(DiskCacheTest, CreateBackend) { TEST_F(DiskCacheBackendTest, ExternalFiles) { InitCache(); // First, lets create a file on the folder. - FilePath filename = path().AppendASCII("f_000001"); + FilePath filename = GetCacheFilePath().AppendASCII("f_000001"); const int kSize = 50; scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize); @@ -246,18 +246,19 @@ TEST_F(DiskCacheBackendTest, ExternalFiles) { // Tests that we deal with file-level pending operations at destruction time. TEST_F(DiskCacheTest, ShutdownWithPendingIO) { - ScopedTestCache test_cache; TestCompletionCallback cb; { + FilePath path = GetCacheFilePath(); + ASSERT_TRUE(DeleteCache(path)); base::Thread cache_thread("CacheThread"); ASSERT_TRUE(cache_thread.StartWithOptions( base::Thread::Options(MessageLoop::TYPE_IO, 0))); disk_cache::Backend* cache; int rv = disk_cache::BackendImpl::CreateBackend( - test_cache.path(), false, 0, net::DISK_CACHE, disk_cache::kNoRandom, - base::MessageLoopProxy::CreateForCurrentThread(), &cache, &cb); + path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, + base::MessageLoopProxy::CreateForCurrentThread(), &cache, &cb); ASSERT_EQ(net::OK, cb.GetResult(rv)); disk_cache::EntryImpl* entry; @@ -296,18 +297,19 @@ TEST_F(DiskCacheTest, ShutdownWithPendingIO) { // Tests that we deal with background-thread pending operations. TEST_F(DiskCacheTest, ShutdownWithPendingIO2) { - ScopedTestCache test_cache; TestCompletionCallback cb; { + FilePath path = GetCacheFilePath(); + ASSERT_TRUE(DeleteCache(path)); base::Thread cache_thread("CacheThread"); ASSERT_TRUE(cache_thread.StartWithOptions( base::Thread::Options(MessageLoop::TYPE_IO, 0))); disk_cache::Backend* cache; int rv = disk_cache::BackendImpl::CreateBackend( - test_cache.path(), false, 0, net::DISK_CACHE, disk_cache::kNoRandom, - cache_thread.message_loop_proxy(), &cache, &cb); + path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, + cache_thread.message_loop_proxy(), &cache, &cb); ASSERT_EQ(net::OK, cb.GetResult(rv)); disk_cache::Entry* entry; @@ -331,9 +333,9 @@ TEST_F(DiskCacheTest, ShutdownWithPendingIO2) { } TEST_F(DiskCacheTest, TruncatedIndex) { - ScopedTestCache test_cache; - - FilePath index = test_cache.path().AppendASCII("index"); + FilePath path = GetCacheFilePath(); + ASSERT_TRUE(DeleteCache(path)); + FilePath index = path.AppendASCII("index"); ASSERT_EQ(5, file_util::WriteFile(index, "hello", 5)); base::Thread cache_thread("CacheThread"); @@ -343,8 +345,8 @@ TEST_F(DiskCacheTest, TruncatedIndex) { disk_cache::Backend* backend = NULL; int rv = disk_cache::BackendImpl::CreateBackend( - test_cache.path(), false, 0, net::DISK_CACHE, disk_cache::kNone, - cache_thread.message_loop_proxy(), &backend, &cb); + path, false, 0, net::DISK_CACHE, disk_cache::kNone, + cache_thread.message_loop_proxy(), &backend, &cb); ASSERT_NE(net::OK, cb.GetResult(rv)); ASSERT_TRUE(backend == NULL); @@ -1143,7 +1145,7 @@ TEST_F(DiskCacheBackendTest, MemoryOnlyDoomBetween) { void DiskCacheBackendTest::BackendTransaction(const std::string& name, int num_entries, bool load) { success_ = false; - ASSERT_TRUE(CopyTestCache(name, path())); + ASSERT_TRUE(CopyTestCache(name)); DisableFirstCleanup(); if (load) { @@ -1174,7 +1176,7 @@ void DiskCacheBackendTest::BackendTransaction(const std::string& name, cache_ = NULL; cache_impl_ = NULL; - ASSERT_TRUE(CheckCacheIntegrity(path(), new_eviction_)); + ASSERT_TRUE(CheckCacheIntegrity(GetCacheFilePath(), new_eviction_)); success_ = true; } @@ -1264,9 +1266,8 @@ TEST_F(DiskCacheBackendTest, NewEvictionRecoverRemove) { // Tests dealing with cache files that cannot be recovered. TEST_F(DiskCacheTest, DeleteOld) { - ScopedTestCache test_cache; - - ASSERT_TRUE(CopyTestCache("wrong_version", test_cache.path())); + ASSERT_TRUE(CopyTestCache("wrong_version")); + FilePath path = GetCacheFilePath(); base::Thread cache_thread("CacheThread"); ASSERT_TRUE(cache_thread.StartWithOptions( base::Thread::Options(MessageLoop::TYPE_IO, 0))); @@ -1274,8 +1275,8 @@ TEST_F(DiskCacheTest, DeleteOld) { disk_cache::Backend* cache; int rv = disk_cache::BackendImpl::CreateBackend( - test_cache.path(), true, 0, net::DISK_CACHE, disk_cache::kNoRandom, - cache_thread.message_loop_proxy(), &cache, &cb); + path, true, 0, net::DISK_CACHE, disk_cache::kNoRandom, + cache_thread.message_loop_proxy(), &cache, &cb); ASSERT_EQ(net::OK, cb.GetResult(rv)); MessageLoopHelper helper; @@ -1288,7 +1289,7 @@ TEST_F(DiskCacheTest, DeleteOld) { // We want to be able to deal with messed up entries on disk. void DiskCacheBackendTest::BackendInvalidEntry2() { - ASSERT_TRUE(CopyTestCache("bad_entry", path())); + ASSERT_TRUE(CopyTestCache("bad_entry")); DisableFirstCleanup(); InitCache(); @@ -1312,7 +1313,7 @@ TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry2) { // We want to be able to deal with abnormal dirty entries. void DiskCacheBackendTest::BackendNotMarkedButDirty(const std::string& name) { - ASSERT_TRUE(CopyTestCache(name, path())); + ASSERT_TRUE(CopyTestCache(name)); DisableFirstCleanup(); InitCache(); @@ -1342,7 +1343,8 @@ TEST_F(DiskCacheBackendTest, NewEvictionNotMarkedButDirty2) { // We want to be able to deal with messed up entries on disk. void DiskCacheBackendTest::BackendInvalidRankings2() { - ASSERT_TRUE(CopyTestCache("bad_rankings", path())); + ASSERT_TRUE(CopyTestCache("bad_rankings")); + FilePath path = GetCacheFilePath(); DisableFirstCleanup(); InitCache(); @@ -1378,7 +1380,7 @@ void DiskCacheBackendTest::BackendInvalidRankings() { } TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) { - ASSERT_TRUE(CopyTestCache("bad_rankings", path())); + ASSERT_TRUE(CopyTestCache("bad_rankings")); DisableFirstCleanup(); SetDirectMode(); InitCache(); @@ -1386,7 +1388,7 @@ TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) { } TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankingsSuccess) { - ASSERT_TRUE(CopyTestCache("bad_rankings", path())); + ASSERT_TRUE(CopyTestCache("bad_rankings")); DisableFirstCleanup(); SetDirectMode(); SetNewEviction(); @@ -1395,7 +1397,7 @@ TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankingsSuccess) { } TEST_F(DiskCacheBackendTest, InvalidRankingsFailure) { - ASSERT_TRUE(CopyTestCache("bad_rankings", path())); + ASSERT_TRUE(CopyTestCache("bad_rankings")); DisableFirstCleanup(); SetDirectMode(); InitCache(); @@ -1404,7 +1406,7 @@ TEST_F(DiskCacheBackendTest, InvalidRankingsFailure) { } TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankingsFailure) { - ASSERT_TRUE(CopyTestCache("bad_rankings", path())); + ASSERT_TRUE(CopyTestCache("bad_rankings")); DisableFirstCleanup(); SetDirectMode(); SetNewEviction(); @@ -1431,7 +1433,7 @@ void DiskCacheBackendTest::BackendDisable() { } TEST_F(DiskCacheBackendTest, DisableSuccess) { - ASSERT_TRUE(CopyTestCache("bad_rankings", path())); + ASSERT_TRUE(CopyTestCache("bad_rankings")); DisableFirstCleanup(); SetDirectMode(); InitCache(); @@ -1439,7 +1441,7 @@ TEST_F(DiskCacheBackendTest, DisableSuccess) { } TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess) { - ASSERT_TRUE(CopyTestCache("bad_rankings", path())); + ASSERT_TRUE(CopyTestCache("bad_rankings")); DisableFirstCleanup(); SetDirectMode(); SetNewEviction(); @@ -1448,7 +1450,7 @@ TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess) { } TEST_F(DiskCacheBackendTest, DisableFailure) { - ASSERT_TRUE(CopyTestCache("bad_rankings", path())); + ASSERT_TRUE(CopyTestCache("bad_rankings")); DisableFirstCleanup(); SetDirectMode(); InitCache(); @@ -1457,7 +1459,7 @@ TEST_F(DiskCacheBackendTest, DisableFailure) { } TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure) { - ASSERT_TRUE(CopyTestCache("bad_rankings", path())); + ASSERT_TRUE(CopyTestCache("bad_rankings")); DisableFirstCleanup(); SetDirectMode(); SetNewEviction(); @@ -1485,7 +1487,7 @@ void DiskCacheBackendTest::BackendDisable2() { } TEST_F(DiskCacheBackendTest, DisableSuccess2) { - ASSERT_TRUE(CopyTestCache("list_loop", path())); + ASSERT_TRUE(CopyTestCache("list_loop")); DisableFirstCleanup(); SetDirectMode(); InitCache(); @@ -1493,7 +1495,7 @@ TEST_F(DiskCacheBackendTest, DisableSuccess2) { } TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess2) { - ASSERT_TRUE(CopyTestCache("list_loop", path())); + ASSERT_TRUE(CopyTestCache("list_loop")); DisableFirstCleanup(); SetNewEviction(); SetDirectMode(); @@ -1502,7 +1504,7 @@ TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess2) { } TEST_F(DiskCacheBackendTest, DisableFailure2) { - ASSERT_TRUE(CopyTestCache("list_loop", path())); + ASSERT_TRUE(CopyTestCache("list_loop")); DisableFirstCleanup(); SetDirectMode(); InitCache(); @@ -1511,7 +1513,7 @@ TEST_F(DiskCacheBackendTest, DisableFailure2) { } TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure2) { - ASSERT_TRUE(CopyTestCache("list_loop", path())); + ASSERT_TRUE(CopyTestCache("list_loop")); DisableFirstCleanup(); SetDirectMode(); SetNewEviction(); @@ -1538,7 +1540,7 @@ void DiskCacheBackendTest::BackendDisable3() { } TEST_F(DiskCacheBackendTest, DisableSuccess3) { - ASSERT_TRUE(CopyTestCache("bad_rankings2", path())); + ASSERT_TRUE(CopyTestCache("bad_rankings2")); DisableFirstCleanup(); SetMaxSize(20 * 1024 * 1024); InitCache(); @@ -1546,7 +1548,7 @@ TEST_F(DiskCacheBackendTest, DisableSuccess3) { } TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess3) { - ASSERT_TRUE(CopyTestCache("bad_rankings2", path())); + ASSERT_TRUE(CopyTestCache("bad_rankings2")); DisableFirstCleanup(); SetMaxSize(20 * 1024 * 1024); SetNewEviction(); @@ -1604,7 +1606,7 @@ void DiskCacheBackendTest::BackendDisable4() { } TEST_F(DiskCacheBackendTest, DisableSuccess4) { - ASSERT_TRUE(CopyTestCache("bad_rankings", path())); + ASSERT_TRUE(CopyTestCache("bad_rankings")); DisableFirstCleanup(); SetDirectMode(); InitCache(); @@ -1612,7 +1614,7 @@ TEST_F(DiskCacheBackendTest, DisableSuccess4) { } TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess4) { - ASSERT_TRUE(CopyTestCache("bad_rankings", path())); + ASSERT_TRUE(CopyTestCache("bad_rankings")); DisableFirstCleanup(); SetDirectMode(); SetNewEviction(); @@ -1621,14 +1623,13 @@ TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess4) { } TEST_F(DiskCacheTest, Backend_UsageStats) { - ScopedTestCache test_cache; - MessageLoopHelper helper; + FilePath path = GetCacheFilePath(); + ASSERT_TRUE(DeleteCache(path)); scoped_ptr<disk_cache::BackendImpl> cache; cache.reset(new disk_cache::BackendImpl( - test_cache.path(), - base::MessageLoopProxy::CreateForCurrentThread())); + path, base::MessageLoopProxy::CreateForCurrentThread())); ASSERT_TRUE(NULL != cache.get()); cache->SetUnitTestMode(); ASSERT_EQ(net::OK, cache->SyncInit()); @@ -1714,7 +1715,7 @@ void DiskCacheBackendTest::BackendDoomAll2() { } TEST_F(DiskCacheBackendTest, DoomAll2) { - ASSERT_TRUE(CopyTestCache("bad_rankings2", path())); + ASSERT_TRUE(CopyTestCache("bad_rankings2")); DisableFirstCleanup(); SetMaxSize(20 * 1024 * 1024); InitCache(); @@ -1722,7 +1723,7 @@ TEST_F(DiskCacheBackendTest, DoomAll2) { } TEST_F(DiskCacheBackendTest, NewEvictionDoomAll2) { - ASSERT_TRUE(CopyTestCache("bad_rankings2", path())); + ASSERT_TRUE(CopyTestCache("bad_rankings2")); DisableFirstCleanup(); SetMaxSize(20 * 1024 * 1024); SetNewEviction(); @@ -1734,8 +1735,8 @@ TEST_F(DiskCacheBackendTest, NewEvictionDoomAll2) { // of the cache. TEST_F(DiskCacheTest, MultipleInstances) { ScopedTestCache store1; - ScopedTestCache store2; - ScopedTestCache store3; + ScopedTestCache store2("cache_test2"); + ScopedTestCache store3("cache_test3"); base::Thread cache_thread("CacheThread"); ASSERT_TRUE(cache_thread.StartWithOptions( base::Thread::Options(MessageLoop::TYPE_IO, 0))); diff --git a/net/disk_cache/block_files_unittest.cc b/net/disk_cache/block_files_unittest.cc index 4455dab..90bf048 100644 --- a/net/disk_cache/block_files_unittest.cc +++ b/net/disk_cache/block_files_unittest.cc @@ -28,9 +28,11 @@ int NumberOfFiles(const FilePath& path) { namespace disk_cache { TEST_F(DiskCacheTest, BlockFiles_Grow) { - ScopedTestCache test_cache; + FilePath path = GetCacheFilePath(); + ASSERT_TRUE(DeleteCache(path)); + ASSERT_TRUE(file_util::CreateDirectory(path)); - BlockFiles files(test_cache.path()); + BlockFiles files(path); ASSERT_TRUE(files.Init(true)); const int kMaxSize = 35000; @@ -40,7 +42,7 @@ TEST_F(DiskCacheTest, BlockFiles_Grow) { for (int i = 0; i < kMaxSize; i++) { EXPECT_TRUE(files.CreateBlock(RANKINGS, 4, &address[i])); } - EXPECT_EQ(6, NumberOfFiles(test_cache.path())); + EXPECT_EQ(6, NumberOfFiles(path)); // Make sure we don't keep adding files. for (int i = 0; i < kMaxSize * 4; i += 2) { @@ -48,14 +50,16 @@ TEST_F(DiskCacheTest, BlockFiles_Grow) { files.DeleteBlock(address[target], false); EXPECT_TRUE(files.CreateBlock(RANKINGS, 4, &address[target])); } - EXPECT_EQ(6, NumberOfFiles(test_cache.path())); + EXPECT_EQ(6, NumberOfFiles(path)); } // We should be able to delete empty block files. TEST_F(DiskCacheTest, BlockFiles_Shrink) { - ScopedTestCache test_cache; + FilePath path = GetCacheFilePath(); + ASSERT_TRUE(DeleteCache(path)); + ASSERT_TRUE(file_util::CreateDirectory(path)); - BlockFiles files(test_cache.path()); + BlockFiles files(path); ASSERT_TRUE(files.Init(true)); const int kMaxSize = 35000; @@ -70,14 +74,16 @@ TEST_F(DiskCacheTest, BlockFiles_Shrink) { for (int i = 0; i < kMaxSize; i++) { files.DeleteBlock(address[i], false); } - EXPECT_EQ(4, NumberOfFiles(test_cache.path())); + EXPECT_EQ(4, NumberOfFiles(path)); } // Handling of block files not properly closed. TEST_F(DiskCacheTest, BlockFiles_Recover) { - ScopedTestCache test_cache; + FilePath path = GetCacheFilePath(); + ASSERT_TRUE(DeleteCache(path)); + ASSERT_TRUE(file_util::CreateDirectory(path)); - BlockFiles files(test_cache.path()); + BlockFiles files(path); ASSERT_TRUE(files.Init(true)); const int kNumEntries = 2000; @@ -151,9 +157,11 @@ TEST_F(DiskCacheTest, BlockFiles_Recover) { // Handling of truncated files. TEST_F(DiskCacheTest, BlockFiles_ZeroSizeFile) { - ScopedTestCache test_cache; + FilePath path = GetCacheFilePath(); + ASSERT_TRUE(DeleteCache(path)); + ASSERT_TRUE(file_util::CreateDirectory(path)); - BlockFiles files(test_cache.path()); + BlockFiles files(path); ASSERT_TRUE(files.Init(true)); FilePath filename = files.Name(0); @@ -171,9 +179,11 @@ TEST_F(DiskCacheTest, BlockFiles_ZeroSizeFile) { // An invalid file can be detected after init. TEST_F(DiskCacheTest, BlockFiles_InvalidFile) { - ScopedTestCache test_cache; + FilePath path = GetCacheFilePath(); + ASSERT_TRUE(DeleteCache(path)); + ASSERT_TRUE(file_util::CreateDirectory(path)); - BlockFiles files(test_cache.path()); + BlockFiles files(path); ASSERT_TRUE(files.Init(true)); // Let's access block 10 of file 5. (There is no file). @@ -195,11 +205,10 @@ TEST_F(DiskCacheTest, BlockFiles_InvalidFile) { // Tests that we generate the correct file stats. TEST_F(DiskCacheTest, BlockFiles_Stats) { - ScopedTestCache test_cache; + ASSERT_TRUE(CopyTestCache("remove_load1")); + FilePath path = GetCacheFilePath(); - ASSERT_TRUE(CopyTestCache("remove_load1", test_cache.path())); - - BlockFiles files(test_cache.path()); + BlockFiles files(path); ASSERT_TRUE(files.Init(false)); int used, load; @@ -218,9 +227,11 @@ TEST_F(DiskCacheTest, BlockFiles_Stats) { // Tests that we add and remove blocks correctly. TEST_F(DiskCacheTest, AllocationMap) { - ScopedTestCache test_cache; + FilePath path = GetCacheFilePath(); + ASSERT_TRUE(DeleteCache(path)); + ASSERT_TRUE(file_util::CreateDirectory(path)); - BlockFiles files(test_cache.path()); + BlockFiles files(path); ASSERT_TRUE(files.Init(true)); // Create a bunch of entries. diff --git a/net/disk_cache/disk_cache_test_base.cc b/net/disk_cache/disk_cache_test_base.cc index 2d3d376..cffe3fa 100644 --- a/net/disk_cache/disk_cache_test_base.cc +++ b/net/disk_cache/disk_cache_test_base.cc @@ -55,8 +55,9 @@ void DiskCacheTestWithCache::InitMemoryCache() { } void DiskCacheTestWithCache::InitDiskCache() { + FilePath path = GetCacheFilePath(); if (first_cleanup_) - ASSERT_TRUE(DeleteCache(test_cache_.path())); + ASSERT_TRUE(DeleteCache(path)); if (!cache_thread_.IsRunning()) { EXPECT_TRUE(cache_thread_.StartWithOptions( @@ -65,7 +66,7 @@ void DiskCacheTestWithCache::InitDiskCache() { ASSERT_TRUE(cache_thread_.message_loop() != NULL); if (implementation_) - return InitDiskCacheImpl(test_cache_.path()); + return InitDiskCacheImpl(path); scoped_refptr<base::MessageLoopProxy> thread = use_current_thread_ ? base::MessageLoopProxy::CreateForCurrentThread() : @@ -73,8 +74,8 @@ void DiskCacheTestWithCache::InitDiskCache() { TestCompletionCallback cb; int rv = disk_cache::BackendImpl::CreateBackend( - test_cache_.path(), force_creation_, size_, type_, - disk_cache::kNoRandom, thread, &cache_, &cb); + path, force_creation_, size_, type_, + disk_cache::kNoRandom, thread, &cache_, &cb); ASSERT_EQ(net::OK, cb.GetResult(rv)); } @@ -110,7 +111,8 @@ void DiskCacheTestWithCache::TearDown() { cache_thread_.Stop(); if (!memory_only_ && integrity_) { - EXPECT_TRUE(CheckCacheIntegrity(path(), new_eviction_)); + FilePath path = GetCacheFilePath(); + EXPECT_TRUE(CheckCacheIntegrity(path, new_eviction_)); } PlatformTest::TearDown(); @@ -125,9 +127,10 @@ void DiskCacheTestWithCache::SimulateCrash() { cache_impl_->ClearRefCountForTest(); delete cache_impl_; - EXPECT_TRUE(CheckCacheIntegrity(path(), new_eviction_)); + FilePath path = GetCacheFilePath(); + EXPECT_TRUE(CheckCacheIntegrity(path, new_eviction_)); - InitDiskCacheImpl(path()); + InitDiskCacheImpl(path); } void DiskCacheTestWithCache::SetTestMode() { diff --git a/net/disk_cache/disk_cache_test_base.h b/net/disk_cache/disk_cache_test_base.h index 0121191..faecc17 100644 --- a/net/disk_cache/disk_cache_test_base.h +++ b/net/disk_cache/disk_cache_test_base.h @@ -9,7 +9,6 @@ #include "base/basictypes.h" #include "base/thread.h" #include "net/base/cache_type.h" -#include "net/disk_cache/disk_cache_test_util.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" @@ -93,10 +92,6 @@ class DiskCacheTestWithCache : public DiskCacheTest { type_ = type; } - FilePath path() const { - return test_cache_.path(); - } - // Utility methods to access the cache and wait for each operation to finish. int OpenEntry(const std::string& key, disk_cache::Entry** entry); int CreateEntry(const std::string& key, disk_cache::Entry** entry); @@ -141,9 +136,7 @@ class DiskCacheTestWithCache : public DiskCacheTest { void InitDiskCache(); void InitDiskCacheImpl(const FilePath& path); - ScopedTestCache test_cache_; base::Thread cache_thread_; - DISALLOW_COPY_AND_ASSIGN(DiskCacheTestWithCache); }; diff --git a/net/disk_cache/disk_cache_test_util.cc b/net/disk_cache/disk_cache_test_util.cc index 095b693..7dd618a 100644 --- a/net/disk_cache/disk_cache_test_util.cc +++ b/net/disk_cache/disk_cache_test_util.cc @@ -16,6 +16,20 @@ using base::Time; using base::TimeDelta; +namespace { + +FilePath BuildCachePath(const std::string& name) { + FilePath path; + PathService::Get(base::DIR_TEMP, &path); // Ignore return value; + path = path.AppendASCII(name); + if (!file_util::PathExists(path)) + file_util::CreateDirectory(path); + + return path; +} + +} // namespace. + std::string GenerateKey(bool same_length) { char key[200]; CacheTestFillBuffer(key, sizeof(key), same_length); @@ -41,6 +55,10 @@ void CacheTestFillBuffer(char* buffer, size_t len, bool no_nulls) { buffer[0] = 'g'; } +FilePath GetCacheFilePath() { + return BuildCachePath("cache_test"); +} + bool CreateCacheTestFile(const FilePath& name) { int flags = base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_READ | @@ -60,7 +78,7 @@ bool DeleteCache(const FilePath& path) { return true; } -bool CopyTestCache(const std::string& name, const FilePath& destination) { +bool CopyTestCache(const std::string& name) { FilePath path; PathService::Get(base::DIR_SOURCE_ROOT, &path); path = path.AppendASCII("net"); @@ -68,9 +86,10 @@ bool CopyTestCache(const std::string& name, const FilePath& destination) { path = path.AppendASCII("cache_tests"); path = path.AppendASCII(name); - if (!DeleteCache(destination)) + FilePath dest = GetCacheFilePath(); + if (!DeleteCache(dest)) return false; - return file_util::CopyDirectory(path, destination, false); + return file_util::CopyDirectory(path, dest, false); } bool CheckCacheIntegrity(const FilePath& path, bool new_eviction) { @@ -86,11 +105,19 @@ bool CheckCacheIntegrity(const FilePath& path, bool new_eviction) { return cache->SelfCheck() >= 0; } -ScopedTestCache::ScopedTestCache() { - temp_dir_.CreateUniqueTempDir(); +ScopedTestCache::ScopedTestCache() : path_(GetCacheFilePath()) { + bool result = DeleteCache(path_); + DCHECK(result); +} + +ScopedTestCache::ScopedTestCache(const std::string& name) + : path_(BuildCachePath(name)) { + bool result = DeleteCache(path_); + DCHECK(result); } ScopedTestCache::~ScopedTestCache() { + file_util::Delete(path(), true); } // ----------------------------------------------------------------------- diff --git a/net/disk_cache/disk_cache_test_util.h b/net/disk_cache/disk_cache_test_util.h index f4864bb..f6348e9 100644 --- a/net/disk_cache/disk_cache_test_util.h +++ b/net/disk_cache/disk_cache_test_util.h @@ -11,7 +11,6 @@ #include "base/callback.h" #include "base/file_path.h" #include "base/message_loop.h" -#include "base/scoped_temp_dir.h" #include "base/timer.h" #include "build/build_config.h" @@ -21,8 +20,11 @@ bool CreateCacheTestFile(const FilePath& name); // Deletes all file son the cache. bool DeleteCache(const FilePath& path); -// Copies a set of cache files from the data folder to the destination folder. -bool CopyTestCache(const std::string& name, const FilePath& destination); +// Copies a set of cache files from the data folder to the test folder. +bool CopyTestCache(const std::string& name); + +// Gets the path to the cache test folder. +FilePath GetCacheFilePath(); // Fills buffer with random values (may contain nulls unless no_nulls is true). void CacheTestFillBuffer(char* buffer, size_t len, bool no_nulls); @@ -38,12 +40,14 @@ bool CheckCacheIntegrity(const FilePath& path, bool new_eviction); class ScopedTestCache { public: ScopedTestCache(); + // Use a specific folder name. + explicit ScopedTestCache(const std::string& name); ~ScopedTestCache(); - FilePath path() const { return temp_dir_.path(); } + FilePath path() const { return path_; } private: - ScopedTempDir temp_dir_; + const FilePath path_; // Path to the cache test folder. DISALLOW_COPY_AND_ASSIGN(ScopedTestCache); }; diff --git a/net/disk_cache/mapped_file_unittest.cc b/net/disk_cache/mapped_file_unittest.cc index 4404be6..8b01a7d 100644 --- a/net/disk_cache/mapped_file_unittest.cc +++ b/net/disk_cache/mapped_file_unittest.cc @@ -61,9 +61,7 @@ void WaitForCallbacks(int expected) { } // namespace TEST_F(DiskCacheTest, MappedFile_SyncIO) { - ScopedTestCache test_cache; - FilePath filename = test_cache.path().AppendASCII("a_test"); - + FilePath filename = GetCacheFilePath().AppendASCII("a_test"); scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); ASSERT_TRUE(CreateCacheTestFile(filename)); ASSERT_TRUE(file->Init(filename, 8192)); @@ -78,9 +76,7 @@ TEST_F(DiskCacheTest, MappedFile_SyncIO) { } TEST_F(DiskCacheTest, MappedFile_AsyncIO) { - ScopedTestCache test_cache; - FilePath filename = test_cache.path().AppendASCII("a_test"); - + FilePath filename = GetCacheFilePath().AppendASCII("a_test"); scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); ASSERT_TRUE(CreateCacheTestFile(filename)); ASSERT_TRUE(file->Init(filename, 8192)); diff --git a/net/disk_cache/storage_block_unittest.cc b/net/disk_cache/storage_block_unittest.cc index abaa4a7..c9406b6 100644 --- a/net/disk_cache/storage_block_unittest.cc +++ b/net/disk_cache/storage_block_unittest.cc @@ -10,9 +10,7 @@ #include "testing/gtest/include/gtest/gtest.h" TEST_F(DiskCacheTest, StorageBlock_LoadStore) { - ScopedTestCache test_cache; - FilePath filename = test_cache.path().AppendASCII("a_test"); - + FilePath filename = GetCacheFilePath().AppendASCII("a_test"); scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); ASSERT_TRUE(CreateCacheTestFile(filename)); ASSERT_TRUE(file->Init(filename, 8192)); @@ -32,9 +30,7 @@ TEST_F(DiskCacheTest, StorageBlock_LoadStore) { } TEST_F(DiskCacheTest, StorageBlock_SetData) { - ScopedTestCache test_cache; - FilePath filename = test_cache.path().AppendASCII("a_test"); - + FilePath filename = GetCacheFilePath().AppendASCII("a_test"); scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); ASSERT_TRUE(CreateCacheTestFile(filename)); ASSERT_TRUE(file->Init(filename, 8192)); @@ -54,9 +50,7 @@ TEST_F(DiskCacheTest, StorageBlock_SetData) { } TEST_F(DiskCacheTest, StorageBlock_SetModified) { - ScopedTestCache test_cache; - FilePath filename = test_cache.path().AppendASCII("a_test"); - + FilePath filename = GetCacheFilePath().AppendASCII("a_test"); scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); ASSERT_TRUE(CreateCacheTestFile(filename)); ASSERT_TRUE(file->Init(filename, 8192)); diff --git a/net/disk_cache/stress_cache.cc b/net/disk_cache/stress_cache.cc index 51fda4c..98dcbe1 100644 --- a/net/disk_cache/stress_cache.cc +++ b/net/disk_cache/stress_cache.cc @@ -29,7 +29,6 @@ #include "base/command_line.h" #include "base/debug_util.h" #include "base/file_path.h" -#include "base/file_util.h" #include "base/logging.h" #include "base/message_loop.h" #include "base/path_service.h" @@ -51,16 +50,6 @@ using base::Time; const int kError = -1; const int kExpectedCrash = 100; -FilePath GetStressCacheFilePath() { - FilePath path; - PathService::Get(base::DIR_TEMP, &path); // Ignore return value; - path = path.AppendASCII("cache_test_stress"); - if (!file_util::PathExists(path)) - file_util::CreateDirectory(path); - - return path; -} - // Starts a new process. int RunSlave(int iteration) { FilePath exe; @@ -103,7 +92,7 @@ int MasterCode() { // to know which instance of the application wrote them. void StressTheCache(int iteration) { int cache_size = 0x800000; // 8MB - FilePath path = GetStressCacheFilePath(); + FilePath path = GetCacheFilePath().InsertBeforeExtensionASCII("_stress"); base::Thread cache_thread("CacheThread"); if (!cache_thread.StartWithOptions( |