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

Side by Side Diff: chrome/browser/private_working_set_snapshot_win_unittest.cc

Issue 2098713003: Moved a bunch of win-specific files to the new win folder in chrome/browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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
OLDNEW
(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 "chrome/browser/private_working_set_snapshot.h"
6
7 #include <stddef.h>
8
9 #include "base/win/windows_version.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 using PrivateWorkingSetSnapshotWinTest = testing::Test;
13
14 TEST_F(PrivateWorkingSetSnapshotWinTest, FindPidSelfTest) {
15 // The Pdh APIs are supported on Windows XP and above, but the "Working Set -
16 // Private" counter that PrivateWorkingSetSnapshot depends on is not defined
17 // until Windows Vista and is not reliable until Windows 7. Early-out to avoid
18 // test failure.
19 if (base::win::GetVersion() <= base::win::VERSION_VISTA)
20 return;
21
22 // Sample this process.
23 base::ProcessId pid = base::GetCurrentProcId();
24
25 PrivateWorkingSetSnapshot private_ws_snapshot;
26
27 private_ws_snapshot.AddToMonitorList("unit_tests");
28 private_ws_snapshot.Sample();
29
30 size_t private_ws = private_ws_snapshot.GetPrivateWorkingSet(pid);
31 if (private_ws == 0) {
32 // The Pdh APIs which PrivateWorkingSetSnapshot depends on are flaky and
33 // sometimes (~5% of the time on win_chromium_rel_ng) give back a result of
34 // zero. This is handled seamlessly in task manager by falling back to the
35 // old calculations so it is not a critical failure. Checking for this case
36 // and skipping the test stops flaky-test failures.
37 return;
38 }
39
40 // Private working set is difficult to predict but should be at least several
41 // MB. Initial tests show a value of 19+ MB depending on how many tests and
42 // processes are used. Anomalously small or large values would warrant
43 // investigation.
44 EXPECT_GT(private_ws, 2000000u);
45 // Check that the WS is less than 1500 MB. This is set very high to reduce the
46 // chance that unrelated changes could ever make this fail. This mostly just
47 // checks against some uncaught error that might return 0xFFFFFFFF. When run
48 // under Dr Memory the private working set was seen to be about 850 MB, which
49 // is why such a high threshold has been chosen.
50 EXPECT_LT(private_ws, 1500000000u);
51
52 // Allocate and touch a large block of memory (vector's constructor will zero
53 // every entry). This will increase the private working set.
54 const size_t alloc_size = 10000000;
55 std::vector<char> big_memory(alloc_size);
56
57 size_t private_ws2 = private_ws_snapshot.GetPrivateWorkingSet(pid);
58 EXPECT_EQ(private_ws, private_ws2) << "GetPrivateWorkingSet should be "
59 "consistent until the next call to "
60 "Sample()";
61
62 private_ws_snapshot.Sample();
63 size_t private_ws3 = private_ws_snapshot.GetPrivateWorkingSet(pid);
64 EXPECT_GT(private_ws3, private_ws2 + alloc_size / 2)
65 << "GetPrivateWorkingSet should increase as we allocate more memory";
66 }
OLDNEW
« no previous file with comments | « chrome/browser/private_working_set_snapshot_win.cc ('k') | chrome/browser/process_singleton_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698