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

Side by Side Diff: components/metrics/leak_detector/protobuf_to_mojo_converter_unittest.cc

Issue 2166553003: Revert of Mojo interface/service for Leak Detector on remote process (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « components/metrics/leak_detector/protobuf_to_mojo_converter.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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 "components/metrics/leak_detector/protobuf_to_mojo_converter.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace metrics {
10 namespace leak_detector {
11
12 TEST(protobuf_to_mojo_converterTest, ConvertParams) {
13 MemoryLeakReportProto::Params params;
14 params.set_sampling_rate(0.75);
15 params.set_max_stack_depth(19);
16 params.set_analysis_interval_bytes(25 * 1024 * 1024);
17 params.set_size_suspicion_threshold(8);
18 params.set_call_stack_suspicion_threshold(11);
19
20 // Convert to equivalent Mojo struct.
21 mojo::StructPtr<mojom::LeakDetectorParams> mojo_params =
22 mojom::LeakDetectorParams::New();
23 protobuf_to_mojo_converter::ParamsToMojo(params, mojo_params.get());
24
25 EXPECT_DOUBLE_EQ(0.75, mojo_params->sampling_rate);
26 EXPECT_EQ(19U, mojo_params->max_stack_depth);
27 EXPECT_EQ(25U * 1024 * 1024, mojo_params->analysis_interval_bytes);
28 EXPECT_EQ(8U, mojo_params->size_suspicion_threshold);
29 EXPECT_EQ(11U, mojo_params->call_stack_suspicion_threshold);
30
31 // Convert Mojo struct back to protobuf.
32 MemoryLeakReportProto::Params new_params;
33 protobuf_to_mojo_converter::MojoToParams(*mojo_params, &new_params);
34
35 EXPECT_DOUBLE_EQ(0.75, new_params.sampling_rate());
36 EXPECT_EQ(19U, new_params.max_stack_depth());
37 EXPECT_EQ(25U * 1024 * 1024, new_params.analysis_interval_bytes());
38 EXPECT_EQ(8U, new_params.size_suspicion_threshold());
39 EXPECT_EQ(11U, new_params.call_stack_suspicion_threshold());
40 }
41
42 TEST(protobuf_to_mojo_converterTest, ConvertReport) {
43 MemoryLeakReportProto report;
44 report.add_call_stack(0xdeadbeef);
45 report.add_call_stack(0xc001d00d);
46 report.add_call_stack(0x900df00d);
47 report.set_size_bytes(24);
48
49 auto entry1 = report.add_alloc_breakdown_history();
50 entry1->add_counts_by_size(1);
51 entry1->add_counts_by_size(2);
52 entry1->add_counts_by_size(3);
53 entry1->set_count_for_call_stack(4);
54
55 auto entry2 = report.add_alloc_breakdown_history();
56 entry2->add_counts_by_size(11);
57 entry2->add_counts_by_size(12);
58 entry2->add_counts_by_size(13);
59 entry2->add_counts_by_size(14);
60 entry2->set_count_for_call_stack(15);
61
62 auto entry3 = report.add_alloc_breakdown_history();
63 entry3->add_counts_by_size(21);
64 entry3->add_counts_by_size(22);
65 entry3->add_counts_by_size(23);
66 entry3->add_counts_by_size(24);
67 entry3->add_counts_by_size(25);
68 entry3->set_count_for_call_stack(26);
69
70 // Convert to equivalent Mojo struct.
71 mojo::StructPtr<mojom::MemoryLeakReport> mojo_report =
72 mojom::MemoryLeakReport::New();
73 protobuf_to_mojo_converter::ReportToMojo(report, mojo_report.get());
74
75 ASSERT_EQ(3U, mojo_report->call_stack.size());
76 EXPECT_EQ(0xdeadbeef, mojo_report->call_stack[0]);
77 EXPECT_EQ(0xc001d00d, mojo_report->call_stack[1]);
78 EXPECT_EQ(0x900df00d, mojo_report->call_stack[2]);
79 EXPECT_EQ(24U, mojo_report->size_bytes);
80
81 ASSERT_EQ(3U, mojo_report->alloc_breakdown_history.size());
82
83 ASSERT_EQ(3U, mojo_report->alloc_breakdown_history[0]->counts_by_size.size());
84 EXPECT_EQ(1U, mojo_report->alloc_breakdown_history[0]->counts_by_size[0]);
85 EXPECT_EQ(2U, mojo_report->alloc_breakdown_history[0]->counts_by_size[1]);
86 EXPECT_EQ(3U, mojo_report->alloc_breakdown_history[0]->counts_by_size[2]);
87 EXPECT_EQ(4U, mojo_report->alloc_breakdown_history[0]->count_for_call_stack);
88
89 ASSERT_EQ(4U, mojo_report->alloc_breakdown_history[1]->counts_by_size.size());
90 EXPECT_EQ(11U, mojo_report->alloc_breakdown_history[1]->counts_by_size[0]);
91 EXPECT_EQ(12U, mojo_report->alloc_breakdown_history[1]->counts_by_size[1]);
92 EXPECT_EQ(13U, mojo_report->alloc_breakdown_history[1]->counts_by_size[2]);
93 EXPECT_EQ(14U, mojo_report->alloc_breakdown_history[1]->counts_by_size[3]);
94 EXPECT_EQ(15U, mojo_report->alloc_breakdown_history[1]->count_for_call_stack);
95
96 ASSERT_EQ(5U, mojo_report->alloc_breakdown_history[2]->counts_by_size.size());
97 EXPECT_EQ(21U, mojo_report->alloc_breakdown_history[2]->counts_by_size[0]);
98 EXPECT_EQ(22U, mojo_report->alloc_breakdown_history[2]->counts_by_size[1]);
99 EXPECT_EQ(23U, mojo_report->alloc_breakdown_history[2]->counts_by_size[2]);
100 EXPECT_EQ(24U, mojo_report->alloc_breakdown_history[2]->counts_by_size[3]);
101 EXPECT_EQ(25U, mojo_report->alloc_breakdown_history[2]->counts_by_size[4]);
102 EXPECT_EQ(26U, mojo_report->alloc_breakdown_history[2]->count_for_call_stack);
103
104 // Convert Mojo struct back to protobuf.
105 MemoryLeakReportProto new_report;
106 protobuf_to_mojo_converter::MojoToReport(*mojo_report, &new_report);
107
108 ASSERT_EQ(3, new_report.call_stack().size());
109 EXPECT_EQ(0xdeadbeef, new_report.call_stack(0));
110 EXPECT_EQ(0xc001d00d, new_report.call_stack(1));
111 EXPECT_EQ(0x900df00d, new_report.call_stack(2));
112 EXPECT_EQ(24U, new_report.size_bytes());
113
114 ASSERT_EQ(3, new_report.alloc_breakdown_history().size());
115
116 ASSERT_EQ(3, new_report.alloc_breakdown_history(0).counts_by_size().size());
117 EXPECT_EQ(1U, new_report.alloc_breakdown_history(0).counts_by_size(0));
118 EXPECT_EQ(2U, new_report.alloc_breakdown_history(0).counts_by_size(1));
119 EXPECT_EQ(3U, new_report.alloc_breakdown_history(0).counts_by_size(2));
120 EXPECT_EQ(4U, new_report.alloc_breakdown_history(0).count_for_call_stack());
121
122 ASSERT_EQ(4, new_report.alloc_breakdown_history(1).counts_by_size().size());
123 EXPECT_EQ(11U, new_report.alloc_breakdown_history(1).counts_by_size(0));
124 EXPECT_EQ(12U, new_report.alloc_breakdown_history(1).counts_by_size(1));
125 EXPECT_EQ(13U, new_report.alloc_breakdown_history(1).counts_by_size(2));
126 EXPECT_EQ(14U, new_report.alloc_breakdown_history(1).counts_by_size(3));
127 EXPECT_EQ(15U, new_report.alloc_breakdown_history(1).count_for_call_stack());
128
129 ASSERT_EQ(5, new_report.alloc_breakdown_history(2).counts_by_size().size());
130 EXPECT_EQ(21U, new_report.alloc_breakdown_history(2).counts_by_size(0));
131 EXPECT_EQ(22U, new_report.alloc_breakdown_history(2).counts_by_size(1));
132 EXPECT_EQ(23U, new_report.alloc_breakdown_history(2).counts_by_size(2));
133 EXPECT_EQ(24U, new_report.alloc_breakdown_history(2).counts_by_size(3));
134 EXPECT_EQ(25U, new_report.alloc_breakdown_history(2).counts_by_size(4));
135 EXPECT_EQ(26U, new_report.alloc_breakdown_history(2).count_for_call_stack());
136 }
137
138 } // namespace leak_detector
139 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/leak_detector/protobuf_to_mojo_converter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698