OLD | NEW |
| (Empty) |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/trace_event/memory_allocator_dump.h" | |
6 #include "base/trace_event/process_memory_dump.h" | |
7 #include "base/trace_event/trace_event_argument.h" | |
8 #include "components/tracing/graphics_memory_dump_provider_android.h" | |
9 #include "testing/gtest/include/gtest/gtest.h" | |
10 | |
11 namespace tracing { | |
12 | |
13 TEST(GraphicsMemoryDumpProviderTest, ParseResponse) { | |
14 const char* kDumpBaseName = GraphicsMemoryDumpProvider::kDumpBaseName; | |
15 | |
16 base::trace_event::ProcessMemoryDump pmd(nullptr); | |
17 auto instance = GraphicsMemoryDumpProvider::GetInstance(); | |
18 char buf[] = "graphics_total 12\ngraphics_pss 34\ngl_total 56\ngl_pss 78"; | |
19 instance->ParseResponseAndAddToDump(buf, strlen(buf), &pmd); | |
20 | |
21 // Check the "graphics" row. | |
22 auto mad = pmd.GetAllocatorDump(kDumpBaseName + std::string("graphics")); | |
23 ASSERT_TRUE(mad); | |
24 std::string json; | |
25 mad->attributes_for_testing()->AppendAsTraceFormat(&json); | |
26 ASSERT_EQ( | |
27 "{\"memtrack_pss\":{\"type\":\"scalar\",\"units\":\"bytes\",\"value\":" | |
28 "\"22\"}," | |
29 "\"memtrack_total\":{\"type\":\"scalar\",\"units\":\"bytes\",\"value\":" | |
30 "\"c\"}}", | |
31 json); | |
32 | |
33 // Check the "gl" row. | |
34 mad = pmd.GetAllocatorDump(kDumpBaseName + std::string("gl")); | |
35 ASSERT_TRUE(mad); | |
36 json = ""; | |
37 mad->attributes_for_testing()->AppendAsTraceFormat(&json); | |
38 ASSERT_EQ( | |
39 "{\"memtrack_pss\":{\"type\":\"scalar\",\"units\":\"bytes\",\"value\":" | |
40 "\"4e\"}," | |
41 "\"memtrack_total\":{\"type\":\"scalar\",\"units\":\"bytes\",\"value\":" | |
42 "\"38\"}}", | |
43 json); | |
44 | |
45 // Test for truncated input. | |
46 pmd.Clear(); | |
47 instance->ParseResponseAndAddToDump(buf, strlen(buf) - 14, &pmd); | |
48 ASSERT_TRUE(pmd.GetAllocatorDump(kDumpBaseName + std::string("graphics"))); | |
49 ASSERT_FALSE(pmd.GetAllocatorDump(kDumpBaseName + std::string("gl"))); | |
50 } | |
51 | |
52 } // namespace tracing | |
OLD | NEW |