OLD | NEW |
(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 "base/win/windows_version.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 using PrivateWorkingSetSnapshotWinTest = testing::Test; |
| 11 |
| 12 TEST_F(PrivateWorkingSetSnapshotWinTest, FindPidSelfTest) { |
| 13 // The Pdh APIs are supported on Windows XP and above, but the "Working Set - |
| 14 // Private" counter that PrivateWorkingSetSnapshot depends on is not defined |
| 15 // until Windows Vista and is not reliable until Windows 7. Early-out to avoid |
| 16 // test failure. |
| 17 if (base::win::GetVersion() <= base::win::VERSION_VISTA) |
| 18 return; |
| 19 |
| 20 // Sample this process. |
| 21 base::ProcessId pid = base::GetCurrentProcId(); |
| 22 |
| 23 PrivateWorkingSetSnapshot private_ws_snapshot; |
| 24 |
| 25 private_ws_snapshot.AddToMonitorList("unit_tests"); |
| 26 private_ws_snapshot.Sample(); |
| 27 |
| 28 size_t private_ws = private_ws_snapshot.GetPrivateWorkingSet(pid); |
| 29 // Private working set is difficult to predict but should be at least several |
| 30 // MB. Initial tests show a value of 19+ MB depending on how many tests and |
| 31 // processes are used. Anomalously small or large values would warrant |
| 32 // investigation. |
| 33 EXPECT_GT(private_ws, 2000000u); |
| 34 // Check that the WS is less than 1500 MB. This is set very high to reduce the |
| 35 // chance that unrelated changes could ever make this fail. This mostly just |
| 36 // checks against some uncaught error that might return 0xFFFFFFFF. When run |
| 37 // under Dr Memory the private working set was seen to be about 850 MB, which |
| 38 // is why such a high threshold has been chosen. |
| 39 EXPECT_LT(private_ws, 1500000000u); |
| 40 |
| 41 // Allocate and touch a large block of memory (vector's constructor will zero |
| 42 // every entry). This will increase the private working set. |
| 43 const size_t alloc_size = 10000000; |
| 44 std::vector<char> big_memory(alloc_size); |
| 45 |
| 46 size_t private_ws2 = private_ws_snapshot.GetPrivateWorkingSet(pid); |
| 47 EXPECT_EQ(private_ws, private_ws2) << "GetPrivateWorkingSet should be " |
| 48 "consistent until the next call to " |
| 49 "Sample()"; |
| 50 |
| 51 private_ws_snapshot.Sample(); |
| 52 size_t private_ws3 = private_ws_snapshot.GetPrivateWorkingSet(pid); |
| 53 EXPECT_GT(private_ws3, private_ws2 + alloc_size / 2) |
| 54 << "GetPrivateWorkingSet should increase as we allocate more memory"; |
| 55 } |
OLD | NEW |