summaryrefslogtreecommitdiff
path: root/apct-tests/perftests/textclassifier
diff options
context:
space:
mode:
authorTony Mak <tonymak@google.com>2019-04-02 18:23:54 +0100
committerTony Mak <tonymak@google.com>2019-04-04 17:09:58 +0100
commit751afc9821625cad83d782394aaa1a344feec8d8 (patch)
tree0f95ef367e450d0bbc8290a3bde97f7b1ebefd84 /apct-tests/perftests/textclassifier
parent0454f3b8aefdf1387468a96e6de60530fcf55f83 (diff)
Add getTextClassifier perf test
This helps us to evaluate the fix. BUG: 129695635 Test: frameworks/base/apct-tests/perftests/textclassifier/run.sh Change-Id: I7d2d019faecb3721c044a43e24d86d98a08be64b
Diffstat (limited to 'apct-tests/perftests/textclassifier')
-rwxr-xr-xapct-tests/perftests/textclassifier/run.sh8
-rw-r--r--apct-tests/perftests/textclassifier/src/android/view/textclassifier/TextClassificationManagerPerfTest.java74
2 files changed, 80 insertions, 2 deletions
diff --git a/apct-tests/perftests/textclassifier/run.sh b/apct-tests/perftests/textclassifier/run.sh
index c6782d1a72f2..8660d26388ac 100755
--- a/apct-tests/perftests/textclassifier/run.sh
+++ b/apct-tests/perftests/textclassifier/run.sh
@@ -1,4 +1,8 @@
set -e
-make TextClassifierPerfTests
+make TextClassifierPerfTests perf-setup.sh
+adb install ${OUT}/testcases/TextClassifierPerfTests/arm64/TextClassifierPerfTests.apk
adb shell cmd package compile -m speed -f com.android.perftests.textclassifier
-adb shell am instrument -w -e class android.view.textclassifier.TextClassifierPerfTest com.android.perftests.textclassifier/androidx.test.runner.AndroidJUnitRunner
+adb push ${OUT}/obj/EXECUTABLES/perf-setup.sh_intermediates/perf-setup.sh /data/local/tmp/
+adb shell chmod +x /data/local/tmp/perf-setup.sh
+adb shell /data/local/tmp/perf-setup.sh
+adb shell am instrument -w -e package android.view.textclassifier com.android.perftests.textclassifier/androidx.test.runner.AndroidJUnitRunner \ No newline at end of file
diff --git a/apct-tests/perftests/textclassifier/src/android/view/textclassifier/TextClassificationManagerPerfTest.java b/apct-tests/perftests/textclassifier/src/android/view/textclassifier/TextClassificationManagerPerfTest.java
new file mode 100644
index 000000000000..c1491956c798
--- /dev/null
+++ b/apct-tests/perftests/textclassifier/src/android/view/textclassifier/TextClassificationManagerPerfTest.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.view.textclassifier;
+
+import android.content.Context;
+import android.perftests.utils.BenchmarkState;
+import android.perftests.utils.PerfStatusReporter;
+import android.perftests.utils.SettingsHelper;
+import android.provider.Settings;
+
+import androidx.test.InstrumentationRegistry;
+import androidx.test.filters.LargeTest;
+
+import org.junit.After;
+import org.junit.Rule;
+import org.junit.Test;
+
+@LargeTest
+public class TextClassificationManagerPerfTest {
+
+ @Rule
+ public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
+
+ @After
+ public void tearDown() {
+ SettingsHelper.delete(
+ SettingsHelper.NAMESPACE_GLOBAL, Settings.Global.TEXT_CLASSIFIER_CONSTANTS);
+ }
+
+ @Test
+ public void testGetTextClassifier_systemTextClassifierDisabled() {
+ Context context = InstrumentationRegistry.getTargetContext();
+ SettingsHelper.set(
+ SettingsHelper.NAMESPACE_GLOBAL,
+ Settings.Global.TEXT_CLASSIFIER_CONSTANTS,
+ "system_textclassifier_enabled=false");
+ TextClassificationManager textClassificationManager =
+ context.getSystemService(TextClassificationManager.class);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ textClassificationManager.getTextClassifier();
+ textClassificationManager.invalidate();
+ }
+ }
+
+ @Test
+ public void testGetTextClassifier_systemTextClassifierEnabled() {
+ Context context = InstrumentationRegistry.getTargetContext();
+ SettingsHelper.set(
+ SettingsHelper.NAMESPACE_GLOBAL,
+ Settings.Global.TEXT_CLASSIFIER_CONSTANTS,
+ "system_textclassifier_enabled=true");
+ TextClassificationManager textClassificationManager =
+ context.getSystemService(TextClassificationManager.class);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ textClassificationManager.getTextClassifier();
+ textClassificationManager.invalidate();
+ }
+ }
+}