aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKailin Luo <karenluo@google.com>2020-01-15 15:11:07 -0800
committerYuexi Ma <yuexima@google.com>2020-01-16 01:59:38 +0000
commit485455a9d535af009708cdc026ca175897c7342a (patch)
tree4649403b83d3d0a596059431e00b607894e73fbb
parente223f4eb3b0b5310378e14cc85d3c7203182ebeb (diff)
downloadcsuite-485455a9d535af009708cdc026ca175897c7342a.tar.gz
Reformat all existing Java code
Use google_java_format linter in preupload hooks to format all existing java code. Test: make csuite Change-Id: I155b279628d24e243533cbd5e98cd123fd3bf660
-rw-r--r--harness/src/main/java/com/android/compatibility/AppCompatibilityTest.java205
-rw-r--r--harness/src/main/java/com/android/compatibility/AppCrawlerCompatibilityTest.java40
-rw-r--r--harness/src/main/java/com/android/compatibility/AppLaunchCompatibilityTest.java18
-rw-r--r--harness/src/main/java/com/android/compatibility/FailureCollectingListener.java7
-rw-r--r--harness/src/main/java/com/android/compatibility/targetprep/AppSetupPreparer.java197
-rw-r--r--harness/src/main/java/com/android/compatibility/testtype/AppLaunchTest.java628
-rw-r--r--harness/src/main/java/com/android/tradefed/result/CompatibilityTestResult.java9
-rw-r--r--harness/src/main/java/com/android/tradefed/util/PublicApkUtil.java61
-rw-r--r--harness/src/test/java/com/android/compatibility/AppCompatibilityTestTest.java436
-rw-r--r--harness/src/test/java/com/android/compatibility/targetprep/AppSetupPreparerTest.java241
-rw-r--r--harness/src/test/java/com/android/compatibility/testtype/AppLaunchTestTest.java580
-rw-r--r--instrumentation/launch/src/main/java/com/android/compatibilitytest/AppCompatibility.java77
-rw-r--r--tools/csuite-tradefed/src/test/java/com/android/compatibility/tradefed/CSuiteTradefedTest.java68
13 files changed, 1274 insertions, 1293 deletions
diff --git a/harness/src/main/java/com/android/compatibility/AppCompatibilityTest.java b/harness/src/main/java/com/android/compatibility/AppCompatibilityTest.java
index 5ad2787..ff0fba9 100644
--- a/harness/src/main/java/com/android/compatibility/AppCompatibilityTest.java
+++ b/harness/src/main/java/com/android/compatibility/AppCompatibilityTest.java
@@ -70,48 +70,55 @@ import java.util.HashSet;
* directory. The test installs, launches, and uninstalls each apk.
*/
public abstract class AppCompatibilityTest
- implements IDeviceTest, IRemoteTest, IShardableTest, IConfigurationReceiver, ITestFilterReceiver {
+ implements IDeviceTest,
+ IRemoteTest,
+ IShardableTest,
+ IConfigurationReceiver,
+ ITestFilterReceiver {
- @Option(name = "product",
- description = "The product, corresponding to the borgcron job product arg.")
+ @Option(
+ name = "product",
+ description = "The product, corresponding to the borgcron job product arg.")
private String mProduct;
@Option(
- name = "base-dir",
- description = "The directory of the results excluding the date.",
- importance = Option.Importance.ALWAYS)
+ name = "base-dir",
+ description = "The directory of the results excluding the date.",
+ importance = Option.Importance.ALWAYS)
// TODO(b/36786754): Add `mandatory = true` when cmdfiles are moved over
private File mBaseDir;
- @Option(name = "date",
- description = "The date to run, in the form YYYYMMDD. If not set, then the latest "
- + "results will be used.")
+ @Option(
+ name = "date",
+ description =
+ "The date to run, in the form YYYYMMDD. If not set, then the latest "
+ + "results will be used.")
private String mDate;
- @Option(name = "test-label",
- description = "Unique test identifier label.")
+ @Option(name = "test-label", description = "Unique test identifier label.")
private String mTestLabel = "AppCompatibility";
- @Option(name = "reboot-after-apks",
- description = "Reboot the device after a centain number of apks. 0 means no reboot.")
+ @Option(
+ name = "reboot-after-apks",
+ description = "Reboot the device after a centain number of apks. 0 means no reboot.")
private int mRebootNumber = 100;
- @Option(name = "fallback-to-apk-scan",
- description = "Fallback to scanning for apks in base directory if ranking information "
- + "is missing.")
+ @Option(
+ name = "fallback-to-apk-scan",
+ description =
+ "Fallback to scanning for apks in base directory if ranking information "
+ + "is missing.")
private boolean mFallbackToApkScan = false;
@Option(
- name = "retry-count",
- description = "Number of times to retry a failed test case. 0 means no retry.")
+ name = "retry-count",
+ description = "Number of times to retry a failed test case. 0 means no retry.")
private int mRetryCount = 5;
- @Option(name = "include-filter",
- description = "The include filter of the test names to run.")
+ @Option(name = "include-filter", description = "The include filter of the test names to run.")
protected Set<String> mIncludeFilters = new HashSet<>();
- @Option(name = "exclude-filter",
- description = "The exclude filter of the test names to run.")
+ @Option(name = "exclude-filter", description = "The exclude filter of the test names to run.")
protected Set<String> mExcludeFilters = new HashSet<>();
private static final long DOWNLOAD_TIMEOUT_MS = 60 * 1000;
@@ -135,7 +142,7 @@ public abstract class AppCompatibilityTest
protected final String packageBeingTestedKey;
protected AppCompatibilityTest(
- String launcherPackage, String runnerClass, String packageBeingTestedKey) {
+ String launcherPackage, String runnerClass, String packageBeingTestedKey) {
this.launcherPackage = launcherPackage;
this.runnerClass = runnerClass;
this.packageBeingTestedKey = packageBeingTestedKey;
@@ -149,7 +156,7 @@ public abstract class AppCompatibilityTest
/** Sets up some default aspects of the instrumentation test. */
protected final InstrumentationTest createDefaultInstrumentationTest(
- String packageBeingTested) {
+ String packageBeingTested) {
InstrumentationTest instrTest = new InstrumentationTest();
instrTest.setPackageName(launcherPackage);
instrTest.setConfiguration(mConfiguration);
@@ -172,9 +179,10 @@ public abstract class AppCompatibilityTest
CLog.i("\"--product\" not specified, using property from device instead: %s", mProduct);
}
Assert.assertTrue(
- String.format("Shard index out of range: expected [0, %d), got %d",
- mShardCount, mShardIndex),
- mShardIndex >= 0 && mShardIndex < mShardCount);
+ String.format(
+ "Shard index out of range: expected [0, %d), got %d",
+ mShardCount, mShardIndex),
+ mShardIndex >= 0 && mShardIndex < mShardCount);
File apkDir = null;
try {
@@ -208,12 +216,12 @@ public abstract class AppCompatibilityTest
} catch (InterruptedException e) {
CLog.e(e);
throw new RuntimeException(e);
- }finally {
+ } finally {
mLogcat.stop();
listener.testRunEnded(
- System.currentTimeMillis() - start, new HashMap<String, Metric>());
+ System.currentTimeMillis() - start, new HashMap<String, Metric>());
+ }
}
- }
/**
* Downloads and tests all the APKs in the apk list.
@@ -224,8 +232,9 @@ public abstract class AppCompatibilityTest
* @throws DeviceNotAvailableException
* @throws InterruptedException if a download thread was interrupted.
*/
- private void downloadAndTestApks(ITestInvocationListener listener, File kharonDir,
- List<ApkInfo> apkList) throws DeviceNotAvailableException, InterruptedException {
+ private void downloadAndTestApks(
+ ITestInvocationListener listener, File kharonDir, List<ApkInfo> apkList)
+ throws DeviceNotAvailableException, InterruptedException {
CLog.d("Started downloading and testing apks.");
ApkInfo testingApk = null;
File testingFile = null;
@@ -259,15 +268,15 @@ public abstract class AppCompatibilityTest
* @throws DeviceNotAvailableException
*/
private void testApk(ITestInvocationListener listener, ApkInfo apkInfo, File apkFile)
- throws DeviceNotAvailableException {
+ throws DeviceNotAvailableException {
if (apkInfo == null || apkFile == null) {
CLog.d("apkInfo or apkFile is null.");
FileUtil.deleteFile(apkFile);
return;
}
CLog.d(
- "Started testing package: %s, apk file: %s.",
- apkInfo.packageName, apkFile.getAbsolutePath());
+ "Started testing package: %s, apk file: %s.",
+ apkInfo.packageName, apkFile.getAbsolutePath());
mTestCount++;
if (mRebootNumber != 0 && mTestCount % mRebootNumber == 0) {
@@ -299,7 +308,7 @@ public abstract class AppCompatibilityTest
result.message = null;
launchApk(result);
mDevice.executeShellCommand(
- String.format("am force-stop %s", apkInfo.packageName));
+ String.format("am force-stop %s", apkInfo.packageName));
}
if (result.status == null) {
result.status = CompatibilityTestResult.STATUS_SUCCESS;
@@ -317,8 +326,8 @@ public abstract class AppCompatibilityTest
} catch (JSONException e) {
CLog.w("Posting failed: %s.", e.getMessage());
}
- listener.testEnded(testId, System.currentTimeMillis(),
- Collections.<String, String> emptyMap());
+ listener.testEnded(
+ testId, System.currentTimeMillis(), Collections.<String, String>emptyMap());
FileUtil.deleteFile(apkFile);
CLog.d("Completed testing package: %s.", apkInfo.packageName);
}
@@ -326,24 +335,23 @@ public abstract class AppCompatibilityTest
/**
* Checks that the file is correct and attempts to install it.
- * <p>
- * Will set the result status to error if the APK could not be installed or if it contains
+ *
+ * <p>Will set the result status to error if the APK could not be installed or if it contains
* conflicting information.
- * </p>
*
* @param result the {@link CompatibilityTestResult} containing the APK info.
* @param apkFile the APK file to install.
* @throws DeviceNotAvailableException
*/
private void installApk(CompatibilityTestResult result, File apkFile, boolean skipAaptCheck)
- throws DeviceNotAvailableException {
+ throws DeviceNotAvailableException {
if (!skipAaptCheck) {
CLog.d("Parsing apk file: %s.", apkFile.getAbsolutePath());
AaptParser parser = AaptParser.parse(apkFile);
if (parser == null) {
CLog.d(
- "Failed to parse apk file: %s, package: %s, error: %s.",
- apkFile.getAbsolutePath(), result.packageName, result.message);
+ "Failed to parse apk file: %s, package: %s, error: %s.",
+ apkFile.getAbsolutePath(), result.packageName, result.message);
result.status = CompatibilityTestResult.STATUS_ERROR;
result.message = "aapt fail";
return;
@@ -352,11 +360,16 @@ public abstract class AppCompatibilityTest
result.name = parser.getLabel();
if (!equalsOrNull(result.packageName, parser.getPackageName())
- || !equalsOrNull(result.versionString, parser.getVersionName())
- || !equalsOrNull(result.versionCode, parser.getVersionCode())) {
- CLog.d("Package info mismatch: want %s v%s (%s), got %s v%s (%s)",
- result.packageName, result.versionCode, result.versionString,
- parser.getPackageName(), parser.getVersionCode(), parser.getVersionName());
+ || !equalsOrNull(result.versionString, parser.getVersionName())
+ || !equalsOrNull(result.versionCode, parser.getVersionCode())) {
+ CLog.d(
+ "Package info mismatch: want %s v%s (%s), got %s v%s (%s)",
+ result.packageName,
+ result.versionCode,
+ result.versionString,
+ parser.getPackageName(),
+ parser.getVersionCode(),
+ parser.getVersionName());
result.status = CompatibilityTestResult.STATUS_ERROR;
result.message = "package info mismatch";
return;
@@ -370,16 +383,16 @@ public abstract class AppCompatibilityTest
result.status = CompatibilityTestResult.STATUS_ERROR;
result.message = error;
CLog.d(
- "Failed to install apk file: %s, package: %s, error: %s.",
- apkFile.getAbsolutePath(), result.packageName, result.message);
+ "Failed to install apk file: %s, package: %s, error: %s.",
+ apkFile.getAbsolutePath(), result.packageName, result.message);
return;
}
} catch (DeviceUnresponsiveException e) {
result.status = CompatibilityTestResult.STATUS_ERROR;
result.message = "install timeout";
CLog.d(
- "Installing apk file %s timed out, package: %s, error: %s.",
- apkFile.getAbsolutePath(), result.packageName, result.message);
+ "Installing apk file %s timed out, package: %s, error: %s.",
+ apkFile.getAbsolutePath(), result.packageName, result.message);
return;
}
CLog.d("Completed installing apk file %s.", apkFile.getAbsolutePath());
@@ -387,15 +400,13 @@ public abstract class AppCompatibilityTest
/**
* Method which attempts to launch an APK.
- * <p>
- * Will set the result status to failure if the APK could not be launched.
- * </p>
+ *
+ * <p>Will set the result status to failure if the APK could not be launched.
*
* @param result the {@link CompatibilityTestResult} containing the APK info.
* @throws DeviceNotAvailableException
*/
- private void launchApk(CompatibilityTestResult result)
- throws DeviceNotAvailableException {
+ private void launchApk(CompatibilityTestResult result) throws DeviceNotAvailableException {
CLog.d("Lauching package: %s.", result.packageName);
InstrumentationTest instrTest = createInstrumentationTest(result.packageName);
instrTest.setDevice(mDevice);
@@ -414,7 +425,7 @@ public abstract class AppCompatibilityTest
/** Helper method which reports a test failed if the status is either a failure or an error. */
private void reportResult(
- ITestInvocationListener listener, TestDescription id, CompatibilityTestResult result) {
+ ITestInvocationListener listener, TestDescription id, CompatibilityTestResult result) {
String message = result.message != null ? result.message : "unknown";
if (CompatibilityTestResult.STATUS_ERROR.equals(result.status)) {
listener.testFailed(id, "ERROR:" + message);
@@ -423,14 +434,16 @@ public abstract class AppCompatibilityTest
}
}
- /**
- * Helper method which posts the logcat.
- */
- private void postLogcat(CompatibilityTestResult result,
- ITestInvocationListener listener) throws JSONException {
+ /** Helper method which posts the logcat. */
+ private void postLogcat(CompatibilityTestResult result, ITestInvocationListener listener)
+ throws JSONException {
InputStreamSource stream = null;
- String header = String.format("%s%s%s\n", CompatibilityTestResult.SEPARATOR,
- result.toJsonString(), CompatibilityTestResult.SEPARATOR);
+ String header =
+ String.format(
+ "%s%s%s\n",
+ CompatibilityTestResult.SEPARATOR,
+ result.toJsonString(),
+ CompatibilityTestResult.SEPARATOR);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (InputStreamSource logcatData = mLogcat.getLogcatData()) {
try {
@@ -451,9 +464,7 @@ public abstract class AppCompatibilityTest
}
}
- /**
- * Helper method which takes a list of {@link ApkInfo} objects and returns the sharded list.
- */
+ /** Helper method which takes a list of {@link ApkInfo} objects and returns the sharded list. */
private List<ApkInfo> shardApkList(List<ApkInfo> apkList) {
List<ApkInfo> shardedList = new ArrayList<>(apkList.size() / mShardCount + 1);
for (int i = mShardIndex; i < apkList.size(); i += mShardCount) {
@@ -492,16 +503,12 @@ public abstract class AppCompatibilityTest
return false;
}
- /**
- * Returns true if either object is null or if both objects are equal.
- */
+ /** Returns true if either object is null or if both objects are equal. */
private static boolean equalsOrNull(Object a, Object b) {
return a == null || b == null || a.equals(b);
}
- /**
- * Helper {@link Runnable} which downloads a file, and can be used in another thread.
- */
+ /** Helper {@link Runnable} which downloads a file, and can be used in another thread. */
private class ApkDownloadRunnable implements Runnable {
private final File mKharonDir;
private final ApkInfo mApkInfo;
@@ -524,8 +531,8 @@ public abstract class AppCompatibilityTest
File sourceFile = new File(mKharonDir, mApkInfo.fileName);
try {
mDownloadedFile =
- PublicApkUtil.downloadFile(
- sourceFile, DOWNLOAD_TIMEOUT_MS, DOWNLOAD_RETRIES);
+ PublicApkUtil.downloadFile(
+ sourceFile, DOWNLOAD_TIMEOUT_MS, DOWNLOAD_RETRIES);
} catch (IOException e) {
// Log and ignore
CLog.e("Could not download apk from %s.", sourceFile);
@@ -560,9 +567,7 @@ public abstract class AppCompatibilityTest
return mDevice;
}
- /**
- * Return a {@link IRunUtil} instance to execute commands with.
- */
+ /** Return a {@link IRunUtil} instance to execute commands with. */
IRunUtil getRunUtil() {
return RunUtil.getDefault();
}
@@ -573,12 +578,12 @@ public abstract class AppCompatibilityTest
shard = getClass().newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new IllegalStateException(
- "The class "
- + getClass().getName()
- + " has no public constructor with no arguments, but all subclasses of "
- + AppCompatibilityTest.class.getName()
- + " should",
- e);
+ "The class "
+ + getClass().getName()
+ + " has no public constructor with no arguments, but all subclasses of "
+ + AppCompatibilityTest.class.getName()
+ + " should",
+ e);
}
try {
OptionCopier.copyOptions(this, shard);
@@ -612,27 +617,21 @@ public abstract class AppCompatibilityTest
return new TestDescription(launcherPackage, packageBeingTested);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
@Override
public void addIncludeFilter(String filter) {
checkArgument(!Strings.isNullOrEmpty(filter), "Include filter cannot be null or empty.");
mIncludeFilters.add(filter);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
@Override
public void addAllIncludeFilters(Set<String> filters) {
checkNotNull(filters, "Include filters cannot be null.");
mIncludeFilters.addAll(filters);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
@Override
public void clearIncludeFilters() {
mIncludeFilters.clear();
@@ -644,35 +643,27 @@ public abstract class AppCompatibilityTest
return Collections.unmodifiableSet(mIncludeFilters);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
@Override
public void addExcludeFilter(String filter) {
checkArgument(!Strings.isNullOrEmpty(filter), "Exclude filter cannot be null or empty.");
mExcludeFilters.add(filter);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
@Override
public void addAllExcludeFilters(Set<String> filters) {
checkNotNull(filters, "Exclude filters cannot be null.");
mExcludeFilters.addAll(filters);
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
@Override
public void clearExcludeFilters() {
mExcludeFilters.clear();
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
@Override
public Set<String> getExcludeFilters() {
return Collections.unmodifiableSet(mExcludeFilters);
diff --git a/harness/src/main/java/com/android/compatibility/AppCrawlerCompatibilityTest.java b/harness/src/main/java/com/android/compatibility/AppCrawlerCompatibilityTest.java
index a1538d8..bb239c2 100644
--- a/harness/src/main/java/com/android/compatibility/AppCrawlerCompatibilityTest.java
+++ b/harness/src/main/java/com/android/compatibility/AppCrawlerCompatibilityTest.java
@@ -30,32 +30,32 @@ public final class AppCrawlerCompatibilityTest extends AppCompatibilityTest {
private static final String WALKMAN_STEPS_LABEL = "maxSteps";
@Option(
- name = "walkman-run-ms",
- description = "Time to run walkman in msecs (only used if test-strategy=walkman).")
+ name = "walkman-run-ms",
+ description = "Time to run walkman in msecs (only used if test-strategy=walkman).")
private int mWalkmanRunMs = 60 * 1000;
@Option(
- name = "walkman-steps",
- description =
- "Max number of steps to run walkman (only used if test-strategy=walkman)."
- + " -1 for no limit")
+ name = "walkman-steps",
+ description =
+ "Max number of steps to run walkman (only used if test-strategy=walkman)."
+ + " -1 for no limit")
private int mWalkmanSteps = -1;
public AppCrawlerCompatibilityTest() {
super(
- "com.google.android.apps.common.walkman.apps",
- "com.google.android.apps.common.testing.testrunner"
- + ".Google3InstrumentationTestRunner",
- /*
- * We are using /google/data/ro/teams/walkman/walkman.apk which has parameter
- * "packages" unlike the up-to-date version in source which uses "package"
- * see: com.google.android.apps.common.walkman.apps.EngineFactory::getCrawlEngine.
- * This currently works with the up-to-date version in source, as well.
- *
- * Neither of these should be confused with "package_to_launch", which is used by
- * AppCompatibilityRunner
- */
- "packages");
+ "com.google.android.apps.common.walkman.apps",
+ "com.google.android.apps.common.testing.testrunner"
+ + ".Google3InstrumentationTestRunner",
+ /*
+ * We are using /google/data/ro/teams/walkman/walkman.apk which has parameter
+ * "packages" unlike the up-to-date version in source which uses "package"
+ * see: com.google.android.apps.common.walkman.apps.EngineFactory::getCrawlEngine.
+ * This currently works with the up-to-date version in source, as well.
+ *
+ * Neither of these should be confused with "package_to_launch", which is used by
+ * AppCompatibilityRunner
+ */
+ "packages");
}
@Override
@@ -75,7 +75,7 @@ public final class AppCrawlerCompatibilityTest extends AppCompatibilityTest {
* This list is required to be mutable, so we wrap in ArrayList.
*/
instrTest.setTestsToRun(
- new ArrayList<>(Arrays.asList(new TestDescription(launcherClass, "testEntry"))));
+ new ArrayList<>(Arrays.asList(new TestDescription(launcherClass, "testEntry"))));
return instrTest;
}
diff --git a/harness/src/main/java/com/android/compatibility/AppLaunchCompatibilityTest.java b/harness/src/main/java/com/android/compatibility/AppLaunchCompatibilityTest.java
index 4c2a48f..8592980 100644
--- a/harness/src/main/java/com/android/compatibility/AppLaunchCompatibilityTest.java
+++ b/harness/src/main/java/com/android/compatibility/AppLaunchCompatibilityTest.java
@@ -27,29 +27,29 @@ public final class AppLaunchCompatibilityTest extends AppCompatibilityTest {
private static final String WORKSPACE_LAUNCH_TIMEOUT_LABEL = "workspace_launch_timeout_ms";
@Option(
- name = "app-launch-timeout-ms",
- description = "Time to wait for app to launch in msecs.")
+ name = "app-launch-timeout-ms",
+ description = "Time to wait for app to launch in msecs.")
private int mAppLaunchTimeoutMs = 15000;
@Option(
- name = "workspace-launch-timeout-ms",
- description = "Time to wait when launched back into the workspace in msecs.")
+ name = "workspace-launch-timeout-ms",
+ description = "Time to wait when launched back into the workspace in msecs.")
private int mWorkspaceLaunchTimeoutMs = 2000;
public AppLaunchCompatibilityTest() {
super(
- "com.android.compatibilitytest",
- "com.android.compatibilitytest.AppCompatibilityRunner",
- "package_to_launch");
+ "com.android.compatibilitytest",
+ "com.android.compatibilitytest.AppCompatibilityRunner",
+ "package_to_launch");
}
@Override
public InstrumentationTest createInstrumentationTest(String packageBeingTested) {
InstrumentationTest instrTest = createDefaultInstrumentationTest(packageBeingTested);
instrTest.addInstrumentationArg(
- APP_LAUNCH_TIMEOUT_LABEL, Integer.toString(mAppLaunchTimeoutMs));
+ APP_LAUNCH_TIMEOUT_LABEL, Integer.toString(mAppLaunchTimeoutMs));
instrTest.addInstrumentationArg(
- WORKSPACE_LAUNCH_TIMEOUT_LABEL, Integer.toString(mWorkspaceLaunchTimeoutMs));
+ WORKSPACE_LAUNCH_TIMEOUT_LABEL, Integer.toString(mWorkspaceLaunchTimeoutMs));
return instrTest;
}
}
diff --git a/harness/src/main/java/com/android/compatibility/FailureCollectingListener.java b/harness/src/main/java/com/android/compatibility/FailureCollectingListener.java
index 5a3e93b..92434b3 100644
--- a/harness/src/main/java/com/android/compatibility/FailureCollectingListener.java
+++ b/harness/src/main/java/com/android/compatibility/FailureCollectingListener.java
@@ -32,10 +32,7 @@ public final class FailureCollectingListener implements ITestInvocationListener
setStackTrace(trace != null ? trace : "unknown assumption failure");
}
-
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
@Override
public void testRunFailed(String errorMessage) {
setStackTrace(errorMessage);
@@ -43,6 +40,7 @@ public final class FailureCollectingListener implements ITestInvocationListener
/**
* Fetches the stack trace if any.
+ *
* @return the stack trace.
*/
public String getStackTrace() {
@@ -51,6 +49,7 @@ public final class FailureCollectingListener implements ITestInvocationListener
/**
* Sets the stack trace.
+ *
* @param stackTrace {@link String} stack trace to set.
*/
public void setStackTrace(String stackTrace) {
diff --git a/harness/src/main/java/com/android/compatibility/targetprep/AppSetupPreparer.java b/harness/src/main/java/com/android/compatibility/targetprep/AppSetupPreparer.java
index 6cfa083..f1c9cb8 100644
--- a/harness/src/main/java/com/android/compatibility/targetprep/AppSetupPreparer.java
+++ b/harness/src/main/java/com/android/compatibility/targetprep/AppSetupPreparer.java
@@ -42,130 +42,131 @@ import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Collectors;
-/**
- * A Tradefed preparer that downloads and installs an app on the target device.
- */
+/** A Tradefed preparer that downloads and installs an app on the target device. */
public class AppSetupPreparer implements ITargetPreparer, ITargetCleaner {
- public static final String OPTION_GCS_APK_DIR = "gcs-apk-dir";
+ public static final String OPTION_GCS_APK_DIR = "gcs-apk-dir";
- @Option(
- name = "package-name",
- description = "Package name of the app being tested."
- )
- private String mPackageName;
+ @Option(name = "package-name", description = "Package name of the app being tested.")
+ private String mPackageName;
- @Option(
- name = "base-dir",
- description = "The directory where app APKs are located.",
- importance = Option.Importance.ALWAYS
- )
- private File mBaseDir;
+ @Option(
+ name = "base-dir",
+ description = "The directory where app APKs are located.",
+ importance = Option.Importance.ALWAYS)
+ private File mBaseDir;
- private TestAppInstallSetup appInstallSetup;
+ private TestAppInstallSetup appInstallSetup;
- public AppSetupPreparer() {
- this(null, null, new TestAppInstallSetup());
- }
+ public AppSetupPreparer() {
+ this(null, null, new TestAppInstallSetup());
+ }
- @VisibleForTesting
- public AppSetupPreparer(String packageName, File baseDir, TestAppInstallSetup appInstallSetup) {
- this.mPackageName = packageName;
- this.mBaseDir = baseDir;
- this.appInstallSetup = appInstallSetup;
- }
+ @VisibleForTesting
+ public AppSetupPreparer(String packageName, File baseDir, TestAppInstallSetup appInstallSetup) {
+ this.mPackageName = packageName;
+ this.mBaseDir = baseDir;
+ this.appInstallSetup = appInstallSetup;
+ }
/** {@inheritDoc} */
@Override
public void setUp(ITestDevice device, IBuildInfo buildInfo)
throws DeviceNotAvailableException, BuildError, TargetSetupError {
- if (mBaseDir == null) {
- // TODO(b/147159584): Use a utility to get dynamic options.
- String baseDirOption = buildInfo.getBuildAttributes().get(OPTION_GCS_APK_DIR);
- checkNotNull(baseDirOption, "Option %s is not set.", OPTION_GCS_APK_DIR);
- mBaseDir = new File(baseDirOption);
+ if (mBaseDir == null) {
+ // TODO(b/147159584): Use a utility to get dynamic options.
+ String baseDirOption = buildInfo.getBuildAttributes().get(OPTION_GCS_APK_DIR);
+ checkNotNull(baseDirOption, "Option %s is not set.", OPTION_GCS_APK_DIR);
+ mBaseDir = new File(baseDirOption);
+ }
+
+ checkArgument(
+ mBaseDir.isDirectory(), String.format("mBaseDir %s is not a directory", mBaseDir));
+
+ File downloadDir = prepareDownloadDir(buildInfo);
+
+ try {
+ downloadPackage(downloadDir);
+ } catch (IOException e) {
+ throw new TargetSetupError(
+ String.format("Failed to download package from %s.", downloadDir), e);
+ }
+ appInstallSetup.setAltDir(downloadDir);
+
+ List<String> apkFiles;
+ try {
+ apkFiles = listApkFiles(downloadDir);
+ } catch (IOException e) {
+ throw new TargetSetupError(
+ String.format("Failed to access files in %s.", downloadDir), e);
+ }
+
+ if (apkFiles.isEmpty()) {
+ throw new TargetSetupError(
+ String.format("Failed to find apk files in %s.", downloadDir));
+ }
+
+ if (apkFiles.size() == 1) {
+ appInstallSetup.addTestFileName(apkFiles.get(0));
+ } else {
+ appInstallSetup.addSplitApkFileNames(String.join(",", apkFiles));
+ }
+
+ appInstallSetup.setUp(device, buildInfo);
}
- checkArgument(mBaseDir.isDirectory(),
- String.format("mBaseDir %s is not a directory", mBaseDir));
-
- File downloadDir = prepareDownloadDir(buildInfo);
-
- try {
- downloadPackage(downloadDir);
- } catch (IOException e) {
- throw new TargetSetupError
- (String.format("Failed to download package from %s.", downloadDir), e);
+ /** {@inheritDoc} */
+ @Override
+ public void tearDown(ITestDevice device, IBuildInfo buildInfo, Throwable e)
+ throws DeviceNotAvailableException {
+ deleteDownloadDir(buildInfo);
+ appInstallSetup.tearDown(device, buildInfo, e);
}
- appInstallSetup.setAltDir(downloadDir);
- List<String> apkFiles;
- try {
- apkFiles = listApkFiles(downloadDir);
- } catch (IOException e) {
- throw new TargetSetupError(String.format("Failed to access files in %s.", downloadDir), e);
- }
+ protected File prepareDownloadDir(IBuildInfo buildInfo) throws TargetSetupError {
+ File downloadDir = deleteDownloadDir(buildInfo);
- if (apkFiles.isEmpty()) {
- throw new TargetSetupError(String.format("Failed to find apk files in %s.", downloadDir));
- }
+ try {
+ Files.createDirectory(Paths.get(downloadDir.getPath()));
+ } catch (IOException e) {
+ throw new TargetSetupError(
+ String.format("Failed to create download directory %s.", downloadDir), e);
+ }
- if (apkFiles.size() == 1) {
- appInstallSetup.addTestFileName(apkFiles.get(0));
- } else {
- appInstallSetup.addSplitApkFileNames(String.join(",", apkFiles));
+ return downloadDir;
}
- appInstallSetup.setUp(device, buildInfo);
- }
+ private File deleteDownloadDir(IBuildInfo buildInfo) {
+ File downloadDir = getDownloadDir(buildInfo);
+ FileUtil.recursiveDelete(downloadDir);
- /** {@inheritDoc} */
- @Override
- public void tearDown(ITestDevice device, IBuildInfo buildInfo, Throwable e)
- throws DeviceNotAvailableException {
- deleteDownloadDir(buildInfo);
- appInstallSetup.tearDown(device, buildInfo, e);
- }
-
- protected File prepareDownloadDir(IBuildInfo buildInfo) throws TargetSetupError {
- File downloadDir = deleteDownloadDir(buildInfo);
-
- try {
- Files.createDirectory(Paths.get(downloadDir.getPath()));
- } catch (IOException e) {
- throw new TargetSetupError(
- String.format("Failed to create download directory %s.", downloadDir), e);
+ return downloadDir;
}
- return downloadDir;
- }
-
- private File deleteDownloadDir(IBuildInfo buildInfo) {
- File downloadDir = getDownloadDir(buildInfo);
- FileUtil.recursiveDelete(downloadDir);
-
- return downloadDir;
- }
-
- protected void downloadPackage(File destDir) throws IOException {
- File sourceDir = new File(mBaseDir.getPath(), mPackageName);
+ protected void downloadPackage(File destDir) throws IOException {
+ File sourceDir = new File(mBaseDir.getPath(), mPackageName);
- checkArgument(sourceDir.isDirectory(),
- String.format("sourceDir %s is not a directory", sourceDir));
+ checkArgument(
+ sourceDir.isDirectory(),
+ String.format("sourceDir %s is not a directory", sourceDir));
- FileUtil.recursiveCopy(sourceDir, destDir);
- }
+ FileUtil.recursiveCopy(sourceDir, destDir);
+ }
- private List<String> listApkFiles(File downloadDir) throws IOException {
- return Files.walk(Paths.get(downloadDir.getPath()))
- .filter(s -> s.toString().endsWith("apk"))
- .map(x -> x.getFileName().toString()).collect(Collectors.toList());
- }
+ private List<String> listApkFiles(File downloadDir) throws IOException {
+ return Files.walk(Paths.get(downloadDir.getPath()))
+ .filter(s -> s.toString().endsWith("apk"))
+ .map(x -> x.getFileName().toString())
+ .collect(Collectors.toList());
+ }
- protected File getDownloadDir(IBuildInfo buildInfo) {
- checkArgument(buildInfo instanceof IDeviceBuildInfo,
- String.format("Provided buildInfo is not a %s", IDeviceBuildInfo.class.getCanonicalName()));
+ protected File getDownloadDir(IBuildInfo buildInfo) {
+ checkArgument(
+ buildInfo instanceof IDeviceBuildInfo,
+ String.format(
+ "Provided buildInfo is not a %s",
+ IDeviceBuildInfo.class.getCanonicalName()));
- return new File(((IDeviceBuildInfo) buildInfo).getTestsDir(), mPackageName);
+ return new File(((IDeviceBuildInfo) buildInfo).getTestsDir(), mPackageName);
+ }
}
-}
diff --git a/harness/src/main/java/com/android/compatibility/testtype/AppLaunchTest.java b/harness/src/main/java/com/android/compatibility/testtype/AppLaunchTest.java
index 72afc2a..3852b4b 100644
--- a/harness/src/main/java/com/android/compatibility/testtype/AppLaunchTest.java
+++ b/harness/src/main/java/com/android/compatibility/testtype/AppLaunchTest.java
@@ -20,7 +20,6 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.android.compatibility.FailureCollectingListener;
-import com.android.tradefed.config.ConfigurationException;
import com.android.tradefed.config.IConfiguration;
import com.android.tradefed.config.IConfigurationReceiver;
import com.android.tradefed.config.Option;
@@ -56,380 +55,353 @@ import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
-/**
- * A test that verifies that a single app can be successfully launched.
- */
+/** A test that verifies that a single app can be successfully launched. */
public class AppLaunchTest
- implements IDeviceTest, IRemoteTest, IConfigurationReceiver, ITestFilterReceiver {
-
- @Option(name = "package-name",
- description = "Package name of testing app.")
- private String mPackageName;
-
- @Option(name = "test-label",
- description = "Unique test identifier label.")
- private String mTestLabel = "AppCompatibility";
-
- @Option(
- name = "retry-count",
- description = "Number of times to retry a failed test case. 0 means no retry.")
- private int mRetryCount = 5;
-
- @Option(name = "include-filter",
- description = "The include filter of the test type.")
- protected Set<String> mIncludeFilters = new HashSet<>();
-
- @Option(name = "exclude-filter",
- description = "The exclude filter of the test type.")
- protected Set<String> mExcludeFilters = new HashSet<>();
-
- @Option(
- name = "app-launch-timeout-ms",
- description = "Time to wait for app to launch in msecs.")
- private int mAppLaunchTimeoutMs = 15000;
-
- private static final String LAUNCH_TEST_RUNNER =
- "com.android.compatibilitytest.AppCompatibilityRunner";
- private static final String LAUNCH_TEST_PACKAGE = "com.android.compatibilitytest";
- private static final String PACKAGE_TO_LAUNCH = "package_to_launch";
- private static final String APP_LAUNCH_TIMEOUT_LABEL = "app_launch_timeout_ms";
- private static final int LOGCAT_SIZE_BYTES = 20 * 1024 * 1024;
- private static final String TEST_TYPE = "launch";
-
- private ITestDevice mDevice;
- private LogcatReceiver mLogcat;
- private IConfiguration mConfiguration;
-
- public AppLaunchTest() {
- }
+ implements IDeviceTest, IRemoteTest, IConfigurationReceiver, ITestFilterReceiver {
- @VisibleForTesting
- public AppLaunchTest(String packageName) {
- this.mPackageName = packageName;
- }
+ @Option(name = "package-name", description = "Package name of testing app.")
+ private String mPackageName;
- @VisibleForTesting
- public AppLaunchTest(String packageName, int retryCount) {
- this.mPackageName = packageName;
- this.mRetryCount = retryCount;
- }
+ @Option(name = "test-label", description = "Unique test identifier label.")
+ private String mTestLabel = "AppCompatibility";
- /**
- * Creates and sets up an instrumentation test with information about the test runner as well as
- * the package being tested (provided as a parameter).
- */
- protected InstrumentationTest createInstrumentationTest(String packageBeingTested) {
- InstrumentationTest instrTest = new InstrumentationTest();
-
- instrTest.setPackageName(LAUNCH_TEST_PACKAGE);
- instrTest.setConfiguration(mConfiguration);
- instrTest.addInstrumentationArg(PACKAGE_TO_LAUNCH, packageBeingTested);
- instrTest.setRunnerName(LAUNCH_TEST_RUNNER);
- instrTest.setDevice(mDevice);
- instrTest.addInstrumentationArg(
- APP_LAUNCH_TIMEOUT_LABEL, Integer.toString(mAppLaunchTimeoutMs));
-
- return instrTest;
- }
+ @Option(
+ name = "retry-count",
+ description = "Number of times to retry a failed test case. 0 means no retry.")
+ private int mRetryCount = 5;
+
+ @Option(name = "include-filter", description = "The include filter of the test type.")
+ protected Set<String> mIncludeFilters = new HashSet<>();
+
+ @Option(name = "exclude-filter", description = "The exclude filter of the test type.")
+ protected Set<String> mExcludeFilters = new HashSet<>();
+
+ @Option(
+ name = "app-launch-timeout-ms",
+ description = "Time to wait for app to launch in msecs.")
+ private int mAppLaunchTimeoutMs = 15000;
+
+ private static final String LAUNCH_TEST_RUNNER =
+ "com.android.compatibilitytest.AppCompatibilityRunner";
+ private static final String LAUNCH_TEST_PACKAGE = "com.android.compatibilitytest";
+ private static final String PACKAGE_TO_LAUNCH = "package_to_launch";
+ private static final String APP_LAUNCH_TIMEOUT_LABEL = "app_launch_timeout_ms";
+ private static final int LOGCAT_SIZE_BYTES = 20 * 1024 * 1024;
+ private static final String TEST_TYPE = "launch";
- /*
- * {@inheritDoc}
- */
- @Override
- public void run(ITestInvocationListener listener) throws DeviceNotAvailableException {
- CLog.d("Start of run method.");
+ private ITestDevice mDevice;
+ private LogcatReceiver mLogcat;
+ private IConfiguration mConfiguration;
- Assert.assertNotNull("Package name cannot be null", mPackageName);
+ public AppLaunchTest() {}
- CLog.d("Include filters: %s", mIncludeFilters);
- CLog.d("Exclude filters: %s", mExcludeFilters);
+ @VisibleForTesting
+ public AppLaunchTest(String packageName) {
+ this.mPackageName = packageName;
+ }
- if (!inFilter(TEST_TYPE)) {
- CLog.d("Test type %s doesn't match any filter", TEST_TYPE);
- return;
+ @VisibleForTesting
+ public AppLaunchTest(String packageName, int retryCount) {
+ this.mPackageName = packageName;
+ this.mRetryCount = retryCount;
}
- CLog.d("Complete filtering test type: %s", TEST_TYPE);
-
- long start = System.currentTimeMillis();
- listener.testRunStarted(mTestLabel, 1);
- mLogcat = new LogcatReceiver(getDevice(), LOGCAT_SIZE_BYTES, 0);
- mLogcat.start();
-
- try {
- testPackage(listener);
- } catch (InterruptedException e) {
- CLog.e(e);
- throw new RuntimeException(e);
- } finally {
- mLogcat.stop();
- listener.testRunEnded(
- System.currentTimeMillis() - start, new HashMap<String, Metric>());
+
+ /**
+ * Creates and sets up an instrumentation test with information about the test runner as well as
+ * the package being tested (provided as a parameter).
+ */
+ protected InstrumentationTest createInstrumentationTest(String packageBeingTested) {
+ InstrumentationTest instrTest = new InstrumentationTest();
+
+ instrTest.setPackageName(LAUNCH_TEST_PACKAGE);
+ instrTest.setConfiguration(mConfiguration);
+ instrTest.addInstrumentationArg(PACKAGE_TO_LAUNCH, packageBeingTested);
+ instrTest.setRunnerName(LAUNCH_TEST_RUNNER);
+ instrTest.setDevice(mDevice);
+ instrTest.addInstrumentationArg(
+ APP_LAUNCH_TIMEOUT_LABEL, Integer.toString(mAppLaunchTimeoutMs));
+
+ return instrTest;
}
- }
- /**
- * Attempts to test a package and reports the results.
- *
- * @param listener The {@link ITestInvocationListener}.
- * @throws DeviceNotAvailableException
- */
- private void testPackage(ITestInvocationListener listener)
- throws DeviceNotAvailableException, InterruptedException {
- CLog.d(
- "Started testing package: %s.", mPackageName);
-
- TestDescription testId = createTestDescription(mPackageName);
- listener.testStarted(testId, System.currentTimeMillis());
-
- CompatibilityTestResult result = createCompatibilityTestResult();
- result.packageName = mPackageName;
-
- try {
- for (int i = 0; i <= mRetryCount; i++) {
- result.status = null;
- result.message = null;
- // Clear test result between retries.
- launchPackage(result);
- if (result.status == CompatibilityTestResult.STATUS_SUCCESS) {
- return;
- }
+ /*
+ * {@inheritDoc}
+ */
+ @Override
+ public void run(ITestInvocationListener listener) throws DeviceNotAvailableException {
+ CLog.d("Start of run method.");
+
+ Assert.assertNotNull("Package name cannot be null", mPackageName);
+
+ CLog.d("Include filters: %s", mIncludeFilters);
+ CLog.d("Exclude filters: %s", mExcludeFilters);
+
+ if (!inFilter(TEST_TYPE)) {
+ CLog.d("Test type %s doesn't match any filter", TEST_TYPE);
+ return;
}
- } finally {
- reportResult(listener, testId, result);
- stopPackage();
+ CLog.d("Complete filtering test type: %s", TEST_TYPE);
+
+ long start = System.currentTimeMillis();
+ listener.testRunStarted(mTestLabel, 1);
+ mLogcat = new LogcatReceiver(getDevice(), LOGCAT_SIZE_BYTES, 0);
+ mLogcat.start();
+
try {
- postLogcat(result, listener);
- } catch (JSONException e) {
- CLog.w("Posting failed: %s.", e.getMessage());
+ testPackage(listener);
+ } catch (InterruptedException e) {
+ CLog.e(e);
+ throw new RuntimeException(e);
+ } finally {
+ mLogcat.stop();
+ listener.testRunEnded(
+ System.currentTimeMillis() - start, new HashMap<String, Metric>());
}
- listener.testEnded(testId, System.currentTimeMillis(),
- Collections.<String, String> emptyMap());
-
- CLog.d("Completed testing package: %s.", mPackageName);
}
- }
- /**
- * Method which attempts to launch a package.
- *
- * Will set the result status to success if the package could be launched.
- * Otherwise the result status will be set to failure.
- *
- * @param result the {@link CompatibilityTestResult} containing the package info.
- * @throws DeviceNotAvailableException
- */
- private void launchPackage(CompatibilityTestResult result)
- throws DeviceNotAvailableException {
- CLog.d("Launching package: %s.", result.packageName);
-
- CommandResult resetResult = resetPackage();
- if (resetResult.getStatus() != CommandStatus.SUCCESS){
- result.status = CompatibilityTestResult.STATUS_ERROR;
- result.message = resetResult.getStatus() + resetResult.getStderr();
- return;
+ /**
+ * Attempts to test a package and reports the results.
+ *
+ * @param listener The {@link ITestInvocationListener}.
+ * @throws DeviceNotAvailableException
+ */
+ private void testPackage(ITestInvocationListener listener)
+ throws DeviceNotAvailableException, InterruptedException {
+ CLog.d("Started testing package: %s.", mPackageName);
+
+ TestDescription testId = createTestDescription(mPackageName);
+ listener.testStarted(testId, System.currentTimeMillis());
+
+ CompatibilityTestResult result = createCompatibilityTestResult();
+ result.packageName = mPackageName;
+
+ try {
+ for (int i = 0; i <= mRetryCount; i++) {
+ result.status = null;
+ result.message = null;
+ // Clear test result between retries.
+ launchPackage(result);
+ if (result.status == CompatibilityTestResult.STATUS_SUCCESS) {
+ return;
+ }
+ }
+ } finally {
+ reportResult(listener, testId, result);
+ stopPackage();
+ try {
+ postLogcat(result, listener);
+ } catch (JSONException e) {
+ CLog.w("Posting failed: %s.", e.getMessage());
+ }
+ listener.testEnded(
+ testId, System.currentTimeMillis(), Collections.<String, String>emptyMap());
+
+ CLog.d("Completed testing package: %s.", mPackageName);
+ }
}
- InstrumentationTest instrTest = createInstrumentationTest(result.packageName);
+ /**
+ * Method which attempts to launch a package.
+ *
+ * <p>Will set the result status to success if the package could be launched. Otherwise the
+ * result status will be set to failure.
+ *
+ * @param result the {@link CompatibilityTestResult} containing the package info.
+ * @throws DeviceNotAvailableException
+ */
+ private void launchPackage(CompatibilityTestResult result) throws DeviceNotAvailableException {
+ CLog.d("Launching package: %s.", result.packageName);
+
+ CommandResult resetResult = resetPackage();
+ if (resetResult.getStatus() != CommandStatus.SUCCESS) {
+ result.status = CompatibilityTestResult.STATUS_ERROR;
+ result.message = resetResult.getStatus() + resetResult.getStderr();
+ return;
+ }
- FailureCollectingListener failureListener = createFailureListener();
- instrTest.run(failureListener);
- CLog.d("Stack Trace: %s", failureListener.getStackTrace());
+ InstrumentationTest instrTest = createInstrumentationTest(result.packageName);
- if (failureListener.getStackTrace() != null) {
- CLog.w("Failed to launch package: %s.", result.packageName);
- result.status = CompatibilityTestResult.STATUS_FAILURE;
- result.message = failureListener.getStackTrace();
- } else {
- result.status = CompatibilityTestResult.STATUS_SUCCESS;
- }
+ FailureCollectingListener failureListener = createFailureListener();
+ instrTest.run(failureListener);
+ CLog.d("Stack Trace: %s", failureListener.getStackTrace());
- CLog.d("Completed launching package: %s", result.packageName);
- }
+ if (failureListener.getStackTrace() != null) {
+ CLog.w("Failed to launch package: %s.", result.packageName);
+ result.status = CompatibilityTestResult.STATUS_FAILURE;
+ result.message = failureListener.getStackTrace();
+ } else {
+ result.status = CompatibilityTestResult.STATUS_SUCCESS;
+ }
- /**
- * Helper method which reports a test failed if the status is either a failure or an error.
- */
- private void reportResult(
- ITestInvocationListener listener, TestDescription id, CompatibilityTestResult result) {
- String message = result.message != null ? result.message : "unknown";
- String tag = errorStatusToTag(result.status);
- if (tag != null) {
- listener.testFailed(id, result.status + ":" + message);
+ CLog.d("Completed launching package: %s", result.packageName);
}
- }
- private String errorStatusToTag(String status) {
- if (status.equals(CompatibilityTestResult.STATUS_ERROR)) {
- return "ERROR";
+ /** Helper method which reports a test failed if the status is either a failure or an error. */
+ private void reportResult(
+ ITestInvocationListener listener, TestDescription id, CompatibilityTestResult result) {
+ String message = result.message != null ? result.message : "unknown";
+ String tag = errorStatusToTag(result.status);
+ if (tag != null) {
+ listener.testFailed(id, result.status + ":" + message);
+ }
}
- if (status.equals(CompatibilityTestResult.STATUS_FAILURE)) {
- return "FAILURE";
+
+ private String errorStatusToTag(String status) {
+ if (status.equals(CompatibilityTestResult.STATUS_ERROR)) {
+ return "ERROR";
+ }
+ if (status.equals(CompatibilityTestResult.STATUS_FAILURE)) {
+ return "FAILURE";
+ }
+ return null;
}
- return null;
- }
- /**
- * Helper method which posts the logcat.
- */
- private void postLogcat(CompatibilityTestResult result,
- ITestInvocationListener listener) throws JSONException {
- InputStreamSource stream = null;
- String header = String.format("%s%s%s\n", CompatibilityTestResult.SEPARATOR,
- result.toJsonString(), CompatibilityTestResult.SEPARATOR);
-
- try (InputStreamSource logcatData = mLogcat.getLogcatData()) {
- try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
- baos.write(header.getBytes());
- StreamUtil.copyStreams(logcatData.createInputStream(), baos);
- stream = new ByteArrayInputStreamSource(baos.toByteArray());
- } catch (IOException e) {
- CLog.e("error inserting compatibility test result into logcat");
- CLog.e(e);
- // fallback to logcat data
- stream = logcatData;
+ /** Helper method which posts the logcat. */
+ private void postLogcat(CompatibilityTestResult result, ITestInvocationListener listener)
+ throws JSONException {
+ InputStreamSource stream = null;
+ String header =
+ String.format(
+ "%s%s%s\n",
+ CompatibilityTestResult.SEPARATOR,
+ result.toJsonString(),
+ CompatibilityTestResult.SEPARATOR);
+
+ try (InputStreamSource logcatData = mLogcat.getLogcatData()) {
+ try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+ baos.write(header.getBytes());
+ StreamUtil.copyStreams(logcatData.createInputStream(), baos);
+ stream = new ByteArrayInputStreamSource(baos.toByteArray());
+ } catch (IOException e) {
+ CLog.e("error inserting compatibility test result into logcat");
+ CLog.e(e);
+ // fallback to logcat data
+ stream = logcatData;
+ }
+ listener.testLog("logcat_" + result.packageName, LogDataType.LOGCAT, stream);
+ } finally {
+ StreamUtil.cancel(stream);
}
- listener.testLog("logcat_" + result.packageName, LogDataType.LOGCAT, stream);
- } finally {
- StreamUtil.cancel(stream);
}
- }
- /**
- * Return true if a test matches one or more of the include filters AND does not match any of
- * the exclude filters. If no include filters are given all tests should return true as long as
- * they do not match any of the exclude filters.
- */
- protected boolean inFilter(String testName) {
- if (mExcludeFilters.contains(testName)) {
+ /**
+ * Return true if a test matches one or more of the include filters AND does not match any of
+ * the exclude filters. If no include filters are given all tests should return true as long as
+ * they do not match any of the exclude filters.
+ */
+ protected boolean inFilter(String testName) {
+ if (mExcludeFilters.contains(testName)) {
+ return false;
+ }
+ if (mIncludeFilters.size() == 0 || mIncludeFilters.contains(testName)) {
+ return true;
+ }
return false;
}
- if (mIncludeFilters.size() == 0 || mIncludeFilters.contains(testName)) {
- return true;
- }
- return false;
- }
- protected CommandResult resetPackage() throws DeviceNotAvailableException {
- return mDevice.executeShellV2Command(
- String.format("pm clear %s", mPackageName));
- }
+ protected CommandResult resetPackage() throws DeviceNotAvailableException {
+ return mDevice.executeShellV2Command(String.format("pm clear %s", mPackageName));
+ }
- private void stopPackage() throws DeviceNotAvailableException {
- mDevice.executeShellCommand(
- String.format("am force-stop %s", mPackageName));
- }
+ private void stopPackage() throws DeviceNotAvailableException {
+ mDevice.executeShellCommand(String.format("am force-stop %s", mPackageName));
+ }
- @Override
- public void setConfiguration(IConfiguration configuration) {
- mConfiguration = configuration;
- }
+ @Override
+ public void setConfiguration(IConfiguration configuration) {
+ mConfiguration = configuration;
+ }
- /*
- * {@inheritDoc}
- */
- @Override
- public void setDevice(ITestDevice device) {
- mDevice = device;
- }
+ /*
+ * {@inheritDoc}
+ */
+ @Override
+ public void setDevice(ITestDevice device) {
+ mDevice = device;
+ }
- /*
- * {@inheritDoc}
- */
- @Override
- public ITestDevice getDevice() {
- return mDevice;
- }
+ /*
+ * {@inheritDoc}
+ */
+ @Override
+ public ITestDevice getDevice() {
+ return mDevice;
+ }
- public int getmRetryCount(){
- return mRetryCount;
- }
+ public int getmRetryCount() {
+ return mRetryCount;
+ }
- /**
- * Get a test description for use in logging. For compatibility with logs, this should be
- * TestDescription(launcher package, package being run).
- */
- private TestDescription createTestDescription(String packageBeingTested) {
- return new TestDescription(LAUNCH_TEST_PACKAGE, packageBeingTested);
- }
+ /**
+ * Get a test description for use in logging. For compatibility with logs, this should be
+ * TestDescription(launcher package, package being run).
+ */
+ private TestDescription createTestDescription(String packageBeingTested) {
+ return new TestDescription(LAUNCH_TEST_PACKAGE, packageBeingTested);
+ }
- /**
- * Get a FailureCollectingListener for failure listening.
- */
- private FailureCollectingListener createFailureListener() {
- return new FailureCollectingListener();
- }
+ /** Get a FailureCollectingListener for failure listening. */
+ private FailureCollectingListener createFailureListener() {
+ return new FailureCollectingListener();
+ }
- /**
- * Get a CompatibilityTestResult for encapsulating compatibility run results for a single
- * app package tested.
- */
- private CompatibilityTestResult createCompatibilityTestResult() {
- return new CompatibilityTestResult();
- }
+ /**
+ * Get a CompatibilityTestResult for encapsulating compatibility run results for a single app
+ * package tested.
+ */
+ private CompatibilityTestResult createCompatibilityTestResult() {
+ return new CompatibilityTestResult();
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public void addIncludeFilter(String filter) {
- checkArgument(!Strings.isNullOrEmpty(filter), "Include filter cannot be null or empty.");
- mIncludeFilters.add(filter);
- }
+ /** {@inheritDoc} */
+ @Override
+ public void addIncludeFilter(String filter) {
+ checkArgument(!Strings.isNullOrEmpty(filter), "Include filter cannot be null or empty.");
+ mIncludeFilters.add(filter);
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public void addAllIncludeFilters(Set<String> filters) {
- checkNotNull(filters, "Include filters cannot be null.");
- mIncludeFilters.addAll(filters);
- }
+ /** {@inheritDoc} */
+ @Override
+ public void addAllIncludeFilters(Set<String> filters) {
+ checkNotNull(filters, "Include filters cannot be null.");
+ mIncludeFilters.addAll(filters);
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public void clearIncludeFilters() {
- mIncludeFilters.clear();
- }
+ /** {@inheritDoc} */
+ @Override
+ public void clearIncludeFilters() {
+ mIncludeFilters.clear();
+ }
- /** {@inheritDoc} */
- @Override
- public Set<String> getIncludeFilters() {
- return Collections.unmodifiableSet(mIncludeFilters);
- }
+ /** {@inheritDoc} */
+ @Override
+ public Set<String> getIncludeFilters() {
+ return Collections.unmodifiableSet(mIncludeFilters);
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public void addExcludeFilter(String filter) {
- checkArgument(!Strings.isNullOrEmpty(filter), "Exclude filter cannot be null or empty.");
- mExcludeFilters.add(filter);
- }
+ /** {@inheritDoc} */
+ @Override
+ public void addExcludeFilter(String filter) {
+ checkArgument(!Strings.isNullOrEmpty(filter), "Exclude filter cannot be null or empty.");
+ mExcludeFilters.add(filter);
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public void addAllExcludeFilters(Set<String> filters) {
- checkNotNull(filters, "Exclude filters cannot be null.");
- mExcludeFilters.addAll(filters);
- }
+ /** {@inheritDoc} */
+ @Override
+ public void addAllExcludeFilters(Set<String> filters) {
+ checkNotNull(filters, "Exclude filters cannot be null.");
+ mExcludeFilters.addAll(filters);
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public void clearExcludeFilters() {
- mExcludeFilters.clear();
- }
+ /** {@inheritDoc} */
+ @Override
+ public void clearExcludeFilters() {
+ mExcludeFilters.clear();
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public Set<String> getExcludeFilters() {
- return Collections.unmodifiableSet(mExcludeFilters);
+ /** {@inheritDoc} */
+ @Override
+ public Set<String> getExcludeFilters() {
+ return Collections.unmodifiableSet(mExcludeFilters);
+ }
}
-}
diff --git a/harness/src/main/java/com/android/tradefed/result/CompatibilityTestResult.java b/harness/src/main/java/com/android/tradefed/result/CompatibilityTestResult.java
index 5080531..5a4b970 100644
--- a/harness/src/main/java/com/android/tradefed/result/CompatibilityTestResult.java
+++ b/harness/src/main/java/com/android/tradefed/result/CompatibilityTestResult.java
@@ -21,9 +21,7 @@ import org.json.JSONObject;
import java.util.regex.Pattern;
-/**
- * encapsulates compatibility run results for a single app package tested
- */
+/** encapsulates compatibility run results for a single app package tested */
public class CompatibilityTestResult {
public static final String KEY_PACKAGE = "app_package";
@@ -36,8 +34,8 @@ public class CompatibilityTestResult {
public static final String KEY_MESSAGE = "message";
public static final String SEPARATOR = "=@ppcomp@t=";
- public static final Pattern REGEX = Pattern.compile(String.format("^%s(.*?)%s",
- SEPARATOR, SEPARATOR));
+ public static final Pattern REGEX =
+ Pattern.compile(String.format("^%s(.*?)%s", SEPARATOR, SEPARATOR));
public static final String STATUS_SUCCESS = "success";
public static final String STATUS_ERROR = "error"; // installation errors etc
@@ -70,6 +68,7 @@ public class CompatibilityTestResult {
/**
* Reconstructs an instance from a JSON string
+ *
* @param json
* @return the {@link CompatibilityTestResult} instance from the JSON serialized string.
* @throws JSONException
diff --git a/harness/src/main/java/com/android/tradefed/util/PublicApkUtil.java b/harness/src/main/java/com/android/tradefed/util/PublicApkUtil.java
index 675ece3..65b5947 100644
--- a/harness/src/main/java/com/android/tradefed/util/PublicApkUtil.java
+++ b/harness/src/main/java/com/android/tradefed/util/PublicApkUtil.java
@@ -17,10 +17,6 @@
package com.android.tradefed.util;
import com.android.tradefed.log.LogUtil.CLog;
-import com.android.tradefed.util.AaptParser;
-import com.android.tradefed.util.FileUtil;
-import com.android.tradefed.util.QuotationAwareTokenizer;
-import com.android.tradefed.util.StreamUtil;
import java.io.BufferedReader;
import java.io.File;
@@ -57,8 +53,8 @@ public class PublicApkUtil {
File latestFile = null;
try {
latestFile =
- downloadFile(
- new File(baseDir, LATEST_FILE), DOWNLOAD_TIMEOUT_MS, DOWNLOAD_RETRIES);
+ downloadFile(
+ new File(baseDir, LATEST_FILE), DOWNLOAD_TIMEOUT_MS, DOWNLOAD_RETRIES);
String date = FileUtil.readStringFromFile(latestFile).trim();
if (DATE_FORMAT.matcher(date).matches()) {
return new File(baseDir, date);
@@ -79,7 +75,7 @@ public class PublicApkUtil {
* @throws IOException
*/
public static File downloadFile(File remoteFile, long downloadTimeout, int downloadRetries)
- throws IOException {
+ throws IOException {
CLog.i("Attempting to download %s", remoteFile);
File tmpFile = FileUtil.createTempFile(remoteFile.getName(), null);
FileUtil.copyFile(remoteFile, tmpFile);
@@ -96,7 +92,7 @@ public class PublicApkUtil {
* @throws IOException
*/
public static List<ApkInfo> getApkList(String flavor, File dir, boolean fallbackToApkScan)
- throws IOException {
+ throws IOException {
File apkFile = new File(dir, String.format("%s_ranking.csv", flavor));
if (!apkFile.exists() && fallbackToApkScan) {
return getApkListFromDirectory(dir);
@@ -116,21 +112,28 @@ public class PublicApkUtil {
*/
private static List<ApkInfo> getApkListFromDirectory(File baseDir) throws IOException {
List<ApkInfo> apkList = new ArrayList<>();
- File[] apks = baseDir.listFiles(new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
- // filters out all apk files
- return name.endsWith(".apk");
- }
- });
+ File[] apks =
+ baseDir.listFiles(
+ new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ // filters out all apk files
+ return name.endsWith(".apk");
+ }
+ });
for (File apk : apks) {
AaptParser parser = AaptParser.parse(apk);
if (parser == null) {
- throw new IOException(String.format(
- "Failed to parse apk file %s", apk.getCanonicalPath()));
+ throw new IOException(
+ String.format("Failed to parse apk file %s", apk.getCanonicalPath()));
}
- ApkInfo apkInfo = new ApkInfo(-1, parser.getPackageName(), parser.getVersionName(),
- parser.getVersionCode(), apk.getName());
+ ApkInfo apkInfo =
+ new ApkInfo(
+ -1,
+ parser.getPackageName(),
+ parser.getVersionName(),
+ parser.getVersionCode(),
+ apk.getName());
apkList.add(apkInfo);
}
return apkList;
@@ -139,6 +142,7 @@ public class PublicApkUtil {
/**
* Parses ranking information csv file into the data structure representing a list of apks with
* ranking and package information
+ *
* @param rankingInfo the path to ranking csv file
* @return
* @throws IOException
@@ -181,8 +185,12 @@ public class PublicApkUtil {
public final String versionCode;
public final String fileName;
- public ApkInfo(int rank, String packageName, String versionString, String versionCode,
- String fileName) {
+ public ApkInfo(
+ int rank,
+ String packageName,
+ String versionString,
+ String versionCode,
+ String fileName) {
this.rank = rank;
this.packageName = packageName;
this.versionString = versionString;
@@ -198,19 +206,20 @@ public class PublicApkUtil {
} catch (NumberFormatException e) {
// rethrow as IAE with content of problematic line
throw new IllegalArgumentException(
- String.format("Invalid line (rank field not a number): %s", line), e);
+ String.format("Invalid line (rank field not a number): %s", line), e);
}
if (cols.length != 5) {
throw new IllegalArgumentException(
- String.format("Invalid line (expected 5 data columns): %s", line));
+ String.format("Invalid line (expected 5 data columns): %s", line));
}
return new ApkInfo(rank, cols[1], cols[2], cols[3], cols[4]);
}
@Override
public String toString() {
- return String.format("Package: %s v%s (%s), rank: %d, file: %s", packageName,
- versionCode, versionString, rank, fileName);
+ return String.format(
+ "Package: %s v%s (%s), rank: %d, file: %s",
+ packageName, versionCode, versionString, rank, fileName);
+ }
}
}
-}
diff --git a/harness/src/test/java/com/android/compatibility/AppCompatibilityTestTest.java b/harness/src/test/java/com/android/compatibility/AppCompatibilityTestTest.java
index 110ab83..780dfe5 100644
--- a/harness/src/test/java/com/android/compatibility/AppCompatibilityTestTest.java
+++ b/harness/src/test/java/com/android/compatibility/AppCompatibilityTestTest.java
@@ -17,17 +17,13 @@ package com.android.compatibility;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import com.android.tradefed.testtype.InstrumentationTest;
-import com.android.tradefed.util.PublicApkUtil;
import com.android.tradefed.util.PublicApkUtil.ApkInfo;
-import java.io.IOException;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -41,298 +37,298 @@ import java.util.TreeSet;
@RunWith(JUnit4.class)
public final class AppCompatibilityTestTest {
- private ConcreteAppCompatibilityTest sut;
+ private ConcreteAppCompatibilityTest sut;
- private class ConcreteAppCompatibilityTest extends AppCompatibilityTest {
+ private class ConcreteAppCompatibilityTest extends AppCompatibilityTest {
- public ConcreteAppCompatibilityTest() {
- super(null, null, null);
- }
+ public ConcreteAppCompatibilityTest() {
+ super(null, null, null);
+ }
- @Override
- protected InstrumentationTest createInstrumentationTest(String packageBeingTested){
- return null;
+ @Override
+ protected InstrumentationTest createInstrumentationTest(String packageBeingTested) {
+ return null;
+ }
}
- }
- @Before
- public void setUp() {
- sut = new ConcreteAppCompatibilityTest();
- }
+ @Before
+ public void setUp() {
+ sut = new ConcreteAppCompatibilityTest();
+ }
- @Test(expected = IllegalArgumentException.class)
- public void addIncludeFilter_nullIncludeFilter_throwsException() {
- sut.addIncludeFilter(null);
- }
+ @Test(expected = IllegalArgumentException.class)
+ public void addIncludeFilter_nullIncludeFilter_throwsException() {
+ sut.addIncludeFilter(null);
+ }
- @Test(expected = IllegalArgumentException.class)
- public void addIncludeFilter_emptyIncludeFilter_throwsException() {
- sut.addIncludeFilter("");
- }
+ @Test(expected = IllegalArgumentException.class)
+ public void addIncludeFilter_emptyIncludeFilter_throwsException() {
+ sut.addIncludeFilter("");
+ }
- @Test
- public void addIncludeFilter_validIncludeFilter() {
- sut.addIncludeFilter("test_filter");
+ @Test
+ public void addIncludeFilter_validIncludeFilter() {
+ sut.addIncludeFilter("test_filter");
- assertTrue(sut.mIncludeFilters.contains("test_filter"));
- }
+ assertTrue(sut.mIncludeFilters.contains("test_filter"));
+ }
- @Test(expected = NullPointerException.class)
- public void addAllIncludeFilters_nullIncludeFilter_throwsException() {
- sut.addAllIncludeFilters(null);
- }
+ @Test(expected = NullPointerException.class)
+ public void addAllIncludeFilters_nullIncludeFilter_throwsException() {
+ sut.addAllIncludeFilters(null);
+ }
- @Test
- public void addAllIncludeFilters_validIncludeFilters() {
- Set<String> test_filters = new TreeSet<>();
- test_filters.add("filter_one");
- test_filters.add("filter_two");
+ @Test
+ public void addAllIncludeFilters_validIncludeFilters() {
+ Set<String> test_filters = new TreeSet<>();
+ test_filters.add("filter_one");
+ test_filters.add("filter_two");
- sut.addAllIncludeFilters(test_filters);
+ sut.addAllIncludeFilters(test_filters);
- assertTrue(sut.mIncludeFilters.contains("filter_one"));
- assertTrue(sut.mIncludeFilters.contains("filter_two"));
- }
+ assertTrue(sut.mIncludeFilters.contains("filter_one"));
+ assertTrue(sut.mIncludeFilters.contains("filter_two"));
+ }
- @Test
- public void clearIncludeFilters() {
- sut.addIncludeFilter("filter_test");
+ @Test
+ public void clearIncludeFilters() {
+ sut.addIncludeFilter("filter_test");
- sut.clearIncludeFilters();
+ sut.clearIncludeFilters();
- assertTrue(sut.mIncludeFilters.isEmpty());
- }
+ assertTrue(sut.mIncludeFilters.isEmpty());
+ }
- @Test
- public void getIncludeFilters() {
- sut.addIncludeFilter("filter_test");
+ @Test
+ public void getIncludeFilters() {
+ sut.addIncludeFilter("filter_test");
- assertEquals(sut.mIncludeFilters, sut.getIncludeFilters());
- }
+ assertEquals(sut.mIncludeFilters, sut.getIncludeFilters());
+ }
- @Test(expected = IllegalArgumentException.class)
- public void addExcludeFilter_nullExcludeFilter_throwsException() {
- sut.addExcludeFilter(null);
- }
+ @Test(expected = IllegalArgumentException.class)
+ public void addExcludeFilter_nullExcludeFilter_throwsException() {
+ sut.addExcludeFilter(null);
+ }
- @Test(expected = IllegalArgumentException.class)
- public void addExcludeFilter_emptyExcludeFilter_throwsException() {
- sut.addExcludeFilter("");
- }
+ @Test(expected = IllegalArgumentException.class)
+ public void addExcludeFilter_emptyExcludeFilter_throwsException() {
+ sut.addExcludeFilter("");
+ }
- @Test
- public void addExcludeFilter_validExcludeFilter() {
- sut.addExcludeFilter("test_filter");
+ @Test
+ public void addExcludeFilter_validExcludeFilter() {
+ sut.addExcludeFilter("test_filter");
- assertTrue(sut.mExcludeFilters.contains("test_filter"));
- }
+ assertTrue(sut.mExcludeFilters.contains("test_filter"));
+ }
- @Test(expected = NullPointerException.class)
- public void addAllExcludeFilters_nullExcludeFilters_throwsException() {
- sut.addAllExcludeFilters(null);
- }
+ @Test(expected = NullPointerException.class)
+ public void addAllExcludeFilters_nullExcludeFilters_throwsException() {
+ sut.addAllExcludeFilters(null);
+ }
- @Test
- public void addAllExcludeFilters_validExcludeFilters() {
- Set<String> test_filters = new TreeSet<>();
- test_filters.add("filter_one");
- test_filters.add("filter_two");
+ @Test
+ public void addAllExcludeFilters_validExcludeFilters() {
+ Set<String> test_filters = new TreeSet<>();
+ test_filters.add("filter_one");
+ test_filters.add("filter_two");
- sut.addAllExcludeFilters(test_filters);
+ sut.addAllExcludeFilters(test_filters);
- assertTrue(sut.mExcludeFilters.contains("filter_one"));
- assertTrue(sut.mExcludeFilters.contains("filter_two"));
- }
+ assertTrue(sut.mExcludeFilters.contains("filter_one"));
+ assertTrue(sut.mExcludeFilters.contains("filter_two"));
+ }
- @Test
- public void clearExcludeFilters() {
- sut.addExcludeFilter("filter_test");
+ @Test
+ public void clearExcludeFilters() {
+ sut.addExcludeFilter("filter_test");
- sut.clearExcludeFilters();
+ sut.clearExcludeFilters();
- assertTrue(sut.mExcludeFilters.isEmpty());
- }
+ assertTrue(sut.mExcludeFilters.isEmpty());
+ }
- @Test
- public void getExcludeFilters() {
- sut.addExcludeFilter("filter_test");
+ @Test
+ public void getExcludeFilters() {
+ sut.addExcludeFilter("filter_test");
- assertEquals(sut.mExcludeFilters, sut.getExcludeFilters());
- }
+ assertEquals(sut.mExcludeFilters, sut.getExcludeFilters());
+ }
- @Test
- public void filterApk_withNoFilter() {
- List<ApkInfo> testList = createApkList();
+ @Test
+ public void filterApk_withNoFilter() {
+ List<ApkInfo> testList = createApkList();
- List<ApkInfo> filteredList = sut.filterApk(testList);
+ List<ApkInfo> filteredList = sut.filterApk(testList);
- assertEquals(filteredList, testList);
- }
+ assertEquals(filteredList, testList);
+ }
- @Test
- public void filterApk_withRelatedIncludeFilters() {
- List<ApkInfo> testList = createApkList();
- sut.addIncludeFilter("filter_one");
+ @Test
+ public void filterApk_withRelatedIncludeFilters() {
+ List<ApkInfo> testList = createApkList();
+ sut.addIncludeFilter("filter_one");
- List<ApkInfo> filteredList = sut.filterApk(testList);
+ List<ApkInfo> filteredList = sut.filterApk(testList);
- assertEquals(convertList(filteredList), Arrays.asList("filter_one"));
- }
+ assertEquals(convertList(filteredList), Arrays.asList("filter_one"));
+ }
- @Test
- public void filterApk_withUnrelatedIncludeFilters() {
- List<ApkInfo> testList = createApkList();
- sut.addIncludeFilter("filter_three");
+ @Test
+ public void filterApk_withUnrelatedIncludeFilters() {
+ List<ApkInfo> testList = createApkList();
+ sut.addIncludeFilter("filter_three");
- List<ApkInfo> filteredList = sut.filterApk(testList);
+ List<ApkInfo> filteredList = sut.filterApk(testList);
- assertTrue(filteredList.isEmpty());
- }
+ assertTrue(filteredList.isEmpty());
+ }
- @Test
- public void filterApk_withRelatedExcludeFilters() {
- List<ApkInfo> testList = createApkList();
- sut.addExcludeFilter("filter_one");
+ @Test
+ public void filterApk_withRelatedExcludeFilters() {
+ List<ApkInfo> testList = createApkList();
+ sut.addExcludeFilter("filter_one");
- List<ApkInfo> filteredList = sut.filterApk(testList);
+ List<ApkInfo> filteredList = sut.filterApk(testList);
- assertEquals(convertList(filteredList), Arrays.asList("filter_two"));
- }
+ assertEquals(convertList(filteredList), Arrays.asList("filter_two"));
+ }
- @Test
- public void filterApk_withUnrelatedExcludeFilters() {
- List<ApkInfo> testList = createApkList();
- sut.addExcludeFilter("filter_three");
+ @Test
+ public void filterApk_withUnrelatedExcludeFilters() {
+ List<ApkInfo> testList = createApkList();
+ sut.addExcludeFilter("filter_three");
- List<ApkInfo> filteredList = sut.filterApk(testList);
+ List<ApkInfo> filteredList = sut.filterApk(testList);
- assertEquals(filteredList, testList);
- }
+ assertEquals(filteredList, testList);
+ }
- @Test
- public void filterApk_withSameIncludeAndExcludeFilters() {
- List<ApkInfo> testList = createApkList();
- sut.addIncludeFilter("filter_one");
- sut.addExcludeFilter("filter_one");
+ @Test
+ public void filterApk_withSameIncludeAndExcludeFilters() {
+ List<ApkInfo> testList = createApkList();
+ sut.addIncludeFilter("filter_one");
+ sut.addExcludeFilter("filter_one");
- List<ApkInfo> filteredList = sut.filterApk(testList);
+ List<ApkInfo> filteredList = sut.filterApk(testList);
- assertTrue(filteredList.isEmpty());
- }
+ assertTrue(filteredList.isEmpty());
+ }
- @Test
- public void filterApk_withDifferentIncludeAndExcludeFilter() {
- List<ApkInfo> testList = createApkList();
- sut.addIncludeFilter("filter_one");
- sut.addIncludeFilter("filter_two");
- sut.addExcludeFilter("filter_two");
+ @Test
+ public void filterApk_withDifferentIncludeAndExcludeFilter() {
+ List<ApkInfo> testList = createApkList();
+ sut.addIncludeFilter("filter_one");
+ sut.addIncludeFilter("filter_two");
+ sut.addExcludeFilter("filter_two");
- List<ApkInfo> filteredList = sut.filterApk(testList);
+ List<ApkInfo> filteredList = sut.filterApk(testList);
- assertEquals(convertList(filteredList), Arrays.asList("filter_one"));
- }
+ assertEquals(convertList(filteredList), Arrays.asList("filter_one"));
+ }
- @Test
- public void filterApk_withUnrelatedIncludeFilterAndRelatedExcludeFilter() {
- List<ApkInfo> testList = createApkList();
- sut.addIncludeFilter("filter_three");
- sut.addExcludeFilter("filter_two");
+ @Test
+ public void filterApk_withUnrelatedIncludeFilterAndRelatedExcludeFilter() {
+ List<ApkInfo> testList = createApkList();
+ sut.addIncludeFilter("filter_three");
+ sut.addExcludeFilter("filter_two");
- List<ApkInfo> filteredList = sut.filterApk(testList);
+ List<ApkInfo> filteredList = sut.filterApk(testList);
- assertTrue(filteredList.isEmpty());
- }
+ assertTrue(filteredList.isEmpty());
+ }
- @Test
- public void filterApk_withRelatedIncludeFilterAndUnrelatedExcludeFilter() {
- List<ApkInfo> testList = createApkList();
- sut.addIncludeFilter("filter_one");
- sut.addExcludeFilter("filter_three");
+ @Test
+ public void filterApk_withRelatedIncludeFilterAndUnrelatedExcludeFilter() {
+ List<ApkInfo> testList = createApkList();
+ sut.addIncludeFilter("filter_one");
+ sut.addExcludeFilter("filter_three");
- List<ApkInfo> filteredList = sut.filterApk(testList);
+ List<ApkInfo> filteredList = sut.filterApk(testList);
- assertEquals(convertList(filteredList), Arrays.asList("filter_one"));
- }
+ assertEquals(convertList(filteredList), Arrays.asList("filter_one"));
+ }
- private List<ApkInfo> createApkList() {
- List<ApkInfo> testList = new ArrayList<>();
- ApkInfo apk_info_one = new ApkInfo(0, "filter_one", "", "", "");
- ApkInfo apk_info_two = new ApkInfo(0, "filter_two", "", "", "");
- testList.add(apk_info_one);
- testList.add(apk_info_two);
- return testList;
- }
+ private List<ApkInfo> createApkList() {
+ List<ApkInfo> testList = new ArrayList<>();
+ ApkInfo apk_info_one = new ApkInfo(0, "filter_one", "", "", "");
+ ApkInfo apk_info_two = new ApkInfo(0, "filter_two", "", "", "");
+ testList.add(apk_info_one);
+ testList.add(apk_info_two);
+ return testList;
+ }
- private List<String> convertList(List<ApkInfo> apkList) {
- List<String> convertedList = new ArrayList<>();
- for (ApkInfo apkInfo : apkList) {
- convertedList.add(apkInfo.packageName);
+ private List<String> convertList(List<ApkInfo> apkList) {
+ List<String> convertedList = new ArrayList<>();
+ for (ApkInfo apkInfo : apkList) {
+ convertedList.add(apkInfo.packageName);
+ }
+ return convertedList;
}
- return convertedList;
- }
- @Test
- public void filterTest_withEmptyFilter() {
- assertTrue(sut.filterTest("filter_one"));
- }
+ @Test
+ public void filterTest_withEmptyFilter() {
+ assertTrue(sut.filterTest("filter_one"));
+ }
- @Test
- public void filterTest_withRelatedIncludeFilter() {
- sut.addIncludeFilter("filter_one");
+ @Test
+ public void filterTest_withRelatedIncludeFilter() {
+ sut.addIncludeFilter("filter_one");
- assertTrue(sut.filterTest("filter_one"));
- }
+ assertTrue(sut.filterTest("filter_one"));
+ }
- @Test
- public void filterTest_withUnrelatedIncludeFilter() {
- sut.addIncludeFilter("filter_two");
+ @Test
+ public void filterTest_withUnrelatedIncludeFilter() {
+ sut.addIncludeFilter("filter_two");
- assertFalse(sut.filterTest("filter_one"));
- }
+ assertFalse(sut.filterTest("filter_one"));
+ }
- @Test
- public void filterTest_withRelatedExcludeFilter() {
- sut.addExcludeFilter("filter_one");
+ @Test
+ public void filterTest_withRelatedExcludeFilter() {
+ sut.addExcludeFilter("filter_one");
- assertFalse(sut.filterTest("filter_one"));
- }
+ assertFalse(sut.filterTest("filter_one"));
+ }
- @Test
- public void filterTest_withUnrelatedExcludeFilter() {
- sut.addExcludeFilter("filter_two");
+ @Test
+ public void filterTest_withUnrelatedExcludeFilter() {
+ sut.addExcludeFilter("filter_two");
- assertTrue(sut.filterTest("filter_one"));
- }
+ assertTrue(sut.filterTest("filter_one"));
+ }
- @Test
- public void filterTest_withSameIncludeAndExcludeFilters() {
- sut.addIncludeFilter("filter_one");
- sut.addExcludeFilter("filter_one");
+ @Test
+ public void filterTest_withSameIncludeAndExcludeFilters() {
+ sut.addIncludeFilter("filter_one");
+ sut.addExcludeFilter("filter_one");
- assertFalse(sut.filterTest("filter_one"));
- }
+ assertFalse(sut.filterTest("filter_one"));
+ }
- @Test
- public void filterTest_withUnrelatedIncludeFilterAndRelatedExcludeFilter() {
- sut.addIncludeFilter("filter_one");
- sut.addExcludeFilter("filter_two");
+ @Test
+ public void filterTest_withUnrelatedIncludeFilterAndRelatedExcludeFilter() {
+ sut.addIncludeFilter("filter_one");
+ sut.addExcludeFilter("filter_two");
- assertFalse(sut.filterTest("filter_two"));
- }
+ assertFalse(sut.filterTest("filter_two"));
+ }
- @Test
- public void filterTest_withRelatedIncludeFilterAndUnrelatedExcludeFilter() {
- sut.addIncludeFilter("filter_one");
- sut.addExcludeFilter("filter_two");
+ @Test
+ public void filterTest_withRelatedIncludeFilterAndUnrelatedExcludeFilter() {
+ sut.addIncludeFilter("filter_one");
+ sut.addExcludeFilter("filter_two");
- assertTrue(sut.filterTest("filter_one"));
- }
+ assertTrue(sut.filterTest("filter_one"));
+ }
- @Test
- public void filterTest_withUnRelatedIncludeFilterAndUnrelatedExcludeFilter() {
- sut.addIncludeFilter("filter_one");
- sut.addExcludeFilter("filter_two");
+ @Test
+ public void filterTest_withUnRelatedIncludeFilterAndUnrelatedExcludeFilter() {
+ sut.addIncludeFilter("filter_one");
+ sut.addExcludeFilter("filter_two");
- assertFalse(sut.filterTest("filter_three"));
+ assertFalse(sut.filterTest("filter_three"));
+ }
}
-}
diff --git a/harness/src/test/java/com/android/compatibility/targetprep/AppSetupPreparerTest.java b/harness/src/test/java/com/android/compatibility/targetprep/AppSetupPreparerTest.java
index 06bb76d..ebb0c8f 100644
--- a/harness/src/test/java/com/android/compatibility/targetprep/AppSetupPreparerTest.java
+++ b/harness/src/test/java/com/android/compatibility/targetprep/AppSetupPreparerTest.java
@@ -15,7 +15,6 @@
*/
package com.android.compatibility.targetprep;
-
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.testng.Assert.assertThrows;
@@ -48,156 +47,156 @@ import java.io.IOException;
@RunWith(JUnit4.class)
public final class AppSetupPreparerTest {
- @Rule public TemporaryFolder testSourceFolder = new TemporaryFolder();
- @Rule public TemporaryFolder testDestFolder = new TemporaryFolder();
+ @Rule public TemporaryFolder testSourceFolder = new TemporaryFolder();
+ @Rule public TemporaryFolder testDestFolder = new TemporaryFolder();
- private ITestDevice mockDevice;
- private IDeviceBuildInfo mockDeviceBuildInfo;
- private TestAppInstallSetup mockAppInstallSetup;
+ private ITestDevice mockDevice;
+ private IDeviceBuildInfo mockDeviceBuildInfo;
+ private TestAppInstallSetup mockAppInstallSetup;
- @Before
- public void setUp() throws Exception {
- mockDevice = mock(ITestDevice.class);
+ @Before
+ public void setUp() throws Exception {
+ mockDevice = mock(ITestDevice.class);
- File testDir = testDestFolder.newFolder("download_dir");
- mockDeviceBuildInfo = mock(IDeviceBuildInfo.class);
- when(mockDeviceBuildInfo.getTestsDir()).thenReturn(testDir);
+ File testDir = testDestFolder.newFolder("download_dir");
+ mockDeviceBuildInfo = mock(IDeviceBuildInfo.class);
+ when(mockDeviceBuildInfo.getTestsDir()).thenReturn(testDir);
- mockAppInstallSetup = mock(TestAppInstallSetup.class);
- }
+ mockAppInstallSetup = mock(TestAppInstallSetup.class);
+ }
- @Test
- public void setUp_baseDirIsNull_throwsException()
- throws DeviceNotAvailableException, TargetSetupError {
- AppSetupPreparer preparer =
- new AppSetupPreparer("package_name", null, mockAppInstallSetup);
+ @Test
+ public void setUp_baseDirIsNull_throwsException()
+ throws DeviceNotAvailableException, TargetSetupError {
+ AppSetupPreparer preparer = new AppSetupPreparer("package_name", null, mockAppInstallSetup);
- assertThrows(NullPointerException.class,
- () -> preparer.setUp(mockDevice, mockDeviceBuildInfo));
- }
+ assertThrows(
+ NullPointerException.class, () -> preparer.setUp(mockDevice, mockDeviceBuildInfo));
+ }
- @Test
- public void setUp_baseDirIsNotDir_throwsException()
- throws IOException, DeviceNotAvailableException, TargetSetupError {
- File tempFile = testSourceFolder.newFile("temp_file_name");
- AppSetupPreparer preparer =
- new AppSetupPreparer("package_name", tempFile, mockAppInstallSetup);
+ @Test
+ public void setUp_baseDirIsNotDir_throwsException()
+ throws IOException, DeviceNotAvailableException, TargetSetupError {
+ File tempFile = testSourceFolder.newFile("temp_file_name");
+ AppSetupPreparer preparer =
+ new AppSetupPreparer("package_name", tempFile, mockAppInstallSetup);
- assertThrows(IllegalArgumentException.class,
- () -> preparer.setUp(mockDevice, mockDeviceBuildInfo));
- }
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> preparer.setUp(mockDevice, mockDeviceBuildInfo));
+ }
- @Test
- public void setUp_packageDirDoesNotExist_throwsError()
- throws IOException, DeviceNotAvailableException, TargetSetupError {
- File baseDir = testSourceFolder.newFolder("base_dir");
- AppSetupPreparer preparer =
- new AppSetupPreparer("package_name", baseDir, mockAppInstallSetup);
+ @Test
+ public void setUp_packageDirDoesNotExist_throwsError()
+ throws IOException, DeviceNotAvailableException, TargetSetupError {
+ File baseDir = testSourceFolder.newFolder("base_dir");
+ AppSetupPreparer preparer =
+ new AppSetupPreparer("package_name", baseDir, mockAppInstallSetup);
- assertThrows(IllegalArgumentException.class,
- () -> preparer.setUp(mockDevice, mockDeviceBuildInfo));
- }
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> preparer.setUp(mockDevice, mockDeviceBuildInfo));
+ }
- @Test
- public void prepareDownloadDir_containsStaleFiles() throws IOException, TargetSetupError {
- File baseDir = testSourceFolder.newFolder("base_dir");
- File staleDownloadDir = testDestFolder.newFolder("stale_download_dir");
- File staleFile = new File(staleDownloadDir, "stale_file");
- staleFile.createNewFile();
- AppSetupPreparer preparer =
- new AppSetupPreparer("package_name", baseDir, mockAppInstallSetup) {
- @Override
- protected File getDownloadDir(IBuildInfo buildInfo) {
+ @Test
+ public void prepareDownloadDir_containsStaleFiles() throws IOException, TargetSetupError {
+ File baseDir = testSourceFolder.newFolder("base_dir");
+ File staleDownloadDir = testDestFolder.newFolder("stale_download_dir");
+ File staleFile = new File(staleDownloadDir, "stale_file");
+ staleFile.createNewFile();
+ AppSetupPreparer preparer =
+ new AppSetupPreparer("package_name", baseDir, mockAppInstallSetup) {
+ @Override
+ protected File getDownloadDir(IBuildInfo buildInfo) {
- return staleDownloadDir;
- }
- };
+ return staleDownloadDir;
+ }
+ };
- File downloadDir = preparer.prepareDownloadDir(mockDeviceBuildInfo);
+ File downloadDir = preparer.prepareDownloadDir(mockDeviceBuildInfo);
- assertFalse(new File(downloadDir, "stale_file.apk").exists());
- }
+ assertFalse(new File(downloadDir, "stale_file.apk").exists());
+ }
@Test
- public void downloadPackage_success() throws IOException, TargetSetupError {
- File baseDir = testSourceFolder.newFolder("base_dir");
- createPackageFile(baseDir, "package_name", "apk_name_1.apk");
- createPackageFile(baseDir, "package_name", "apk_name_2.apk");
- AppSetupPreparer preparer =
- new AppSetupPreparer("package_name", baseDir, mockAppInstallSetup);
- File destDownloadDir = testDestFolder.newFolder("dest_dir_name");
-
- preparer.downloadPackage(destDownloadDir);
-
- assertTrue(new File(destDownloadDir, "apk_name_1.apk").exists());
- assertTrue(new File(destDownloadDir, "apk_name_2.apk").exists());
- }
+ public void downloadPackage_success() throws IOException, TargetSetupError {
+ File baseDir = testSourceFolder.newFolder("base_dir");
+ createPackageFile(baseDir, "package_name", "apk_name_1.apk");
+ createPackageFile(baseDir, "package_name", "apk_name_2.apk");
+ AppSetupPreparer preparer =
+ new AppSetupPreparer("package_name", baseDir, mockAppInstallSetup);
+ File destDownloadDir = testDestFolder.newFolder("dest_dir_name");
+
+ preparer.downloadPackage(destDownloadDir);
+
+ assertTrue(new File(destDownloadDir, "apk_name_1.apk").exists());
+ assertTrue(new File(destDownloadDir, "apk_name_2.apk").exists());
+ }
@Test
public void setUp_apkDoesNotExist() throws Exception {
- File baseDir = testSourceFolder.newFolder("base_dir");
- // Create a file in package_name folder, but the file extension is not apk.
- createPackageFile(baseDir, "package_name", "non_apk_file");
- AppSetupPreparer preparer =
- new AppSetupPreparer("package_name", baseDir, mockAppInstallSetup);
-
- assertThrows(TargetSetupError.class,
- () -> preparer.setUp(mockDevice, mockDeviceBuildInfo));
- }
+ File baseDir = testSourceFolder.newFolder("base_dir");
+ // Create a file in package_name folder, but the file extension is not apk.
+ createPackageFile(baseDir, "package_name", "non_apk_file");
+ AppSetupPreparer preparer =
+ new AppSetupPreparer("package_name", baseDir, mockAppInstallSetup);
+
+ assertThrows(TargetSetupError.class, () -> preparer.setUp(mockDevice, mockDeviceBuildInfo));
+ }
@Test
public void setUp_installSplitApk() throws Exception {
- File baseDir = testSourceFolder.newFolder("base_dir");
- createPackageFile(baseDir, "package_name", "apk_name_1.apk");
- createPackageFile(baseDir, "package_name", "apk_name_2.apk");
- AppSetupPreparer preparer =
- new AppSetupPreparer("package_name", baseDir, mockAppInstallSetup);
+ File baseDir = testSourceFolder.newFolder("base_dir");
+ createPackageFile(baseDir, "package_name", "apk_name_1.apk");
+ createPackageFile(baseDir, "package_name", "apk_name_2.apk");
+ AppSetupPreparer preparer =
+ new AppSetupPreparer("package_name", baseDir, mockAppInstallSetup);
- preparer.setUp(mockDevice, mockDeviceBuildInfo);
+ preparer.setUp(mockDevice, mockDeviceBuildInfo);
- verify(mockAppInstallSetup, times(1)).setAltDir(any());
- verify(mockAppInstallSetup, times(1)).addSplitApkFileNames(anyString());
- verify(mockAppInstallSetup, times(1)).setUp(any(), any());
- }
+ verify(mockAppInstallSetup, times(1)).setAltDir(any());
+ verify(mockAppInstallSetup, times(1)).addSplitApkFileNames(anyString());
+ verify(mockAppInstallSetup, times(1)).setUp(any(), any());
+ }
@Test
public void setUp_installNonSplitApk() throws Exception {
- File baseDir = testSourceFolder.newFolder("base_dir");
- createPackageFile(baseDir, "package_name", "apk_name_1.apk");
- AppSetupPreparer preparer =
- new AppSetupPreparer("package_name", baseDir, mockAppInstallSetup);
+ File baseDir = testSourceFolder.newFolder("base_dir");
+ createPackageFile(baseDir, "package_name", "apk_name_1.apk");
+ AppSetupPreparer preparer =
+ new AppSetupPreparer("package_name", baseDir, mockAppInstallSetup);
- preparer.setUp(mockDevice, mockDeviceBuildInfo);
+ preparer.setUp(mockDevice, mockDeviceBuildInfo);
- verify(mockAppInstallSetup, times(1)).setAltDir(any());
- verify(mockAppInstallSetup, times(1)).addTestFileName(anyString());
- verify(mockAppInstallSetup, times(1)).setUp(any(), any());
- }
+ verify(mockAppInstallSetup, times(1)).setAltDir(any());
+ verify(mockAppInstallSetup, times(1)).addTestFileName(anyString());
+ verify(mockAppInstallSetup, times(1)).setUp(any(), any());
+ }
@Test
public void tearDown() throws Exception {
- File baseDir = testSourceFolder.newFolder("base_dir");
- createPackageFile(baseDir, "package_name", "apk_name_1.apk");
- createPackageFile(baseDir, "package_name", "apk_name_2.apk");
- AppSetupPreparer preparer =
- new AppSetupPreparer("package_name", baseDir, mockAppInstallSetup);
- preparer.setUp(mockDevice, mockDeviceBuildInfo);
-
- preparer.tearDown(mockDevice, mockDeviceBuildInfo, mock(Throwable.class));
-
- File destDir = preparer.getDownloadDir(mockDeviceBuildInfo);
- assertFalse(new File(destDir, "apk_name_1.apk").exists());
- assertFalse(new File(destDir, "apk_name_2.apk").exists());
- verify(mockAppInstallSetup, times(1)).tearDown(any(), any(), any());
- }
-
- private File createPackageFile(File parentDir, String packageName, String apkName)
- throws IOException {
- File packageDir = new File(parentDir, packageName);
- packageDir.mkdirs();
- File apkFile = new File(packageDir, apkName);
- apkFile.createNewFile();
-
- return apkFile;
+ File baseDir = testSourceFolder.newFolder("base_dir");
+ createPackageFile(baseDir, "package_name", "apk_name_1.apk");
+ createPackageFile(baseDir, "package_name", "apk_name_2.apk");
+ AppSetupPreparer preparer =
+ new AppSetupPreparer("package_name", baseDir, mockAppInstallSetup);
+ preparer.setUp(mockDevice, mockDeviceBuildInfo);
+
+ preparer.tearDown(mockDevice, mockDeviceBuildInfo, mock(Throwable.class));
+
+ File destDir = preparer.getDownloadDir(mockDeviceBuildInfo);
+ assertFalse(new File(destDir, "apk_name_1.apk").exists());
+ assertFalse(new File(destDir, "apk_name_2.apk").exists());
+ verify(mockAppInstallSetup, times(1)).tearDown(any(), any(), any());
+ }
+
+ private File createPackageFile(File parentDir, String packageName, String apkName)
+ throws IOException {
+ File packageDir = new File(parentDir, packageName);
+ packageDir.mkdirs();
+ File apkFile = new File(packageDir, apkName);
+ apkFile.createNewFile();
+
+ return apkFile;
+ }
}
-}
diff --git a/harness/src/test/java/com/android/compatibility/testtype/AppLaunchTestTest.java b/harness/src/test/java/com/android/compatibility/testtype/AppLaunchTestTest.java
index a3f5abd..054dd94 100644
--- a/harness/src/test/java/com/android/compatibility/testtype/AppLaunchTestTest.java
+++ b/harness/src/test/java/com/android/compatibility/testtype/AppLaunchTestTest.java
@@ -29,7 +29,6 @@ import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.android.tradefed.device.DeviceNotAvailableException;
@@ -47,7 +46,6 @@ import java.util.Set;
import java.util.HashSet;
import org.mockito.InOrder;
-import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -55,372 +53,378 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public final class AppLaunchTestTest {
- private final ITestInvocationListener mMockListener = mock(ITestInvocationListener.class);
- private static final String TEST_PACKAGE_NAME = "package_name";
+ private final ITestInvocationListener mMockListener = mock(ITestInvocationListener.class);
+ private static final String TEST_PACKAGE_NAME = "package_name";
- @Test
- public void run_testFailed() throws DeviceNotAvailableException {
- InstrumentationTest instrumentationTest = createFailingInstrumentationTest();
- AppLaunchTest appLaunchTest = createLaunchTestWithInstrumentation(instrumentationTest);
+ @Test
+ public void run_testFailed() throws DeviceNotAvailableException {
+ InstrumentationTest instrumentationTest = createFailingInstrumentationTest();
+ AppLaunchTest appLaunchTest = createLaunchTestWithInstrumentation(instrumentationTest);
- appLaunchTest.run(mMockListener);
+ appLaunchTest.run(mMockListener);
- verifyFailedAndEndedCall(mMockListener);
- }
+ verifyFailedAndEndedCall(mMockListener);
+ }
- @Test
- public void run_testPassed() throws DeviceNotAvailableException {
- InstrumentationTest instrumentationTest = createPassingInstrumentationTest();
- AppLaunchTest appLaunchTest = createLaunchTestWithInstrumentation(instrumentationTest);
+ @Test
+ public void run_testPassed() throws DeviceNotAvailableException {
+ InstrumentationTest instrumentationTest = createPassingInstrumentationTest();
+ AppLaunchTest appLaunchTest = createLaunchTestWithInstrumentation(instrumentationTest);
- appLaunchTest.run(mMockListener);
+ appLaunchTest.run(mMockListener);
- verifyPassedAndEndedCall(mMockListener);
- }
+ verifyPassedAndEndedCall(mMockListener);
+ }
- @Test
- public void run_packageResetSuccess() throws DeviceNotAvailableException {
- ITestDevice mMockDevice = mock(ITestDevice.class);
- when(mMockDevice.executeShellV2Command(String.format("pm clear %s", TEST_PACKAGE_NAME)))
- .thenReturn(new CommandResult(CommandStatus.SUCCESS));
- AppLaunchTest appLaunchTest = createLaunchTestWithMockDevice(mMockDevice);
+ @Test
+ public void run_packageResetSuccess() throws DeviceNotAvailableException {
+ ITestDevice mMockDevice = mock(ITestDevice.class);
+ when(mMockDevice.executeShellV2Command(String.format("pm clear %s", TEST_PACKAGE_NAME)))
+ .thenReturn(new CommandResult(CommandStatus.SUCCESS));
+ AppLaunchTest appLaunchTest = createLaunchTestWithMockDevice(mMockDevice);
- appLaunchTest.run(mMockListener);
+ appLaunchTest.run(mMockListener);
- verifyPassedAndEndedCall(mMockListener);
- }
+ verifyPassedAndEndedCall(mMockListener);
+ }
- @Test
- public void run_packageResetError() throws DeviceNotAvailableException {
- ITestDevice mMockDevice = mock(ITestDevice.class);
- when(mMockDevice.executeShellV2Command(String.format("pm clear %s", TEST_PACKAGE_NAME)))
- .thenReturn(new CommandResult(CommandStatus.FAILED));
- AppLaunchTest appLaunchTest = createLaunchTestWithMockDevice(mMockDevice);
+ @Test
+ public void run_packageResetError() throws DeviceNotAvailableException {
+ ITestDevice mMockDevice = mock(ITestDevice.class);
+ when(mMockDevice.executeShellV2Command(String.format("pm clear %s", TEST_PACKAGE_NAME)))
+ .thenReturn(new CommandResult(CommandStatus.FAILED));
+ AppLaunchTest appLaunchTest = createLaunchTestWithMockDevice(mMockDevice);
- appLaunchTest.run(mMockListener);
+ appLaunchTest.run(mMockListener);
- verifyFailedAndEndedCall(mMockListener);
- }
+ verifyFailedAndEndedCall(mMockListener);
+ }
- @Test
- public void run_testRetry_passedAfterTwoFailings() throws Exception {
- InstrumentationTest instrumentationTest
- = createPassingInstrumentationTestAfterFailing(2);
- AppLaunchTest appLaunchTest = createLaunchTestWithRetry(instrumentationTest, 2);
+ @Test
+ public void run_testRetry_passedAfterTwoFailings() throws Exception {
+ InstrumentationTest instrumentationTest = createPassingInstrumentationTestAfterFailing(2);
+ AppLaunchTest appLaunchTest = createLaunchTestWithRetry(instrumentationTest, 2);
- appLaunchTest.run(mMockListener);
+ appLaunchTest.run(mMockListener);
- verifyPassedAndEndedCall(mMockListener);
- }
+ verifyPassedAndEndedCall(mMockListener);
+ }
- @Test
- public void run_testRetry_failedAfterThreeFailings() throws Exception {
- InstrumentationTest instrumentationTest
- = createPassingInstrumentationTestAfterFailing(3);
- AppLaunchTest appLaunchTest = createLaunchTestWithRetry(instrumentationTest, 2);
+ @Test
+ public void run_testRetry_failedAfterThreeFailings() throws Exception {
+ InstrumentationTest instrumentationTest = createPassingInstrumentationTestAfterFailing(3);
+ AppLaunchTest appLaunchTest = createLaunchTestWithRetry(instrumentationTest, 2);
- appLaunchTest.run(mMockListener);
+ appLaunchTest.run(mMockListener);
- verifyFailedAndEndedCall(mMockListener);
- }
+ verifyFailedAndEndedCall(mMockListener);
+ }
- @Test(expected = IllegalArgumentException.class)
- public void addIncludeFilter_nullIncludeFilter_throwsException() {
- AppLaunchTest sut = new AppLaunchTest();
-
- sut.addIncludeFilter(null);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void addIncludeFilter_emptyIncludeFilter_throwsException() {
- AppLaunchTest sut = new AppLaunchTest();
-
- sut.addIncludeFilter("");
- }
+ @Test(expected = IllegalArgumentException.class)
+ public void addIncludeFilter_nullIncludeFilter_throwsException() {
+ AppLaunchTest sut = new AppLaunchTest();
- @Test
- public void addIncludeFilter_validIncludeFilter() {
- AppLaunchTest sut = new AppLaunchTest();
+ sut.addIncludeFilter(null);
+ }
- sut.addIncludeFilter("test_filter");
+ @Test(expected = IllegalArgumentException.class)
+ public void addIncludeFilter_emptyIncludeFilter_throwsException() {
+ AppLaunchTest sut = new AppLaunchTest();
- assertTrue(sut.mIncludeFilters.contains("test_filter"));
- }
+ sut.addIncludeFilter("");
+ }
- @Test(expected = NullPointerException.class)
- public void addAllIncludeFilters_nullIncludeFilter_throwsException() {
- AppLaunchTest sut = new AppLaunchTest();
+ @Test
+ public void addIncludeFilter_validIncludeFilter() {
+ AppLaunchTest sut = new AppLaunchTest();
- sut.addAllIncludeFilters(null);
- }
+ sut.addIncludeFilter("test_filter");
- @Test
- public void addAllIncludeFilters_validIncludeFilters() {
- AppLaunchTest sut = new AppLaunchTest();
- Set<String> test_filters = new HashSet<>();
- test_filters.add("filter_one");
- test_filters.add("filter_two");
+ assertTrue(sut.mIncludeFilters.contains("test_filter"));
+ }
- sut.addAllIncludeFilters(test_filters);
+ @Test(expected = NullPointerException.class)
+ public void addAllIncludeFilters_nullIncludeFilter_throwsException() {
+ AppLaunchTest sut = new AppLaunchTest();
- assertTrue(sut.mIncludeFilters.contains("filter_one"));
- assertTrue(sut.mIncludeFilters.contains("filter_two"));
- }
+ sut.addAllIncludeFilters(null);
+ }
- @Test
- public void clearIncludeFilters() {
- AppLaunchTest sut = new AppLaunchTest();
- sut.addIncludeFilter("filter_test");
+ @Test
+ public void addAllIncludeFilters_validIncludeFilters() {
+ AppLaunchTest sut = new AppLaunchTest();
+ Set<String> test_filters = new HashSet<>();
+ test_filters.add("filter_one");
+ test_filters.add("filter_two");
- sut.clearIncludeFilters();
+ sut.addAllIncludeFilters(test_filters);
- assertTrue(sut.mIncludeFilters.isEmpty());
- }
+ assertTrue(sut.mIncludeFilters.contains("filter_one"));
+ assertTrue(sut.mIncludeFilters.contains("filter_two"));
+ }
- @Test
- public void getIncludeFilters() {
- AppLaunchTest sut = new AppLaunchTest();
- sut.addIncludeFilter("filter_test");
+ @Test
+ public void clearIncludeFilters() {
+ AppLaunchTest sut = new AppLaunchTest();
+ sut.addIncludeFilter("filter_test");
- assertEquals(sut.mIncludeFilters, sut.getIncludeFilters());
- }
+ sut.clearIncludeFilters();
- @Test(expected = IllegalArgumentException.class)
- public void addExcludeFilter_nullExcludeFilter_throwsException() {
- AppLaunchTest sut = new AppLaunchTest();
+ assertTrue(sut.mIncludeFilters.isEmpty());
+ }
- sut.addExcludeFilter(null);
- }
+ @Test
+ public void getIncludeFilters() {
+ AppLaunchTest sut = new AppLaunchTest();
+ sut.addIncludeFilter("filter_test");
- @Test(expected = IllegalArgumentException.class)
- public void addExcludeFilter_emptyExcludeFilter_throwsException() {
- AppLaunchTest sut = new AppLaunchTest();
+ assertEquals(sut.mIncludeFilters, sut.getIncludeFilters());
+ }
- sut.addExcludeFilter("");
- }
+ @Test(expected = IllegalArgumentException.class)
+ public void addExcludeFilter_nullExcludeFilter_throwsException() {
+ AppLaunchTest sut = new AppLaunchTest();
- @Test
- public void addExcludeFilter_validExcludeFilter() {
- AppLaunchTest sut = new AppLaunchTest();
+ sut.addExcludeFilter(null);
+ }
- sut.addExcludeFilter("test_filter");
+ @Test(expected = IllegalArgumentException.class)
+ public void addExcludeFilter_emptyExcludeFilter_throwsException() {
+ AppLaunchTest sut = new AppLaunchTest();
- assertTrue(sut.mExcludeFilters.contains("test_filter"));
- }
+ sut.addExcludeFilter("");
+ }
- @Test(expected = NullPointerException.class)
- public void addAllExcludeFilters_nullExcludeFilters_throwsException() {
- AppLaunchTest sut = new AppLaunchTest();
+ @Test
+ public void addExcludeFilter_validExcludeFilter() {
+ AppLaunchTest sut = new AppLaunchTest();
- sut.addAllExcludeFilters(null);
- }
+ sut.addExcludeFilter("test_filter");
- @Test
- public void addAllExcludeFilters_validExcludeFilters() {
- AppLaunchTest sut = new AppLaunchTest();
- Set<String> test_filters = new HashSet<>();
- test_filters.add("filter_one");
- test_filters.add("filter_two");
+ assertTrue(sut.mExcludeFilters.contains("test_filter"));
+ }
- sut.addAllExcludeFilters(test_filters);
+ @Test(expected = NullPointerException.class)
+ public void addAllExcludeFilters_nullExcludeFilters_throwsException() {
+ AppLaunchTest sut = new AppLaunchTest();
- assertTrue(sut.mExcludeFilters.contains("filter_one"));
- assertTrue(sut.mExcludeFilters.contains("filter_two"));
- }
+ sut.addAllExcludeFilters(null);
+ }
- @Test
- public void clearExcludeFilters() {
- AppLaunchTest sut = new AppLaunchTest();
- sut.addExcludeFilter("filter_test");
+ @Test
+ public void addAllExcludeFilters_validExcludeFilters() {
+ AppLaunchTest sut = new AppLaunchTest();
+ Set<String> test_filters = new HashSet<>();
+ test_filters.add("filter_one");
+ test_filters.add("filter_two");
- sut.clearExcludeFilters();
+ sut.addAllExcludeFilters(test_filters);
- assertTrue(sut.mExcludeFilters.isEmpty());
- }
+ assertTrue(sut.mExcludeFilters.contains("filter_one"));
+ assertTrue(sut.mExcludeFilters.contains("filter_two"));
+ }
- @Test
- public void getExcludeFilters() {
- AppLaunchTest sut = new AppLaunchTest();
+ @Test
+ public void clearExcludeFilters() {
+ AppLaunchTest sut = new AppLaunchTest();
+ sut.addExcludeFilter("filter_test");
- sut.addExcludeFilter("filter_test");
+ sut.clearExcludeFilters();
- assertEquals(sut.mExcludeFilters, sut.getExcludeFilters());
- }
+ assertTrue(sut.mExcludeFilters.isEmpty());
+ }
- @Test
- public void inFilter_withEmptyFilter() {
- AppLaunchTest sut = new AppLaunchTest();
+ @Test
+ public void getExcludeFilters() {
+ AppLaunchTest sut = new AppLaunchTest();
- assertTrue(sut.inFilter("filter_one"));
- }
+ sut.addExcludeFilter("filter_test");
- @Test
- public void inFilter_withRelatedIncludeFilter() {
- AppLaunchTest sut = new AppLaunchTest();
+ assertEquals(sut.mExcludeFilters, sut.getExcludeFilters());
+ }
- sut.addIncludeFilter("filter_one");
+ @Test
+ public void inFilter_withEmptyFilter() {
+ AppLaunchTest sut = new AppLaunchTest();
- assertTrue(sut.inFilter("filter_one"));
- }
+ assertTrue(sut.inFilter("filter_one"));
+ }
- @Test
- public void inFilter_withUnrelatedIncludeFilter() {
- AppLaunchTest sut = new AppLaunchTest();
+ @Test
+ public void inFilter_withRelatedIncludeFilter() {
+ AppLaunchTest sut = new AppLaunchTest();
- sut.addIncludeFilter("filter_two");
+ sut.addIncludeFilter("filter_one");
- assertFalse(sut.inFilter("filter_one"));
- }
+ assertTrue(sut.inFilter("filter_one"));
+ }
- @Test
- public void inFilter_withRelatedExcludeFilter() {
- AppLaunchTest sut = new AppLaunchTest();
+ @Test
+ public void inFilter_withUnrelatedIncludeFilter() {
+ AppLaunchTest sut = new AppLaunchTest();
- sut.addExcludeFilter("filter_one");
+ sut.addIncludeFilter("filter_two");
- assertFalse(sut.inFilter("filter_one"));
- }
+ assertFalse(sut.inFilter("filter_one"));
+ }
- @Test
- public void inFilter_withUnrelatedExcludeFilter() {
- AppLaunchTest sut = new AppLaunchTest();
+ @Test
+ public void inFilter_withRelatedExcludeFilter() {
+ AppLaunchTest sut = new AppLaunchTest();
- sut.addExcludeFilter("filter_two");
+ sut.addExcludeFilter("filter_one");
- assertTrue(sut.inFilter("filter_one"));
- }
+ assertFalse(sut.inFilter("filter_one"));
+ }
- @Test
- public void inFilter_withSameIncludeAndExcludeFilters() {
- AppLaunchTest sut = new AppLaunchTest();
+ @Test
+ public void inFilter_withUnrelatedExcludeFilter() {
+ AppLaunchTest sut = new AppLaunchTest();
- sut.addIncludeFilter("filter_one");
- sut.addExcludeFilter("filter_one");
+ sut.addExcludeFilter("filter_two");
- assertFalse(sut.inFilter("filter_one"));
- }
+ assertTrue(sut.inFilter("filter_one"));
+ }
- @Test
- public void inFilter_withUnrelatedIncludeFilterAndRelatedExcludeFilter() {
- AppLaunchTest sut = new AppLaunchTest();
+ @Test
+ public void inFilter_withSameIncludeAndExcludeFilters() {
+ AppLaunchTest sut = new AppLaunchTest();
- sut.addIncludeFilter("filter_one");
- sut.addExcludeFilter("filter_two");
+ sut.addIncludeFilter("filter_one");
+ sut.addExcludeFilter("filter_one");
- assertFalse(sut.inFilter("filter_two"));
- }
+ assertFalse(sut.inFilter("filter_one"));
+ }
- @Test
- public void inFilter_withRelatedIncludeFilterAndUnrelatedExcludeFilter() {
- AppLaunchTest sut = new AppLaunchTest();
+ @Test
+ public void inFilter_withUnrelatedIncludeFilterAndRelatedExcludeFilter() {
+ AppLaunchTest sut = new AppLaunchTest();
- sut.addIncludeFilter("filter_one");
- sut.addExcludeFilter("filter_two");
+ sut.addIncludeFilter("filter_one");
+ sut.addExcludeFilter("filter_two");
- assertTrue(sut.inFilter("filter_one"));
- }
+ assertFalse(sut.inFilter("filter_two"));
+ }
- @Test
- public void inFilter_withUnrelatedIncludeFilterAndUnrelatedExcludeFilter() {
- AppLaunchTest sut = new AppLaunchTest();
+ @Test
+ public void inFilter_withRelatedIncludeFilterAndUnrelatedExcludeFilter() {
+ AppLaunchTest sut = new AppLaunchTest();
- sut.addIncludeFilter("filter_one");
- sut.addExcludeFilter("filter_two");
+ sut.addIncludeFilter("filter_one");
+ sut.addExcludeFilter("filter_two");
- assertFalse(sut.inFilter("filter_three"));
- }
+ assertTrue(sut.inFilter("filter_one"));
+ }
- private InstrumentationTest createFailingInstrumentationTest() {
- InstrumentationTest instrumentation = new InstrumentationTest() {
- @Override
- public void run(final ITestInvocationListener listener) throws DeviceNotAvailableException {
- listener.testFailed(new TestDescription("", ""), "test failed");
- }
- };
- return instrumentation;
- }
+ @Test
+ public void inFilter_withUnrelatedIncludeFilterAndUnrelatedExcludeFilter() {
+ AppLaunchTest sut = new AppLaunchTest();
- private InstrumentationTest createPassingInstrumentationTest() {
- InstrumentationTest instrumentation = new InstrumentationTest() {
- @Override
- public void run(final ITestInvocationListener listener) throws DeviceNotAvailableException {
- }
- };
- return instrumentation;
- }
+ sut.addIncludeFilter("filter_one");
+ sut.addExcludeFilter("filter_two");
- private InstrumentationTest createPassingInstrumentationTestAfterFailing(int failedCount) {
- InstrumentationTest instrumentation = new InstrumentationTest() {
- private int retryCount = 0;
- @Override
- public void run(final ITestInvocationListener listener) throws DeviceNotAvailableException {
- if (retryCount < failedCount) {
- listener.testFailed(new TestDescription("", ""), "test failed");
- }
- retryCount ++;
- }
- };
- return instrumentation;
- }
+ assertFalse(sut.inFilter("filter_three"));
+ }
- private AppLaunchTest createLaunchTestWithInstrumentation(InstrumentationTest instrumentation) {
- AppLaunchTest appLaunchTest = new AppLaunchTest(TEST_PACKAGE_NAME) {
- @Override
- protected InstrumentationTest createInstrumentationTest(String packageBeingTested) {
+ private InstrumentationTest createFailingInstrumentationTest() {
+ InstrumentationTest instrumentation =
+ new InstrumentationTest() {
+ @Override
+ public void run(final ITestInvocationListener listener)
+ throws DeviceNotAvailableException {
+ listener.testFailed(new TestDescription("", ""), "test failed");
+ }
+ };
return instrumentation;
- }
-
- @Override
- protected CommandResult resetPackage() throws DeviceNotAvailableException {
- return new CommandResult(CommandStatus.SUCCESS);
- }
- };
- appLaunchTest.setDevice(mock(ITestDevice.class));
- return appLaunchTest;
- }
-
- private AppLaunchTest createLaunchTestWithRetry
- (InstrumentationTest instrumentation, int retryCount) {
- AppLaunchTest appLaunchTest = new AppLaunchTest(TEST_PACKAGE_NAME, retryCount) {
- @Override
- protected InstrumentationTest createInstrumentationTest(String packageBeingTested) {
+ }
+
+ private InstrumentationTest createPassingInstrumentationTest() {
+ InstrumentationTest instrumentation =
+ new InstrumentationTest() {
+ @Override
+ public void run(final ITestInvocationListener listener)
+ throws DeviceNotAvailableException {}
+ };
return instrumentation;
- }
-
- @Override
- protected CommandResult resetPackage() throws DeviceNotAvailableException {
- return new CommandResult(CommandStatus.SUCCESS);
- }
- };
- appLaunchTest.setDevice(mock(ITestDevice.class));
- return appLaunchTest;
- }
-
- private AppLaunchTest createLaunchTestWithMockDevice(ITestDevice device) {
- AppLaunchTest appLaunchTest = new AppLaunchTest(TEST_PACKAGE_NAME);
- appLaunchTest.setDevice(device);
- return appLaunchTest;
- }
-
- private static void verifyFailedAndEndedCall(ITestInvocationListener listener) {
- InOrder inOrder = inOrder(listener);
- inOrder.verify(listener, times(1)).testRunStarted(anyString(), anyInt());
- inOrder.verify(listener, times(1)).testStarted(anyObject(), anyLong());
- inOrder.verify(listener, times(1)).testFailed(any(), any());
- inOrder.verify(listener, times(1))
- .testEnded(anyObject(), anyLong(), (Map<String, String>) any());
- inOrder.verify(listener, times(1))
- .testRunEnded(anyLong(), (HashMap<String, Metric>) any());
- }
-
- private static void verifyPassedAndEndedCall(ITestInvocationListener listener) {
- InOrder inOrder = inOrder(listener);
- inOrder.verify(listener, times(1)).testRunStarted(anyString(), anyInt());
- inOrder.verify(listener, times(1)).testStarted(anyObject(), anyLong());
- inOrder.verify(listener, never()).testFailed(any(), any());
- inOrder.verify(listener, times(1))
- .testEnded(anyObject(), anyLong(), (Map<String, String>) any());
- inOrder.verify(listener, times(1))
- .testRunEnded(anyLong(), (HashMap<String, Metric>) any());
+ }
+
+ private InstrumentationTest createPassingInstrumentationTestAfterFailing(int failedCount) {
+ InstrumentationTest instrumentation =
+ new InstrumentationTest() {
+ private int retryCount = 0;
+
+ @Override
+ public void run(final ITestInvocationListener listener)
+ throws DeviceNotAvailableException {
+ if (retryCount < failedCount) {
+ listener.testFailed(new TestDescription("", ""), "test failed");
+ }
+ retryCount++;
+ }
+ };
+ return instrumentation;
+ }
+
+ private AppLaunchTest createLaunchTestWithInstrumentation(InstrumentationTest instrumentation) {
+ AppLaunchTest appLaunchTest =
+ new AppLaunchTest(TEST_PACKAGE_NAME) {
+ @Override
+ protected InstrumentationTest createInstrumentationTest(
+ String packageBeingTested) {
+ return instrumentation;
+ }
+
+ @Override
+ protected CommandResult resetPackage() throws DeviceNotAvailableException {
+ return new CommandResult(CommandStatus.SUCCESS);
+ }
+ };
+ appLaunchTest.setDevice(mock(ITestDevice.class));
+ return appLaunchTest;
+ }
+
+ private AppLaunchTest createLaunchTestWithRetry(
+ InstrumentationTest instrumentation, int retryCount) {
+ AppLaunchTest appLaunchTest =
+ new AppLaunchTest(TEST_PACKAGE_NAME, retryCount) {
+ @Override
+ protected InstrumentationTest createInstrumentationTest(
+ String packageBeingTested) {
+ return instrumentation;
+ }
+
+ @Override
+ protected CommandResult resetPackage() throws DeviceNotAvailableException {
+ return new CommandResult(CommandStatus.SUCCESS);
+ }
+ };
+ appLaunchTest.setDevice(mock(ITestDevice.class));
+ return appLaunchTest;
+ }
+
+ private AppLaunchTest createLaunchTestWithMockDevice(ITestDevice device) {
+ AppLaunchTest appLaunchTest = new AppLaunchTest(TEST_PACKAGE_NAME);
+ appLaunchTest.setDevice(device);
+ return appLaunchTest;
+ }
+
+ private static void verifyFailedAndEndedCall(ITestInvocationListener listener) {
+ InOrder inOrder = inOrder(listener);
+ inOrder.verify(listener, times(1)).testRunStarted(anyString(), anyInt());
+ inOrder.verify(listener, times(1)).testStarted(anyObject(), anyLong());
+ inOrder.verify(listener, times(1)).testFailed(any(), any());
+ inOrder.verify(listener, times(1))
+ .testEnded(anyObject(), anyLong(), (Map<String, String>) any());
+ inOrder.verify(listener, times(1)).testRunEnded(anyLong(), (HashMap<String, Metric>) any());
+ }
+
+ private static void verifyPassedAndEndedCall(ITestInvocationListener listener) {
+ InOrder inOrder = inOrder(listener);
+ inOrder.verify(listener, times(1)).testRunStarted(anyString(), anyInt());
+ inOrder.verify(listener, times(1)).testStarted(anyObject(), anyLong());
+ inOrder.verify(listener, never()).testFailed(any(), any());
+ inOrder.verify(listener, times(1))
+ .testEnded(anyObject(), anyLong(), (Map<String, String>) any());
+ inOrder.verify(listener, times(1)).testRunEnded(anyLong(), (HashMap<String, Metric>) any());
+ }
}
-}
diff --git a/instrumentation/launch/src/main/java/com/android/compatibilitytest/AppCompatibility.java b/instrumentation/launch/src/main/java/com/android/compatibilitytest/AppCompatibility.java
index cb48a60..d1fbc8a 100644
--- a/instrumentation/launch/src/main/java/com/android/compatibilitytest/AppCompatibility.java
+++ b/instrumentation/launch/src/main/java/com/android/compatibilitytest/AppCompatibility.java
@@ -52,10 +52,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-/**
- * Application Compatibility Test that launches an application and detects
- * crashes.
- */
+/** Application Compatibility Test that launches an application and detects crashes. */
@RunWith(AndroidJUnit4.class)
public final class AppCompatibility {
@@ -105,8 +102,8 @@ public final class AppCompatibility {
// resolve launcher package name
Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME);
- ResolveInfo resolveInfo = mPackageManager.resolveActivity(
- intent, PackageManager.MATCH_DEFAULT_ONLY);
+ ResolveInfo resolveInfo =
+ mPackageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
mLauncherPackageName = resolveInfo.activityInfo.packageName;
Assert.assertNotNull("failed to resolve package name for launcher", mLauncherPackageName);
Log.v(TAG, "Using launcher package name: " + mLauncherPackageName);
@@ -125,20 +122,19 @@ public final class AppCompatibility {
// set activity controller to suppress crash dialogs and collects them by process name
mAppErrors.clear();
IActivityManager.Stub.asInterface(ServiceManager.checkService(Context.ACTIVITY_SERVICE))
- .setActivityController(mCrashSupressor, false);
+ .setActivityController(mCrashSupressor, false);
}
@After
public void tearDown() throws Exception {
// unset activity controller
IActivityManager.Stub.asInterface(ServiceManager.checkService(Context.ACTIVITY_SERVICE))
- .setActivityController(null, false);
+ .setActivityController(null, false);
mInstrumentation.getUiAutomation().setRotation(UiAutomation.ROTATION_UNFREEZE);
}
/**
- * Actual test case that launches the package and throws an exception on the
- * first error.
+ * Actual test case that launches the package and throws an exception on the first error.
*
* @throws Exception
*/
@@ -157,8 +153,9 @@ public final class AppCompatibility {
try {
checkDropbox(startTime, packageName);
if (mAppErrors.containsKey(packageName)) {
- StringBuilder message = new StringBuilder("Error(s) detected for package: ")
- .append(packageName);
+ StringBuilder message =
+ new StringBuilder("Error(s) detected for package: ")
+ .append(packageName);
List<String> errors = mAppErrors.get(packageName);
for (int i = 0; i < MAX_NUM_CRASH_SNIPPET && i < errors.size(); i++) {
String err = errors.get(i);
@@ -167,27 +164,36 @@ public final class AppCompatibility {
message.append(truncate(err, MAX_CRASH_SNIPPET_LINES));
}
if (errors.size() > MAX_NUM_CRASH_SNIPPET) {
- message.append(String.format("\n... %d more errors omitted ...",
- errors.size() - MAX_NUM_CRASH_SNIPPET));
+ message.append(
+ String.format(
+ "\n... %d more errors omitted ...",
+ errors.size() - MAX_NUM_CRASH_SNIPPET));
}
Assert.fail(message.toString());
}
// last check: see if app process is still running
- Assert.assertTrue("app package \"" + packageName + "\" no longer found in running "
- + "tasks, but no explicit crashes were detected; check logcat for details",
- processStillUp(packageName));
+ Assert.assertTrue(
+ "app package \""
+ + packageName
+ + "\" no longer found in running "
+ + "tasks, but no explicit crashes were detected; check logcat for details",
+ processStillUp(packageName));
} finally {
returnHome();
}
} else {
- Log.d(TAG, "Missing argument, use " + PACKAGE_TO_LAUNCH +
- " to specify the package to launch");
+ Log.d(
+ TAG,
+ "Missing argument, use "
+ + PACKAGE_TO_LAUNCH
+ + " to specify the package to launch");
+ }
}
- }
/**
* Truncate the text to at most the specified number of lines, and append a marker at the end
* when truncated
+ *
* @param text
* @param maxLines
* @return
@@ -209,12 +215,13 @@ public final class AppCompatibility {
/**
* Check dropbox for entries of interest regarding the specified process
+ *
* @param startTime if not 0, only check entries with timestamp later than the start time
* @param processName the process name to check for
*/
private void checkDropbox(long startTime, String processName) {
- DropBoxManager dropbox = (DropBoxManager) mContext
- .getSystemService(Context.DROPBOX_SERVICE);
+ DropBoxManager dropbox =
+ (DropBoxManager) mContext.getSystemService(Context.DROPBOX_SERVICE);
DropBoxManager.Entry entry = null;
while (null != (entry = dropbox.getNextEntry(null, startTime))) {
try {
@@ -263,14 +270,15 @@ public final class AppCompatibility {
/**
* Launches and activity and queries for errors.
*
- * @param packageName {@link String} the package name of the application to
- * launch.
- * @return {@link Collection} of {@link ProcessErrorStateInfo} detected
- * during the app launch.
+ * @param packageName {@link String} the package name of the application to launch.
+ * @return {@link Collection} of {@link ProcessErrorStateInfo} detected during the app launch.
*/
private void launchActivity(String packageName, Intent intent) {
- Log.d(TAG, String.format("launching package \"%s\" with intent: %s",
- packageName, intent.toString()));
+ Log.d(
+ TAG,
+ String.format(
+ "launching package \"%s\" with intent: %s",
+ packageName, intent.toString()));
// Launch Activity
mContext.startActivity(intent);
@@ -289,7 +297,7 @@ public final class AppCompatibility {
List<String> errors;
if (mAppErrors.containsKey(pkgName)) {
errors = mAppErrors.get(pkgName);
- } else {
+ } else {
errors = new ArrayList<>();
}
errors.add(String.format("### Type: %s, Details:\n%s", errorType, errorInfo));
@@ -316,7 +324,6 @@ public final class AppCompatibility {
/**
* An {@link IActivityController} that instructs framework to kill processes hitting crashes
* directly without showing crash dialogs
- *
*/
private class CrashSuppressor extends IActivityController.Stub {
@@ -333,8 +340,14 @@ public final class AppCompatibility {
}
@Override
- public boolean appCrashed(String processName, int pid, String shortMsg, String longMsg,
- long timeMillis, String stackTrace) throws RemoteException {
+ public boolean appCrashed(
+ String processName,
+ int pid,
+ String shortMsg,
+ String longMsg,
+ long timeMillis,
+ String stackTrace)
+ throws RemoteException {
Log.d(TAG, "app crash: " + processName);
addProcessError(processName, "crash", stackTrace);
// don't show dialog
diff --git a/tools/csuite-tradefed/src/test/java/com/android/compatibility/tradefed/CSuiteTradefedTest.java b/tools/csuite-tradefed/src/test/java/com/android/compatibility/tradefed/CSuiteTradefedTest.java
index 42e09af..fbbf98d 100644
--- a/tools/csuite-tradefed/src/test/java/com/android/compatibility/tradefed/CSuiteTradefedTest.java
+++ b/tools/csuite-tradefed/src/test/java/com/android/compatibility/tradefed/CSuiteTradefedTest.java
@@ -16,14 +16,10 @@
package com.android.compatibility.tradefed;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
import com.android.compatibility.common.tradefed.build.CompatibilityBuildHelper;
import com.android.compatibility.common.tradefed.build.CompatibilityBuildProvider;
-import com.android.tradefed.build.IBuildInfo;
-import com.android.tradefed.util.FileUtil;
-import java.io.IOException;
import org.junit.After;
import org.junit.Before;
@@ -38,41 +34,43 @@ import java.io.File;
@RunWith(JUnit4.class)
public class CSuiteTradefedTest {
- @Rule public final TemporaryFolder tempFolder = new TemporaryFolder();
+ @Rule public final TemporaryFolder tempFolder = new TemporaryFolder();
- private static final String ROOT_DIR_PROPERTY_NAME = "CSUITE_ROOT";
- private static final String SUITE_FULL_NAME = "App Compatibility Test Suite";
- private static final String SUITE_NAME = "C-Suite";
+ private static final String ROOT_DIR_PROPERTY_NAME = "CSUITE_ROOT";
+ private static final String SUITE_FULL_NAME = "App Compatibility Test Suite";
+ private static final String SUITE_NAME = "C-Suite";
- private CompatibilityBuildProvider provider;
+ private CompatibilityBuildProvider provider;
- @Before
- public void setUp() throws Exception {
- System.setProperty(ROOT_DIR_PROPERTY_NAME, tempFolder.getRoot().getAbsolutePath());
- File base = tempFolder.newFolder("android-csuite");
- File tests = tempFolder.newFolder("testcases");
+ @Before
+ public void setUp() throws Exception {
+ System.setProperty(ROOT_DIR_PROPERTY_NAME, tempFolder.getRoot().getAbsolutePath());
+ File base = tempFolder.newFolder("android-csuite");
+ File tests = tempFolder.newFolder("testcases");
- provider = new CompatibilityBuildProvider() {
- @Override
- protected String getSuiteInfoName() {
- return SUITE_NAME;
- }
- @Override
- protected String getSuiteInfoFullname() {
- return SUITE_FULL_NAME;
- }
- };
- }
+ provider =
+ new CompatibilityBuildProvider() {
+ @Override
+ protected String getSuiteInfoName() {
+ return SUITE_NAME;
+ }
- @Test
- public void testSuiteInfoLoad() throws Exception {
- CompatibilityBuildHelper helper = new CompatibilityBuildHelper(provider.getBuild());
- assertEquals("Incorrect suite full name", SUITE_FULL_NAME, helper.getSuiteFullName());
- assertEquals("Incorrect suite name", SUITE_NAME, helper.getSuiteName());
- }
+ @Override
+ protected String getSuiteInfoFullname() {
+ return SUITE_FULL_NAME;
+ }
+ };
+ }
+
+ @Test
+ public void testSuiteInfoLoad() throws Exception {
+ CompatibilityBuildHelper helper = new CompatibilityBuildHelper(provider.getBuild());
+ assertEquals("Incorrect suite full name", SUITE_FULL_NAME, helper.getSuiteFullName());
+ assertEquals("Incorrect suite name", SUITE_NAME, helper.getSuiteName());
+ }
- @After
- public void cleanUp() throws Exception {
- System.clearProperty(ROOT_DIR_PROPERTY_NAME);
+ @After
+ public void cleanUp() throws Exception {
+ System.clearProperty(ROOT_DIR_PROPERTY_NAME);
+ }
}
-}