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

Unified Diff: net/socket/ssl_client_socket_unittest.cc

Issue 2541093003: Instrument SSL sockets using MemoryDumpProvider (Closed)
Patch Set: Address davidben and primiano comments 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 side-by-side diff with in-line comments
Download patch
Index: net/socket/ssl_client_socket_unittest.cc
diff --git a/net/socket/ssl_client_socket_unittest.cc b/net/socket/ssl_client_socket_unittest.cc
index b80aa4ddf5af432f12e54a5e7a7012dea7cd1b0a..1331dd02994f527a591d0a5ca97240520c7bc6af 100644
--- a/net/socket/ssl_client_socket_unittest.cc
+++ b/net/socket/ssl_client_socket_unittest.cc
@@ -18,6 +18,10 @@
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
+#include "base/trace_event/memory_allocator_dump.h"
+#include "base/trace_event/process_memory_dump.h"
+#include "base/trace_event/trace_event_argument.h"
+#include "base/values.h"
#include "net/base/address_list.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
@@ -3674,4 +3678,75 @@ TEST_F(SSLClientSocketTest, AccessDeniedClientCerts) {
EXPECT_THAT(rv, IsError(ERR_BAD_SSL_CLIENT_AUTH_CERT));
}
+// Basic test for dumping memory stats.
+TEST_F(SSLClientSocketTest, DumpMemoryStats) {
+ ASSERT_TRUE(StartTestServer(SpawnedTestServer::SSLOptions()));
+
+ int rv;
+ ASSERT_TRUE(CreateAndConnectSSLClientSocket(SSLConfig(), &rv));
+ EXPECT_THAT(rv, IsOk());
+
+ base::trace_event::MemoryDumpArgs dump_args = {
+ base::trace_event::MemoryDumpLevelOfDetail::DETAILED};
+ std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump(
+ new base::trace_event::ProcessMemoryDump(nullptr, dump_args));
+ base::trace_event::MemoryAllocatorDump* parent_dump1 =
+ process_memory_dump->CreateAllocatorDump("parent1");
+ sock_->DumpMemoryStats(process_memory_dump.get(),
+ parent_dump1->absolute_name());
+
+ // Write the request.
+ std::string request_text = "GET / HTTP/1.1\r\n\r\n";
+ scoped_refptr<IOBuffer> request_buffer(new StringIOBuffer(request_text));
+ TestCompletionCallback write_callback;
+ rv = write_callback.GetResult(sock_->Write(
+ request_buffer.get(), request_text.size(), write_callback.callback()));
+ EXPECT_EQ(static_cast<int>(request_text.size()), rv);
+
+ // Read the response.
+ TestCompletionCallback read_callback;
+ scoped_refptr<IOBuffer> buf(new IOBuffer(4096));
+ rv = sock_->Read(buf.get(), 4096, read_callback.callback());
+ rv = read_callback.WaitForResult();
+ EXPECT_GT(rv, 0);
+
+ // Dump memory again and check that |buffer_size| should contain read buffer.
+ base::trace_event::MemoryAllocatorDump* parent_dump3 =
+ process_memory_dump->CreateAllocatorDump("parent2");
+ sock_->DumpMemoryStats(process_memory_dump.get(),
+ parent_dump3->absolute_name());
+
+ const base::trace_event::ProcessMemoryDump::AllocatorDumpsMap&
+ allocator_dumps = process_memory_dump->allocator_dumps();
+ bool did_dump[] = {false, false};
+ // Checks that there are three dumps because DumpMemoryStats() is invoked
+ // before writing the request, before reading the response and after reading
+ // the response.
+ for (const auto& pair : allocator_dumps) {
+ const std::string& dump_name = pair.first;
+ if (dump_name.find("ssl_socket") == std::string::npos)
+ return;
+ std::unique_ptr<base::Value> raw_attrs =
+ pair.second->attributes_for_testing()->ToBaseValue();
+ base::DictionaryValue* attrs;
+ ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs));
+ base::DictionaryValue* buffer_size_attrs;
+ ASSERT_TRUE(attrs->GetDictionary("buffer_size", &buffer_size_attrs));
+ std::string buffer_size;
+ ASSERT_TRUE(buffer_size_attrs->GetString("value", &buffer_size));
+ ASSERT_TRUE(attrs->HasKey("serialized_cert_size"));
+ ASSERT_TRUE(attrs->HasKey("serialized_cert_count"));
+ if (dump_name.find("parent1/ssl_socket") != std::string::npos) {
+ did_dump[0] = true;
+ ASSERT_EQ("0", buffer_size);
+ }
+ if (dump_name.find("parent2/ssl_socket") != std::string::npos) {
+ did_dump[1] = true;
+ // Buffer size should take into account the read buffer size.
davidben 2016/12/07 19:42:58 Perhaps: // The buffers should be released if the
xunjieli 2016/12/07 20:32:25 But in this case, the buffer size is not equals to
+ ASSERT_NE("0", buffer_size);
+ }
+ }
+ EXPECT_THAT(did_dump, testing::ElementsAre(true, true));
+}
+
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698