Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2023 The Android Open Source Project |
| 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 | #undef LOG_TAG |
| 18 | #define LOG_TAG "SmallAreaDetectionAllowMappingsTest" |
| 19 | |
| 20 | #include <gtest/gtest.h> |
| 21 | |
| 22 | #include "Scheduler/SmallAreaDetectionAllowMappings.h" |
| 23 | |
| 24 | namespace android::scheduler { |
| 25 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 26 | class SmallAreaDetectionAllowMappingsTest : public testing::Test { |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 27 | protected: |
| 28 | SmallAreaDetectionAllowMappings mMappings; |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 29 | static constexpr int32_t kAppId1 = 10100; |
| 30 | static constexpr int32_t kAppId2 = 10101; |
| 31 | static constexpr float kThreshold1 = 0.05f; |
| 32 | static constexpr float kThreshold2 = 0.07f; |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | namespace { |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 36 | TEST_F(SmallAreaDetectionAllowMappingsTest, testUpdate) { |
| 37 | std::vector<std::pair<int32_t, float>> mappings; |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 38 | mappings.reserve(2); |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 39 | mappings.push_back(std::make_pair(kAppId1, kThreshold1)); |
| 40 | mappings.push_back(std::make_pair(kAppId2, kThreshold2)); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 41 | |
| 42 | mMappings.update(mappings); |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 43 | ASSERT_EQ(mMappings.getThresholdForAppId(kAppId1).value(), kThreshold1); |
| 44 | ASSERT_EQ(mMappings.getThresholdForAppId(kAppId2).value(), kThreshold2); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Jerry Chang | 3667800 | 2023-11-29 16:56:17 +0000 | [diff] [blame^] | 47 | TEST_F(SmallAreaDetectionAllowMappingsTest, testSetThresholdForAppId) { |
| 48 | mMappings.setThresholdForAppId(kAppId1, kThreshold1); |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 49 | ASSERT_EQ(mMappings.getThresholdForAppId(kAppId1), kThreshold1); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Tony Huang | f362110 | 2023-09-04 17:14:22 +0800 | [diff] [blame] | 52 | TEST_F(SmallAreaDetectionAllowMappingsTest, testAppIdNotInTheMappings) { |
| 53 | ASSERT_EQ(mMappings.getThresholdForAppId(kAppId1), std::nullopt); |
Tony Huang | 9ac5e6e | 2023-08-24 09:01:44 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | } // namespace |
| 57 | } // namespace android::scheduler |