diff options
author | Jinhui Wang <jinhuiw@google.com> | 2016-06-22 13:33:25 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2016-06-22 13:33:25 +0000 |
commit | eb8d822630e0841da4971c461e50ee6b8b9500a0 (patch) | |
tree | d051431b18c1c7ccbda096937a39dcedb5798c0e | |
parent | 631b333f646cf60560a7e869901b484fe5bdb7d4 (diff) | |
parent | 50e07e715726f2d0ab330b2ba3432fd397d3fa1f (diff) | |
download | AfwTestHarness-eb8d822630e0841da4971c461e50ee6b8b9500a0.tar.gz |
Merge "Update a few target preparers" into afw-test-harness-mnc
3 files changed, 50 insertions, 37 deletions
diff --git a/tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestFactoryReset.java b/tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestFactoryReset.java index 4c849f2..5ee82fa 100644 --- a/tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestFactoryReset.java +++ b/tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestFactoryReset.java @@ -25,8 +25,6 @@ import com.android.tradefed.device.ITestDevice; import com.android.tradefed.log.LogUtil.CLog; import com.android.tradefed.targetprep.ITargetPreparer; import com.android.tradefed.targetprep.TargetSetupError; -import com.android.tradefed.util.CommandResult; -import com.android.tradefed.util.CommandStatus; import java.util.concurrent.TimeUnit; @@ -177,38 +175,5 @@ public class AfwTestFactoryReset extends AfwTestTargetPreparer implements ITarge } return result; } - - /** - * Wipes device via fastboot. - * - * @param device test device - */ - private void wipeDevice(ITestDevice device) - throws DeviceNotAvailableException, TargetSetupError { - - CLog.i(String.format("Wiping device %s".format(device.getSerialNumber()))); - - device.rebootIntoBootloader(); - fastbootFormat(device, "cache"); - fastbootFormat(device, "userdata"); - device.executeFastbootCommand("reboot"); - } - - /** - * Performs fastboot erase/format operation on certain partition - * - * @param device test device - * @param partition android partition, e.g. userdata, cache, system - */ - private void fastbootFormat(ITestDevice device, String partition) - throws DeviceNotAvailableException, TargetSetupError { - - CLog.i("Attempting: fastboot format %s", partition); - CommandResult r = device.executeLongFastbootCommand("format", partition); - if (r.getStatus() != CommandStatus.SUCCESS) { - throw new TargetSetupError( - String.format("format %s failed: %s", partition, r.getStderr())); - } - } } diff --git a/tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestTargetPreparer.java b/tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestTargetPreparer.java index b066374..3316e6b 100644 --- a/tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestTargetPreparer.java +++ b/tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestTargetPreparer.java @@ -22,18 +22,23 @@ import com.android.tradefed.build.IBuildInfo; import com.android.tradefed.device.DeviceNotAvailableException; import com.android.tradefed.device.ITestDevice; import com.android.tradefed.device.PackageInfo; +import com.android.tradefed.log.LogUtil.CLog; import com.android.tradefed.targetprep.TargetSetupError; +import com.android.tradefed.util.CommandResult; +import com.android.tradefed.util.CommandStatus; import com.android.tradefed.util.RunUtil; import java.io.File; import java.util.concurrent.TimeUnit; + /** * Abstract class to keep common functionality. */ public abstract class AfwTestTargetPreparer { private CtsBuildHelper mBuildHelper; + private Long mTimeoutSecs = TimeUnit.MINUTES.toSeconds(5); /** * Gets an instance of {@link CtsBuildHelper}. @@ -135,5 +140,43 @@ public abstract class AfwTestTargetPreparer { return TestConfig.getInstance().getTimeoutSize(); } + + /** + * Wipes device via fastboot. + * + * <p> + * Refers to com.android.tradefed.targetprep.DeviceWiper + * </p> + * + * @param device test device + */ + protected void wipeDevice(ITestDevice device) + throws DeviceNotAvailableException, TargetSetupError { + + CLog.i(String.format("Wiping device %s".format(device.getSerialNumber()))); + + device.rebootIntoBootloader(); + fastbootFormat(device, "cache"); + fastbootFormat(device, "userdata"); + device.executeFastbootCommand("reboot"); + } + + + /** + * Performs fastboot erase/format operation on certain partition + * + * @param device test device + * @param partition android partition, e.g. userdata, cache, system + */ + protected void fastbootFormat(ITestDevice device, String partition) + throws DeviceNotAvailableException, TargetSetupError { + + CLog.i("Attempting: fastboot format %s", partition); + CommandResult r = device.executeLongFastbootCommand("format", partition); + if (r.getStatus() != CommandStatus.SUCCESS) { + throw new TargetSetupError( + String.format("format %s failed: %s", partition, r.getStderr())); + } + } } diff --git a/tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestWifiPreparer.java b/tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestWifiPreparer.java index 1a039a4..ffa9def 100644 --- a/tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestWifiPreparer.java +++ b/tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestWifiPreparer.java @@ -91,8 +91,13 @@ public final class AfwTestWifiPreparer extends AfwTestTargetPreparer implements // Implement retry. for (int i = 0; i < mWifiAttempts; ++i) { - if (device.connectToWifiNetworkIfNeeded(wifiSsid, wifiPassword)) { - return; + try { + + if (device.connectToWifiNetworkIfNeeded(wifiSsid, wifiPassword)) { + return; + } + } catch(Exception e) { + CLog.e("Error trying to connect to Wifi:", e); } boolean lastAttempt = (i + 1) == mWifiAttempts; if (!lastAttempt) { |