Skip to content

Commit 09770d8

Browse files
Add function to clear data between runs
1 parent 26651e0 commit 09770d8

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

MacrobenchmarkSample/macrobenchmark/src/main/kotlin/com/example/macrobenchmark/baselineprofile/Common.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,18 @@
1616

1717
package com.example.macrobenchmark.baselineprofile
1818

19-
const val TARGET_PACKAGE = "com.example.macrobenchmark.target"
19+
import androidx.benchmark.macro.MacrobenchmarkScope
20+
import androidx.test.uiautomator.UiDevice
21+
22+
const val TARGET_PACKAGE = "com.example.macrobenchmark.target"
23+
24+
/**
25+
* Clears the application data for the package specified in the [MacrobenchmarkScope].
26+
* @param scope The [MacrobenchmarkScope] providing information about the benchmark,
27+
* including the package name of the app under test.
28+
*/
29+
fun UiDevice.clearData(scope: MacrobenchmarkScope) {
30+
val command = "pm clear $scope.packageName"
31+
val output = executeShellCommand(command)
32+
// Assert.assertEquals("Success", output)
33+
}

MacrobenchmarkSample/macrobenchmark/src/main/kotlin/com/example/macrobenchmark/baselineprofile/LoginBaselineProfileGenerator.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class LoginBaselineProfileGenerator {
3737
maxIterations = 15,
3838
stableIterations = 3
3939
) {
40+
device.clearData(this)
4041
startActivityAndWait(Intent("$packageName.LOGIN_ACTIVITY"))
4142
device.findObject(By.res("userName")).text = "user"
4243
device.findObject(By.res("password")).text = "password"

0 commit comments

Comments
 (0)