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

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

Issue 2779733002: [HttpCache] Store some memcache info to memory dumps for debugging (Closed)
Patch Set: Whitelist strings Created 3 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/files/file.h" 7 #include "base/files/file.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/test/mock_entropy_provider.h" 16 #include "base/test/mock_entropy_provider.h"
17 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 17 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
18 #include "base/threading/platform_thread.h" 18 #include "base/threading/platform_thread.h"
19 #include "base/threading/thread_restrictions.h" 19 #include "base/threading/thread_restrictions.h"
20 #include "base/threading/thread_task_runner_handle.h" 20 #include "base/threading/thread_task_runner_handle.h"
21 #include "base/trace_event/memory_usage_estimator.h" 21 #include "base/trace_event/process_memory_dump.h"
22 #include "net/base/cache_type.h" 22 #include "net/base/cache_type.h"
23 #include "net/base/io_buffer.h" 23 #include "net/base/io_buffer.h"
24 #include "net/base/net_errors.h" 24 #include "net/base/net_errors.h"
25 #include "net/base/test_completion_callback.h" 25 #include "net/base/test_completion_callback.h"
26 #include "net/disk_cache/blockfile/backend_impl.h" 26 #include "net/disk_cache/blockfile/backend_impl.h"
27 #include "net/disk_cache/blockfile/entry_impl.h" 27 #include "net/disk_cache/blockfile/entry_impl.h"
28 #include "net/disk_cache/blockfile/experiments.h" 28 #include "net/disk_cache/blockfile/experiments.h"
29 #include "net/disk_cache/blockfile/histogram_macros.h" 29 #include "net/disk_cache/blockfile/histogram_macros.h"
30 #include "net/disk_cache/blockfile/mapped_file.h" 30 #include "net/disk_cache/blockfile/mapped_file.h"
31 #include "net/disk_cache/cache_util.h" 31 #include "net/disk_cache/cache_util.h"
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 } 317 }
318 318
319 void DiskCacheBackendTest::BackendBasics() { 319 void DiskCacheBackendTest::BackendBasics() {
320 InitCache(); 320 InitCache();
321 disk_cache::Entry *entry1 = NULL, *entry2 = NULL; 321 disk_cache::Entry *entry1 = NULL, *entry2 = NULL;
322 EXPECT_NE(net::OK, OpenEntry("the first key", &entry1)); 322 EXPECT_NE(net::OK, OpenEntry("the first key", &entry1));
323 ASSERT_THAT(CreateEntry("the first key", &entry1), IsOk()); 323 ASSERT_THAT(CreateEntry("the first key", &entry1), IsOk());
324 ASSERT_TRUE(NULL != entry1); 324 ASSERT_TRUE(NULL != entry1);
325 entry1->Close(); 325 entry1->Close();
326 entry1 = NULL; 326 entry1 = NULL;
327 // base::trace_event::EstimateMemoryUsage(cache_) is added to make sure 327 // base::trace_event::EstimateMemoryUsage(cache_) is added to make sure
ssid 2017/03/27 18:59:41 Is this comment still valid?
jkarlin 2017/03/28 15:09:45 Removed.
328 // tracking memory doesn't introduce crashes. 328 // tracking memory doesn't introduce crashes.
329 EXPECT_LT(0u, base::trace_event::EstimateMemoryUsage(cache_)); 329 base::trace_event::MemoryDumpArgs args = {
330 base::trace_event::MemoryDumpLevelOfDetail::DETAILED};
xunjieli 2017/03/27 18:29:06 Could you run this with base::trace_event::MemoryD
jkarlin 2017/03/28 15:09:45 Done, and broke it out into separate tests.
331 base::trace_event::ProcessMemoryDump pmd(nullptr, args);
332 ASSERT_LT(0u, cache_->DumpMemoryStats(&pmd, ""));
333 EXPECT_LT(0u, pmd.allocator_dumps().size());
330 334
331 ASSERT_THAT(OpenEntry("the first key", &entry1), IsOk()); 335 ASSERT_THAT(OpenEntry("the first key", &entry1), IsOk());
332 ASSERT_TRUE(NULL != entry1); 336 ASSERT_TRUE(NULL != entry1);
333 entry1->Close(); 337 entry1->Close();
334 entry1 = NULL; 338 entry1 = NULL;
335 339
336 EXPECT_NE(net::OK, CreateEntry("the first key", &entry1)); 340 EXPECT_NE(net::OK, CreateEntry("the first key", &entry1));
337 ASSERT_THAT(OpenEntry("the first key", &entry1), IsOk()); 341 ASSERT_THAT(OpenEntry("the first key", &entry1), IsOk());
338 EXPECT_NE(net::OK, OpenEntry("some other key", &entry2)); 342 EXPECT_NE(net::OK, OpenEntry("some other key", &entry2));
339 ASSERT_THAT(CreateEntry("some other key", &entry2), IsOk()); 343 ASSERT_THAT(CreateEntry("some other key", &entry2), IsOk());
340 ASSERT_TRUE(NULL != entry1); 344 ASSERT_TRUE(NULL != entry1);
341 ASSERT_TRUE(NULL != entry2); 345 ASSERT_TRUE(NULL != entry2);
342 EXPECT_EQ(2, cache_->GetEntryCount()); 346 EXPECT_EQ(2, cache_->GetEntryCount());
343 EXPECT_LT(0u, base::trace_event::EstimateMemoryUsage(cache_)); 347 base::trace_event::ProcessMemoryDump pmd2(nullptr, args);
348 ASSERT_LT(0u, cache_->DumpMemoryStats(&pmd2, ""));
349 EXPECT_LT(0u, pmd2.allocator_dumps().size());
344 350
345 disk_cache::Entry* entry3 = NULL; 351 disk_cache::Entry* entry3 = NULL;
346 ASSERT_THAT(OpenEntry("some other key", &entry3), IsOk()); 352 ASSERT_THAT(OpenEntry("some other key", &entry3), IsOk());
347 ASSERT_TRUE(NULL != entry3); 353 ASSERT_TRUE(NULL != entry3);
348 EXPECT_TRUE(entry2 == entry3); 354 EXPECT_TRUE(entry2 == entry3);
349 EXPECT_LT(0u, base::trace_event::EstimateMemoryUsage(cache_));
350 355
351 EXPECT_THAT(DoomEntry("some other key"), IsOk()); 356 EXPECT_THAT(DoomEntry("some other key"), IsOk());
352 EXPECT_EQ(1, cache_->GetEntryCount()); 357 EXPECT_EQ(1, cache_->GetEntryCount());
353 entry1->Close(); 358 entry1->Close();
354 entry2->Close(); 359 entry2->Close();
355 entry3->Close(); 360 entry3->Close();
356 EXPECT_LT(0u, base::trace_event::EstimateMemoryUsage(cache_));
357 361
358 EXPECT_THAT(DoomEntry("the first key"), IsOk()); 362 EXPECT_THAT(DoomEntry("the first key"), IsOk());
359 EXPECT_EQ(0, cache_->GetEntryCount()); 363 EXPECT_EQ(0, cache_->GetEntryCount());
360 364
361 ASSERT_THAT(CreateEntry("the first key", &entry1), IsOk()); 365 ASSERT_THAT(CreateEntry("the first key", &entry1), IsOk());
362 ASSERT_THAT(CreateEntry("some other key", &entry2), IsOk()); 366 ASSERT_THAT(CreateEntry("some other key", &entry2), IsOk());
363 entry1->Doom(); 367 entry1->Doom();
364 entry1->Close(); 368 entry1->Close();
365 EXPECT_THAT(DoomEntry("some other key"), IsOk()); 369 EXPECT_THAT(DoomEntry("some other key"), IsOk());
366 EXPECT_EQ(0, cache_->GetEntryCount()); 370 EXPECT_EQ(0, cache_->GetEntryCount());
367 entry2->Close(); 371 entry2->Close();
368 EXPECT_LT(0u, base::trace_event::EstimateMemoryUsage(cache_));
369 } 372 }
370 373
371 TEST_F(DiskCacheBackendTest, Basics) { 374 TEST_F(DiskCacheBackendTest, Basics) {
372 BackendBasics(); 375 BackendBasics();
373 } 376 }
374 377
375 TEST_F(DiskCacheBackendTest, NewEvictionBasics) { 378 TEST_F(DiskCacheBackendTest, NewEvictionBasics) {
376 SetNewEviction(); 379 SetNewEviction();
377 BackendBasics(); 380 BackendBasics();
378 } 381 }
(...skipping 3549 matching lines...) Expand 10 before | Expand all | Expand 10 after
3928 // because that would advance the cache directory mtime and invalidate the 3931 // because that would advance the cache directory mtime and invalidate the
3929 // index. 3932 // index.
3930 entry2->Doom(); 3933 entry2->Doom();
3931 entry2->Close(); 3934 entry2->Close();
3932 3935
3933 DisableFirstCleanup(); 3936 DisableFirstCleanup();
3934 InitCache(); 3937 InitCache();
3935 EXPECT_EQ(disk_cache::SimpleIndex::INITIALIZE_METHOD_LOADED, 3938 EXPECT_EQ(disk_cache::SimpleIndex::INITIALIZE_METHOD_LOADED,
3936 simple_cache_impl_->index()->init_method()); 3939 simple_cache_impl_->index()->init_method());
3937 } 3940 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698