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

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

Issue 2648423006: Fix ExhaustMemory on clang. (Closed)
Patch Set: fixes to tests 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 {
Ilya Sherman 2017/02/07 16:50:26 nit: Please leave a blank space after this line.
Will Harris 2017/02/07 17:45:20 Done.
43 // Check specified histogram for a single bucket entry and then verify that the
44 // bucket entry contains a signal and the signal is |signal|.
45 void verifyRendererExitCodeIsSignal(const base::HistogramTester& hist_tester,
Ilya Sherman 2017/02/07 16:50:26 nit: Please spell out "histogram" rather than "his
Ilya Sherman 2017/02/07 16:50:26 nit: Please start this method with an Uppercase le
Will Harris 2017/02/07 17:45:20 Done.
Will Harris 2017/02/07 17:45:20 Done. Not sure how that happened... too much go in
46 int signal) {
47 const auto buckets = hist_tester.GetAllSamples("CrashExitCodes.Renderer");
48 EXPECT_EQ(1UL, buckets.size());
49 EXPECT_EQ(1, buckets[0].count);
50 int32_t exit_code = buckets[0].min;
Ilya Sherman 2017/02/07 16:50:26 Can you use hist_tester.ExpectUniqueSample() in pl
Will Harris 2017/02/07 17:45:20 yup I can't use the existing APIs because I need t
51 EXPECT_TRUE(WIFSIGNALED(exit_code));
52 EXPECT_EQ(signal, WTERMSIG(exit_code));
53 }
54
55 } // namespace
56 #endif // OS_MACOSX || OS_LINUX
57
31 class MetricsServiceBrowserTest : public InProcessBrowserTest { 58 class MetricsServiceBrowserTest : public InProcessBrowserTest {
32 public: 59 public:
33 void SetUpCommandLine(base::CommandLine* command_line) override { 60 void SetUpCommandLine(base::CommandLine* command_line) override {
34 // Enable the metrics service for testing (in recording-only mode). 61 // Enable the metrics service for testing (in recording-only mode).
35 command_line->AppendSwitch(switches::kMetricsRecordingOnly); 62 command_line->AppendSwitch(switches::kMetricsRecordingOnly);
36 } 63 }
37 64
38 // Open a couple of tabs of random content. 65 // Open a couple of tabs of random content.
39 void OpenTabs() { 66 void OpenTabs() {
40 const int kBrowserTestFlags = 67 const int kBrowserTestFlags =
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 99
73 // Flaky on Linux. See http://crbug.com/131094 100 // Flaky on Linux. See http://crbug.com/131094
74 // Child crashes fail the process on ASan (see crbug.com/411251, 101 // Child crashes fail the process on ASan (see crbug.com/411251,
75 // crbug.com/368525). 102 // crbug.com/368525).
76 #if defined(OS_LINUX) || defined(ADDRESS_SANITIZER) 103 #if defined(OS_LINUX) || defined(ADDRESS_SANITIZER)
77 #define MAYBE_CrashRenderers DISABLED_CrashRenderers 104 #define MAYBE_CrashRenderers DISABLED_CrashRenderers
78 #else 105 #else
79 #define MAYBE_CrashRenderers CrashRenderers 106 #define MAYBE_CrashRenderers CrashRenderers
80 #endif 107 #endif
81 IN_PROC_BROWSER_TEST_F(MetricsServiceBrowserTest, MAYBE_CrashRenderers) { 108 IN_PROC_BROWSER_TEST_F(MetricsServiceBrowserTest, MAYBE_CrashRenderers) {
109 base::HistogramTester hist_tester;
82 OpenTabs(); 110 OpenTabs();
83 111
84 // Kill the process for one of the tabs. 112 // Kill the process for one of the tabs.
85 content::RenderProcessHostWatcher observer( 113 content::RenderProcessHostWatcher observer(
86 browser()->tab_strip_model()->GetActiveWebContents(), 114 browser()->tab_strip_model()->GetActiveWebContents(),
87 content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); 115 content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
88 ui_test_utils::NavigateToURL(browser(), GURL(content::kChromeUICrashURL)); 116 ui_test_utils::NavigateToURL(browser(), GURL(content::kChromeUICrashURL));
89 observer.Wait(); 117 observer.Wait();
90 118
91 // The MetricsService listens for the same notification, so the |observer| 119 // The MetricsService listens for the same notification, so the |observer|
92 // might finish waiting before the MetricsService has a chance to process the 120 // might finish waiting before the MetricsService has a chance to process the
93 // notification. To avoid racing here, we repeatedly run the message loop 121 // notification. To avoid racing here, we repeatedly run the message loop
94 // until the MetricsService catches up. This should happen "real soon now", 122 // until the MetricsService catches up. This should happen "real soon now",
95 // since the notification is posted to all observers essentially 123 // since the notification is posted to all observers essentially
96 // simultaneously... so busy waiting here shouldn't be too bad. 124 // simultaneously... so busy waiting here shouldn't be too bad.
97 const PrefService* prefs = g_browser_process->local_state(); 125 const PrefService* prefs = g_browser_process->local_state();
98 while (!prefs->GetInteger(metrics::prefs::kStabilityRendererCrashCount)) { 126 while (!prefs->GetInteger(metrics::prefs::kStabilityRendererCrashCount)) {
99 content::RunAllPendingInMessageLoop(); 127 content::RunAllPendingInMessageLoop();
100 } 128 }
101 129
102 // Verify that the expected stability metrics were recorded. 130 // Verify that the expected stability metrics were recorded.
103 EXPECT_EQ(1, prefs->GetInteger(metrics::prefs::kStabilityLaunchCount)); 131 EXPECT_EQ(1, prefs->GetInteger(metrics::prefs::kStabilityLaunchCount));
104 EXPECT_EQ(4, prefs->GetInteger(metrics::prefs::kStabilityPageLoadCount)); 132 EXPECT_EQ(4, prefs->GetInteger(metrics::prefs::kStabilityPageLoadCount));
105 EXPECT_EQ(1, prefs->GetInteger(metrics::prefs::kStabilityRendererCrashCount)); 133 EXPECT_EQ(1, prefs->GetInteger(metrics::prefs::kStabilityRendererCrashCount));
106 // TODO(isherman): We should also verify that 134 // TODO(isherman): We should also verify that
107 // metrics::prefs::kStabilityExitedCleanly 135 // metrics::prefs::kStabilityExitedCleanly
108 // is set to true, but this preference isn't set until the browser 136 // 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. 137 // exits... it's not clear to me how to test that.
138
139 #if defined(OS_WIN)
140 hist_tester.ExpectUniqueSample(
141 "CrashExitCodes.Renderer",
142 std::abs(static_cast<int32_t>(STATUS_ACCESS_VIOLATION)), 1);
143 #elif defined(OS_MACOSX) || defined(OS_LINUX)
144 verifyRendererExitCodeIsSignal(hist_tester, SIGSEGV);
145 #endif
146 hist_tester.ExpectUniqueSample("Tabs.SadTab.CrashCreated", 1, 1);
110 } 147 }
111 148
149 // OOM code only works on Windows.
150 #if defined(OS_WIN) && !defined(ADDRESS_SANITIZER)
151 IN_PROC_BROWSER_TEST_F(MetricsServiceBrowserTest, OOMRenderers) {
152 base::HistogramTester hist_tester;
153 OpenTabs();
154
155 // Kill the process for one of the tabs.
156 content::RenderProcessHostWatcher observer(
157 browser()->tab_strip_model()->GetActiveWebContents(),
158 content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
159 ui_test_utils::NavigateToURL(browser(),
160 GURL(content::kChromeUIMemoryExhaustURL));
161 observer.Wait();
162
163 // The MetricsService listens for the same notification, so the |observer|
164 // might finish waiting before the MetricsService has a chance to process the
165 // notification. To avoid racing here, we repeatedly run the message loop
166 // until the MetricsService catches up. This should happen "real soon now",
167 // since the notification is posted to all observers essentially
168 // simultaneously... so busy waiting here shouldn't be too bad.
169 const PrefService* prefs = g_browser_process->local_state();
170 while (!prefs->GetInteger(metrics::prefs::kStabilityRendererCrashCount)) {
171 content::RunAllPendingInMessageLoop();
172 }
173
174 // Verify that the expected stability metrics were recorded.
175 EXPECT_EQ(1, prefs->GetInteger(metrics::prefs::kStabilityLaunchCount));
176 EXPECT_EQ(4, prefs->GetInteger(metrics::prefs::kStabilityPageLoadCount));
Ilya Sherman 2017/02/07 16:50:26 nit: Mebbe document where this page load count is
Will Harris 2017/02/07 17:45:20 Hmm this is copied from above :) tbh I'm not sure
177 EXPECT_EQ(1, prefs->GetInteger(metrics::prefs::kStabilityRendererCrashCount));
178
179 // On 64-bit, the Job object should terminate the renderer on an OOM.
180 #if defined(ARCH_CPU_64_BITS)
181 const int expected_exit_code = sandbox::SBOX_FATAL_MEMORY_EXCEEDED;
182 #else
183 const int expected_exit_code = base::win::kOomExceptionCode;
184 #endif
185
186 // Exit codes are recorded after being passed through std::abs see
187 // MapCrashExitCodeForHistogram.
188 hist_tester.ExpectUniqueSample("CrashExitCodes.Renderer",
189 std::abs(expected_exit_code), 1);
190
191 hist_tester.ExpectUniqueSample("Tabs.SadTab.OomCreated", 1, 1);
192 }
193 #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