Keep track of Tradefed reboot times
If There was a TF reboot API call, skip the system server
pid bugreport. It was most likely intended.
Test: unit tests
Bug: 111515517
Change-Id: Iaec0d7d9137aafe6d446f733aee238125f58173a
diff --git a/src/com/android/tradefed/suite/checker/SystemServerStatusChecker.java b/src/com/android/tradefed/suite/checker/SystemServerStatusChecker.java
index 4d0545f..92950ee 100644
--- a/src/com/android/tradefed/suite/checker/SystemServerStatusChecker.java
+++ b/src/com/android/tradefed/suite/checker/SystemServerStatusChecker.java
@@ -15,6 +15,7 @@
*/
package com.android.tradefed.suite.checker;
+import com.android.annotations.VisibleForTesting;
import com.android.tradefed.device.DeviceNotAvailableException;
import com.android.tradefed.device.ITestDevice;
import com.android.tradefed.log.LogUtil.CLog;
@@ -27,6 +28,7 @@
public class SystemServerStatusChecker implements ISystemStatusChecker {
private String mSystemServerPid = null;
+ private Long mModuleStartTime = null;
/** {@inheritDoc} */
@Override
@@ -41,6 +43,7 @@
result.setStatus(CheckStatus.FAILED);
result.setBugreportNeeded(true);
result.setErrorMessage(message);
+ mModuleStartTime = null;
return result;
}
mSystemServerPid = mSystemServerPid.trim();
@@ -50,6 +53,7 @@
mSystemServerPid);
mSystemServerPid = null;
}
+ mModuleStartTime = getCurrentTime();
return result;
}
@@ -74,11 +78,27 @@
mSystemServerPid, tmpSystemServerPid);
CLog.w(message);
StatusCheckerResult result = new StatusCheckerResult(CheckStatus.FAILED);
- result.setBugreportNeeded(true);
+ // TODO: evaluate if we still need to fail the checker if it was a TF reboot
+ long lastExpectedReboot = device.getLastExpectedRebootTimeMillis();
+ if (mModuleStartTime != null && lastExpectedReboot < mModuleStartTime) {
+ // In case no Tradefed reboot was triggered, we capture a bugreport to figure this out.
+ CLog.w(
+ "System_server pid changed and Tradefed didn't trigger a reboot: "
+ + "last expected reboot: %s, module start time: %s, "
+ + "something went wrong.",
+ lastExpectedReboot, mModuleStartTime);
+ result.setBugreportNeeded(true);
+ }
result.setErrorMessage(message);
return result;
}
+ /** Returns the current time. */
+ @VisibleForTesting
+ protected long getCurrentTime() {
+ return System.currentTimeMillis();
+ }
+
/** Validate that pid is an integer and not empty. */
private boolean checkValidPid(String output) {
if (output.isEmpty()) {