Program: 191114
Project: 191114
Buggy source:
@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);
  timeBase.setRunning(true,clocks.uptimeMillis(),clocks.elapsedRealtime());
  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));
  final Parcel onBatterySummaryParcel=Parcel.obtain();
  timer.writeSummaryFromParcelLocked(onBatterySummaryParcel,clocks.elapsedRealtime() * 1000);
  onBatterySummaryParcel.setDataPosition(0);
  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));
  final Parcel offBatterySummaryParcel=Parcel.obtain();
  timer.writeSummaryFromParcelLocked(offBatterySummaryParcel,clocks.elapsedRealtime() * 1000);
  offBatterySummaryParcel.setDataPosition(0);
  BatteryStatsImpl.SamplingTimer unparceledTimer=new BatteryStatsImpl.SamplingTimer(clocks,timeBase);
  unparceledTimer.readSummaryFromParcelLocked(onBatterySummaryParcel);
  assertEquals(10,unparceledTimer.getTotalTimeLocked(0,BatteryStats.STATS_SINCE_CHARGED));
  assertEquals(1,unparceledTimer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED));
  unparceledTimer=new BatteryStatsImpl.SamplingTimer(clocks,timeBase);
  unparceledTimer.readSummaryFromParcelLocked(offBatterySummaryParcel);
  assertEquals(10,unparceledTimer.getTotalTimeLocked(0,BatteryStats.STATS_SINCE_CHARGED));
  assertEquals(1,unparceledTimer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED));
}

Fixed version (ground truth):
@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);
  timeBase.setRunning(true,clocks.uptimeMillis(),clocks.elapsedRealtime());
  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));
  final Parcel onBatterySummaryParcel=Parcel.obtain();
  timer.writeSummaryFromParcelLocked(onBatterySummaryParcel,clocks.elapsedRealtime() * 1000);
  onBatterySummaryParcel.setDataPosition(0);
  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));
  final Parcel offBatterySummaryParcel=Parcel.obtain();
  timer.writeSummaryFromParcelLocked(offBatterySummaryParcel,clocks.elapsedRealtime() * 1000);
  offBatterySummaryParcel.setDataPosition(0);
  timeBase.setRunning(true,clocks.uptimeMillis(),clocks.elapsedRealtime());
  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));
  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));
  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));
}