From 09770d845b9cd63f92224f86b24e396973d7b8f1 Mon Sep 17 00:00:00 2001 From: Ben Weiss Date: Fri, 30 Aug 2024 11:06:16 +0200 Subject: [PATCH] Add function to clear data between runs --- .../macrobenchmark/baselineprofile/Common.kt | 16 +++++++++++++++- .../LoginBaselineProfileGenerator.kt | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/MacrobenchmarkSample/macrobenchmark/src/main/kotlin/com/example/macrobenchmark/baselineprofile/Common.kt b/MacrobenchmarkSample/macrobenchmark/src/main/kotlin/com/example/macrobenchmark/baselineprofile/Common.kt index 6c2e37af..0eb564b5 100644 --- a/MacrobenchmarkSample/macrobenchmark/src/main/kotlin/com/example/macrobenchmark/baselineprofile/Common.kt +++ b/MacrobenchmarkSample/macrobenchmark/src/main/kotlin/com/example/macrobenchmark/baselineprofile/Common.kt @@ -16,4 +16,18 @@ package com.example.macrobenchmark.baselineprofile -const val TARGET_PACKAGE = "com.example.macrobenchmark.target" \ No newline at end of file +import androidx.benchmark.macro.MacrobenchmarkScope +import androidx.test.uiautomator.UiDevice + +const val TARGET_PACKAGE = "com.example.macrobenchmark.target" + +/** + * Clears the application data for the package specified in the [MacrobenchmarkScope]. + * @param scope The [MacrobenchmarkScope] providing information about the benchmark, + * including the package name of the app under test. + */ +fun UiDevice.clearData(scope: MacrobenchmarkScope) { + val command = "pm clear $scope.packageName" + val output = executeShellCommand(command) +// Assert.assertEquals("Success", output) +} \ No newline at end of file diff --git a/MacrobenchmarkSample/macrobenchmark/src/main/kotlin/com/example/macrobenchmark/baselineprofile/LoginBaselineProfileGenerator.kt b/MacrobenchmarkSample/macrobenchmark/src/main/kotlin/com/example/macrobenchmark/baselineprofile/LoginBaselineProfileGenerator.kt index eff0a373..9792a33d 100644 --- a/MacrobenchmarkSample/macrobenchmark/src/main/kotlin/com/example/macrobenchmark/baselineprofile/LoginBaselineProfileGenerator.kt +++ b/MacrobenchmarkSample/macrobenchmark/src/main/kotlin/com/example/macrobenchmark/baselineprofile/LoginBaselineProfileGenerator.kt @@ -37,6 +37,7 @@ class LoginBaselineProfileGenerator { maxIterations = 15, stableIterations = 3 ) { + device.clearData(this) startActivityAndWait(Intent("$packageName.LOGIN_ACTIVITY")) device.findObject(By.res("userName")).text = "user" device.findObject(By.res("password")).text = "password"