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

Commit c2c0ffc

Browse files
rafaelclpfacebook-github-bot
authored andcommitted
Add flag to prevent apk-under-test from being uninstalled
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
1 parent 03a7ebd commit c2c0ffc

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/com/facebook/buck/testrunner/InstrumentationTestRunner.java

+21-7
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public class InstrumentationTestRunner {
5353
private final String testRunner;
5454
private final File outputDirectory;
5555
private final String exopackageLocalPath;
56-
private final boolean attemptUninstall;
56+
private final boolean attemptUninstallApkUnderTest;
57+
private final boolean attemptUninstallInstrumentationApk;
5758
private final Map<String, String> extraInstrumentationArguments;
5859
private final boolean debug;
5960
private final boolean codeCoverage;
@@ -73,7 +74,8 @@ public InstrumentationTestRunner(
7374
String apkUnderTestPath,
7475
String exopackageLocalPath,
7576
String apkUnderTestExopackageLocalPath,
76-
boolean attemptUninstall,
77+
boolean attemptUninstallApkUnderTest,
78+
boolean attemptUninstallInstrumentationApk,
7779
boolean debug,
7880
boolean codeCoverage,
7981
String codeCoverageOutputFile,
@@ -88,7 +90,8 @@ public InstrumentationTestRunner(
8890
this.apkUnderTestPath = apkUnderTestPath;
8991
this.exopackageLocalPath = exopackageLocalPath;
9092
this.apkUnderTestExopackageLocalPath = apkUnderTestExopackageLocalPath;
91-
this.attemptUninstall = attemptUninstall;
93+
this.attemptUninstallApkUnderTest = attemptUninstallApkUnderTest;
94+
this.attemptUninstallInstrumentationApk = attemptUninstallInstrumentationApk;
9295
this.codeCoverageOutputFile = codeCoverageOutputFile;
9396
this.extraInstrumentationArguments = extraInstrumentationArguments;
9497
this.debug = debug;
@@ -106,7 +109,8 @@ public static InstrumentationTestRunner fromArgs(String... args) {
106109
String codeCoverageOutputFile = null;
107110
String exopackageLocalPath = null;
108111
String apkUnderTestExopackageLocalPath = null;
109-
boolean attemptUninstall = false;
112+
boolean attemptUninstallApkUnderTest = false;
113+
boolean attemptUninstallInstrumentationApk = false;
110114
boolean debug = false;
111115
boolean codeCoverage = false;
112116
Map<String, String> extraInstrumentationArguments = new HashMap<String, String>();
@@ -145,7 +149,14 @@ public static InstrumentationTestRunner fromArgs(String... args) {
145149
apkUnderTestExopackageLocalPath = args[++i];
146150
break;
147151
case "--attempt-uninstall":
148-
attemptUninstall = true;
152+
attemptUninstallApkUnderTest = true;
153+
attemptUninstallInstrumentationApk = true;
154+
break;
155+
case "--attempt-uninstall-apk-under-test":
156+
attemptUninstallApkUnderTest = true;
157+
break;
158+
case "--attempt-uninstall-instrumentation-apk":
159+
attemptUninstallInstrumentationApk = true;
149160
break;
150161
case "--debug":
151162
debug = true;
@@ -210,7 +221,8 @@ public static InstrumentationTestRunner fromArgs(String... args) {
210221
apkUnderTestPath,
211222
exopackageLocalPath,
212223
apkUnderTestExopackageLocalPath,
213-
attemptUninstall,
224+
attemptUninstallApkUnderTest,
225+
attemptUninstallInstrumentationApk,
214226
debug,
215227
codeCoverage,
216228
codeCoverageOutputFile,
@@ -308,9 +320,11 @@ public void testRunStopped(long elapsedTime) {}
308320
"/data/data/" + this.packageName + "/files/coverage.ec", this.codeCoverageOutputFile);
309321
}
310322
} finally {
311-
if (this.attemptUninstall) {
323+
if (this.attemptUninstallInstrumentationApk) {
312324
// Best effort uninstall from the emulator/device.
313325
device.uninstallPackage(this.packageName);
326+
}
327+
if (this.attemptUninstallApkUnderTest) {
314328
device.uninstallPackage(this.targetPackageName);
315329
}
316330
}

0 commit comments

Comments
 (0)