@Test public void readData_noFile() throws IOException{ String[] arr = getAlarmData(); Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(arr); Date traceDateTime = new Date(); Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(false); List<AlarmInfo> list = reader.readData(traceFolder, 123, 124, traceDateTime); assertTrue(list.size() == 0); }
@Override public List<AlarmInfo> readData(String directory, double dumpsysEpochTimestamp, double dumpsysElapsedTimestamp, Date traceDateTime) { List<AlarmInfo> alarmInfos = new ArrayList<AlarmInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.KERNEL_LOG_FILE; double timestamp; double timestampElapsed; double timestampEpoch; double timeDeltaEpochElapsed = dumpsysEpochTimestamp - dumpsysElapsedTimestamp; AlarmType alarmType; String[] lines = null; if (!filereader.fileExist(filepath)) { return alarmInfos; } try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read kernal log file for Alarm Info data: " + filepath); return alarmInfos; } for (String strLineBuf : lines) { if (strLineBuf.indexOf("alarm_timer_triggered") > 0) { String strFields[] = strLineBuf.split(" "); if (strFields.length > 1) { try { timestamp = 0; switch (Integer.parseInt(strFields[strFields.length - 3])) { case 0: alarmType = AlarmType.RTC_WAKEUP; break; case 1: alarmType = AlarmType.RTC; break; case 2: alarmType = AlarmType.ELAPSED_REALTIME_WAKEUP; timestamp = timeDeltaEpochElapsed; break; case 3: alarmType = AlarmType.ELAPSED_REALTIME; timestamp = timeDeltaEpochElapsed; break; default: LOGGER.warn("cannot resolve alarm type: " + timestamp + " type " + Double.parseDouble(strFields[strFields.length - 3])); alarmType = AlarmType.UNKNOWN; break; } timestamp += Double.parseDouble(strFields[strFields.length - 1]) / 1000000; timestampEpoch = timestamp; timestamp = timestamp - traceDateTime.getTime(); timestampElapsed = timestampEpoch - dumpsysEpochTimestamp + dumpsysElapsedTimestamp; alarmInfos.add(new AlarmInfo(timestamp, timestampEpoch, timestampElapsed, alarmType)); } catch (Exception e) { LOGGER.warn("Unexpected error parsing alarm event: " + strLineBuf, e); } } } } return alarmInfos; }
AlarmInfoReaderImpl extends PeripheralBase implements IAlarmInfoReader { @Override public List<AlarmInfo> readData(String directory, double dumpsysEpochTimestamp, double dumpsysElapsedTimestamp, Date traceDateTime) { List<AlarmInfo> alarmInfos = new ArrayList<AlarmInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.KERNEL_LOG_FILE; double timestamp; double timestampElapsed; double timestampEpoch; double timeDeltaEpochElapsed = dumpsysEpochTimestamp - dumpsysElapsedTimestamp; AlarmType alarmType; String[] lines = null; if (!filereader.fileExist(filepath)) { return alarmInfos; } try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read kernal log file for Alarm Info data: " + filepath); return alarmInfos; } for (String strLineBuf : lines) { if (strLineBuf.indexOf("alarm_timer_triggered") > 0) { String strFields[] = strLineBuf.split(" "); if (strFields.length > 1) { try { timestamp = 0; switch (Integer.parseInt(strFields[strFields.length - 3])) { case 0: alarmType = AlarmType.RTC_WAKEUP; break; case 1: alarmType = AlarmType.RTC; break; case 2: alarmType = AlarmType.ELAPSED_REALTIME_WAKEUP; timestamp = timeDeltaEpochElapsed; break; case 3: alarmType = AlarmType.ELAPSED_REALTIME; timestamp = timeDeltaEpochElapsed; break; default: LOGGER.warn("cannot resolve alarm type: " + timestamp + " type " + Double.parseDouble(strFields[strFields.length - 3])); alarmType = AlarmType.UNKNOWN; break; } timestamp += Double.parseDouble(strFields[strFields.length - 1]) / 1000000; timestampEpoch = timestamp; timestamp = timestamp - traceDateTime.getTime(); timestampElapsed = timestampEpoch - dumpsysEpochTimestamp + dumpsysElapsedTimestamp; alarmInfos.add(new AlarmInfo(timestamp, timestampEpoch, timestampElapsed, alarmType)); } catch (Exception e) { LOGGER.warn("Unexpected error parsing alarm event: " + strLineBuf, e); } } } } return alarmInfos; } }
AlarmInfoReaderImpl extends PeripheralBase implements IAlarmInfoReader { @Override public List<AlarmInfo> readData(String directory, double dumpsysEpochTimestamp, double dumpsysElapsedTimestamp, Date traceDateTime) { List<AlarmInfo> alarmInfos = new ArrayList<AlarmInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.KERNEL_LOG_FILE; double timestamp; double timestampElapsed; double timestampEpoch; double timeDeltaEpochElapsed = dumpsysEpochTimestamp - dumpsysElapsedTimestamp; AlarmType alarmType; String[] lines = null; if (!filereader.fileExist(filepath)) { return alarmInfos; } try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read kernal log file for Alarm Info data: " + filepath); return alarmInfos; } for (String strLineBuf : lines) { if (strLineBuf.indexOf("alarm_timer_triggered") > 0) { String strFields[] = strLineBuf.split(" "); if (strFields.length > 1) { try { timestamp = 0; switch (Integer.parseInt(strFields[strFields.length - 3])) { case 0: alarmType = AlarmType.RTC_WAKEUP; break; case 1: alarmType = AlarmType.RTC; break; case 2: alarmType = AlarmType.ELAPSED_REALTIME_WAKEUP; timestamp = timeDeltaEpochElapsed; break; case 3: alarmType = AlarmType.ELAPSED_REALTIME; timestamp = timeDeltaEpochElapsed; break; default: LOGGER.warn("cannot resolve alarm type: " + timestamp + " type " + Double.parseDouble(strFields[strFields.length - 3])); alarmType = AlarmType.UNKNOWN; break; } timestamp += Double.parseDouble(strFields[strFields.length - 1]) / 1000000; timestampEpoch = timestamp; timestamp = timestamp - traceDateTime.getTime(); timestampElapsed = timestampEpoch - dumpsysEpochTimestamp + dumpsysElapsedTimestamp; alarmInfos.add(new AlarmInfo(timestamp, timestampEpoch, timestampElapsed, alarmType)); } catch (Exception e) { LOGGER.warn("Unexpected error parsing alarm event: " + strLineBuf, e); } } } } return alarmInfos; }  }
AlarmInfoReaderImpl extends PeripheralBase implements IAlarmInfoReader { @Override public List<AlarmInfo> readData(String directory, double dumpsysEpochTimestamp, double dumpsysElapsedTimestamp, Date traceDateTime) { List<AlarmInfo> alarmInfos = new ArrayList<AlarmInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.KERNEL_LOG_FILE; double timestamp; double timestampElapsed; double timestampEpoch; double timeDeltaEpochElapsed = dumpsysEpochTimestamp - dumpsysElapsedTimestamp; AlarmType alarmType; String[] lines = null; if (!filereader.fileExist(filepath)) { return alarmInfos; } try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read kernal log file for Alarm Info data: " + filepath); return alarmInfos; } for (String strLineBuf : lines) { if (strLineBuf.indexOf("alarm_timer_triggered") > 0) { String strFields[] = strLineBuf.split(" "); if (strFields.length > 1) { try { timestamp = 0; switch (Integer.parseInt(strFields[strFields.length - 3])) { case 0: alarmType = AlarmType.RTC_WAKEUP; break; case 1: alarmType = AlarmType.RTC; break; case 2: alarmType = AlarmType.ELAPSED_REALTIME_WAKEUP; timestamp = timeDeltaEpochElapsed; break; case 3: alarmType = AlarmType.ELAPSED_REALTIME; timestamp = timeDeltaEpochElapsed; break; default: LOGGER.warn("cannot resolve alarm type: " + timestamp + " type " + Double.parseDouble(strFields[strFields.length - 3])); alarmType = AlarmType.UNKNOWN; break; } timestamp += Double.parseDouble(strFields[strFields.length - 1]) / 1000000; timestampEpoch = timestamp; timestamp = timestamp - traceDateTime.getTime(); timestampElapsed = timestampEpoch - dumpsysEpochTimestamp + dumpsysElapsedTimestamp; alarmInfos.add(new AlarmInfo(timestamp, timestampEpoch, timestampElapsed, alarmType)); } catch (Exception e) { LOGGER.warn("Unexpected error parsing alarm event: " + strLineBuf, e); } } } } return alarmInfos; }  @Override List<AlarmInfo> readData(String directory, double dumpsysEpochTimestamp, double dumpsysElapsedTimestamp, Date traceDateTime); }
AlarmInfoReaderImpl extends PeripheralBase implements IAlarmInfoReader { @Override public List<AlarmInfo> readData(String directory, double dumpsysEpochTimestamp, double dumpsysElapsedTimestamp, Date traceDateTime) { List<AlarmInfo> alarmInfos = new ArrayList<AlarmInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.KERNEL_LOG_FILE; double timestamp; double timestampElapsed; double timestampEpoch; double timeDeltaEpochElapsed = dumpsysEpochTimestamp - dumpsysElapsedTimestamp; AlarmType alarmType; String[] lines = null; if (!filereader.fileExist(filepath)) { return alarmInfos; } try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read kernal log file for Alarm Info data: " + filepath); return alarmInfos; } for (String strLineBuf : lines) { if (strLineBuf.indexOf("alarm_timer_triggered") > 0) { String strFields[] = strLineBuf.split(" "); if (strFields.length > 1) { try { timestamp = 0; switch (Integer.parseInt(strFields[strFields.length - 3])) { case 0: alarmType = AlarmType.RTC_WAKEUP; break; case 1: alarmType = AlarmType.RTC; break; case 2: alarmType = AlarmType.ELAPSED_REALTIME_WAKEUP; timestamp = timeDeltaEpochElapsed; break; case 3: alarmType = AlarmType.ELAPSED_REALTIME; timestamp = timeDeltaEpochElapsed; break; default: LOGGER.warn("cannot resolve alarm type: " + timestamp + " type " + Double.parseDouble(strFields[strFields.length - 3])); alarmType = AlarmType.UNKNOWN; break; } timestamp += Double.parseDouble(strFields[strFields.length - 1]) / 1000000; timestampEpoch = timestamp; timestamp = timestamp - traceDateTime.getTime(); timestampElapsed = timestampEpoch - dumpsysEpochTimestamp + dumpsysElapsedTimestamp; alarmInfos.add(new AlarmInfo(timestamp, timestampEpoch, timestampElapsed, alarmType)); } catch (Exception e) { LOGGER.warn("Unexpected error parsing alarm event: " + strLineBuf, e); } } } } return alarmInfos; }  @Override List<AlarmInfo> readData(String directory, double dumpsysEpochTimestamp, double dumpsysElapsedTimestamp, Date traceDateTime);  }