use of android.support.test.filters.SmallTest in project platform_frameworks_base by android.
the class BatteryStatsSamplingTimerTest method testSampleTimerSummaryParceling.
@SmallTest
public void testSampleTimerSummaryParceling() throws Exception {
final MockClocks clocks = new MockClocks();
clocks.realtime = 0;
clocks.uptime = 0;
final BatteryStatsImpl.TimeBase timeBase = new BatteryStatsImpl.TimeBase();
timeBase.init(clocks.uptimeMillis(), clocks.elapsedRealtime());
BatteryStatsImpl.SamplingTimer timer = new BatteryStatsImpl.SamplingTimer(clocks, timeBase);
// Start running on battery.
timeBase.setRunning(true, clocks.uptimeMillis(), clocks.elapsedRealtime());
// The first update on battery consumes the values as a way of starting cleanly.
timer.add(10, 1);
timer.add(10, 1);
clocks.realtime = 20;
clocks.uptime = 20;
assertEquals(10, timer.getTotalTimeLocked(clocks.elapsedRealtime(), BatteryStats.STATS_SINCE_CHARGED));
assertEquals(1, timer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED));
// Grab a summary parcel while on battery.
final Parcel onBatterySummaryParcel = Parcel.obtain();
timer.writeSummaryFromParcelLocked(onBatterySummaryParcel, clocks.elapsedRealtime() * 1000);
onBatterySummaryParcel.setDataPosition(0);
// Stop running on battery.
timeBase.setRunning(false, clocks.uptimeMillis(), clocks.elapsedRealtime());
assertEquals(10, timer.getTotalTimeLocked(clocks.elapsedRealtime(), BatteryStats.STATS_SINCE_CHARGED));
assertEquals(1, timer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED));
// Grab a summary parcel while not on battery.
final Parcel offBatterySummaryParcel = Parcel.obtain();
timer.writeSummaryFromParcelLocked(offBatterySummaryParcel, clocks.elapsedRealtime() * 1000);
offBatterySummaryParcel.setDataPosition(0);
// Set the timebase running again. That way any issues with tracking reported values
// get tested when we unparcel the timers below.
timeBase.setRunning(true, clocks.uptimeMillis(), clocks.elapsedRealtime());
// Read the on battery summary from the parcel.
BatteryStatsImpl.SamplingTimer unparceledOnBatteryTimer = new BatteryStatsImpl.SamplingTimer(clocks, timeBase);
unparceledOnBatteryTimer.readSummaryFromParcelLocked(onBatterySummaryParcel);
assertEquals(10, unparceledOnBatteryTimer.getTotalTimeLocked(0, BatteryStats.STATS_SINCE_CHARGED));
assertEquals(1, unparceledOnBatteryTimer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED));
// Read the off battery summary from the parcel.
BatteryStatsImpl.SamplingTimer unparceledOffBatteryTimer = new BatteryStatsImpl.SamplingTimer(clocks, timeBase);
unparceledOffBatteryTimer.readSummaryFromParcelLocked(offBatterySummaryParcel);
assertEquals(10, unparceledOffBatteryTimer.getTotalTimeLocked(0, BatteryStats.STATS_SINCE_CHARGED));
assertEquals(1, unparceledOffBatteryTimer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED));
// Now, just like with a fresh timer, the first update should be absorbed to account for
// data being collected when we weren't recording.
unparceledOnBatteryTimer.update(10, 10);
assertEquals(10, unparceledOnBatteryTimer.getTotalTimeLocked(0, BatteryStats.STATS_SINCE_CHARGED));
assertEquals(1, unparceledOnBatteryTimer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED));
unparceledOffBatteryTimer.update(10, 10);
assertEquals(10, unparceledOffBatteryTimer.getTotalTimeLocked(0, BatteryStats.STATS_SINCE_CHARGED));
assertEquals(1, unparceledOffBatteryTimer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED));
}
use of android.support.test.filters.SmallTest in project platform_frameworks_base by android.
the class BatteryStatsServTest method testParceling.
/**
* Test parceling and unparceling.
*/
@SmallTest
public void testParceling() throws Exception {
MockBatteryStatsImpl bsi = new MockBatteryStatsImpl();
TestServ orig = new TestServ(bsi);
orig.populate();
Parcel parcel = Parcel.obtain();
orig.writeToParcelLocked(parcel);
parcel.setDataPosition(0);
TestServ serv = new TestServ(bsi);
serv.readFromParcelLocked(parcel);
Assert.assertEquals(1010, serv.getStartTime());
Assert.assertEquals(2021, serv.getRunningSince());
Assert.assertTrue(serv.getRunning());
Assert.assertEquals(4042, serv.getStarts());
Assert.assertEquals(5053, serv.getLaunchedTime());
Assert.assertEquals(6064, serv.getLaunchedSince());
Assert.assertTrue(serv.getLaunched());
Assert.assertEquals(8085, serv.getLaunches());
Assert.assertEquals(9096, serv.getLoadedStartTime());
Assert.assertEquals(10017, serv.getLoadedStarts());
Assert.assertEquals(11118, serv.getLoadedLaunches());
Assert.assertEquals(0, serv.getLastStartTime());
Assert.assertEquals(0, serv.getLastStarts());
Assert.assertEquals(0, serv.getLastLaunches());
Assert.assertEquals(15512, serv.getUnpluggedStartTime());
Assert.assertEquals(16613, serv.getUnpluggedStarts());
Assert.assertEquals(17714, serv.getUnpluggedLaunches());
}
use of android.support.test.filters.SmallTest in project platform_frameworks_base by android.
the class BatteryStatsTimeBaseTest method testDump.
/**
* Test dump
*/
@SmallTest
public void testDump() throws Exception {
TestTimeBase tb = new TestTimeBase();
tb.populate(100, 200, true, 300, 400, 500, 600, 50, 60);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
tb.dump(pw, "+++++ ");
pw.close();
// note the spaces at the ends of the lines which come from formatTimeMs.
final String CORRECT = "+++++ mRunning=true\n" + "+++++ mUptime=0ms \n" + "+++++ mRealtime=0ms \n" + "+++++ mPastUptime=0ms mUptimeStart=0ms mUnpluggedUptime=0ms \n" + "+++++ mPastRealtime=0ms mRealtimeStart=0ms mUnpluggedRealtime=0ms \n";
Assert.assertEquals(CORRECT, sw.toString());
}
use of android.support.test.filters.SmallTest in project platform_frameworks_base by android.
the class BatteryStatsTimerTest method testRunning.
/**
* Tests that the flow through TimeBase.setRunning propagates through
* to the timer.
*/
@SmallTest
public void testRunning() throws Exception {
TimeBase timeBase = new TimeBase();
MockClocks clocks = new MockClocks();
TestTimer timer = new TestTimer(clocks, 0, timeBase);
timer.nextComputeCurrentCount = 3000;
// Test that starting the timer counts the unplugged time and counters
timer.nextComputeRunTime = 4;
timer.onTimeStarted(10, 20, 50);
Assert.assertEquals(50, timer.lastComputeRunTimeRealtime);
Assert.assertEquals(4, timer.getUnpluggedTime());
Assert.assertEquals(3000, timer.getUnpluggedCount());
// Test that stopping the timer updates mTotalTime and mCount
timer.nextComputeRunTime = 17;
timer.onTimeStopped(100, 130, 170);
Assert.assertEquals(17, timer.getTotalTime());
Assert.assertEquals(3000, timer.getCount());
}
use of android.support.test.filters.SmallTest in project platform_frameworks_base by android.
the class BatteryStatsTimerTest method testGetCountLocked.
/**
* Tests getCountLocked
*/
@SmallTest
public void testGetCountLocked() throws Exception {
TimeBase timeBase = new TimeBase();
timeBase.setRunning(true, 10, 20);
timeBase.setRunning(false, 45, 60);
Assert.assertEquals(40, timeBase.getRealtime(200));
MockClocks clocks = new MockClocks();
TestTimer timer = new TestTimer(clocks, 0, timeBase);
timer.setCount(1);
timer.setLoadedCount(2);
timer.setLastCount(3);
timer.setUnpluggedCount(4);
timer.setTotalTime(100);
timer.setLoadedTime(200);
timer.setLastTime(300);
timer.setUnpluggedTime(400);
timer.setTimeBeforeMark(500);
// Timer.getCountLocked(STATS_SINCE_CHARGED)
timer.nextComputeCurrentCount = 10000;
Assert.assertEquals(10000, timer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED));
// Timer.getCountLocked(STATS_CURRENT)
timer.nextComputeCurrentCount = 10000;
Assert.assertEquals(9998, timer.getCountLocked(BatteryStats.STATS_CURRENT));
// Timer.getCountLocked(STATS_SINCE_UNPLUGGED)
timer.nextComputeCurrentCount = 10000;
Assert.assertEquals(9996, timer.getCountLocked(BatteryStats.STATS_SINCE_UNPLUGGED));
}
Aggregations