OLD | NEW |
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 "base/values.h" |
25 #include "net/base/address_list.h" | 22 #include "net/base/address_list.h" |
26 #include "net/base/io_buffer.h" | 23 #include "net/base/io_buffer.h" |
27 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
28 #include "net/base/test_completion_callback.h" | 25 #include "net/base/test_completion_callback.h" |
29 #include "net/cert/asn1_util.h" | 26 #include "net/cert/asn1_util.h" |
30 #include "net/cert/ct_policy_enforcer.h" | 27 #include "net/cert/ct_policy_enforcer.h" |
31 #include "net/cert/ct_policy_status.h" | 28 #include "net/cert/ct_policy_status.h" |
32 #include "net/cert/ct_verifier.h" | 29 #include "net/cert/ct_verifier.h" |
33 #include "net/cert/do_nothing_ct_verifier.h" | 30 #include "net/cert/do_nothing_ct_verifier.h" |
(...skipping 3586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3620 EXPECT_THAT(rv, IsError(ERR_BAD_SSL_CLIENT_AUTH_CERT)); | 3617 EXPECT_THAT(rv, IsError(ERR_BAD_SSL_CLIENT_AUTH_CERT)); |
3621 } | 3618 } |
3622 | 3619 |
3623 // Basic test for dumping memory stats. | 3620 // Basic test for dumping memory stats. |
3624 TEST_F(SSLClientSocketTest, DumpMemoryStats) { | 3621 TEST_F(SSLClientSocketTest, DumpMemoryStats) { |
3625 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); | 3622 ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions())); |
3626 | 3623 |
3627 int rv; | 3624 int rv; |
3628 ASSERT_TRUE(CreateAndConnectSSLClientSocket(SSLConfig(), &rv)); | 3625 ASSERT_TRUE(CreateAndConnectSSLClientSocket(SSLConfig(), &rv)); |
3629 EXPECT_THAT(rv, IsOk()); | 3626 EXPECT_THAT(rv, IsOk()); |
3630 | 3627 StreamSocket::SocketMemoryStats stats; |
3631 base::trace_event::MemoryDumpArgs dump_args = { | 3628 sock_->DumpMemoryStats(&stats); |
3632 base::trace_event::MemoryDumpLevelOfDetail::DETAILED}; | 3629 EXPECT_EQ(0u, stats.buffer_size); |
3633 std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump( | 3630 EXPECT_EQ(1u, stats.cert_count); |
3634 new base::trace_event::ProcessMemoryDump(nullptr, dump_args)); | 3631 EXPECT_LT(0u, stats.serialized_cert_size); |
3635 base::trace_event::MemoryAllocatorDump* parent_dump1 = | 3632 EXPECT_EQ(stats.serialized_cert_size, stats.total_size); |
3636 process_memory_dump->CreateAllocatorDump("parent1"); | |
3637 sock_->DumpMemoryStats(process_memory_dump.get(), | |
3638 parent_dump1->absolute_name()); | |
3639 | 3633 |
3640 // Read the response without writing a request, so the read will be pending. | 3634 // Read the response without writing a request, so the read will be pending. |
3641 TestCompletionCallback read_callback; | 3635 TestCompletionCallback read_callback; |
3642 scoped_refptr<IOBuffer> buf(new IOBuffer(4096)); | 3636 scoped_refptr<IOBuffer> buf(new IOBuffer(4096)); |
3643 rv = sock_->Read(buf.get(), 4096, read_callback.callback()); | 3637 rv = sock_->Read(buf.get(), 4096, read_callback.callback()); |
3644 EXPECT_EQ(ERR_IO_PENDING, rv); | 3638 EXPECT_EQ(ERR_IO_PENDING, rv); |
3645 | 3639 |
3646 // Dump memory again and check that |buffer_size| contain the read buffer. | 3640 // Dump memory again and check that |buffer_size| contain the read buffer. |
3647 base::trace_event::MemoryAllocatorDump* parent_dump2 = | 3641 StreamSocket::SocketMemoryStats stats2; |
3648 process_memory_dump->CreateAllocatorDump("parent2"); | 3642 sock_->DumpMemoryStats(&stats2); |
3649 sock_->DumpMemoryStats(process_memory_dump.get(), | 3643 EXPECT_EQ(17 * 1024u, stats2.buffer_size); |
3650 parent_dump2->absolute_name()); | 3644 EXPECT_EQ(1u, stats2.cert_count); |
3651 | 3645 EXPECT_LT(0u, stats2.serialized_cert_size); |
3652 const base::trace_event::ProcessMemoryDump::AllocatorDumpsMap& | 3646 EXPECT_LT(17 * 1024u, stats2.total_size); |
3653 allocator_dumps = process_memory_dump->allocator_dumps(); | |
3654 bool did_dump[] = {false, false}; | |
3655 // Checks that there are two dumps because DumpMemoryStats() is invoked twice. | |
3656 for (const auto& pair : allocator_dumps) { | |
3657 const std::string& dump_name = pair.first; | |
3658 if (dump_name.find("ssl_socket") == std::string::npos) | |
3659 continue; | |
3660 std::unique_ptr<base::Value> raw_attrs = | |
3661 pair.second->attributes_for_testing()->ToBaseValue(); | |
3662 base::DictionaryValue* attrs; | |
3663 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs)); | |
3664 base::DictionaryValue* buffer_size_attrs; | |
3665 ASSERT_TRUE(attrs->GetDictionary("buffer_size", &buffer_size_attrs)); | |
3666 std::string buffer_size; | |
3667 ASSERT_TRUE(buffer_size_attrs->GetString("value", &buffer_size)); | |
3668 ASSERT_TRUE(attrs->HasKey("serialized_cert_size")); | |
3669 ASSERT_TRUE(attrs->HasKey("cert_count")); | |
3670 if (dump_name.find("parent1/ssl_socket") != std::string::npos) { | |
3671 did_dump[0] = true; | |
3672 ASSERT_EQ("0", buffer_size); | |
3673 } | |
3674 if (dump_name.find("parent2/ssl_socket") != std::string::npos) { | |
3675 did_dump[1] = true; | |
3676 // The read buffer is not released, so |buffer_size| can't be 0. | |
3677 ASSERT_NE("0", buffer_size); | |
3678 } | |
3679 } | |
3680 EXPECT_THAT(did_dump, testing::ElementsAre(true, true)); | |
3681 } | 3647 } |
3682 | 3648 |
3683 } // namespace net | 3649 } // namespace net |
OLD | NEW |