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