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

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

Issue 2403223002: Leak reports collect information about the last uptrend (Closed)
Patch Set: Created 4 years, 2 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 "components/metrics/leak_detector/protobuf_to_mojo_converter.h" 5 #include "components/metrics/leak_detector/protobuf_to_mojo_converter.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 namespace metrics { 9 namespace metrics {
10 namespace leak_detector { 10 namespace leak_detector {
(...skipping 27 matching lines...) Expand all
38 EXPECT_EQ(8U, new_params.size_suspicion_threshold()); 38 EXPECT_EQ(8U, new_params.size_suspicion_threshold());
39 EXPECT_EQ(11U, new_params.call_stack_suspicion_threshold()); 39 EXPECT_EQ(11U, new_params.call_stack_suspicion_threshold());
40 } 40 }
41 41
42 TEST(protobuf_to_mojo_converterTest, ConvertReport) { 42 TEST(protobuf_to_mojo_converterTest, ConvertReport) {
43 MemoryLeakReportProto report; 43 MemoryLeakReportProto report;
44 report.add_call_stack(0xdeadbeef); 44 report.add_call_stack(0xdeadbeef);
45 report.add_call_stack(0xc001d00d); 45 report.add_call_stack(0xc001d00d);
46 report.add_call_stack(0x900df00d); 46 report.add_call_stack(0x900df00d);
47 report.set_size_bytes(24); 47 report.set_size_bytes(24);
48 report.set_num_rising_intervals(5);
49 report.set_num_allocs_increase(42);
48 50
49 auto entry1 = report.add_alloc_breakdown_history(); 51 auto entry1 = report.add_alloc_breakdown_history();
50 entry1->add_counts_by_size(1); 52 entry1->add_counts_by_size(1);
51 entry1->add_counts_by_size(2); 53 entry1->add_counts_by_size(2);
52 entry1->add_counts_by_size(3); 54 entry1->add_counts_by_size(3);
53 entry1->set_count_for_call_stack(4); 55 entry1->set_count_for_call_stack(4);
54 56
55 auto entry2 = report.add_alloc_breakdown_history(); 57 auto entry2 = report.add_alloc_breakdown_history();
56 entry2->add_counts_by_size(11); 58 entry2->add_counts_by_size(11);
57 entry2->add_counts_by_size(12); 59 entry2->add_counts_by_size(12);
(...skipping 12 matching lines...) Expand all
70 // Convert to equivalent Mojo struct. 72 // Convert to equivalent Mojo struct.
71 mojo::StructPtr<mojom::MemoryLeakReport> mojo_report = 73 mojo::StructPtr<mojom::MemoryLeakReport> mojo_report =
72 mojom::MemoryLeakReport::New(); 74 mojom::MemoryLeakReport::New();
73 protobuf_to_mojo_converter::ReportToMojo(report, mojo_report.get()); 75 protobuf_to_mojo_converter::ReportToMojo(report, mojo_report.get());
74 76
75 ASSERT_EQ(3U, mojo_report->call_stack.size()); 77 ASSERT_EQ(3U, mojo_report->call_stack.size());
76 EXPECT_EQ(0xdeadbeef, mojo_report->call_stack[0]); 78 EXPECT_EQ(0xdeadbeef, mojo_report->call_stack[0]);
77 EXPECT_EQ(0xc001d00d, mojo_report->call_stack[1]); 79 EXPECT_EQ(0xc001d00d, mojo_report->call_stack[1]);
78 EXPECT_EQ(0x900df00d, mojo_report->call_stack[2]); 80 EXPECT_EQ(0x900df00d, mojo_report->call_stack[2]);
79 EXPECT_EQ(24U, mojo_report->size_bytes); 81 EXPECT_EQ(24U, mojo_report->size_bytes);
82 EXPECT_EQ(5U, mojo_report->num_rising_intervals);
83 EXPECT_EQ(42U, mojo_report->num_allocs_increase);
80 84
81 ASSERT_EQ(3U, mojo_report->alloc_breakdown_history.size()); 85 ASSERT_EQ(3U, mojo_report->alloc_breakdown_history.size());
82 86
83 ASSERT_EQ(3U, mojo_report->alloc_breakdown_history[0]->counts_by_size.size()); 87 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]); 88 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]); 89 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]); 90 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); 91 EXPECT_EQ(4U, mojo_report->alloc_breakdown_history[0]->count_for_call_stack);
88 92
89 ASSERT_EQ(4U, mojo_report->alloc_breakdown_history[1]->counts_by_size.size()); 93 ASSERT_EQ(4U, mojo_report->alloc_breakdown_history[1]->counts_by_size.size());
(...skipping 13 matching lines...) Expand all
103 107
104 // Convert Mojo struct back to protobuf. 108 // Convert Mojo struct back to protobuf.
105 MemoryLeakReportProto new_report; 109 MemoryLeakReportProto new_report;
106 protobuf_to_mojo_converter::MojoToReport(*mojo_report, &new_report); 110 protobuf_to_mojo_converter::MojoToReport(*mojo_report, &new_report);
107 111
108 ASSERT_EQ(3, new_report.call_stack().size()); 112 ASSERT_EQ(3, new_report.call_stack().size());
109 EXPECT_EQ(0xdeadbeef, new_report.call_stack(0)); 113 EXPECT_EQ(0xdeadbeef, new_report.call_stack(0));
110 EXPECT_EQ(0xc001d00d, new_report.call_stack(1)); 114 EXPECT_EQ(0xc001d00d, new_report.call_stack(1));
111 EXPECT_EQ(0x900df00d, new_report.call_stack(2)); 115 EXPECT_EQ(0x900df00d, new_report.call_stack(2));
112 EXPECT_EQ(24U, new_report.size_bytes()); 116 EXPECT_EQ(24U, new_report.size_bytes());
117 EXPECT_EQ(5U, new_report.num_rising_intervals());
118 EXPECT_EQ(42U, new_report.num_allocs_increase());
113 119
114 ASSERT_EQ(3, new_report.alloc_breakdown_history().size()); 120 ASSERT_EQ(3, new_report.alloc_breakdown_history().size());
115 121
116 ASSERT_EQ(3, new_report.alloc_breakdown_history(0).counts_by_size().size()); 122 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)); 123 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)); 124 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)); 125 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()); 126 EXPECT_EQ(4U, new_report.alloc_breakdown_history(0).count_for_call_stack());
121 127
122 ASSERT_EQ(4, new_report.alloc_breakdown_history(1).counts_by_size().size()); 128 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)); 129 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)); 130 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)); 131 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)); 132 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()); 133 EXPECT_EQ(15U, new_report.alloc_breakdown_history(1).count_for_call_stack());
128 134
129 ASSERT_EQ(5, new_report.alloc_breakdown_history(2).counts_by_size().size()); 135 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)); 136 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)); 137 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)); 138 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)); 139 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)); 140 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()); 141 EXPECT_EQ(26U, new_report.alloc_breakdown_history(2).count_for_call_stack());
136 } 142 }
137 143
138 } // namespace leak_detector 144 } // namespace leak_detector
139 } // namespace metrics 145 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698