blob: b910485c06282ac32908f38fb83b4982aa55887b [file] [log] [blame]
Tony Huang9ac5e6e2023-08-24 09:01:44 +00001/*
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
24namespace android::scheduler {
25
26class SmallAreaDetectionMappingsAllowTest : public testing::Test {
27protected:
28 SmallAreaDetectionAllowMappings mMappings;
29};
30
31namespace {
32TEST_F(SmallAreaDetectionMappingsAllowTest, testUpdate) {
33 const uid_t uid1 = 10100;
34 const uid_t uid2 = 10101;
35 const float threshold1 = 0.05f;
36 const float threshold2 = 0.07f;
37 std::vector<std::pair<uid_t, float>> mappings;
38 mappings.reserve(2);
39 mappings.push_back(std::make_pair(uid1, threshold1));
40 mappings.push_back(std::make_pair(uid2, threshold2));
41
42 mMappings.update(mappings);
43 ASSERT_EQ(mMappings.getThresholdForUid(uid1).value(), threshold1);
44 ASSERT_EQ(mMappings.getThresholdForUid(uid2).value(), threshold2);
45}
46
47TEST_F(SmallAreaDetectionMappingsAllowTest, testSetThesholdForUid) {
48 const uid_t uid = 10111;
49 const float threshold = 0.05f;
50
51 mMappings.setThesholdForUid(uid, threshold);
52 ASSERT_EQ(mMappings.getThresholdForUid(uid), threshold);
53}
54
55TEST_F(SmallAreaDetectionMappingsAllowTest, testUidNotInTheMappings) {
56 const uid_t uid = 10222;
57 ASSERT_EQ(mMappings.getThresholdForUid(uid), std::nullopt);
58}
59
60} // namespace
61} // namespace android::scheduler