Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
Add flag to prevent apk-under-test from being uninstalled
Browse files Browse the repository at this point in the history
Summary:
I'm bundling multiple tests together with remote execution, sharded by apk-under-test. I want to make it so only the last one uninstalls the apk under test, but I want to uninstall the test apk every time.
I split --attempt-uninstall into --attempt-uninstall-instrumentation-apk and --attempt-uninstall-apk-under-test. I'm keeping --attempt-uninstall for now for back-compatibility.

Reviewed By: IanChilds

fbshipit-source-id: d567880703
  • Loading branch information
rafaelclp authored and facebook-github-bot committed May 22, 2019
1 parent 03a7ebd commit c2c0ffc
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/com/facebook/buck/testrunner/InstrumentationTestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public class InstrumentationTestRunner {
private final String testRunner;
private final File outputDirectory;
private final String exopackageLocalPath;
private final boolean attemptUninstall;
private final boolean attemptUninstallApkUnderTest;
private final boolean attemptUninstallInstrumentationApk;
private final Map<String, String> extraInstrumentationArguments;
private final boolean debug;
private final boolean codeCoverage;
Expand All @@ -73,7 +74,8 @@ public InstrumentationTestRunner(
String apkUnderTestPath,
String exopackageLocalPath,
String apkUnderTestExopackageLocalPath,
boolean attemptUninstall,
boolean attemptUninstallApkUnderTest,
boolean attemptUninstallInstrumentationApk,
boolean debug,
boolean codeCoverage,
String codeCoverageOutputFile,
Expand All @@ -88,7 +90,8 @@ public InstrumentationTestRunner(
this.apkUnderTestPath = apkUnderTestPath;
this.exopackageLocalPath = exopackageLocalPath;
this.apkUnderTestExopackageLocalPath = apkUnderTestExopackageLocalPath;
this.attemptUninstall = attemptUninstall;
this.attemptUninstallApkUnderTest = attemptUninstallApkUnderTest;
this.attemptUninstallInstrumentationApk = attemptUninstallInstrumentationApk;
this.codeCoverageOutputFile = codeCoverageOutputFile;
this.extraInstrumentationArguments = extraInstrumentationArguments;
this.debug = debug;
Expand All @@ -106,7 +109,8 @@ public static InstrumentationTestRunner fromArgs(String... args) {
String codeCoverageOutputFile = null;
String exopackageLocalPath = null;
String apkUnderTestExopackageLocalPath = null;
boolean attemptUninstall = false;
boolean attemptUninstallApkUnderTest = false;
boolean attemptUninstallInstrumentationApk = false;
boolean debug = false;
boolean codeCoverage = false;
Map<String, String> extraInstrumentationArguments = new HashMap<String, String>();
Expand Down Expand Up @@ -145,7 +149,14 @@ public static InstrumentationTestRunner fromArgs(String... args) {
apkUnderTestExopackageLocalPath = args[++i];
break;
case "--attempt-uninstall":
attemptUninstall = true;
attemptUninstallApkUnderTest = true;
attemptUninstallInstrumentationApk = true;
break;
case "--attempt-uninstall-apk-under-test":
attemptUninstallApkUnderTest = true;
break;
case "--attempt-uninstall-instrumentation-apk":
attemptUninstallInstrumentationApk = true;
break;
case "--debug":
debug = true;
Expand Down Expand Up @@ -210,7 +221,8 @@ public static InstrumentationTestRunner fromArgs(String... args) {
apkUnderTestPath,
exopackageLocalPath,
apkUnderTestExopackageLocalPath,
attemptUninstall,
attemptUninstallApkUnderTest,
attemptUninstallInstrumentationApk,
debug,
codeCoverage,
codeCoverageOutputFile,
Expand Down Expand Up @@ -308,9 +320,11 @@ public void testRunStopped(long elapsedTime) {}
"/data/data/" + this.packageName + "/files/coverage.ec", this.codeCoverageOutputFile);
}
} finally {
if (this.attemptUninstall) {
if (this.attemptUninstallInstrumentationApk) {
// Best effort uninstall from the emulator/device.
device.uninstallPackage(this.packageName);
}
if (this.attemptUninstallApkUnderTest) {
device.uninstallPackage(this.targetPackageName);
}
}
Expand Down

0 comments on commit c2c0ffc

Please sign in to comment.