cmsdk: Fix PerformanceManagerTest expectations.

Since the API for PerformanceManager returns the number
  of profiles supported we can assume what the profiles are
  since the HAL provides them in an ordered manner. Thus,
  iterate through the size of the number of profiles and verify
  each one that's possible.

Change-Id: I87f6d1a847c849bd9e544c1e89a666726c61fe83
TICKET: CYNGNOS-2603
This commit is contained in:
Adnan Begovic 2016-04-27 15:54:32 -07:00
parent c6550fd803
commit 94dd91a34c
2 changed files with 34 additions and 15 deletions

View File

@ -66,6 +66,17 @@ public class PerformanceManager {
*/ */
public static final int PROFILE_BIAS_PERFORMANCE = 4; public static final int PROFILE_BIAS_PERFORMANCE = 4;
/**
* @hide
*/
public static final int[] POSSIBLE_POWER_PROFILES = new int[] {
PROFILE_POWER_SAVE,
PROFILE_BALANCED,
PROFILE_HIGH_PERFORMANCE,
PROFILE_BIAS_POWER_SAVE,
PROFILE_BIAS_PERFORMANCE
};
private int mNumberOfProfiles = 0; private int mNumberOfProfiles = 0;
/** /**

View File

@ -56,9 +56,15 @@ public class PerfomanceManagerTest extends AndroidTestCase {
} }
@SmallTest @SmallTest
public void testGetNumberOfPerformanceProfiles() { public void testPowerProfileCantBeSetIfNoneSupported() {
// Assert that we can even set perf profiles // Assert that if we attempt to set a power profile if none supported
assertTrue(mCMPerformanceManager.getNumberOfProfiles() > 0); // then we receive a failed response from the service.
if (mCMPerformanceManager.getNumberOfProfiles() == 0) {
for (int powerProfile = 0; powerProfile <
PerformanceManager.POSSIBLE_POWER_PROFILES.length; powerProfile++) {
assertFalse(mCMPerformanceManager.setPowerProfile(powerProfile));
}
}
} }
@SmallTest @SmallTest
@ -68,18 +74,20 @@ public class PerfomanceManagerTest extends AndroidTestCase {
@SmallTest @SmallTest
public void testSetAndGetPowerProfile() { public void testSetAndGetPowerProfile() {
int[] expectedStates = new int[] { PerformanceManager.PROFILE_POWER_SAVE, // Identify what power profiles are supported. The api currently returns
PerformanceManager.PROFILE_BALANCED, // the total number of profiles supported in an ordered manner, thus we can
PerformanceManager.PROFILE_HIGH_PERFORMANCE}; // assume what they are and if we can set everything correctly.
for (int powerProfile = 0; powerProfile <
// Set the state PerformanceManager.POSSIBLE_POWER_PROFILES.length; powerProfile++) {
for (int profile : expectedStates) { if (powerProfile < mCMPerformanceManager.getNumberOfProfiles()) {
// If the target perf profile is the same as the current one, //It is supported, set it and test if it was set
// setPowerProfile will noop, ignore that scenario if (mCMPerformanceManager.getPowerProfile() != powerProfile) {
if (mCMPerformanceManager.getPowerProfile() != profile) { mCMPerformanceManager.setPowerProfile(powerProfile);
mCMPerformanceManager.setPowerProfile(profile); // Verify that it was set correctly.
// Verify that it was set correctly. assertEquals(powerProfile, mCMPerformanceManager.getPowerProfile());
assertEquals(profile, mCMPerformanceManager.getPowerProfile()); }
} else {
assertFalse(mCMPerformanceManager.setPowerProfile(powerProfile));
} }
} }
} }