1 //
2 // Copyright (C) 2012 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 #include "update_engine/common/cpu_limiter.h"
18
19 #include <gtest/gtest.h>
20
21 namespace chromeos_update_engine {
22
23 class CPULimiterTest : public ::testing::Test {};
24
25 namespace {
26 // Compares cpu shares and returns an integer that is less
27 // than, equal to or greater than 0 if |shares_lhs| is,
28 // respectively, lower than, same as or higher than |shares_rhs|.
CompareCpuShares(CpuShares shares_lhs,CpuShares shares_rhs)29 int CompareCpuShares(CpuShares shares_lhs, CpuShares shares_rhs) {
30 return static_cast<int>(shares_lhs) - static_cast<int>(shares_rhs);
31 }
32 } // namespace
33
34 // Tests the CPU shares enum is in the order we expect it.
TEST(CPULimiterTest,CompareCpuSharesTest)35 TEST(CPULimiterTest, CompareCpuSharesTest) {
36 EXPECT_LT(CompareCpuShares(CpuShares::kLow, CpuShares::kNormal), 0);
37 EXPECT_GT(CompareCpuShares(CpuShares::kNormal, CpuShares::kLow), 0);
38 EXPECT_EQ(CompareCpuShares(CpuShares::kNormal, CpuShares::kNormal), 0);
39 EXPECT_GT(CompareCpuShares(CpuShares::kHigh, CpuShares::kNormal), 0);
40 }
41
42 } // namespace chromeos_update_engine
43