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

Side by Side Diff: chrome/browser/metrics/metrics_service_browsertest.cc

Issue 2648423006: Fix ExhaustMemory on clang. (Closed)
Patch Set: add comment, fix issue Created 3 years, 10 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 | « no previous file | content/renderer/render_frame_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Tests the MetricsService stat recording to make sure that the numbers are 5 // Tests the MetricsService stat recording to make sure that the numbers are
6 // what we expect. 6 // what we expect.
7 7
8 #include "components/metrics/metrics_service.h" 8 #include "components/metrics/metrics_service.h"
9 9
10 #include <string> 10 #include <string>
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/process/memory.h"
16 #include "base/test/histogram_tester.h"
15 #include "build/build_config.h" 17 #include "build/build_config.h"
16 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" 20 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/common/chrome_paths.h" 21 #include "chrome/common/chrome_paths.h"
20 #include "chrome/common/chrome_switches.h" 22 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/url_constants.h" 23 #include "chrome/common/url_constants.h"
22 #include "chrome/test/base/in_process_browser_test.h" 24 #include "chrome/test/base/in_process_browser_test.h"
23 #include "chrome/test/base/ui_test_utils.h" 25 #include "chrome/test/base/ui_test_utils.h"
24 #include "components/metrics/metrics_pref_names.h" 26 #include "components/metrics/metrics_pref_names.h"
25 #include "components/prefs/pref_service.h" 27 #include "components/prefs/pref_service.h"
26 #include "content/public/test/browser_test_utils.h" 28 #include "content/public/test/browser_test_utils.h"
27 #include "net/base/filename_util.h" 29 #include "net/base/filename_util.h"
28 #include "ui/base/window_open_disposition.h" 30 #include "ui/base/window_open_disposition.h"
29 #include "url/gurl.h" 31 #include "url/gurl.h"
30 32
33 #if defined(OS_POSIX)
34 #include <sys/wait.h>
35 #endif
36
37 #if defined(OS_WIN)
38 #include "sandbox/win/src/sandbox_types.h"
39 #endif
40
41 #if defined(OS_MACOSX) || defined(OS_LINUX)
42 namespace {
43
44 // Check CrashExitCodes.Renderer histogram for a single bucket entry and then
45 // verify that the bucket entry contains a signal and the signal is |signal|.
46 void VerifyRendererExitCodeIsSignal(
47 const base::HistogramTester& histogram_tester,
48 int signal) {
49 const auto buckets =
50 histogram_tester.GetAllSamples("CrashExitCodes.Renderer");
51 EXPECT_EQ(1UL, buckets.size());
Ilya Sherman 2017/02/07 19:40:22 nit: This should be an ASSERT_EQ, since you index
Will Harris 2017/02/13 19:24:22 Done. ASSERT halts the test, while EXPECT doesn't
Ilya Sherman 2017/02/13 19:27:20 Yep -- what I meant is: Is it really worth having
52 EXPECT_EQ(1, buckets[0].count);
53 int32_t exit_code = buckets[0].min;
54 EXPECT_TRUE(WIFSIGNALED(exit_code));
55 EXPECT_EQ(signal, WTERMSIG(exit_code));
56 }
57
58 } // namespace
59 #endif // OS_MACOSX || OS_LINUX
60
31 class MetricsServiceBrowserTest : public InProcessBrowserTest { 61 class MetricsServiceBrowserTest : public InProcessBrowserTest {
32 public: 62 public:
33 void SetUpCommandLine(base::CommandLine* command_line) override { 63 void SetUpCommandLine(base::CommandLine* command_line) override {
34 // Enable the metrics service for testing (in recording-only mode). 64 // Enable the metrics service for testing (in recording-only mode).
35 command_line->AppendSwitch(switches::kMetricsRecordingOnly); 65 command_line->AppendSwitch(switches::kMetricsRecordingOnly);
36 } 66 }
37 67
38 // Open a couple of tabs of random content. 68 // Open a couple of tabs of random content.
39 void OpenTabs() { 69 void OpenTabs() {
40 const int kBrowserTestFlags = 70 const int kBrowserTestFlags =
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 102
73 // Flaky on Linux. See http://crbug.com/131094 103 // Flaky on Linux. See http://crbug.com/131094
74 // Child crashes fail the process on ASan (see crbug.com/411251, 104 // Child crashes fail the process on ASan (see crbug.com/411251,
75 // crbug.com/368525). 105 // crbug.com/368525).
76 #if defined(OS_LINUX) || defined(ADDRESS_SANITIZER) 106 #if defined(OS_LINUX) || defined(ADDRESS_SANITIZER)
77 #define MAYBE_CrashRenderers DISABLED_CrashRenderers 107 #define MAYBE_CrashRenderers DISABLED_CrashRenderers
78 #else 108 #else
79 #define MAYBE_CrashRenderers CrashRenderers 109 #define MAYBE_CrashRenderers CrashRenderers
80 #endif 110 #endif
81 IN_PROC_BROWSER_TEST_F(MetricsServiceBrowserTest, MAYBE_CrashRenderers) { 111 IN_PROC_BROWSER_TEST_F(MetricsServiceBrowserTest, MAYBE_CrashRenderers) {
112 base::HistogramTester hist_tester;
Ilya Sherman 2017/02/07 19:40:22 nit: s/hist/histogram (and below, too).
Will Harris 2017/02/13 19:24:22 Done.
82 OpenTabs(); 113 OpenTabs();
83 114
84 // Kill the process for one of the tabs. 115 // Kill the process for one of the tabs.
85 content::RenderProcessHostWatcher observer( 116 content::RenderProcessHostWatcher observer(
86 browser()->tab_strip_model()->GetActiveWebContents(), 117 browser()->tab_strip_model()->GetActiveWebContents(),
87 content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); 118 content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
88 ui_test_utils::NavigateToURL(browser(), GURL(content::kChromeUICrashURL)); 119 ui_test_utils::NavigateToURL(browser(), GURL(content::kChromeUICrashURL));
89 observer.Wait(); 120 observer.Wait();
90 121
91 // The MetricsService listens for the same notification, so the |observer| 122 // The MetricsService listens for the same notification, so the |observer|
92 // might finish waiting before the MetricsService has a chance to process the 123 // might finish waiting before the MetricsService has a chance to process the
93 // notification. To avoid racing here, we repeatedly run the message loop 124 // notification. To avoid racing here, we repeatedly run the message loop
94 // until the MetricsService catches up. This should happen "real soon now", 125 // until the MetricsService catches up. This should happen "real soon now",
95 // since the notification is posted to all observers essentially 126 // since the notification is posted to all observers essentially
96 // simultaneously... so busy waiting here shouldn't be too bad. 127 // simultaneously... so busy waiting here shouldn't be too bad.
97 const PrefService* prefs = g_browser_process->local_state(); 128 const PrefService* prefs = g_browser_process->local_state();
98 while (!prefs->GetInteger(metrics::prefs::kStabilityRendererCrashCount)) { 129 while (!prefs->GetInteger(metrics::prefs::kStabilityRendererCrashCount)) {
99 content::RunAllPendingInMessageLoop(); 130 content::RunAllPendingInMessageLoop();
100 } 131 }
101 132
102 // Verify that the expected stability metrics were recorded. 133 // Verify that the expected stability metrics were recorded.
103 EXPECT_EQ(1, prefs->GetInteger(metrics::prefs::kStabilityLaunchCount)); 134 EXPECT_EQ(1, prefs->GetInteger(metrics::prefs::kStabilityLaunchCount));
135 // Expect four page loads:
136 // 1. title2.html
137 // 2. iframe.html
138 // 3. title1.html (iframed by iframe.html)
139 // 4. chrome://crash
104 EXPECT_EQ(4, prefs->GetInteger(metrics::prefs::kStabilityPageLoadCount)); 140 EXPECT_EQ(4, prefs->GetInteger(metrics::prefs::kStabilityPageLoadCount));
105 EXPECT_EQ(1, prefs->GetInteger(metrics::prefs::kStabilityRendererCrashCount)); 141 EXPECT_EQ(1, prefs->GetInteger(metrics::prefs::kStabilityRendererCrashCount));
106 // TODO(isherman): We should also verify that 142 // TODO(isherman): We should also verify that
107 // metrics::prefs::kStabilityExitedCleanly 143 // metrics::prefs::kStabilityExitedCleanly
108 // is set to true, but this preference isn't set until the browser 144 // is set to true, but this preference isn't set until the browser
109 // exits... it's not clear to me how to test that. 145 // exits... it's not clear to me how to test that.
146
147 #if defined(OS_WIN)
148 hist_tester.ExpectUniqueSample(
149 "CrashExitCodes.Renderer",
150 std::abs(static_cast<int32_t>(STATUS_ACCESS_VIOLATION)), 1);
151 #elif defined(OS_MACOSX) || defined(OS_LINUX)
152 VerifyRendererExitCodeIsSignal(hist_tester, SIGSEGV);
153 #endif
154 hist_tester.ExpectUniqueSample("Tabs.SadTab.CrashCreated", 1, 1);
110 } 155 }
111 156
157 // OOM code only works on Windows.
158 #if defined(OS_WIN) && !defined(ADDRESS_SANITIZER)
159 IN_PROC_BROWSER_TEST_F(MetricsServiceBrowserTest, OOMRenderers) {
160 base::HistogramTester hist_tester;
161 OpenTabs();
162
163 // Kill the process for one of the tabs.
164 content::RenderProcessHostWatcher observer(
165 browser()->tab_strip_model()->GetActiveWebContents(),
166 content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
167 ui_test_utils::NavigateToURL(browser(),
168 GURL(content::kChromeUIMemoryExhaustURL));
169 observer.Wait();
170
171 // The MetricsService listens for the same notification, so the |observer|
172 // might finish waiting before the MetricsService has a chance to process the
173 // notification. To avoid racing here, we repeatedly run the message loop
174 // until the MetricsService catches up. This should happen "real soon now",
175 // since the notification is posted to all observers essentially
176 // simultaneously... so busy waiting here shouldn't be too bad.
177 const PrefService* prefs = g_browser_process->local_state();
178 while (!prefs->GetInteger(metrics::prefs::kStabilityRendererCrashCount)) {
179 content::RunAllPendingInMessageLoop();
180 }
181
182 // Verify that the expected stability metrics were recorded.
183 EXPECT_EQ(1, prefs->GetInteger(metrics::prefs::kStabilityLaunchCount));
184 EXPECT_EQ(4, prefs->GetInteger(metrics::prefs::kStabilityPageLoadCount));
185 EXPECT_EQ(1, prefs->GetInteger(metrics::prefs::kStabilityRendererCrashCount));
186
187 // On 64-bit, the Job object should terminate the renderer on an OOM.
188 #if defined(ARCH_CPU_64_BITS)
189 const int expected_exit_code = sandbox::SBOX_FATAL_MEMORY_EXCEEDED;
190 #else
191 const int expected_exit_code = base::win::kOomExceptionCode;
192 #endif
193
194 // Exit codes are recorded after being passed through std::abs see
195 // MapCrashExitCodeForHistogram.
196 hist_tester.ExpectUniqueSample("CrashExitCodes.Renderer",
197 std::abs(expected_exit_code), 1);
198
199 hist_tester.ExpectUniqueSample("Tabs.SadTab.OomCreated", 1, 1);
200 }
201 #endif // OS_WIN && !ADDRESS_SANITIZER
OLDNEW
« no previous file with comments | « no previous file | content/renderer/render_frame_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698