summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2017-07-26 07:26:02 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2017-07-26 07:26:02 +0000
commit1ec2f341d3e62d70b0322568ff83e45feb013026 (patch)
tree8e74ef6cf9bf17bd63dc57e15c92f8ac5125c694
parentd60eff263b77b90ef3aec26ab7ee59a69f9e04d1 (diff)
parent2d085cf9e426e4577a873b831e35f0249113a4c0 (diff)
downloadTimeZoneData-1ec2f341d3e62d70b0322568ff83e45feb013026.tar.gz
release-request-08461da0-a262-4ebb-8c32-784b60a151df-for-git_oc-mr1-release-4216972 snap-temp-L74000000086000437
Change-Id: Idd5406c74b0780c4240cac978f7f482e6c947937
-rw-r--r--testing/xts/src/com/android/timezone/xts/TimeZoneUpdateHostTest.java61
1 files changed, 13 insertions, 48 deletions
diff --git a/testing/xts/src/com/android/timezone/xts/TimeZoneUpdateHostTest.java b/testing/xts/src/com/android/timezone/xts/TimeZoneUpdateHostTest.java
index e8384e6..694a074 100644
--- a/testing/xts/src/com/android/timezone/xts/TimeZoneUpdateHostTest.java
+++ b/testing/xts/src/com/android/timezone/xts/TimeZoneUpdateHostTest.java
@@ -21,17 +21,9 @@ import com.android.tradefed.config.Option;
import com.android.tradefed.log.LogUtil;
import com.android.tradefed.testtype.DeviceTestCase;
import com.android.tradefed.testtype.IBuildReceiver;
+import com.android.tradefed.util.FileUtil;
import java.io.File;
-import java.io.IOException;
-import java.nio.file.FileVisitResult;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.SimpleFileVisitor;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
import java.util.function.BooleanSupplier;
/**
@@ -65,8 +57,6 @@ public class TimeZoneUpdateHostTest extends DeviceTestCase implements IBuildRece
private static final String STAGED_OPERATION_UNINSTALL = "Uninstall";
private static final String INSTALL_STATE_INSTALLED = "Installed";
- private static final int ALLOWED_BOOT_DELAY = 60000;
-
private IBuildInfo mBuildInfo;
private File mTempDir;
@@ -120,21 +110,7 @@ public class TimeZoneUpdateHostTest extends DeviceTestCase implements IBuildRece
// @After
public void deleteTempDir() throws Exception {
- Files.walkFileTree(mTempDir.toPath(), new SimpleFileVisitor<Path>() {
- @Override
- public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
- throws IOException {
- Files.delete(file);
- return FileVisitResult.CONTINUE;
- }
-
- @Override
- public FileVisitResult postVisitDirectory(Path dir, IOException exc)
- throws IOException {
- Files.delete(dir);
- return FileVisitResult.CONTINUE;
- }
- });
+ FileUtil.recursiveDelete(mTempDir);
}
/**
@@ -192,7 +168,7 @@ public class TimeZoneUpdateHostTest extends DeviceTestCase implements IBuildRece
assertEquals(STAGED_OPERATION_NONE, getStagedOperationType());
File appFile = getTimeZoneDataApkFile("test1");
- installLocalPackageFile(appFile.getAbsolutePath(), "-r");
+ getDevice().installPackage(appFile, true /* reinstall */);
waitForStagedInstall(test1VersionInfo);
@@ -211,7 +187,7 @@ public class TimeZoneUpdateHostTest extends DeviceTestCase implements IBuildRece
// @Test
public void testInstallOlderRulesVersion() throws Exception {
File appFile = getTimeZoneDataApkFile("test2");
- installLocalPackageFile(appFile.getAbsolutePath(), "-r");
+ getDevice().installPackage(appFile, true /* reinstall */);
// The attempt to install a version of the data that is older than the version in the system
// image should be rejected and nothing should be staged. There's currently no way (short of
@@ -224,23 +200,9 @@ public class TimeZoneUpdateHostTest extends DeviceTestCase implements IBuildRece
assertEquals(STAGED_OPERATION_NONE, getStagedOperationType());
}
- private void installLocalPackageFile(String hostApkPath, String... args) throws Exception {
- List<String> command = new ArrayList<>();
- command.add("install");
- if (args.length > 0) {
- Collections.addAll(command, args);
- }
- command.add(hostApkPath);
-
- // Use of "adb install" here rather than installPackage() (which uses adb shell pm) because
- // the latter needs the file on device while "adb install" handles that for us.
- getDevice().executeAdbCommand(command.toArray(new String[0]));
- }
-
private void rebootDeviceAndWaitForRestart() throws Exception {
log("Rebooting device");
- getDevice().rebootUntilOnline();
- assertTrue(getDevice().waitForBootComplete(ALLOWED_BOOT_DELAY));
+ getDevice().reboot();
}
private void logDeviceTimeZoneState() throws Exception {
@@ -322,10 +284,13 @@ public class TimeZoneUpdateHostTest extends DeviceTestCase implements IBuildRece
private static void waitForCondition(BooleanSupplier condition) throws Exception {
int count = 0;
- while (count++ < 30 && !condition.getAsBoolean()) {
+ boolean lastResult;
+ while (!(lastResult = condition.getAsBoolean()) && count++ < 30) {
Thread.sleep(1000);
}
- assertTrue("Failed condition: " + condition, condition.getAsBoolean());
+ // Some conditions may not be stable so using the lastResult instead of
+ // condition.getAsBoolean() ensures we understand why we exited the loop.
+ assertTrue("Failed condition: " + condition, lastResult);
}
private enum StateType {
@@ -361,8 +326,8 @@ public class TimeZoneUpdateHostTest extends DeviceTestCase implements IBuildRece
}
private String getDeviceTimeZoneState(StateType stateType) throws Exception {
- String output = getDevice().executeAdbCommand(
- "shell", "dumpsys", "timezone", "-format_state", stateType.getFormatStateChar());
+ String output = getDevice().executeShellCommand(
+ "dumpsys timezone -format_state " + stateType.getFormatStateChar());
assertNotNull(output);
// Output will be "Foo: bar\n". We want the "bar".
String value = output.split(":")[1];
@@ -370,7 +335,7 @@ public class TimeZoneUpdateHostTest extends DeviceTestCase implements IBuildRece
}
private String dumpEntireTimeZoneStatusToString() throws Exception {
- String output = getDevice().executeAdbCommand("shell", "dumpsys", "timezone");
+ String output = getDevice().executeShellCommand("dumpsys timezone");
assertNotNull(output);
return output;
}