Home | History | Annotate | Download | only in os
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  * Licensed under the Apache License, Version 2.0 (the "License");
      4  * you may not use this file except in compliance with the License.
      5  * You may obtain a copy of the License at
      6  *
      7  *      http://www.apache.org/licenses/LICENSE-2.0
      8  *
      9  * Unless required by applicable law or agreed to in writing, software
     10  * distributed under the License is distributed on an "AS IS" BASIS,
     11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12  * See the License for the specific language governing permissions and
     13  * limitations under the License.
     14  *
     15  *
     16  */
     17 
     18 package com.android.internal.os;
     19 
     20 import android.support.test.InstrumentationRegistry;
     21 import android.support.test.filters.SmallTest;
     22 
     23 import junit.framework.TestCase;
     24 
     25 import org.junit.Before;
     26 import org.junit.Test;
     27 
     28 /*
     29  * Keep this file in sync with frameworks/base/core/res/res/xml/power_profile_test.xml
     30  */
     31 @SmallTest
     32 public class PowerProfileTest extends TestCase {
     33 
     34     private PowerProfile mProfile;
     35 
     36     @Before
     37     public void setUp() {
     38         mProfile = new PowerProfile(InstrumentationRegistry.getContext(), true);
     39     }
     40 
     41     @Test
     42     public void testPowerProfile() {
     43         assertEquals(2, mProfile.getNumCpuClusters());
     44         assertEquals(4, mProfile.getNumCoresInCpuCluster(0));
     45         assertEquals(4, mProfile.getNumCoresInCpuCluster(1));
     46         assertEquals(5.0, mProfile.getAveragePower(PowerProfile.POWER_CPU_SUSPEND));
     47         assertEquals(1.11, mProfile.getAveragePower(PowerProfile.POWER_CPU_IDLE));
     48         assertEquals(2.55, mProfile.getAveragePower(PowerProfile.POWER_CPU_ACTIVE));
     49         assertEquals(2.11, mProfile.getAveragePowerForCpuCluster(0));
     50         assertEquals(2.22, mProfile.getAveragePowerForCpuCluster(1));
     51         assertEquals(3, mProfile.getNumSpeedStepsInCpuCluster(0));
     52         assertEquals(30.0, mProfile.getAveragePowerForCpuCore(0, 2));
     53         assertEquals(4, mProfile.getNumSpeedStepsInCpuCluster(1));
     54         assertEquals(60.0, mProfile.getAveragePowerForCpuCore(1, 3));
     55         assertEquals(3000.0, mProfile.getBatteryCapacity());
     56         assertEquals(0.5, mProfile.getAveragePower(PowerProfile.POWER_AMBIENT_DISPLAY));
     57         assertEquals(100.0, mProfile.getAveragePower(PowerProfile.POWER_AUDIO));
     58         assertEquals(150.0, mProfile.getAveragePower(PowerProfile.POWER_VIDEO));
     59     }
     60 
     61 }
     62