Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 1 | /* |
Ronghua Wu | 67e7f54 | 2015-03-13 10:47:08 -0700 | [diff] [blame] | 2 | * Copyright 2015 The Android Open Source Project |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | //#define LOG_NDEBUG 0 |
| 18 | #define LOG_TAG "ResourceManagerService_test" |
Chong Zhang | a9d45c7 | 2020-09-09 12:41:17 -0700 | [diff] [blame] | 19 | |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 20 | #include <utils/Log.h> |
| 21 | |
Chong Zhang | a9d45c7 | 2020-09-09 12:41:17 -0700 | [diff] [blame] | 22 | #include "ResourceManagerServiceTestUtils.h" |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 23 | #include "ResourceManagerService.h" |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 24 | |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 25 | namespace android { |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 26 | |
Chong Zhang | a9d45c7 | 2020-09-09 12:41:17 -0700 | [diff] [blame] | 27 | class ResourceManagerServiceTest : public ResourceManagerServiceTestBase { |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 28 | private: |
| 29 | static MediaResource createSecureVideoCodecResource(int amount = 1) { |
| 30 | return MediaResource(MediaResource::Type::kSecureCodec, |
| 31 | MediaResource::SubType::kVideoCodec, amount); |
| 32 | } |
| 33 | |
| 34 | static MediaResource createNonSecureVideoCodecResource(int amount = 1) { |
| 35 | return MediaResource(MediaResource::Type::kNonSecureCodec, |
| 36 | MediaResource::SubType::kVideoCodec, amount); |
| 37 | } |
| 38 | |
| 39 | static MediaResource createSecureAudioCodecResource(int amount = 1) { |
| 40 | return MediaResource(MediaResource::Type::kSecureCodec, |
| 41 | MediaResource::SubType::kAudioCodec, amount); |
| 42 | } |
| 43 | |
| 44 | static MediaResource createNonSecureAudioCodecResource(int amount = 1) { |
| 45 | return MediaResource(MediaResource::Type::kNonSecureCodec, |
| 46 | MediaResource::SubType::kAudioCodec, amount); |
| 47 | } |
| 48 | |
| 49 | static MediaResource createSecureImageCodecResource(int amount = 1) { |
| 50 | return MediaResource(MediaResource::Type::kSecureCodec, |
| 51 | MediaResource::SubType::kImageCodec, amount); |
| 52 | } |
| 53 | |
| 54 | static MediaResource createNonSecureImageCodecResource(int amount = 1) { |
| 55 | return MediaResource(MediaResource::Type::kNonSecureCodec, |
| 56 | MediaResource::SubType::kImageCodec, amount); |
| 57 | } |
| 58 | |
| 59 | static MediaResource createGraphicMemoryResource(int amount = 1) { |
| 60 | return MediaResource(MediaResource::Type::kGraphicMemory, |
| 61 | MediaResource::SubType::kUnspecifiedSubType, amount); |
| 62 | } |
| 63 | |
| 64 | static MediaResource createDrmSessionResource(int amount = 1) { |
| 65 | return MediaResource(MediaResource::Type::kDrmSession, |
| 66 | MediaResource::SubType::kUnspecifiedSubType, amount); |
| 67 | } |
| 68 | |
| 69 | static MediaResource createBatteryResource() { |
| 70 | return MediaResource(MediaResource::Type::kBattery, |
| 71 | MediaResource::SubType::kUnspecifiedSubType, 1); |
| 72 | } |
| 73 | |
| 74 | static MediaResource createCpuBoostResource() { |
| 75 | return MediaResource(MediaResource::Type::kCpuBoost, |
| 76 | MediaResource::SubType::kUnspecifiedSubType, 1); |
| 77 | } |
| 78 | |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 79 | public: |
Chong Zhang | a9d45c7 | 2020-09-09 12:41:17 -0700 | [diff] [blame] | 80 | ResourceManagerServiceTest() : ResourceManagerServiceTestBase() {} |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 81 | |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 82 | |
Ronghua Wu | 67e7f54 | 2015-03-13 10:47:08 -0700 | [diff] [blame] | 83 | // test set up |
| 84 | // --------------------------------------------------------------------------------- |
| 85 | // pid priority client type number |
| 86 | // --------------------------------------------------------------------------------- |
| 87 | // kTestPid1(30) 30 mTestClient1 secure codec 1 |
| 88 | // graphic memory 200 |
| 89 | // graphic memory 200 |
| 90 | // --------------------------------------------------------------------------------- |
| 91 | // kTestPid2(20) 20 mTestClient2 non-secure codec 1 |
| 92 | // graphic memory 300 |
| 93 | // ------------------------------------------- |
| 94 | // mTestClient3 secure codec 1 |
| 95 | // graphic memory 100 |
| 96 | // --------------------------------------------------------------------------------- |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 97 | void addResource() { |
| 98 | // kTestPid1 mTestClient1 |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 99 | std::vector<MediaResourceParcel> resources1; |
| 100 | resources1.push_back(MediaResource(MediaResource::Type::kSecureCodec, 1)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 101 | ClientInfoParcel client1Info{.pid = static_cast<int32_t>(kTestPid1), |
| 102 | .uid = static_cast<int32_t>(kTestUid1), |
| 103 | .id = getId(mTestClient1), |
| 104 | .name = "none"}; |
| 105 | mService->addResource(client1Info, mTestClient1, resources1); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 106 | resources1.push_back(MediaResource(MediaResource::Type::kGraphicMemory, 200)); |
| 107 | std::vector<MediaResourceParcel> resources11; |
| 108 | resources11.push_back(MediaResource(MediaResource::Type::kGraphicMemory, 200)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 109 | mService->addResource(client1Info, mTestClient1, resources11); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 110 | |
| 111 | // kTestPid2 mTestClient2 |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 112 | std::vector<MediaResourceParcel> resources2; |
| 113 | resources2.push_back(MediaResource(MediaResource::Type::kNonSecureCodec, 1)); |
| 114 | resources2.push_back(MediaResource(MediaResource::Type::kGraphicMemory, 300)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 115 | ClientInfoParcel client2Info{.pid = static_cast<int32_t>(kTestPid2), |
| 116 | .uid = static_cast<int32_t>(kTestUid2), |
| 117 | .id = getId(mTestClient2), |
| 118 | .name = "none"}; |
| 119 | mService->addResource(client2Info, mTestClient2, resources2); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 120 | |
| 121 | // kTestPid2 mTestClient3 |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 122 | std::vector<MediaResourceParcel> resources3; |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 123 | ClientInfoParcel client3Info{.pid = static_cast<int32_t>(kTestPid2), |
| 124 | .uid = static_cast<int32_t>(kTestUid2), |
| 125 | .id = getId(mTestClient3), |
| 126 | .name = "none"}; |
| 127 | mService->addResource(client3Info, mTestClient3, resources3); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 128 | resources3.push_back(MediaResource(MediaResource::Type::kSecureCodec, 1)); |
| 129 | resources3.push_back(MediaResource(MediaResource::Type::kGraphicMemory, 100)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 130 | mService->addResource(client3Info, mTestClient3, resources3); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 131 | |
| 132 | const PidResourceInfosMap &map = mService->mMap; |
| 133 | EXPECT_EQ(2u, map.size()); |
| 134 | ssize_t index1 = map.indexOfKey(kTestPid1); |
| 135 | ASSERT_GE(index1, 0); |
| 136 | const ResourceInfos &infos1 = map[index1]; |
| 137 | EXPECT_EQ(1u, infos1.size()); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 138 | expectEqResourceInfo(infos1.valueFor(getId(mTestClient1)), kTestUid1, mTestClient1, resources1); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 139 | |
| 140 | ssize_t index2 = map.indexOfKey(kTestPid2); |
| 141 | ASSERT_GE(index2, 0); |
| 142 | const ResourceInfos &infos2 = map[index2]; |
| 143 | EXPECT_EQ(2u, infos2.size()); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 144 | expectEqResourceInfo(infos2.valueFor(getId(mTestClient2)), kTestUid2, mTestClient2, resources2); |
| 145 | expectEqResourceInfo(infos2.valueFor(getId(mTestClient3)), kTestUid2, mTestClient3, resources3); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 148 | void testCombineResourceWithNegativeValues() { |
| 149 | // kTestPid1 mTestClient1 |
| 150 | std::vector<MediaResourceParcel> resources1; |
| 151 | resources1.push_back(MediaResource(MediaResource::Type::kDrmSession, -100)); |
| 152 | resources1.push_back(MediaResource(MediaResource::Type::kNonSecureCodec, -100)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 153 | ClientInfoParcel client1Info{.pid = static_cast<int32_t>(kTestPid1), |
| 154 | .uid = static_cast<int32_t>(kTestUid1), |
| 155 | .id = getId(mTestClient1), |
| 156 | .name = "none"}; |
| 157 | mService->addResource(client1Info, mTestClient1, resources1); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 158 | |
| 159 | // Expected result: |
| 160 | // 1) the client should have been added; |
| 161 | // 2) both resource entries should have been rejected, resource list should be empty. |
| 162 | const PidResourceInfosMap &map = mService->mMap; |
| 163 | EXPECT_EQ(1u, map.size()); |
| 164 | ssize_t index1 = map.indexOfKey(kTestPid1); |
| 165 | ASSERT_GE(index1, 0); |
| 166 | const ResourceInfos &infos1 = map[index1]; |
| 167 | EXPECT_EQ(1u, infos1.size()); |
| 168 | std::vector<MediaResourceParcel> expected; |
| 169 | expectEqResourceInfo(infos1.valueFor(getId(mTestClient1)), kTestUid1, mTestClient1, expected); |
| 170 | |
| 171 | resources1.clear(); |
| 172 | resources1.push_back(MediaResource(MediaResource::Type::kDrmSession, INT64_MAX)); |
| 173 | resources1.push_back(MediaResource(MediaResource::Type::kNonSecureCodec, INT64_MAX)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 174 | mService->addResource(client1Info, mTestClient1, resources1); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 175 | resources1.clear(); |
| 176 | resources1.push_back(MediaResource(MediaResource::Type::kDrmSession, 10)); |
| 177 | resources1.push_back(MediaResource(MediaResource::Type::kNonSecureCodec, 10)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 178 | mService->addResource(client1Info, mTestClient1, resources1); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 179 | |
| 180 | // Expected result: |
| 181 | // Both values should saturate to INT64_MAX |
| 182 | expected.push_back(MediaResource(MediaResource::Type::kDrmSession, INT64_MAX)); |
| 183 | expected.push_back(MediaResource(MediaResource::Type::kNonSecureCodec, INT64_MAX)); |
| 184 | expectEqResourceInfo(infos1.valueFor(getId(mTestClient1)), kTestUid1, mTestClient1, expected); |
| 185 | |
| 186 | resources1.clear(); |
| 187 | resources1.push_back(MediaResource(MediaResource::Type::kDrmSession, -10)); |
| 188 | resources1.push_back(MediaResource(MediaResource::Type::kNonSecureCodec, -10)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 189 | mService->addResource(client1Info, mTestClient1, resources1); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 190 | |
| 191 | // Expected result: |
| 192 | // 1) DrmSession resource should allow negative value addition, and value should drop accordingly |
| 193 | // 2) Non-drm session resource should ignore negative value addition. |
| 194 | expected.push_back(MediaResource(MediaResource::Type::kDrmSession, INT64_MAX - 10)); |
| 195 | expected.push_back(MediaResource(MediaResource::Type::kNonSecureCodec, INT64_MAX)); |
| 196 | expectEqResourceInfo(infos1.valueFor(getId(mTestClient1)), kTestUid1, mTestClient1, expected); |
| 197 | |
| 198 | resources1.clear(); |
| 199 | resources1.push_back(MediaResource(MediaResource::Type::kDrmSession, INT64_MIN)); |
| 200 | expected.push_back(MediaResource(MediaResource::Type::kNonSecureCodec, INT64_MIN)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 201 | mService->addResource(client1Info, mTestClient1, resources1); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 202 | |
| 203 | // Expected result: |
| 204 | // 1) DrmSession resource value should drop to 0, but the entry shouldn't be removed. |
| 205 | // 2) Non-drm session resource should ignore negative value addition. |
| 206 | expected.clear(); |
| 207 | expected.push_back(MediaResource(MediaResource::Type::kDrmSession, 0)); |
| 208 | expected.push_back(MediaResource(MediaResource::Type::kNonSecureCodec, INT64_MAX)); |
| 209 | expectEqResourceInfo(infos1.valueFor(getId(mTestClient1)), kTestUid1, mTestClient1, expected); |
| 210 | } |
| 211 | |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 212 | void testConfig() { |
| 213 | EXPECT_TRUE(mService->mSupportsMultipleSecureCodecs); |
| 214 | EXPECT_TRUE(mService->mSupportsSecureWithNonSecureCodec); |
| 215 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 216 | std::vector<MediaResourcePolicyParcel> policies1; |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 217 | policies1.push_back( |
Ronghua Wu | 9ba21b9 | 2015-04-21 14:23:06 -0700 | [diff] [blame] | 218 | MediaResourcePolicy( |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 219 | IResourceManagerService::kPolicySupportsMultipleSecureCodecs, |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 220 | "true")); |
Ronghua Wu | 9ba21b9 | 2015-04-21 14:23:06 -0700 | [diff] [blame] | 221 | policies1.push_back( |
| 222 | MediaResourcePolicy( |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 223 | IResourceManagerService::kPolicySupportsSecureWithNonSecureCodec, |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 224 | "false")); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 225 | mService->config(policies1); |
| 226 | EXPECT_TRUE(mService->mSupportsMultipleSecureCodecs); |
| 227 | EXPECT_FALSE(mService->mSupportsSecureWithNonSecureCodec); |
| 228 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 229 | std::vector<MediaResourcePolicyParcel> policies2; |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 230 | policies2.push_back( |
Ronghua Wu | 9ba21b9 | 2015-04-21 14:23:06 -0700 | [diff] [blame] | 231 | MediaResourcePolicy( |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 232 | IResourceManagerService::kPolicySupportsMultipleSecureCodecs, |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 233 | "false")); |
Ronghua Wu | 9ba21b9 | 2015-04-21 14:23:06 -0700 | [diff] [blame] | 234 | policies2.push_back( |
| 235 | MediaResourcePolicy( |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 236 | IResourceManagerService::kPolicySupportsSecureWithNonSecureCodec, |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 237 | "true")); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 238 | mService->config(policies2); |
| 239 | EXPECT_FALSE(mService->mSupportsMultipleSecureCodecs); |
| 240 | EXPECT_TRUE(mService->mSupportsSecureWithNonSecureCodec); |
| 241 | } |
| 242 | |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 243 | void testCombineResource() { |
| 244 | // kTestPid1 mTestClient1 |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 245 | std::vector<MediaResourceParcel> resources1; |
| 246 | resources1.push_back(MediaResource(MediaResource::Type::kSecureCodec, 1)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 247 | ClientInfoParcel client1Info{.pid = static_cast<int32_t>(kTestPid1), |
| 248 | .uid = static_cast<int32_t>(kTestUid1), |
| 249 | .id = getId(mTestClient1), |
| 250 | .name = "none"}; |
| 251 | mService->addResource(client1Info, mTestClient1, resources1); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 252 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 253 | std::vector<MediaResourceParcel> resources11; |
| 254 | resources11.push_back(MediaResource(MediaResource::Type::kGraphicMemory, 200)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 255 | mService->addResource(client1Info, mTestClient1, resources11); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 256 | |
| 257 | const PidResourceInfosMap &map = mService->mMap; |
| 258 | EXPECT_EQ(1u, map.size()); |
| 259 | ssize_t index1 = map.indexOfKey(kTestPid1); |
| 260 | ASSERT_GE(index1, 0); |
| 261 | const ResourceInfos &infos1 = map[index1]; |
| 262 | EXPECT_EQ(1u, infos1.size()); |
| 263 | |
| 264 | // test adding existing types to combine values |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 265 | resources1.push_back(MediaResource(MediaResource::Type::kGraphicMemory, 100)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 266 | mService->addResource(client1Info, mTestClient1, resources1); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 267 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 268 | std::vector<MediaResourceParcel> expected; |
| 269 | expected.push_back(MediaResource(MediaResource::Type::kSecureCodec, 2)); |
| 270 | expected.push_back(MediaResource(MediaResource::Type::kGraphicMemory, 300)); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 271 | expectEqResourceInfo(infos1.valueFor(getId(mTestClient1)), kTestUid1, mTestClient1, expected); |
| 272 | |
| 273 | // test adding new types (including types that differs only in subType) |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 274 | resources11.push_back(MediaResource(MediaResource::Type::kNonSecureCodec, 1)); |
| 275 | resources11.push_back(MediaResource(MediaResource::Type::kSecureCodec, MediaResource::SubType::kVideoCodec, 1)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 276 | mService->addResource(client1Info, mTestClient1, resources11); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 277 | |
| 278 | expected.clear(); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 279 | expected.push_back(MediaResource(MediaResource::Type::kSecureCodec, 2)); |
| 280 | expected.push_back(MediaResource(MediaResource::Type::kNonSecureCodec, 1)); |
| 281 | expected.push_back(MediaResource(MediaResource::Type::kSecureCodec, MediaResource::SubType::kVideoCodec, 1)); |
| 282 | expected.push_back(MediaResource(MediaResource::Type::kGraphicMemory, 500)); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 283 | expectEqResourceInfo(infos1.valueFor(getId(mTestClient1)), kTestUid1, mTestClient1, expected); |
| 284 | } |
| 285 | |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 286 | void testRemoveResource() { |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 287 | // kTestPid1 mTestClient1 |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 288 | std::vector<MediaResourceParcel> resources1; |
| 289 | resources1.push_back(MediaResource(MediaResource::Type::kSecureCodec, 1)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 290 | ClientInfoParcel client1Info{.pid = static_cast<int32_t>(kTestPid1), |
| 291 | .uid = static_cast<int32_t>(kTestUid1), |
| 292 | .id = getId(mTestClient1), |
| 293 | .name = "none"}; |
| 294 | mService->addResource(client1Info, mTestClient1, resources1); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 295 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 296 | std::vector<MediaResourceParcel> resources11; |
| 297 | resources11.push_back(MediaResource(MediaResource::Type::kGraphicMemory, 200)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 298 | mService->addResource(client1Info, mTestClient1, resources11); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 299 | |
| 300 | const PidResourceInfosMap &map = mService->mMap; |
| 301 | EXPECT_EQ(1u, map.size()); |
| 302 | ssize_t index1 = map.indexOfKey(kTestPid1); |
| 303 | ASSERT_GE(index1, 0); |
| 304 | const ResourceInfos &infos1 = map[index1]; |
| 305 | EXPECT_EQ(1u, infos1.size()); |
| 306 | |
| 307 | // test partial removal |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 308 | resources11[0].value = 100; |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 309 | mService->removeResource(client1Info, resources11); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 310 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 311 | std::vector<MediaResourceParcel> expected; |
| 312 | expected.push_back(MediaResource(MediaResource::Type::kSecureCodec, 1)); |
| 313 | expected.push_back(MediaResource(MediaResource::Type::kGraphicMemory, 100)); |
| 314 | expectEqResourceInfo(infos1.valueFor(getId(mTestClient1)), kTestUid1, mTestClient1, expected); |
| 315 | |
| 316 | // test removal request with negative value, should be ignored |
| 317 | resources11[0].value = -10000; |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 318 | mService->removeResource(client1Info, resources11); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 319 | |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 320 | expectEqResourceInfo(infos1.valueFor(getId(mTestClient1)), kTestUid1, mTestClient1, expected); |
| 321 | |
| 322 | // test complete removal with overshoot value |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 323 | resources11[0].value = 1000; |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 324 | mService->removeResource(client1Info, resources11); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 325 | |
| 326 | expected.clear(); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 327 | expected.push_back(MediaResource(MediaResource::Type::kSecureCodec, 1)); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 328 | expectEqResourceInfo(infos1.valueFor(getId(mTestClient1)), kTestUid1, mTestClient1, expected); |
| 329 | } |
| 330 | |
Henry Fang | 3276292 | 2020-01-28 18:40:39 -0800 | [diff] [blame] | 331 | void testOverridePid() { |
| 332 | |
Henry Fang | 3276292 | 2020-01-28 18:40:39 -0800 | [diff] [blame] | 333 | std::vector<MediaResourceParcel> resources; |
| 334 | resources.push_back(MediaResource(MediaResource::Type::kSecureCodec, 1)); |
| 335 | resources.push_back(MediaResource(MediaResource::Type::kGraphicMemory, 150)); |
| 336 | |
| 337 | // ### secure codec can't coexist and secure codec can coexist with non-secure codec ### |
| 338 | { |
| 339 | addResource(); |
| 340 | mService->mSupportsMultipleSecureCodecs = false; |
| 341 | mService->mSupportsSecureWithNonSecureCodec = true; |
| 342 | |
| 343 | // priority too low to reclaim resource |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 344 | ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(kLowPriorityPid), |
| 345 | .uid = static_cast<int32_t>(kTestUid1), |
| 346 | .id = 0, |
| 347 | .name = "none"}; |
| 348 | CHECK_STATUS_FALSE(mService->reclaimResource(clientInfo, resources, &result)); |
Henry Fang | 3276292 | 2020-01-28 18:40:39 -0800 | [diff] [blame] | 349 | |
| 350 | // override Low Priority Pid with High Priority Pid |
| 351 | mService->overridePid(kLowPriorityPid, kHighPriorityPid); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 352 | CHECK_STATUS_TRUE(mService->reclaimResource(clientInfo, resources, &result)); |
Henry Fang | 3276292 | 2020-01-28 18:40:39 -0800 | [diff] [blame] | 353 | |
| 354 | // restore Low Priority Pid |
| 355 | mService->overridePid(kLowPriorityPid, -1); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 356 | CHECK_STATUS_FALSE(mService->reclaimResource(clientInfo, resources, &result)); |
Henry Fang | 3276292 | 2020-01-28 18:40:39 -0800 | [diff] [blame] | 357 | } |
| 358 | } |
| 359 | |
Wonsik Kim | d20e936 | 2020-04-28 10:42:57 -0700 | [diff] [blame] | 360 | void testMarkClientForPendingRemoval() { |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 361 | ClientInfoParcel client1Info{.pid = static_cast<int32_t>(kTestPid1), |
| 362 | .uid = static_cast<int32_t>(kTestUid1), |
| 363 | .id = getId(mTestClient1), |
| 364 | .name = "none"}; |
| 365 | ClientInfoParcel client2Info{.pid = static_cast<int32_t>(kTestPid2), |
| 366 | .uid = static_cast<int32_t>(kTestUid2), |
| 367 | .id = getId(mTestClient2), |
| 368 | .name = "none"}; |
| 369 | ClientInfoParcel client3Info{.pid = static_cast<int32_t>(kTestPid2), |
| 370 | .uid = static_cast<int32_t>(kTestUid2), |
| 371 | .id = getId(mTestClient3), |
| 372 | .name = "none"}; |
Wonsik Kim | d20e936 | 2020-04-28 10:42:57 -0700 | [diff] [blame] | 373 | { |
| 374 | addResource(); |
| 375 | mService->mSupportsSecureWithNonSecureCodec = true; |
| 376 | |
| 377 | std::vector<MediaResourceParcel> resources; |
| 378 | resources.push_back(MediaResource(MediaResource::Type::kNonSecureCodec, 1)); |
| 379 | |
| 380 | // Remove low priority clients |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 381 | mService->removeClient(client1Info); |
Wonsik Kim | d20e936 | 2020-04-28 10:42:57 -0700 | [diff] [blame] | 382 | |
| 383 | // no lower priority client |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 384 | CHECK_STATUS_FALSE(mService->reclaimResource(client2Info, resources, &result)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 385 | EXPECT_EQ(false, toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 386 | EXPECT_EQ(false, toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 387 | EXPECT_EQ(false, toTestClient(mTestClient3)->checkIfReclaimedAndReset()); |
Wonsik Kim | d20e936 | 2020-04-28 10:42:57 -0700 | [diff] [blame] | 388 | |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 389 | mService->markClientForPendingRemoval(client2Info); |
Wonsik Kim | d20e936 | 2020-04-28 10:42:57 -0700 | [diff] [blame] | 390 | |
| 391 | // client marked for pending removal from the same process got reclaimed |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 392 | CHECK_STATUS_TRUE(mService->reclaimResource(client2Info, resources, &result)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 393 | EXPECT_EQ(false, toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 394 | EXPECT_EQ(true, toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 395 | EXPECT_EQ(false, toTestClient(mTestClient3)->checkIfReclaimedAndReset()); |
Wonsik Kim | d20e936 | 2020-04-28 10:42:57 -0700 | [diff] [blame] | 396 | |
| 397 | // clean up client 3 which still left |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 398 | mService->removeClient(client3Info); |
Wonsik Kim | d20e936 | 2020-04-28 10:42:57 -0700 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | { |
| 402 | addResource(); |
| 403 | mService->mSupportsSecureWithNonSecureCodec = true; |
| 404 | |
| 405 | std::vector<MediaResourceParcel> resources; |
| 406 | resources.push_back(MediaResource(MediaResource::Type::kNonSecureCodec, 1)); |
| 407 | |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 408 | mService->markClientForPendingRemoval(client2Info); |
Wonsik Kim | d20e936 | 2020-04-28 10:42:57 -0700 | [diff] [blame] | 409 | |
| 410 | // client marked for pending removal from the same process got reclaimed |
| 411 | // first, even though there are lower priority process |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 412 | CHECK_STATUS_TRUE(mService->reclaimResource(client2Info, resources, &result)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 413 | EXPECT_EQ(false, toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 414 | EXPECT_EQ(true, toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 415 | EXPECT_EQ(false, toTestClient(mTestClient3)->checkIfReclaimedAndReset()); |
Wonsik Kim | d20e936 | 2020-04-28 10:42:57 -0700 | [diff] [blame] | 416 | |
| 417 | // lower priority client got reclaimed |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 418 | CHECK_STATUS_TRUE(mService->reclaimResource(client2Info, resources, &result)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 419 | EXPECT_EQ(true, toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 420 | EXPECT_EQ(false, toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 421 | EXPECT_EQ(false, toTestClient(mTestClient3)->checkIfReclaimedAndReset()); |
Wonsik Kim | d20e936 | 2020-04-28 10:42:57 -0700 | [diff] [blame] | 422 | |
| 423 | // clean up client 3 which still left |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 424 | mService->removeClient(client3Info); |
Wonsik Kim | d20e936 | 2020-04-28 10:42:57 -0700 | [diff] [blame] | 425 | } |
Wonsik Kim | 271429d | 2020-10-01 10:12:56 -0700 | [diff] [blame] | 426 | |
| 427 | { |
| 428 | addResource(); |
| 429 | mService->mSupportsSecureWithNonSecureCodec = true; |
| 430 | |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 431 | mService->markClientForPendingRemoval(client2Info); |
Wonsik Kim | 271429d | 2020-10-01 10:12:56 -0700 | [diff] [blame] | 432 | |
| 433 | // client marked for pending removal got reclaimed |
| 434 | EXPECT_TRUE(mService->reclaimResourcesFromClientsPendingRemoval(kTestPid2).isOk()); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 435 | EXPECT_EQ(false, toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 436 | EXPECT_EQ(true, toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 437 | EXPECT_EQ(false, toTestClient(mTestClient3)->checkIfReclaimedAndReset()); |
Wonsik Kim | 271429d | 2020-10-01 10:12:56 -0700 | [diff] [blame] | 438 | |
| 439 | // No more clients marked for removal |
| 440 | EXPECT_TRUE(mService->reclaimResourcesFromClientsPendingRemoval(kTestPid2).isOk()); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 441 | EXPECT_EQ(false, toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 442 | EXPECT_EQ(false, toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 443 | EXPECT_EQ(false, toTestClient(mTestClient3)->checkIfReclaimedAndReset()); |
Wonsik Kim | 271429d | 2020-10-01 10:12:56 -0700 | [diff] [blame] | 444 | |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 445 | mService->markClientForPendingRemoval(client3Info); |
Wonsik Kim | 271429d | 2020-10-01 10:12:56 -0700 | [diff] [blame] | 446 | |
| 447 | // client marked for pending removal got reclaimed |
| 448 | EXPECT_TRUE(mService->reclaimResourcesFromClientsPendingRemoval(kTestPid2).isOk()); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 449 | EXPECT_EQ(false, toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 450 | EXPECT_EQ(false, toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 451 | EXPECT_EQ(true, toTestClient(mTestClient3)->checkIfReclaimedAndReset()); |
Wonsik Kim | 271429d | 2020-10-01 10:12:56 -0700 | [diff] [blame] | 452 | |
| 453 | // clean up client 1 which still left |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 454 | mService->removeClient(client1Info); |
Wonsik Kim | 271429d | 2020-10-01 10:12:56 -0700 | [diff] [blame] | 455 | } |
Wonsik Kim | d20e936 | 2020-04-28 10:42:57 -0700 | [diff] [blame] | 456 | } |
| 457 | |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 458 | void testRemoveClient() { |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 459 | addResource(); |
| 460 | |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 461 | ClientInfoParcel client2Info{.pid = static_cast<int32_t>(kTestPid2), |
| 462 | .uid = static_cast<int32_t>(kTestUid2), |
| 463 | .id = getId(mTestClient2), |
| 464 | .name = "none"}; |
| 465 | mService->removeClient(client2Info); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 466 | |
| 467 | const PidResourceInfosMap &map = mService->mMap; |
| 468 | EXPECT_EQ(2u, map.size()); |
| 469 | const ResourceInfos &infos1 = map.valueFor(kTestPid1); |
| 470 | const ResourceInfos &infos2 = map.valueFor(kTestPid2); |
| 471 | EXPECT_EQ(1u, infos1.size()); |
| 472 | EXPECT_EQ(1u, infos2.size()); |
| 473 | // mTestClient2 has been removed. |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 474 | // (OK to use infos2[0] as there is only 1 entry) |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 475 | EXPECT_EQ(mTestClient3, infos2[0].client); |
| 476 | } |
| 477 | |
| 478 | void testGetAllClients() { |
| 479 | addResource(); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 480 | MediaResource::Type type = MediaResource::Type::kSecureCodec; |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 481 | MediaResource::SubType subType = MediaResource::SubType::kUnspecifiedSubType; |
| 482 | |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 483 | Vector<std::shared_ptr<IResourceManagerClient> > clients; |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 484 | PidUidVector idList; |
| 485 | EXPECT_FALSE(mService->getAllClients_l(kLowPriorityPid, type, subType, &idList, &clients)); |
Ronghua Wu | 67e7f54 | 2015-03-13 10:47:08 -0700 | [diff] [blame] | 486 | // some higher priority process (e.g. kTestPid2) owns the resource, so getAllClients_l |
| 487 | // will fail. |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 488 | EXPECT_FALSE(mService->getAllClients_l(kMidPriorityPid, type, subType, &idList, &clients)); |
| 489 | EXPECT_TRUE(mService->getAllClients_l(kHighPriorityPid, type, subType, &idList, &clients)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 490 | |
| 491 | EXPECT_EQ(2u, clients.size()); |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 492 | // (OK to require ordering in clients[], as the pid map is sorted) |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 493 | EXPECT_EQ(mTestClient3, clients[0]); |
| 494 | EXPECT_EQ(mTestClient1, clients[1]); |
| 495 | } |
| 496 | |
| 497 | void testReclaimResourceSecure() { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 498 | std::vector<MediaResourceParcel> resources; |
| 499 | resources.push_back(MediaResource(MediaResource::Type::kSecureCodec, 1)); |
| 500 | resources.push_back(MediaResource(MediaResource::Type::kGraphicMemory, 150)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 501 | |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 502 | ClientInfoParcel lowPriorityClient{.pid = static_cast<int32_t>(kLowPriorityPid), |
| 503 | .uid = static_cast<int32_t>(kTestUid2), |
| 504 | .id = 0, |
| 505 | .name = "none"}; |
| 506 | ClientInfoParcel midPriorityClient{.pid = static_cast<int32_t>(kMidPriorityPid), |
| 507 | .uid = static_cast<int32_t>(kTestUid2), |
| 508 | .id = 0, |
| 509 | .name = "none"}; |
| 510 | ClientInfoParcel highPriorityClient{.pid = static_cast<int32_t>(kHighPriorityPid), |
| 511 | .uid = static_cast<int32_t>(kTestUid2), |
| 512 | .id = 0, |
| 513 | .name = "none"}; |
| 514 | |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 515 | // ### secure codec can't coexist and secure codec can coexist with non-secure codec ### |
| 516 | { |
| 517 | addResource(); |
| 518 | mService->mSupportsMultipleSecureCodecs = false; |
| 519 | mService->mSupportsSecureWithNonSecureCodec = true; |
| 520 | |
| 521 | // priority too low |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 522 | CHECK_STATUS_FALSE(mService->reclaimResource(lowPriorityClient, resources, &result)); |
| 523 | CHECK_STATUS_FALSE(mService->reclaimResource(midPriorityClient, resources, &result)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 524 | |
| 525 | // reclaim all secure codecs |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 526 | CHECK_STATUS_TRUE(mService->reclaimResource(highPriorityClient, resources, &result)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 527 | EXPECT_TRUE(toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 528 | EXPECT_FALSE(toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 529 | EXPECT_TRUE(toTestClient(mTestClient3)->checkIfReclaimedAndReset()); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 530 | |
| 531 | // call again should reclaim one largest graphic memory from lowest process |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 532 | CHECK_STATUS_TRUE(mService->reclaimResource(highPriorityClient, resources, &result)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 533 | EXPECT_FALSE(toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 534 | EXPECT_TRUE(toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 535 | EXPECT_FALSE(toTestClient(mTestClient3)->checkIfReclaimedAndReset()); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 536 | |
| 537 | // nothing left |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 538 | CHECK_STATUS_FALSE(mService->reclaimResource(highPriorityClient, resources, &result)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | // ### secure codecs can't coexist and secure codec can't coexist with non-secure codec ### |
| 542 | { |
| 543 | addResource(); |
| 544 | mService->mSupportsMultipleSecureCodecs = false; |
| 545 | mService->mSupportsSecureWithNonSecureCodec = false; |
| 546 | |
| 547 | // priority too low |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 548 | CHECK_STATUS_FALSE(mService->reclaimResource(lowPriorityClient, resources, &result)); |
| 549 | CHECK_STATUS_FALSE(mService->reclaimResource(midPriorityClient, resources, &result)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 550 | |
| 551 | // reclaim all secure and non-secure codecs |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 552 | CHECK_STATUS_TRUE(mService->reclaimResource(highPriorityClient, resources, &result)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 553 | EXPECT_TRUE(toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 554 | EXPECT_TRUE(toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 555 | EXPECT_TRUE(toTestClient(mTestClient3)->checkIfReclaimedAndReset()); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 556 | |
| 557 | // nothing left |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 558 | CHECK_STATUS_FALSE(mService->reclaimResource(highPriorityClient, resources, &result)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | |
| 562 | // ### secure codecs can coexist but secure codec can't coexist with non-secure codec ### |
| 563 | { |
| 564 | addResource(); |
| 565 | mService->mSupportsMultipleSecureCodecs = true; |
| 566 | mService->mSupportsSecureWithNonSecureCodec = false; |
| 567 | |
| 568 | // priority too low |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 569 | CHECK_STATUS_FALSE(mService->reclaimResource(lowPriorityClient, resources, &result)); |
| 570 | CHECK_STATUS_FALSE(mService->reclaimResource(midPriorityClient, resources, &result)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 571 | |
| 572 | // reclaim all non-secure codecs |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 573 | CHECK_STATUS_TRUE(mService->reclaimResource(highPriorityClient, resources, &result)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 574 | EXPECT_FALSE(toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 575 | EXPECT_TRUE(toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 576 | EXPECT_FALSE(toTestClient(mTestClient3)->checkIfReclaimedAndReset()); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 577 | |
| 578 | // call again should reclaim one largest graphic memory from lowest process |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 579 | CHECK_STATUS_TRUE(mService->reclaimResource(highPriorityClient, resources, &result)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 580 | EXPECT_TRUE(toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 581 | EXPECT_FALSE(toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 582 | EXPECT_FALSE(toTestClient(mTestClient3)->checkIfReclaimedAndReset()); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 583 | |
| 584 | // call again should reclaim another largest graphic memory from lowest process |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 585 | CHECK_STATUS_TRUE(mService->reclaimResource(highPriorityClient, resources, &result)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 586 | EXPECT_FALSE(toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 587 | EXPECT_FALSE(toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 588 | EXPECT_TRUE(toTestClient(mTestClient3)->checkIfReclaimedAndReset()); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 589 | |
| 590 | // nothing left |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 591 | CHECK_STATUS_FALSE(mService->reclaimResource(highPriorityClient, resources, &result)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | // ### secure codecs can coexist and secure codec can coexist with non-secure codec ### |
| 595 | { |
| 596 | addResource(); |
| 597 | mService->mSupportsMultipleSecureCodecs = true; |
| 598 | mService->mSupportsSecureWithNonSecureCodec = true; |
| 599 | |
| 600 | // priority too low |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 601 | CHECK_STATUS_FALSE(mService->reclaimResource(lowPriorityClient, resources, &result)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 602 | |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 603 | CHECK_STATUS_TRUE(mService->reclaimResource(highPriorityClient, resources, &result)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 604 | // one largest graphic memory from lowest process got reclaimed |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 605 | EXPECT_TRUE(toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 606 | EXPECT_FALSE(toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 607 | EXPECT_FALSE(toTestClient(mTestClient3)->checkIfReclaimedAndReset()); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 608 | |
| 609 | // call again should reclaim another graphic memory from lowest process |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 610 | CHECK_STATUS_TRUE(mService->reclaimResource(highPriorityClient, resources, &result)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 611 | EXPECT_FALSE(toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 612 | EXPECT_TRUE(toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 613 | EXPECT_FALSE(toTestClient(mTestClient3)->checkIfReclaimedAndReset()); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 614 | |
| 615 | // call again should reclaim another graphic memory from lowest process |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 616 | CHECK_STATUS_TRUE(mService->reclaimResource(highPriorityClient, resources, &result)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 617 | EXPECT_FALSE(toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 618 | EXPECT_FALSE(toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 619 | EXPECT_TRUE(toTestClient(mTestClient3)->checkIfReclaimedAndReset()); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 620 | |
| 621 | // nothing left |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 622 | CHECK_STATUS_FALSE(mService->reclaimResource(highPriorityClient, resources, &result)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 623 | } |
Ronghua Wu | 67e7f54 | 2015-03-13 10:47:08 -0700 | [diff] [blame] | 624 | |
| 625 | // ### secure codecs can coexist and secure codec can coexist with non-secure codec ### |
| 626 | { |
| 627 | addResource(); |
| 628 | mService->mSupportsMultipleSecureCodecs = true; |
| 629 | mService->mSupportsSecureWithNonSecureCodec = true; |
| 630 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 631 | std::vector<MediaResourceParcel> resources; |
| 632 | resources.push_back(MediaResource(MediaResource::Type::kSecureCodec, 1)); |
Ronghua Wu | 67e7f54 | 2015-03-13 10:47:08 -0700 | [diff] [blame] | 633 | |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 634 | CHECK_STATUS_TRUE(mService->reclaimResource(highPriorityClient, resources, &result)); |
Ronghua Wu | 67e7f54 | 2015-03-13 10:47:08 -0700 | [diff] [blame] | 635 | // secure codec from lowest process got reclaimed |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 636 | EXPECT_TRUE(toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 637 | EXPECT_FALSE(toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 638 | EXPECT_FALSE(toTestClient(mTestClient3)->checkIfReclaimedAndReset()); |
Ronghua Wu | 67e7f54 | 2015-03-13 10:47:08 -0700 | [diff] [blame] | 639 | |
| 640 | // call again should reclaim another secure codec from lowest process |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 641 | CHECK_STATUS_TRUE(mService->reclaimResource(highPriorityClient, resources, &result)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 642 | EXPECT_FALSE(toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 643 | EXPECT_FALSE(toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 644 | EXPECT_TRUE(toTestClient(mTestClient3)->checkIfReclaimedAndReset()); |
Ronghua Wu | 67e7f54 | 2015-03-13 10:47:08 -0700 | [diff] [blame] | 645 | |
Ronghua Wu | 05d89f1 | 2015-07-07 16:47:42 -0700 | [diff] [blame] | 646 | // no more secure codec, non-secure codec will be reclaimed. |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 647 | CHECK_STATUS_TRUE(mService->reclaimResource(highPriorityClient, resources, &result)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 648 | EXPECT_FALSE(toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 649 | EXPECT_TRUE(toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 650 | EXPECT_FALSE(toTestClient(mTestClient3)->checkIfReclaimedAndReset()); |
Ronghua Wu | 67e7f54 | 2015-03-13 10:47:08 -0700 | [diff] [blame] | 651 | } |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | void testReclaimResourceNonSecure() { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 655 | std::vector<MediaResourceParcel> resources; |
| 656 | resources.push_back(MediaResource(MediaResource::Type::kNonSecureCodec, 1)); |
| 657 | resources.push_back(MediaResource(MediaResource::Type::kGraphicMemory, 150)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 658 | |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 659 | ClientInfoParcel lowPriorityClient{.pid = static_cast<int32_t>(kLowPriorityPid), |
| 660 | .uid = static_cast<int32_t>(kTestUid2), |
| 661 | .id = 0, |
| 662 | .name = "none"}; |
| 663 | ClientInfoParcel midPriorityClient{.pid = static_cast<int32_t>(kMidPriorityPid), |
| 664 | .uid = static_cast<int32_t>(kTestUid2), |
| 665 | .id = 0, |
| 666 | .name = "none"}; |
| 667 | ClientInfoParcel highPriorityClient{.pid = static_cast<int32_t>(kHighPriorityPid), |
| 668 | .uid = static_cast<int32_t>(kTestUid2), |
| 669 | .id = 0, |
| 670 | .name = "none"}; |
| 671 | |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 672 | // ### secure codec can't coexist with non-secure codec ### |
| 673 | { |
| 674 | addResource(); |
| 675 | mService->mSupportsSecureWithNonSecureCodec = false; |
| 676 | |
| 677 | // priority too low |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 678 | CHECK_STATUS_FALSE(mService->reclaimResource(lowPriorityClient, resources, &result)); |
| 679 | CHECK_STATUS_FALSE(mService->reclaimResource(midPriorityClient, resources, &result)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 680 | |
| 681 | // reclaim all secure codecs |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 682 | CHECK_STATUS_TRUE(mService->reclaimResource(highPriorityClient, resources, &result)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 683 | EXPECT_TRUE(toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 684 | EXPECT_FALSE(toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 685 | EXPECT_TRUE(toTestClient(mTestClient3)->checkIfReclaimedAndReset()); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 686 | |
| 687 | // call again should reclaim one graphic memory from lowest process |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 688 | CHECK_STATUS_TRUE(mService->reclaimResource(highPriorityClient, resources, &result)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 689 | EXPECT_FALSE(toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 690 | EXPECT_TRUE(toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 691 | EXPECT_FALSE(toTestClient(mTestClient3)->checkIfReclaimedAndReset()); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 692 | |
| 693 | // nothing left |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 694 | CHECK_STATUS_FALSE(mService->reclaimResource(highPriorityClient, resources, &result)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | |
| 698 | // ### secure codec can coexist with non-secure codec ### |
| 699 | { |
| 700 | addResource(); |
| 701 | mService->mSupportsSecureWithNonSecureCodec = true; |
| 702 | |
| 703 | // priority too low |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 704 | CHECK_STATUS_FALSE(mService->reclaimResource(lowPriorityClient, resources, &result)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 705 | |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 706 | CHECK_STATUS_TRUE(mService->reclaimResource(highPriorityClient, resources, &result)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 707 | // one largest graphic memory from lowest process got reclaimed |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 708 | EXPECT_TRUE(toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 709 | EXPECT_FALSE(toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 710 | EXPECT_FALSE(toTestClient(mTestClient3)->checkIfReclaimedAndReset()); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 711 | |
| 712 | // call again should reclaim another graphic memory from lowest process |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 713 | CHECK_STATUS_TRUE(mService->reclaimResource(highPriorityClient, resources, &result)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 714 | EXPECT_FALSE(toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 715 | EXPECT_TRUE(toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 716 | EXPECT_FALSE(toTestClient(mTestClient3)->checkIfReclaimedAndReset()); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 717 | |
| 718 | // call again should reclaim another graphic memory from lowest process |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 719 | CHECK_STATUS_TRUE(mService->reclaimResource(highPriorityClient, resources, &result)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 720 | EXPECT_FALSE(toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 721 | EXPECT_FALSE(toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 722 | EXPECT_TRUE(toTestClient(mTestClient3)->checkIfReclaimedAndReset()); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 723 | |
| 724 | // nothing left |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 725 | CHECK_STATUS_FALSE(mService->reclaimResource(highPriorityClient, resources, &result)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 726 | } |
Ronghua Wu | 67e7f54 | 2015-03-13 10:47:08 -0700 | [diff] [blame] | 727 | |
| 728 | // ### secure codec can coexist with non-secure codec ### |
| 729 | { |
| 730 | addResource(); |
| 731 | mService->mSupportsSecureWithNonSecureCodec = true; |
| 732 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 733 | std::vector<MediaResourceParcel> resources; |
| 734 | resources.push_back(MediaResource(MediaResource::Type::kNonSecureCodec, 1)); |
Ronghua Wu | 67e7f54 | 2015-03-13 10:47:08 -0700 | [diff] [blame] | 735 | |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 736 | CHECK_STATUS_TRUE(mService->reclaimResource(highPriorityClient, resources, &result)); |
Ronghua Wu | 67e7f54 | 2015-03-13 10:47:08 -0700 | [diff] [blame] | 737 | // one non secure codec from lowest process got reclaimed |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 738 | EXPECT_FALSE(toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 739 | EXPECT_TRUE(toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 740 | EXPECT_FALSE(toTestClient(mTestClient3)->checkIfReclaimedAndReset()); |
Ronghua Wu | 67e7f54 | 2015-03-13 10:47:08 -0700 | [diff] [blame] | 741 | |
Ronghua Wu | 05d89f1 | 2015-07-07 16:47:42 -0700 | [diff] [blame] | 742 | // no more non-secure codec, secure codec from lowest priority process will be reclaimed |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 743 | CHECK_STATUS_TRUE(mService->reclaimResource(highPriorityClient, resources, &result)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 744 | EXPECT_TRUE(toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 745 | EXPECT_FALSE(toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 746 | EXPECT_FALSE(toTestClient(mTestClient3)->checkIfReclaimedAndReset()); |
Ronghua Wu | 67e7f54 | 2015-03-13 10:47:08 -0700 | [diff] [blame] | 747 | |
Ronghua Wu | 05d89f1 | 2015-07-07 16:47:42 -0700 | [diff] [blame] | 748 | // clean up client 3 which still left |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 749 | ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(kTestPid2), |
| 750 | .uid = static_cast<int32_t>(kTestUid2), |
| 751 | .id = getId(mTestClient3), |
| 752 | .name = "none"}; |
| 753 | mService->removeClient(clientInfo); |
Ronghua Wu | 67e7f54 | 2015-03-13 10:47:08 -0700 | [diff] [blame] | 754 | } |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | void testGetLowestPriorityBiggestClient() { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 758 | MediaResource::Type type = MediaResource::Type::kGraphicMemory; |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 759 | MediaResource::SubType subType = MediaResource::SubType::kUnspecifiedSubType; |
Chong Zhang | fdd512a | 2019-11-22 11:03:14 -0800 | [diff] [blame] | 760 | std::shared_ptr<IResourceManagerClient> client; |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 761 | PidUidVector idList; |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 762 | EXPECT_FALSE(mService->getLowestPriorityBiggestClient_l(kHighPriorityPid, type, subType, |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 763 | &idList, &client)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 764 | |
| 765 | addResource(); |
| 766 | |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 767 | EXPECT_FALSE(mService->getLowestPriorityBiggestClient_l(kLowPriorityPid, type, subType, |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 768 | &idList, &client)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 769 | EXPECT_TRUE(mService->getLowestPriorityBiggestClient_l(kHighPriorityPid, type, subType, |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 770 | &idList, &client)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 771 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 772 | // kTestPid1 is the lowest priority process with MediaResource::Type::kGraphicMemory. |
| 773 | // mTestClient1 has the largest MediaResource::Type::kGraphicMemory within kTestPid1. |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 774 | EXPECT_EQ(mTestClient1, client); |
| 775 | } |
| 776 | |
| 777 | void testGetLowestPriorityPid() { |
| 778 | int pid; |
| 779 | int priority; |
| 780 | TestProcessInfo processInfo; |
| 781 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 782 | MediaResource::Type type = MediaResource::Type::kGraphicMemory; |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 783 | MediaResource::SubType subType = MediaResource::SubType::kUnspecifiedSubType; |
| 784 | EXPECT_FALSE(mService->getLowestPriorityPid_l(type, subType, &pid, &priority)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 785 | |
| 786 | addResource(); |
| 787 | |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 788 | EXPECT_TRUE(mService->getLowestPriorityPid_l(type, subType, &pid, &priority)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 789 | EXPECT_EQ(kTestPid1, pid); |
| 790 | int priority1; |
| 791 | processInfo.getPriority(kTestPid1, &priority1); |
| 792 | EXPECT_EQ(priority1, priority); |
| 793 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 794 | type = MediaResource::Type::kNonSecureCodec; |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 795 | EXPECT_TRUE(mService->getLowestPriorityPid_l(type, subType, &pid, &priority)); |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 796 | EXPECT_EQ(kTestPid2, pid); |
| 797 | int priority2; |
| 798 | processInfo.getPriority(kTestPid2, &priority2); |
| 799 | EXPECT_EQ(priority2, priority); |
| 800 | } |
| 801 | |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 802 | void testIsCallingPriorityHigher() { |
| 803 | EXPECT_FALSE(mService->isCallingPriorityHigher_l(101, 100)); |
| 804 | EXPECT_FALSE(mService->isCallingPriorityHigher_l(100, 100)); |
| 805 | EXPECT_TRUE(mService->isCallingPriorityHigher_l(99, 100)); |
| 806 | } |
| 807 | |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 808 | void testBatteryStats() { |
| 809 | // reset should always be called when ResourceManagerService is created (restarted) |
| 810 | EXPECT_EQ(1u, mSystemCB->eventCount()); |
| 811 | EXPECT_EQ(EventType::VIDEO_RESET, mSystemCB->lastEventType()); |
| 812 | |
| 813 | // new client request should cause VIDEO_ON |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 814 | std::vector<MediaResourceParcel> resources1; |
| 815 | resources1.push_back(MediaResource(MediaResource::Type::kBattery, MediaResource::SubType::kVideoCodec, 1)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 816 | ClientInfoParcel client1Info{.pid = static_cast<int32_t>(kTestPid1), |
| 817 | .uid = static_cast<int32_t>(kTestUid1), |
| 818 | .id = getId(mTestClient1), |
| 819 | .name = "none"}; |
| 820 | mService->addResource(client1Info, mTestClient1, resources1); |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 821 | EXPECT_EQ(2u, mSystemCB->eventCount()); |
| 822 | EXPECT_EQ(EventEntry({EventType::VIDEO_ON, kTestUid1}), mSystemCB->lastEvent()); |
| 823 | |
| 824 | // each client should only cause 1 VIDEO_ON |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 825 | mService->addResource(client1Info, mTestClient1, resources1); |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 826 | EXPECT_EQ(2u, mSystemCB->eventCount()); |
| 827 | |
| 828 | // new client request should cause VIDEO_ON |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 829 | std::vector<MediaResourceParcel> resources2; |
| 830 | resources2.push_back(MediaResource(MediaResource::Type::kBattery, MediaResource::SubType::kVideoCodec, 2)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 831 | ClientInfoParcel client2Info{.pid = static_cast<int32_t>(kTestPid2), |
| 832 | .uid = static_cast<int32_t>(kTestUid2), |
| 833 | .id = getId(mTestClient2), |
| 834 | .name = "none"}; |
| 835 | mService->addResource(client2Info, mTestClient2, resources2); |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 836 | EXPECT_EQ(3u, mSystemCB->eventCount()); |
| 837 | EXPECT_EQ(EventEntry({EventType::VIDEO_ON, kTestUid2}), mSystemCB->lastEvent()); |
| 838 | |
| 839 | // partially remove mTestClient1's request, shouldn't be any VIDEO_OFF |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 840 | mService->removeResource(client1Info, resources1); |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 841 | EXPECT_EQ(3u, mSystemCB->eventCount()); |
| 842 | |
| 843 | // remove mTestClient1's request, should be VIDEO_OFF for kTestUid1 |
| 844 | // (use resource2 to test removing more instances than previously requested) |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 845 | mService->removeResource(client1Info, resources2); |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 846 | EXPECT_EQ(4u, mSystemCB->eventCount()); |
| 847 | EXPECT_EQ(EventEntry({EventType::VIDEO_OFF, kTestUid1}), mSystemCB->lastEvent()); |
| 848 | |
| 849 | // remove mTestClient2, should be VIDEO_OFF for kTestUid2 |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 850 | mService->removeClient(client2Info); |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 851 | EXPECT_EQ(5u, mSystemCB->eventCount()); |
| 852 | EXPECT_EQ(EventEntry({EventType::VIDEO_OFF, kTestUid2}), mSystemCB->lastEvent()); |
| 853 | } |
| 854 | |
| 855 | void testCpusetBoost() { |
| 856 | // reset should always be called when ResourceManagerService is created (restarted) |
| 857 | EXPECT_EQ(1u, mSystemCB->eventCount()); |
| 858 | EXPECT_EQ(EventType::VIDEO_RESET, mSystemCB->lastEventType()); |
| 859 | |
| 860 | // new client request should cause CPUSET_ENABLE |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 861 | std::vector<MediaResourceParcel> resources1; |
| 862 | resources1.push_back(MediaResource(MediaResource::Type::kCpuBoost, 1)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 863 | ClientInfoParcel client1Info{.pid = static_cast<int32_t>(kTestPid1), |
| 864 | .uid = static_cast<int32_t>(kTestUid1), |
| 865 | .id = getId(mTestClient1), |
| 866 | .name = "none"}; |
| 867 | mService->addResource(client1Info, mTestClient1, resources1); |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 868 | EXPECT_EQ(2u, mSystemCB->eventCount()); |
| 869 | EXPECT_EQ(EventType::CPUSET_ENABLE, mSystemCB->lastEventType()); |
| 870 | |
| 871 | // each client should only cause 1 CPUSET_ENABLE |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 872 | mService->addResource(client1Info, mTestClient1, resources1); |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 873 | EXPECT_EQ(2u, mSystemCB->eventCount()); |
| 874 | |
| 875 | // new client request should cause CPUSET_ENABLE |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 876 | std::vector<MediaResourceParcel> resources2; |
| 877 | resources2.push_back(MediaResource(MediaResource::Type::kCpuBoost, 2)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 878 | ClientInfoParcel client2Info{.pid = static_cast<int32_t>(kTestPid2), |
| 879 | .uid = static_cast<int32_t>(kTestUid2), |
| 880 | .id = getId(mTestClient2), |
| 881 | .name = "none"}; |
| 882 | mService->addResource(client2Info, mTestClient2, resources2); |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 883 | EXPECT_EQ(3u, mSystemCB->eventCount()); |
| 884 | EXPECT_EQ(EventType::CPUSET_ENABLE, mSystemCB->lastEventType()); |
| 885 | |
| 886 | // remove mTestClient2 should not cause CPUSET_DISABLE, mTestClient1 still active |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 887 | mService->removeClient(client2Info); |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 888 | EXPECT_EQ(3u, mSystemCB->eventCount()); |
| 889 | |
| 890 | // remove 1 cpuboost from mTestClient1, should not be CPUSET_DISABLE (still 1 left) |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 891 | mService->removeResource(client1Info, resources1); |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 892 | EXPECT_EQ(3u, mSystemCB->eventCount()); |
| 893 | |
| 894 | // remove 2 cpuboost from mTestClient1, should be CPUSET_DISABLE |
| 895 | // (use resource2 to test removing more than previously requested) |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 896 | mService->removeResource(client1Info, resources2); |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 897 | EXPECT_EQ(4u, mSystemCB->eventCount()); |
| 898 | EXPECT_EQ(EventType::CPUSET_DISABLE, mSystemCB->lastEventType()); |
| 899 | } |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 900 | |
| 901 | void testReclaimResources_withVideoCodec_reclaimsOnlyVideoCodec() { |
| 902 | const std::shared_ptr<IResourceManagerClient>& audioImageTestClient = mTestClient1; |
| 903 | const std::shared_ptr<IResourceManagerClient>& videoTestClient = mTestClient2; |
| 904 | |
| 905 | // Create an audio and image codec resource |
| 906 | std::vector<MediaResourceParcel> audioImageResources; |
| 907 | audioImageResources.push_back(createNonSecureAudioCodecResource()); |
| 908 | audioImageResources.push_back(createNonSecureImageCodecResource()); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 909 | ClientInfoParcel client1Info{.pid = static_cast<int32_t>(kLowPriorityPid), |
| 910 | .uid = static_cast<int32_t>(kTestUid1), |
| 911 | .id = getId(audioImageTestClient), |
| 912 | .name = "none"}; |
| 913 | mService->addResource(client1Info, audioImageTestClient, audioImageResources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 914 | |
| 915 | // Fail to reclaim a video codec resource |
| 916 | std::vector<MediaResourceParcel> reclaimResources; |
| 917 | reclaimResources.push_back(createNonSecureVideoCodecResource()); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 918 | ClientInfoParcel highPriorityClient{.pid = static_cast<int32_t>(kHighPriorityPid), |
| 919 | .uid = static_cast<int32_t>(kTestUid2), |
| 920 | .id = 0, |
| 921 | .name = "none"}; |
| 922 | CHECK_STATUS_FALSE(mService->reclaimResource(highPriorityClient, reclaimResources, &result)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 923 | |
| 924 | // Now add a video codec resource |
| 925 | std::vector<MediaResourceParcel> videoResources; |
| 926 | videoResources.push_back(createNonSecureVideoCodecResource()); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 927 | ClientInfoParcel client2Info{.pid = static_cast<int32_t>(kLowPriorityPid), |
| 928 | .uid = static_cast<int32_t>(kTestUid1), |
| 929 | .id = getId(videoTestClient), |
| 930 | .name = "none"}; |
| 931 | mService->addResource(client2Info, videoTestClient, videoResources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 932 | |
| 933 | // Verify that the newly-created video codec resource can be reclaimed |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 934 | CHECK_STATUS_TRUE(mService->reclaimResource(highPriorityClient, reclaimResources, &result)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 935 | |
| 936 | // Verify that the audio and image resources are untouched |
| 937 | EXPECT_FALSE(toTestClient(audioImageTestClient)->checkIfReclaimedAndReset()); |
| 938 | // But the video resource was reclaimed |
| 939 | EXPECT_TRUE(toTestClient(videoTestClient)->checkIfReclaimedAndReset()); |
| 940 | } |
| 941 | |
| 942 | void testReclaimResources_withAudioCodec_reclaimsOnlyAudioCodec() { |
| 943 | const auto & videoImageTestClient = mTestClient1; |
| 944 | const auto & audioTestClient = mTestClient2; |
| 945 | |
| 946 | // Create a video and audio codec resource |
| 947 | std::vector<MediaResourceParcel> videoImageResources; |
| 948 | videoImageResources.push_back(createNonSecureVideoCodecResource()); |
| 949 | videoImageResources.push_back(createNonSecureImageCodecResource()); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 950 | ClientInfoParcel client1Info{.pid = static_cast<int32_t>(kLowPriorityPid), |
| 951 | .uid = static_cast<int32_t>(kTestUid1), |
| 952 | .id = getId(videoImageTestClient), |
| 953 | .name = "none"}; |
| 954 | mService->addResource(client1Info, videoImageTestClient, videoImageResources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 955 | |
| 956 | // Fail to reclaim an audio codec resource |
| 957 | std::vector<MediaResourceParcel> reclaimResources; |
| 958 | reclaimResources.push_back(createNonSecureAudioCodecResource()); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 959 | ClientInfoParcel highPriorityClient{.pid = static_cast<int32_t>(kHighPriorityPid), |
| 960 | .uid = static_cast<int32_t>(kTestUid2), |
| 961 | .id = 0, |
| 962 | .name = "none"}; |
| 963 | CHECK_STATUS_FALSE(mService->reclaimResource(highPriorityClient, reclaimResources, &result)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 964 | |
| 965 | // Now add an audio codec resource |
| 966 | std::vector<MediaResourceParcel> audioResources; |
| 967 | audioResources.push_back(createNonSecureAudioCodecResource()); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 968 | ClientInfoParcel client2Info{.pid = static_cast<int32_t>(kLowPriorityPid), |
| 969 | .uid = static_cast<int32_t>(kTestUid2), |
| 970 | .id = getId(audioTestClient), |
| 971 | .name = "none"}; |
| 972 | mService->addResource(client2Info, audioTestClient, audioResources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 973 | |
| 974 | // Verify that the newly-created audio codec resource can be reclaimed |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 975 | CHECK_STATUS_TRUE(mService->reclaimResource(highPriorityClient, reclaimResources, &result)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 976 | |
| 977 | // Verify that the video and image resources are untouched |
| 978 | EXPECT_FALSE(toTestClient(videoImageTestClient)->checkIfReclaimedAndReset()); |
| 979 | // But the audio resource was reclaimed |
| 980 | EXPECT_TRUE(toTestClient(audioTestClient)->checkIfReclaimedAndReset()); |
| 981 | } |
| 982 | |
| 983 | void testReclaimResources_withImageCodec_reclaimsOnlyImageCodec() { |
| 984 | const auto & videoAudioTestClient = mTestClient1; |
| 985 | const auto & imageTestClient = mTestClient2; |
| 986 | |
| 987 | // Create a video and audio codec resource |
| 988 | std::vector<MediaResourceParcel> videoAudioResources; |
| 989 | videoAudioResources.push_back(createNonSecureVideoCodecResource()); |
| 990 | videoAudioResources.push_back(createNonSecureAudioCodecResource()); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 991 | ClientInfoParcel client1Info{.pid = static_cast<int32_t>(kLowPriorityPid), |
| 992 | .uid = static_cast<int32_t>(kTestUid1), |
| 993 | .id = getId(videoAudioTestClient), |
| 994 | .name = "none"}; |
| 995 | mService->addResource(client1Info, videoAudioTestClient, videoAudioResources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 996 | |
| 997 | // Fail to reclaim an image codec resource |
| 998 | std::vector<MediaResourceParcel> reclaimResources; |
| 999 | reclaimResources.push_back(createNonSecureImageCodecResource()); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1000 | ClientInfoParcel highPriorityClient{.pid = static_cast<int32_t>(kHighPriorityPid), |
| 1001 | .uid = static_cast<int32_t>(kTestUid2), |
| 1002 | .id = 0, |
| 1003 | .name = "none"}; |
| 1004 | CHECK_STATUS_FALSE(mService->reclaimResource(highPriorityClient, reclaimResources, &result)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1005 | |
| 1006 | // Now add an image codec resource |
| 1007 | std::vector<MediaResourceParcel> imageResources; |
| 1008 | imageResources.push_back(createNonSecureImageCodecResource()); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1009 | ClientInfoParcel client2Info{.pid = static_cast<int32_t>(kLowPriorityPid), |
| 1010 | .uid = static_cast<int32_t>(kTestUid2), |
| 1011 | .id = getId(imageTestClient), |
| 1012 | .name = "none"}; |
| 1013 | mService->addResource(client2Info, imageTestClient, imageResources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1014 | |
| 1015 | // Verify that the newly-created image codec resource can be reclaimed |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1016 | CHECK_STATUS_TRUE(mService->reclaimResource(highPriorityClient, reclaimResources, &result)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1017 | |
| 1018 | // Verify that the video and audio resources are untouched |
| 1019 | EXPECT_FALSE(toTestClient(mTestClient1)->checkIfReclaimedAndReset()); |
| 1020 | // But the image resource was reclaimed |
| 1021 | EXPECT_TRUE(toTestClient(mTestClient2)->checkIfReclaimedAndReset()); |
| 1022 | } |
| 1023 | |
| 1024 | void testReclaimResources_whenPartialResourceMatch_reclaims() { |
| 1025 | const int onlyUid = kTestUid1; |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1026 | const auto onlyClient = createTestClient(kLowPriorityPid, onlyUid); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1027 | |
| 1028 | std::vector<MediaResourceParcel> ownedResources; |
| 1029 | ownedResources.push_back(createNonSecureVideoCodecResource()); |
| 1030 | ownedResources.push_back(createGraphicMemoryResource(100)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1031 | ClientInfoParcel onlyClientInfo{.pid = static_cast<int32_t>(kLowPriorityPid), |
| 1032 | .uid = static_cast<int32_t>(onlyUid), |
| 1033 | .id = getId(onlyClient), |
| 1034 | .name = "none"}; |
| 1035 | mService->addResource(onlyClientInfo, onlyClient, ownedResources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1036 | |
| 1037 | // Reclaim an image codec instead of the video codec that is owned, but also reclaim |
| 1038 | // graphics memory, which will trigger the reclaim. |
| 1039 | std::vector<MediaResourceParcel> reclaimResources; |
| 1040 | reclaimResources.push_back(createNonSecureImageCodecResource()); |
| 1041 | reclaimResources.push_back(createGraphicMemoryResource(100)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1042 | ClientInfoParcel highPriorityClient{.pid = static_cast<int32_t>(kHighPriorityPid), |
| 1043 | .uid = static_cast<int32_t>(kTestUid2), |
| 1044 | .id = 0, |
| 1045 | .name = "none"}; |
| 1046 | CHECK_STATUS_TRUE(mService->reclaimResource(highPriorityClient, reclaimResources, &result)); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1047 | |
| 1048 | // Verify that the video codec resources (including the needed graphic memory) is reclaimed |
| 1049 | EXPECT_TRUE(toTestClient(onlyClient)->checkIfReclaimedAndReset()); |
| 1050 | } |
| 1051 | |
| 1052 | void testReclaimResourcesFromMarkedClients_removesBiggestMarkedClientForSomeResources() { |
| 1053 | // this test only uses one pid and one uid |
| 1054 | const int onlyPid = kTestPid1; |
| 1055 | const int onlyUid = kTestUid1; |
| 1056 | |
| 1057 | // secure video codec |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1058 | const auto smallSecureVideoMarkedClient = createTestClient(onlyPid, onlyUid); |
| 1059 | const auto largeSecureVideoMarkedClient = createTestClient(onlyPid, onlyUid); |
| 1060 | const auto largestSecureVideoActiveClient = createTestClient(onlyPid, onlyUid); |
| 1061 | ClientInfoParcel clientA{.pid = static_cast<int32_t>(onlyPid), |
| 1062 | .uid = static_cast<int32_t>(onlyUid), |
| 1063 | .id = getId(smallSecureVideoMarkedClient), |
| 1064 | .name = "none"}; |
| 1065 | ClientInfoParcel clientB{.pid = static_cast<int32_t>(onlyPid), |
| 1066 | .uid = static_cast<int32_t>(onlyUid), |
| 1067 | .id = getId(largeSecureVideoMarkedClient), |
| 1068 | .name = "none"}; |
| 1069 | ClientInfoParcel clientC{.pid = static_cast<int32_t>(onlyPid), |
| 1070 | .uid = static_cast<int32_t>(onlyUid), |
| 1071 | .id = getId(largestSecureVideoActiveClient), |
| 1072 | .name = "none"}; |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1073 | { |
| 1074 | std::vector<MediaResourceParcel> resources; |
| 1075 | resources.push_back(createSecureVideoCodecResource(1)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1076 | mService->addResource(clientA, smallSecureVideoMarkedClient, resources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1077 | resources.clear(); |
| 1078 | resources.push_back(createSecureVideoCodecResource(2)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1079 | mService->addResource(clientB, largeSecureVideoMarkedClient, resources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1080 | resources.clear(); |
| 1081 | resources.push_back(createSecureVideoCodecResource(3)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1082 | mService->addResource(clientC, largestSecureVideoActiveClient, resources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1083 | } |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1084 | mService->markClientForPendingRemoval(clientA); |
| 1085 | mService->markClientForPendingRemoval(clientB); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1086 | // don't mark the largest client |
| 1087 | |
| 1088 | // non-secure video codec |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1089 | const auto smallNonSecureVideoMarkedClient = createTestClient(onlyPid, onlyUid); |
| 1090 | const auto largeNonSecureVideoMarkedClient = createTestClient(onlyPid, onlyUid); |
| 1091 | const auto largestNonSecureVideoActiveClient = createTestClient(onlyPid, onlyUid); |
| 1092 | ClientInfoParcel clientD{.pid = static_cast<int32_t>(onlyPid), |
| 1093 | .uid = static_cast<int32_t>(onlyUid), |
| 1094 | .id = getId(smallNonSecureVideoMarkedClient), |
| 1095 | .name = "none"}; |
| 1096 | ClientInfoParcel clientE{.pid = static_cast<int32_t>(onlyPid), |
| 1097 | .uid = static_cast<int32_t>(onlyUid), |
| 1098 | .id = getId(largeNonSecureVideoMarkedClient), |
| 1099 | .name = "none"}; |
| 1100 | ClientInfoParcel clientF{.pid = static_cast<int32_t>(onlyPid), |
| 1101 | .uid = static_cast<int32_t>(onlyUid), |
| 1102 | .id = getId(largestNonSecureVideoActiveClient), |
| 1103 | .name = "none"}; |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1104 | { |
| 1105 | std::vector<MediaResourceParcel> resources; |
| 1106 | resources.push_back(createNonSecureVideoCodecResource(1)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1107 | mService->addResource(clientD, smallNonSecureVideoMarkedClient, resources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1108 | resources.clear(); |
| 1109 | resources.push_back(createNonSecureVideoCodecResource(2)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1110 | mService->addResource(clientE, largeNonSecureVideoMarkedClient, resources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1111 | resources.clear(); |
| 1112 | resources.push_back(createNonSecureVideoCodecResource(3)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1113 | mService->addResource(clientF, largestNonSecureVideoActiveClient, resources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1114 | } |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1115 | mService->markClientForPendingRemoval(clientD); |
| 1116 | mService->markClientForPendingRemoval(clientE); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1117 | // don't mark the largest client |
| 1118 | |
| 1119 | // secure audio codec |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1120 | const auto smallSecureAudioMarkedClient = createTestClient(onlyPid, onlyUid); |
| 1121 | const auto largeSecureAudioMarkedClient = createTestClient(onlyPid, onlyUid); |
| 1122 | const auto largestSecureAudioActiveClient = createTestClient(onlyPid, onlyUid); |
| 1123 | ClientInfoParcel clientG{.pid = static_cast<int32_t>(onlyPid), |
| 1124 | .uid = static_cast<int32_t>(onlyUid), |
| 1125 | .id = getId(smallSecureAudioMarkedClient), |
| 1126 | .name = "none"}; |
| 1127 | ClientInfoParcel clientH{.pid = static_cast<int32_t>(onlyPid), |
| 1128 | .uid = static_cast<int32_t>(onlyUid), |
| 1129 | .id = getId(largeSecureAudioMarkedClient), |
| 1130 | .name = "none"}; |
| 1131 | ClientInfoParcel clientI{.pid = static_cast<int32_t>(onlyPid), |
| 1132 | .uid = static_cast<int32_t>(onlyUid), |
| 1133 | .id = getId(largestSecureVideoActiveClient), |
| 1134 | .name = "none"}; |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1135 | { |
| 1136 | std::vector<MediaResourceParcel> resources; |
| 1137 | resources.push_back(createSecureAudioCodecResource(1)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1138 | mService->addResource(clientG, smallSecureAudioMarkedClient, resources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1139 | resources.clear(); |
| 1140 | resources.push_back(createSecureAudioCodecResource(2)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1141 | mService->addResource(clientH, largeSecureAudioMarkedClient, resources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1142 | resources.clear(); |
| 1143 | resources.push_back(createSecureAudioCodecResource(3)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1144 | mService->addResource(clientI, largestSecureVideoActiveClient, resources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1145 | } |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1146 | mService->markClientForPendingRemoval(clientG); |
| 1147 | mService->markClientForPendingRemoval(clientH); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1148 | // don't mark the largest client |
| 1149 | |
| 1150 | // non-secure audio codec |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1151 | const auto smallNonSecureAudioMarkedClient = createTestClient(onlyPid, onlyUid); |
| 1152 | const auto largeNonSecureAudioMarkedClient = createTestClient(onlyPid, onlyUid); |
| 1153 | const auto largestNonSecureAudioActiveClient = createTestClient(onlyPid, onlyUid); |
| 1154 | ClientInfoParcel clientJ{.pid = static_cast<int32_t>(onlyPid), |
| 1155 | .uid = static_cast<int32_t>(onlyUid), |
| 1156 | .id = getId(smallNonSecureAudioMarkedClient), |
| 1157 | .name = "none"}; |
| 1158 | ClientInfoParcel clientK{.pid = static_cast<int32_t>(onlyPid), |
| 1159 | .uid = static_cast<int32_t>(onlyUid), |
| 1160 | .id = getId(largeNonSecureAudioMarkedClient), |
| 1161 | .name = "none"}; |
| 1162 | ClientInfoParcel clientL{.pid = static_cast<int32_t>(onlyPid), |
| 1163 | .uid = static_cast<int32_t>(onlyUid), |
| 1164 | .id = getId(largestNonSecureAudioActiveClient), |
| 1165 | .name = "none"}; |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1166 | { |
| 1167 | std::vector<MediaResourceParcel> resources; |
| 1168 | resources.push_back(createNonSecureAudioCodecResource(1)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1169 | mService->addResource(clientJ, smallNonSecureAudioMarkedClient, resources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1170 | resources.clear(); |
| 1171 | resources.push_back(createNonSecureAudioCodecResource(2)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1172 | mService->addResource(clientK, largeNonSecureAudioMarkedClient, resources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1173 | resources.clear(); |
| 1174 | resources.push_back(createNonSecureAudioCodecResource(3)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1175 | mService->addResource(clientL, largestNonSecureAudioActiveClient, resources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1176 | } |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1177 | mService->markClientForPendingRemoval(clientJ); |
| 1178 | mService->markClientForPendingRemoval(clientK); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1179 | // don't mark the largest client |
| 1180 | |
| 1181 | // secure image codec |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1182 | const auto smallSecureImageMarkedClient = createTestClient(onlyPid, onlyUid); |
| 1183 | const auto largeSecureImageMarkedClient = createTestClient(onlyPid, onlyUid); |
| 1184 | const auto largestSecureImageActiveClient = createTestClient(onlyPid, onlyUid); |
| 1185 | ClientInfoParcel clientM{.pid = static_cast<int32_t>(onlyPid), |
| 1186 | .uid = static_cast<int32_t>(onlyUid), |
| 1187 | .id = getId(smallSecureImageMarkedClient), |
| 1188 | .name = "none"}; |
| 1189 | ClientInfoParcel clientN{.pid = static_cast<int32_t>(onlyPid), |
| 1190 | .uid = static_cast<int32_t>(onlyUid), |
| 1191 | .id = getId(largeSecureImageMarkedClient), |
| 1192 | .name = "none"}; |
| 1193 | ClientInfoParcel clientO{.pid = static_cast<int32_t>(onlyPid), |
| 1194 | .uid = static_cast<int32_t>(onlyUid), |
| 1195 | .id = getId(largestSecureImageActiveClient), |
| 1196 | .name = "none"}; |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1197 | { |
| 1198 | std::vector<MediaResourceParcel> resources; |
| 1199 | resources.push_back(createSecureImageCodecResource(1)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1200 | mService->addResource(clientM, smallSecureImageMarkedClient, resources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1201 | resources.clear(); |
| 1202 | resources.push_back(createSecureImageCodecResource(2)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1203 | mService->addResource(clientN, largeSecureImageMarkedClient, resources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1204 | resources.clear(); |
| 1205 | resources.push_back(createSecureImageCodecResource(3)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1206 | mService->addResource(clientO, largestSecureImageActiveClient, resources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1207 | } |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1208 | mService->markClientForPendingRemoval(clientM); |
| 1209 | mService->markClientForPendingRemoval(clientN); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1210 | // don't mark the largest client |
| 1211 | |
| 1212 | // non-secure image codec |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1213 | const auto smallNonSecureImageMarkedClient = createTestClient(onlyPid, onlyUid); |
| 1214 | const auto largeNonSecureImageMarkedClient = createTestClient(onlyPid, onlyUid); |
| 1215 | const auto largestNonSecureImageActiveClient = createTestClient(onlyPid, onlyUid); |
| 1216 | ClientInfoParcel clientP{.pid = static_cast<int32_t>(onlyPid), |
| 1217 | .uid = static_cast<int32_t>(onlyUid), |
| 1218 | .id = getId(smallNonSecureImageMarkedClient), |
| 1219 | .name = "none"}; |
| 1220 | ClientInfoParcel clientQ{.pid = static_cast<int32_t>(onlyPid), |
| 1221 | .uid = static_cast<int32_t>(onlyUid), |
| 1222 | .id = getId(largeNonSecureImageMarkedClient), |
| 1223 | .name = "none"}; |
| 1224 | ClientInfoParcel clientR{.pid = static_cast<int32_t>(onlyPid), |
| 1225 | .uid = static_cast<int32_t>(onlyUid), |
| 1226 | .id = getId(largestNonSecureImageActiveClient), |
| 1227 | .name = "none"}; |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1228 | { |
| 1229 | std::vector<MediaResourceParcel> resources; |
| 1230 | resources.push_back(createNonSecureImageCodecResource(1)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1231 | mService->addResource(clientP, smallNonSecureImageMarkedClient, resources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1232 | resources.clear(); |
| 1233 | resources.push_back(createNonSecureImageCodecResource(2)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1234 | mService->addResource(clientQ, largeNonSecureImageMarkedClient, resources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1235 | resources.clear(); |
| 1236 | resources.push_back(createNonSecureImageCodecResource(3)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1237 | mService->addResource(clientR, largestNonSecureImageActiveClient, resources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1238 | } |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1239 | mService->markClientForPendingRemoval(clientP); |
| 1240 | mService->markClientForPendingRemoval(clientQ); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1241 | // don't mark the largest client |
| 1242 | |
| 1243 | // graphic memory |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1244 | const auto smallGraphicMemoryMarkedClient = createTestClient(onlyPid, onlyUid); |
| 1245 | const auto largeGraphicMemoryMarkedClient = createTestClient(onlyPid, onlyUid); |
| 1246 | const auto largestGraphicMemoryActiveClient = createTestClient(onlyPid, onlyUid); |
| 1247 | ClientInfoParcel clientS{.pid = static_cast<int32_t>(onlyPid), |
| 1248 | .uid = static_cast<int32_t>(onlyUid), |
| 1249 | .id = getId(smallGraphicMemoryMarkedClient), |
| 1250 | .name = "none"}; |
| 1251 | ClientInfoParcel clientT{.pid = static_cast<int32_t>(onlyPid), |
| 1252 | .uid = static_cast<int32_t>(onlyUid), |
| 1253 | .id = getId(largeGraphicMemoryMarkedClient), |
| 1254 | .name = "none"}; |
| 1255 | ClientInfoParcel clientU{.pid = static_cast<int32_t>(onlyPid), |
| 1256 | .uid = static_cast<int32_t>(onlyUid), |
| 1257 | .id = getId(largestGraphicMemoryActiveClient), |
| 1258 | .name = "none"}; |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1259 | { |
| 1260 | std::vector<MediaResourceParcel> resources; |
| 1261 | resources.push_back(createGraphicMemoryResource(100)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1262 | mService->addResource(clientS, smallGraphicMemoryMarkedClient, resources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1263 | resources.clear(); |
| 1264 | resources.push_back(createGraphicMemoryResource(200)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1265 | mService->addResource(clientT, largeGraphicMemoryMarkedClient, resources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1266 | resources.clear(); |
| 1267 | resources.push_back(createGraphicMemoryResource(300)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1268 | mService->addResource(clientU, largestGraphicMemoryActiveClient, resources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1269 | } |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1270 | mService->markClientForPendingRemoval(clientS); |
| 1271 | mService->markClientForPendingRemoval(clientT); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1272 | // don't mark the largest client |
| 1273 | |
| 1274 | // DRM session |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1275 | const auto smallDrmSessionMarkedClient = createTestClient(onlyPid, onlyUid); |
| 1276 | const auto largeDrmSessionMarkedClient = createTestClient(onlyPid, onlyUid); |
| 1277 | const auto largestDrmSessionActiveClient = createTestClient(onlyPid, onlyUid); |
| 1278 | ClientInfoParcel clientV{.pid = static_cast<int32_t>(onlyPid), |
| 1279 | .uid = static_cast<int32_t>(onlyUid), |
| 1280 | .id = getId(smallDrmSessionMarkedClient), |
| 1281 | .name = "none"}; |
| 1282 | ClientInfoParcel clientW{.pid = static_cast<int32_t>(onlyPid), |
| 1283 | .uid = static_cast<int32_t>(onlyUid), |
| 1284 | .id = getId(largeDrmSessionMarkedClient), |
| 1285 | .name = "none"}; |
| 1286 | ClientInfoParcel clientX{.pid = static_cast<int32_t>(onlyPid), |
| 1287 | .uid = static_cast<int32_t>(onlyUid), |
| 1288 | .id = getId(largestDrmSessionActiveClient), |
| 1289 | .name = "none"}; |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1290 | { |
| 1291 | std::vector<MediaResourceParcel> resources; |
| 1292 | resources.push_back(createDrmSessionResource(1)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1293 | mService->addResource(clientV, smallDrmSessionMarkedClient, resources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1294 | resources.clear(); |
| 1295 | resources.push_back(createDrmSessionResource(2)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1296 | mService->addResource(clientW, largeDrmSessionMarkedClient, resources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1297 | resources.clear(); |
| 1298 | resources.push_back(createDrmSessionResource(3)); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1299 | mService->addResource(clientX, largestDrmSessionActiveClient, resources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1300 | } |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1301 | mService->markClientForPendingRemoval(clientV); |
| 1302 | mService->markClientForPendingRemoval(clientW); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1303 | // don't mark the largest client |
| 1304 | |
| 1305 | // battery |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1306 | const auto batteryMarkedClient = createTestClient(onlyPid, onlyUid); |
| 1307 | ClientInfoParcel clientY{.pid = static_cast<int32_t>(onlyPid), |
| 1308 | .uid = static_cast<int32_t>(onlyUid), |
| 1309 | .id = getId(batteryMarkedClient), |
| 1310 | .name = "none"}; |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1311 | { |
| 1312 | std::vector<MediaResourceParcel> resources; |
| 1313 | resources.push_back(createBatteryResource()); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1314 | mService->addResource(clientY, batteryMarkedClient, resources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1315 | } |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1316 | mService->markClientForPendingRemoval(clientY); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1317 | |
| 1318 | // CPU boost |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1319 | const auto cpuBoostMarkedClient = createTestClient(onlyPid, onlyUid); |
| 1320 | ClientInfoParcel clientZ{.pid = static_cast<int32_t>(onlyPid), |
| 1321 | .uid = static_cast<int32_t>(onlyUid), |
| 1322 | .id = getId(cpuBoostMarkedClient), |
| 1323 | .name = "none"}; |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1324 | { |
| 1325 | std::vector<MediaResourceParcel> resources; |
| 1326 | resources.push_back(createCpuBoostResource()); |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1327 | mService->addResource(clientZ, cpuBoostMarkedClient, resources); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1328 | } |
Girish | 9128e24 | 2022-11-23 20:52:29 +0000 | [diff] [blame] | 1329 | mService->markClientForPendingRemoval(clientZ); |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1330 | |
| 1331 | // now we expect that we only reclaim resources from the biggest marked client |
| 1332 | EXPECT_TRUE(mService->reclaimResourcesFromClientsPendingRemoval(onlyPid).isOk()); |
| 1333 | // secure video codec |
| 1334 | EXPECT_FALSE(toTestClient(smallSecureVideoMarkedClient)->checkIfReclaimedAndReset()); |
| 1335 | EXPECT_TRUE(toTestClient(largeSecureVideoMarkedClient)->checkIfReclaimedAndReset()); |
| 1336 | EXPECT_FALSE(toTestClient(largestSecureVideoActiveClient)->checkIfReclaimedAndReset()); |
| 1337 | // non-secure video codec |
| 1338 | EXPECT_FALSE(toTestClient(smallNonSecureVideoMarkedClient)->checkIfReclaimedAndReset()); |
| 1339 | EXPECT_TRUE(toTestClient(largeNonSecureVideoMarkedClient)->checkIfReclaimedAndReset()); |
| 1340 | EXPECT_FALSE(toTestClient(largestNonSecureVideoActiveClient)->checkIfReclaimedAndReset()); |
| 1341 | // secure audio codec |
| 1342 | EXPECT_FALSE(toTestClient(smallSecureAudioMarkedClient)->checkIfReclaimedAndReset()); |
| 1343 | EXPECT_TRUE(toTestClient(largeSecureAudioMarkedClient)->checkIfReclaimedAndReset()); |
| 1344 | EXPECT_FALSE(toTestClient(largestSecureAudioActiveClient)->checkIfReclaimedAndReset()); |
| 1345 | // non-secure audio codec |
| 1346 | EXPECT_FALSE(toTestClient(smallNonSecureAudioMarkedClient)->checkIfReclaimedAndReset()); |
| 1347 | EXPECT_TRUE(toTestClient(largeNonSecureAudioMarkedClient)->checkIfReclaimedAndReset()); |
| 1348 | EXPECT_FALSE(toTestClient(largestNonSecureAudioActiveClient)->checkIfReclaimedAndReset()); |
| 1349 | // secure image codec |
| 1350 | EXPECT_FALSE(toTestClient(smallSecureImageMarkedClient)->checkIfReclaimedAndReset()); |
| 1351 | EXPECT_TRUE(toTestClient(largeSecureImageMarkedClient)->checkIfReclaimedAndReset()); |
| 1352 | EXPECT_FALSE(toTestClient(largestSecureImageActiveClient)->checkIfReclaimedAndReset()); |
| 1353 | // non-secure image codec |
| 1354 | EXPECT_FALSE(toTestClient(smallNonSecureImageMarkedClient)->checkIfReclaimedAndReset()); |
| 1355 | EXPECT_TRUE(toTestClient(largeNonSecureImageMarkedClient)->checkIfReclaimedAndReset()); |
| 1356 | EXPECT_FALSE(toTestClient(largestNonSecureImageActiveClient)->checkIfReclaimedAndReset()); |
| 1357 | // graphic memory |
| 1358 | EXPECT_FALSE(toTestClient(smallGraphicMemoryMarkedClient)->checkIfReclaimedAndReset()); |
| 1359 | EXPECT_TRUE(toTestClient(largeGraphicMemoryMarkedClient)->checkIfReclaimedAndReset()); |
| 1360 | EXPECT_FALSE(toTestClient(largestGraphicMemoryActiveClient)->checkIfReclaimedAndReset()); |
| 1361 | // DRM session |
| 1362 | EXPECT_FALSE(toTestClient(smallDrmSessionMarkedClient)->checkIfReclaimedAndReset()); |
| 1363 | EXPECT_TRUE(toTestClient(largeDrmSessionMarkedClient)->checkIfReclaimedAndReset()); |
| 1364 | EXPECT_FALSE(toTestClient(largestDrmSessionActiveClient)->checkIfReclaimedAndReset()); |
| 1365 | // battery is not expected to be reclaimed when marked as pending removal |
| 1366 | EXPECT_FALSE(toTestClient(batteryMarkedClient)->checkIfReclaimedAndReset()); |
| 1367 | // CPU boost is not expected to be reclaimed when marked as pending removal |
| 1368 | EXPECT_FALSE(toTestClient(cpuBoostMarkedClient)->checkIfReclaimedAndReset()); |
| 1369 | } |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 1370 | }; |
| 1371 | |
| 1372 | TEST_F(ResourceManagerServiceTest, config) { |
| 1373 | testConfig(); |
| 1374 | } |
| 1375 | |
| 1376 | TEST_F(ResourceManagerServiceTest, addResource) { |
| 1377 | addResource(); |
| 1378 | } |
| 1379 | |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 1380 | TEST_F(ResourceManagerServiceTest, combineResource) { |
| 1381 | testCombineResource(); |
| 1382 | } |
| 1383 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 1384 | TEST_F(ResourceManagerServiceTest, combineResourceNegative) { |
| 1385 | testCombineResourceWithNegativeValues(); |
| 1386 | } |
| 1387 | |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 1388 | TEST_F(ResourceManagerServiceTest, removeResource) { |
| 1389 | testRemoveResource(); |
| 1390 | } |
| 1391 | |
Chong Zhang | fb092d3 | 2019-08-12 09:45:44 -0700 | [diff] [blame] | 1392 | TEST_F(ResourceManagerServiceTest, removeClient) { |
| 1393 | testRemoveClient(); |
| 1394 | } |
| 1395 | |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 1396 | TEST_F(ResourceManagerServiceTest, reclaimResource) { |
| 1397 | testReclaimResourceSecure(); |
| 1398 | testReclaimResourceNonSecure(); |
| 1399 | } |
| 1400 | |
| 1401 | TEST_F(ResourceManagerServiceTest, getAllClients_l) { |
| 1402 | testGetAllClients(); |
| 1403 | } |
| 1404 | |
| 1405 | TEST_F(ResourceManagerServiceTest, getLowestPriorityBiggestClient_l) { |
| 1406 | testGetLowestPriorityBiggestClient(); |
| 1407 | } |
| 1408 | |
| 1409 | TEST_F(ResourceManagerServiceTest, getLowestPriorityPid_l) { |
| 1410 | testGetLowestPriorityPid(); |
| 1411 | } |
| 1412 | |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 1413 | TEST_F(ResourceManagerServiceTest, isCallingPriorityHigher_l) { |
| 1414 | testIsCallingPriorityHigher(); |
| 1415 | } |
| 1416 | |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1417 | TEST_F(ResourceManagerServiceTest, batteryStats) { |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 1418 | testBatteryStats(); |
| 1419 | } |
| 1420 | |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1421 | TEST_F(ResourceManagerServiceTest, cpusetBoost) { |
Chong Zhang | dd72680 | 2019-08-21 17:24:13 -0700 | [diff] [blame] | 1422 | testCpusetBoost(); |
| 1423 | } |
| 1424 | |
Henry Fang | 3276292 | 2020-01-28 18:40:39 -0800 | [diff] [blame] | 1425 | TEST_F(ResourceManagerServiceTest, overridePid) { |
| 1426 | testOverridePid(); |
| 1427 | } |
| 1428 | |
Wonsik Kim | d20e936 | 2020-04-28 10:42:57 -0700 | [diff] [blame] | 1429 | TEST_F(ResourceManagerServiceTest, markClientForPendingRemoval) { |
| 1430 | testMarkClientForPendingRemoval(); |
| 1431 | } |
| 1432 | |
Brian Lindahl | 64ee945 | 2022-01-14 13:31:16 +0100 | [diff] [blame] | 1433 | TEST_F(ResourceManagerServiceTest, reclaimResources_withVideoCodec_reclaimsOnlyVideoCodec) { |
| 1434 | testReclaimResources_withVideoCodec_reclaimsOnlyVideoCodec(); |
| 1435 | } |
| 1436 | |
| 1437 | TEST_F(ResourceManagerServiceTest, reclaimResources_withAudioCodec_reclaimsOnlyAudioCodec) { |
| 1438 | testReclaimResources_withAudioCodec_reclaimsOnlyAudioCodec(); |
| 1439 | } |
| 1440 | |
| 1441 | TEST_F(ResourceManagerServiceTest, reclaimResources_withImageCodec_reclaimsOnlyImageCodec) { |
| 1442 | testReclaimResources_withImageCodec_reclaimsOnlyImageCodec(); |
| 1443 | } |
| 1444 | |
| 1445 | TEST_F(ResourceManagerServiceTest, reclaimResources_whenPartialResourceMatch_reclaims) { |
| 1446 | testReclaimResources_whenPartialResourceMatch_reclaims(); |
| 1447 | } |
| 1448 | |
| 1449 | TEST_F(ResourceManagerServiceTest, |
| 1450 | reclaimResourcesFromMarkedClients_removesBiggestMarkedClientForSomeResources) { |
| 1451 | testReclaimResourcesFromMarkedClients_removesBiggestMarkedClientForSomeResources(); |
| 1452 | } |
| 1453 | |
Ronghua Wu | 231c3d1 | 2015-03-11 15:10:32 -0700 | [diff] [blame] | 1454 | } // namespace android |