Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "chrome/browser/chromeos/arc/process/arc_process.h" | 5 #include "chrome/browser/chromeos/arc/process/arc_process.h" |
| 6 | 6 |
| 7 #include <assert.h> | 7 #include <assert.h> |
| 8 #include <list> | 8 #include <list> |
| 9 | 9 |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 namespace arc { | 12 namespace arc { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 // Tests that ArcProcess objects can be sorted by their priority (higher to | 16 // Tests that ArcProcess objects can be sorted by their priority (higher to |
| 17 // lower). This is critical for the OOM handler to work correctly. | 17 // lower). This is critical for the OOM handler to work correctly. |
| 18 TEST(ArcProcess, TestSorting) { | 18 TEST(ArcProcess, TestSorting) { |
| 19 constexpr int64_t kNow = 1234567890; | 19 constexpr int64_t kNow = 1234567890; |
| 20 | 20 |
| 21 std::list<ArcProcess> processes; // use list<> for emplace_front. | 21 std::list<ArcProcess> processes; // use list<> for emplace_front. |
| 22 processes.emplace_back(0, 0, "process 0", mojom::ProcessState::PERSISTENT, | 22 processes.emplace_back(0, 0, "process 0", mojom::ProcessState::PERSISTENT, |
| 23 false /* is_foreground */, kNow + 1); | 23 false /* is_focused */, kNow + 1); |
|
Yusuke Sato
2017/05/09 22:54:35
fixed a typo, sorry.
| |
| 24 processes.emplace_front(1, 1, "process 1", mojom::ProcessState::PERSISTENT, | 24 processes.emplace_front(1, 1, "process 1", mojom::ProcessState::PERSISTENT, |
| 25 false, kNow); | 25 false, kNow); |
| 26 processes.emplace_back(2, 2, "process 2", mojom::ProcessState::LAST_ACTIVITY, | 26 processes.emplace_back(2, 2, "process 2", mojom::ProcessState::LAST_ACTIVITY, |
| 27 false, kNow); | 27 false, kNow); |
| 28 processes.emplace_front(3, 3, "process 3", mojom::ProcessState::LAST_ACTIVITY, | 28 processes.emplace_front(3, 3, "process 3", mojom::ProcessState::LAST_ACTIVITY, |
| 29 false, kNow + 1); | 29 false, kNow + 1); |
| 30 processes.emplace_back(4, 4, "process 4", mojom::ProcessState::CACHED_EMPTY, | 30 processes.emplace_back(4, 4, "process 4", mojom::ProcessState::CACHED_EMPTY, |
| 31 false, kNow + 1); | 31 false, kNow + 1); |
| 32 processes.emplace_front(5, 5, "process 5", mojom::ProcessState::CACHED_EMPTY, | 32 processes.emplace_front(5, 5, "process 5", mojom::ProcessState::CACHED_EMPTY, |
| 33 false, kNow); | 33 false, kNow); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 50 EXPECT_EQ(3, it->pid()); | 50 EXPECT_EQ(3, it->pid()); |
| 51 ++it; | 51 ++it; |
| 52 EXPECT_EQ(2, it->pid()); | 52 EXPECT_EQ(2, it->pid()); |
| 53 ++it; | 53 ++it; |
| 54 // Same, 4 should have higher priority. | 54 // Same, 4 should have higher priority. |
| 55 EXPECT_EQ(4, it->pid()); | 55 EXPECT_EQ(4, it->pid()); |
| 56 ++it; | 56 ++it; |
| 57 EXPECT_EQ(5, it->pid()); | 57 EXPECT_EQ(5, it->pid()); |
| 58 } | 58 } |
| 59 | 59 |
| 60 TEST(ArcProcess, TestIsUserVisible) { | |
| 61 constexpr bool kIsFocused = false; | |
| 62 | |
| 63 // Processes up to IMPORTANT_FOREGROUND are considered visible. | |
| 64 EXPECT_TRUE(ArcProcess(0, 0, "process", mojom::ProcessState::PERSISTENT, | |
| 65 kIsFocused, 0) | |
| 66 .IsUserVisible()); | |
| 67 EXPECT_TRUE(ArcProcess(0, 0, "process", mojom::ProcessState::PERSISTENT_UI, | |
| 68 kIsFocused, 0) | |
| 69 .IsUserVisible()); | |
| 70 EXPECT_TRUE(ArcProcess(0, 0, "process", mojom::ProcessState::TOP, true, 0) | |
| 71 .IsUserVisible()); | |
| 72 EXPECT_TRUE(ArcProcess(0, 0, "process", mojom::ProcessState::TOP, false, 0) | |
| 73 .IsUserVisible()); | |
| 74 EXPECT_TRUE(ArcProcess(0, 0, "process", | |
| 75 mojom::ProcessState::BOUND_FOREGROUND_SERVICE, | |
| 76 kIsFocused, 0) | |
| 77 .IsUserVisible()); | |
| 78 EXPECT_TRUE(ArcProcess(0, 0, "process", | |
| 79 mojom::ProcessState::FOREGROUND_SERVICE, kIsFocused, 0) | |
| 80 .IsUserVisible()); | |
| 81 EXPECT_TRUE(ArcProcess(0, 0, "process", mojom::ProcessState::TOP_SLEEPING, | |
| 82 kIsFocused, 0) | |
| 83 .IsUserVisible()); | |
| 84 EXPECT_TRUE(ArcProcess(0, 0, "process", | |
| 85 mojom::ProcessState::IMPORTANT_FOREGROUND, kIsFocused, | |
| 86 0) | |
| 87 .IsUserVisible()); | |
| 88 | |
| 89 // Others are non-visible. | |
| 90 EXPECT_FALSE(ArcProcess(0, 0, "process", | |
| 91 mojom::ProcessState::IMPORTANT_BACKGROUND, kIsFocused, | |
| 92 0) | |
| 93 .IsUserVisible()); | |
| 94 EXPECT_FALSE( | |
| 95 ArcProcess(0, 0, "process", mojom::ProcessState::BACKUP, kIsFocused, 0) | |
| 96 .IsUserVisible()); | |
| 97 EXPECT_FALSE(ArcProcess(0, 0, "process", mojom::ProcessState::HEAVY_WEIGHT, | |
| 98 kIsFocused, 0) | |
| 99 .IsUserVisible()); | |
| 100 EXPECT_FALSE( | |
| 101 ArcProcess(0, 0, "process", mojom::ProcessState::SERVICE, kIsFocused, 0) | |
| 102 .IsUserVisible()); | |
| 103 EXPECT_FALSE( | |
| 104 ArcProcess(0, 0, "process", mojom::ProcessState::RECEIVER, kIsFocused, 0) | |
| 105 .IsUserVisible()); | |
| 106 EXPECT_FALSE( | |
| 107 ArcProcess(0, 0, "process", mojom::ProcessState::HOME, kIsFocused, 0) | |
| 108 .IsUserVisible()); | |
| 109 EXPECT_FALSE(ArcProcess(0, 0, "process", mojom::ProcessState::LAST_ACTIVITY, | |
| 110 kIsFocused, 0) | |
| 111 .IsUserVisible()); | |
| 112 EXPECT_FALSE(ArcProcess(0, 0, "process", mojom::ProcessState::CACHED_ACTIVITY, | |
| 113 kIsFocused, 0) | |
| 114 .IsUserVisible()); | |
| 115 EXPECT_FALSE(ArcProcess(0, 0, "process", | |
| 116 mojom::ProcessState::CACHED_ACTIVITY_CLIENT, | |
| 117 kIsFocused, 0) | |
| 118 .IsUserVisible()); | |
| 119 EXPECT_FALSE(ArcProcess(0, 0, "process", mojom::ProcessState::CACHED_EMPTY, | |
| 120 kIsFocused, 0) | |
| 121 .IsUserVisible()); | |
| 122 | |
| 123 // Exceptions: the function always returns true ignoring ProcessState for our | |
| 124 // HOME process. | |
| 125 EXPECT_TRUE(ArcProcess(0, 0, "org.chromium.arc.home", | |
| 126 mojom::ProcessState::TOP, kIsFocused, 0) | |
| 127 .IsUserVisible()); | |
| 128 EXPECT_TRUE(ArcProcess(0, 0, "org.chromium.arc.home", | |
| 129 mojom::ProcessState::HOME, kIsFocused, 0) | |
| 130 .IsUserVisible()); | |
| 131 } | |
| 132 | |
| 133 TEST(ArcProcess, TestIsKillableForKernel) { | |
| 134 constexpr bool kIsFocused = false; | |
| 135 | |
| 136 // Only PERSISITENT* processes are protected from the kernel OOM killer. | |
| 137 EXPECT_FALSE(ArcProcess(0, 0, "process", mojom::ProcessState::PERSISTENT, | |
| 138 kIsFocused, 0) | |
| 139 .IsKillableForKernel()); | |
| 140 EXPECT_FALSE(ArcProcess(0, 0, "process", mojom::ProcessState::PERSISTENT_UI, | |
| 141 kIsFocused, 0) | |
| 142 .IsKillableForKernel()); | |
| 143 | |
| 144 // Both TOP+focused and TOP apps are still kernel-killable. | |
| 145 EXPECT_TRUE(ArcProcess(0, 0, "process", mojom::ProcessState::TOP, true, 0) | |
| 146 .IsKillableForKernel()); | |
| 147 EXPECT_TRUE(ArcProcess(0, 0, "process", mojom::ProcessState::TOP, false, 0) | |
| 148 .IsKillableForKernel()); | |
| 149 | |
| 150 // Others are kernel-killable. | |
| 151 EXPECT_TRUE(ArcProcess(0, 0, "process", | |
| 152 mojom::ProcessState::BOUND_FOREGROUND_SERVICE, | |
| 153 kIsFocused, 0) | |
| 154 .IsKillableForKernel()); | |
| 155 EXPECT_TRUE(ArcProcess(0, 0, "process", | |
| 156 mojom::ProcessState::FOREGROUND_SERVICE, kIsFocused, 0) | |
| 157 .IsKillableForKernel()); | |
| 158 EXPECT_TRUE(ArcProcess(0, 0, "process", mojom::ProcessState::TOP_SLEEPING, | |
| 159 kIsFocused, 0) | |
| 160 .IsKillableForKernel()); | |
| 161 EXPECT_TRUE(ArcProcess(0, 0, "process", | |
| 162 mojom::ProcessState::IMPORTANT_FOREGROUND, kIsFocused, | |
| 163 0) | |
| 164 .IsKillableForKernel()); | |
| 165 EXPECT_TRUE(ArcProcess(0, 0, "process", | |
| 166 mojom::ProcessState::IMPORTANT_BACKGROUND, kIsFocused, | |
| 167 0) | |
| 168 .IsKillableForKernel()); | |
| 169 EXPECT_TRUE( | |
| 170 ArcProcess(0, 0, "process", mojom::ProcessState::BACKUP, kIsFocused, 0) | |
| 171 .IsKillableForKernel()); | |
| 172 EXPECT_TRUE(ArcProcess(0, 0, "process", mojom::ProcessState::HEAVY_WEIGHT, | |
| 173 kIsFocused, 0) | |
| 174 .IsKillableForKernel()); | |
| 175 EXPECT_TRUE( | |
| 176 ArcProcess(0, 0, "process", mojom::ProcessState::SERVICE, kIsFocused, 0) | |
| 177 .IsKillableForKernel()); | |
| 178 EXPECT_TRUE( | |
| 179 ArcProcess(0, 0, "process", mojom::ProcessState::RECEIVER, kIsFocused, 0) | |
| 180 .IsKillableForKernel()); | |
| 181 EXPECT_TRUE( | |
| 182 ArcProcess(0, 0, "process", mojom::ProcessState::HOME, kIsFocused, 0) | |
| 183 .IsKillableForKernel()); | |
| 184 EXPECT_TRUE(ArcProcess(0, 0, "process", mojom::ProcessState::LAST_ACTIVITY, | |
| 185 kIsFocused, 0) | |
| 186 .IsKillableForKernel()); | |
| 187 EXPECT_TRUE(ArcProcess(0, 0, "process", mojom::ProcessState::CACHED_ACTIVITY, | |
| 188 kIsFocused, 0) | |
| 189 .IsKillableForKernel()); | |
| 190 EXPECT_TRUE(ArcProcess(0, 0, "process", | |
| 191 mojom::ProcessState::CACHED_ACTIVITY_CLIENT, | |
| 192 kIsFocused, 0) | |
| 193 .IsKillableForKernel()); | |
| 194 EXPECT_TRUE(ArcProcess(0, 0, "process", mojom::ProcessState::CACHED_EMPTY, | |
| 195 kIsFocused, 0) | |
| 196 .IsKillableForKernel()); | |
| 197 | |
| 198 // Exceptions: the function always returns false ignoring ProcessState for our | |
| 199 // HOME process. | |
| 200 EXPECT_FALSE(ArcProcess(0, 0, "org.chromium.arc.home", | |
| 201 mojom::ProcessState::TOP, kIsFocused, 0) | |
| 202 .IsKillableForKernel()); | |
| 203 EXPECT_FALSE(ArcProcess(0, 0, "org.chromium.arc.home", | |
| 204 mojom::ProcessState::HOME, kIsFocused, 0) | |
| 205 .IsKillableForKernel()); | |
| 206 } | |
| 207 | |
| 60 } // namespace | 208 } // namespace |
| 61 | 209 |
| 62 } // namespace arc | 210 } // namespace arc |
| OLD | NEW |