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

Side by Side Diff: net/socket/ssl_client_socket_unittest.cc

Issue 2541093003: Instrument SSL sockets using MemoryDumpProvider (Closed)
Patch Set: Fix flaky test Created 4 years 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
« no previous file with comments | « net/socket/ssl_client_socket_pool.cc ('k') | net/socket/stream_socket.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) 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 "net/socket/ssl_client_socket.h" 5 #include "net/socket/ssl_client_socket.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/callback_helpers.h" 12 #include "base/callback_helpers.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
19 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
20 #include "base/time/time.h" 20 #include "base/time/time.h"
21 #include "base/trace_event/memory_allocator_dump.h"
22 #include "base/trace_event/process_memory_dump.h"
23 #include "base/trace_event/trace_event_argument.h"
24 #include "base/values.h"
21 #include "net/base/address_list.h" 25 #include "net/base/address_list.h"
22 #include "net/base/io_buffer.h" 26 #include "net/base/io_buffer.h"
23 #include "net/base/net_errors.h" 27 #include "net/base/net_errors.h"
24 #include "net/base/test_completion_callback.h" 28 #include "net/base/test_completion_callback.h"
25 #include "net/cert/asn1_util.h" 29 #include "net/cert/asn1_util.h"
26 #include "net/cert/ct_policy_enforcer.h" 30 #include "net/cert/ct_policy_enforcer.h"
27 #include "net/cert/ct_policy_status.h" 31 #include "net/cert/ct_policy_status.h"
28 #include "net/cert/ct_verifier.h" 32 #include "net/cert/ct_verifier.h"
29 #include "net/cert/mock_cert_verifier.h" 33 #include "net/cert/mock_cert_verifier.h"
30 #include "net/cert/signed_certificate_timestamp_and_status.h" 34 #include "net/cert/signed_certificate_timestamp_and_status.h"
(...skipping 3636 matching lines...) Expand 10 before | Expand all | Expand 10 after
3667 3671
3668 // Replace it with an alert. 3672 // Replace it with an alert.
3669 raw_transport->ReplaceReadResult( 3673 raw_transport->ReplaceReadResult(
3670 FormatTLS12Alert(49 /* AlertDescription.access_denied */)); 3674 FormatTLS12Alert(49 /* AlertDescription.access_denied */));
3671 raw_transport->UnblockReadResult(); 3675 raw_transport->UnblockReadResult();
3672 3676
3673 rv = callback.GetResult(rv); 3677 rv = callback.GetResult(rv);
3674 EXPECT_THAT(rv, IsError(ERR_BAD_SSL_CLIENT_AUTH_CERT)); 3678 EXPECT_THAT(rv, IsError(ERR_BAD_SSL_CLIENT_AUTH_CERT));
3675 } 3679 }
3676 3680
3681 // Basic test for dumping memory stats.
3682 TEST_F(SSLClientSocketTest, DumpMemoryStats) {
3683 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
3684
3685 int rv;
3686 ASSERT_TRUE(CreateAndConnectSSLClientSocket(SSLConfig(), &rv));
3687 EXPECT_THAT(rv, IsOk());
3688
3689 base::trace_event::MemoryDumpArgs dump_args = {
3690 base::trace_event::MemoryDumpLevelOfDetail::DETAILED};
3691 std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump(
3692 new base::trace_event::ProcessMemoryDump(nullptr, dump_args));
3693 base::trace_event::MemoryAllocatorDump* parent_dump1 =
3694 process_memory_dump->CreateAllocatorDump("parent1");
3695 sock_->DumpMemoryStats(process_memory_dump.get(),
3696 parent_dump1->absolute_name());
3697
3698 // Read the response without writing a request, so the read will be pending.
3699 TestCompletionCallback read_callback;
3700 scoped_refptr<IOBuffer> buf(new IOBuffer(4096));
3701 rv = sock_->Read(buf.get(), 4096, read_callback.callback());
3702 EXPECT_EQ(ERR_IO_PENDING, rv);
3703
3704 // Dump memory again and check that |buffer_size| contain the read buffer.
3705 base::trace_event::MemoryAllocatorDump* parent_dump2 =
3706 process_memory_dump->CreateAllocatorDump("parent2");
3707 sock_->DumpMemoryStats(process_memory_dump.get(),
3708 parent_dump2->absolute_name());
3709
3710 const base::trace_event::ProcessMemoryDump::AllocatorDumpsMap&
3711 allocator_dumps = process_memory_dump->allocator_dumps();
3712 bool did_dump[] = {false, false};
3713 // Checks that there are two dumps because DumpMemoryStats() is invoked twice.
3714 for (const auto& pair : allocator_dumps) {
3715 const std::string& dump_name = pair.first;
3716 if (dump_name.find("ssl_socket") == std::string::npos)
3717 return;
3718 std::unique_ptr<base::Value> raw_attrs =
3719 pair.second->attributes_for_testing()->ToBaseValue();
3720 base::DictionaryValue* attrs;
3721 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs));
3722 base::DictionaryValue* buffer_size_attrs;
3723 ASSERT_TRUE(attrs->GetDictionary("buffer_size", &buffer_size_attrs));
3724 std::string buffer_size;
3725 ASSERT_TRUE(buffer_size_attrs->GetString("value", &buffer_size));
3726 ASSERT_TRUE(attrs->HasKey("serialized_cert_size"));
3727 ASSERT_TRUE(attrs->HasKey("cert_count"));
3728 if (dump_name.find("parent1/ssl_socket") != std::string::npos) {
3729 did_dump[0] = true;
3730 ASSERT_EQ("0", buffer_size);
3731 }
3732 if (dump_name.find("parent2/ssl_socket") != std::string::npos) {
3733 did_dump[1] = true;
3734 // The read buffer is not released, so |buffer_size| can't be 0.
3735 ASSERT_NE("0", buffer_size);
3736 }
3737 }
3738 EXPECT_THAT(did_dump, testing::ElementsAre(true, true));
3739 }
3740
3677 } // namespace net 3741 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/ssl_client_socket_pool.cc ('k') | net/socket/stream_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698