From e5ee70516e5a3abc4110c31f16f0a96f1c3c6249 Mon Sep 17 00:00:00 2001 From: Tony Mak Date: Mon, 1 Apr 2019 20:51:37 +0100 Subject: Move TextClassifierPerfTest to a separate package So, other tests in other package no longer affect us. Currently, TextClassifierPerfTest is not run continuously because of failures in other packages. BUG: 129695635 Test: Run run.sh Change-Id: I2253360d98404608193b53c8b34611c2ff1b231e --- .../textclassifier/TextClassifierPerfTest.java | 114 --------------------- apct-tests/perftests/textclassifier/Android.bp | 25 +++++ .../perftests/textclassifier/AndroidManifest.xml | 25 +++++ .../perftests/textclassifier/AndroidTest.xml | 28 +++++ apct-tests/perftests/textclassifier/run.sh | 4 + .../textclassifier/TextClassifierPerfTest.java | 110 ++++++++++++++++++++ 6 files changed, 192 insertions(+), 114 deletions(-) delete mode 100644 apct-tests/perftests/core/src/android/textclassifier/TextClassifierPerfTest.java create mode 100644 apct-tests/perftests/textclassifier/Android.bp create mode 100644 apct-tests/perftests/textclassifier/AndroidManifest.xml create mode 100644 apct-tests/perftests/textclassifier/AndroidTest.xml create mode 100755 apct-tests/perftests/textclassifier/run.sh create mode 100644 apct-tests/perftests/textclassifier/src/android/view/textclassifier/TextClassifierPerfTest.java diff --git a/apct-tests/perftests/core/src/android/textclassifier/TextClassifierPerfTest.java b/apct-tests/perftests/core/src/android/textclassifier/TextClassifierPerfTest.java deleted file mode 100644 index c5d89b23420..00000000000 --- a/apct-tests/perftests/core/src/android/textclassifier/TextClassifierPerfTest.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * 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.textclassifier; - -import android.content.Context; -import android.perftests.utils.BenchmarkState; -import android.perftests.utils.PerfStatusReporter; -import android.view.textclassifier.ConversationActions; -import android.view.textclassifier.TextClassificationManager; -import android.view.textclassifier.TextClassifier; -import android.view.textclassifier.TextLanguage; - -import androidx.test.InstrumentationRegistry; -import androidx.test.filters.LargeTest; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Random; - -@RunWith(Parameterized.class) -@LargeTest -public class TextClassifierPerfTest { - /** Request contains meaning text, rather than garbled text. */ - private static final int ACTUAL_REQUEST = 0; - private static final String RANDOM_CHAR_SET = "abcdefghijklmnopqrstuvwxyz0123456789"; - - @Rule - public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); - - @Parameterized.Parameters(name = "size{0}") - public static Collection data() { - return Arrays.asList(new Object[][]{{ACTUAL_REQUEST}, {10}, {100}, {1000}}); - } - - private TextClassifier mTextClassifier; - private final int mSize; - - public TextClassifierPerfTest(int size) { - mSize = size; - } - - @Before - public void setUp() { - Context context = InstrumentationRegistry.getTargetContext(); - TextClassificationManager textClassificationManager = - context.getSystemService(TextClassificationManager.class); - mTextClassifier = textClassificationManager.getTextClassifier(TextClassifier.LOCAL); - } - - @Test - public void testSuggestConversationActions() { - String text = mSize == ACTUAL_REQUEST ? "Where are you?" : generateRandomString(mSize); - ConversationActions.Request request = createConversationActionsRequest(text); - BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); - while (state.keepRunning()) { - mTextClassifier.suggestConversationActions(request); - } - } - - @Test - public void testDetectLanguage() { - String text = mSize == ACTUAL_REQUEST - ? "これは日本語のテキストです" : generateRandomString(mSize); - TextLanguage.Request request = createTextLanguageRequest(text); - BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); - while (state.keepRunning()) { - mTextClassifier.detectLanguage(request); - } - } - - private static ConversationActions.Request createConversationActionsRequest(CharSequence text) { - ConversationActions.Message message = - new ConversationActions.Message.Builder( - ConversationActions.Message.PERSON_USER_OTHERS) - .setText(text) - .build(); - return new ConversationActions.Request.Builder(Collections.singletonList(message)) - .build(); - } - - private static TextLanguage.Request createTextLanguageRequest(CharSequence text) { - return new TextLanguage.Request.Builder(text).build(); - } - - private static String generateRandomString(int length) { - Random random = new Random(); - StringBuilder stringBuilder = new StringBuilder(length); - for (int i = 0; i < length; i++) { - int index = random.nextInt(RANDOM_CHAR_SET.length()); - stringBuilder.append(RANDOM_CHAR_SET.charAt(index)); - } - return stringBuilder.toString(); - } -} diff --git a/apct-tests/perftests/textclassifier/Android.bp b/apct-tests/perftests/textclassifier/Android.bp new file mode 100644 index 00000000000..49952dc1d00 --- /dev/null +++ b/apct-tests/perftests/textclassifier/Android.bp @@ -0,0 +1,25 @@ +// Copyright (C) 2019 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. + +android_test { + name: "TextClassifierPerfTests", + srcs: ["src/**/*.java"], + static_libs: [ + "androidx.test.rules", + "androidx.annotation_annotation", + "apct-perftests-utils", + ], + platform_apis: true, + test_suites: ["device-tests"], +} diff --git a/apct-tests/perftests/textclassifier/AndroidManifest.xml b/apct-tests/perftests/textclassifier/AndroidManifest.xml new file mode 100644 index 00000000000..7cf487f2eb7 --- /dev/null +++ b/apct-tests/perftests/textclassifier/AndroidManifest.xml @@ -0,0 +1,25 @@ + + + + + + + + + + diff --git a/apct-tests/perftests/textclassifier/AndroidTest.xml b/apct-tests/perftests/textclassifier/AndroidTest.xml new file mode 100644 index 00000000000..29f9f94bcac --- /dev/null +++ b/apct-tests/perftests/textclassifier/AndroidTest.xml @@ -0,0 +1,28 @@ + + + + diff --git a/apct-tests/perftests/textclassifier/run.sh b/apct-tests/perftests/textclassifier/run.sh new file mode 100755 index 00000000000..c6782d1a72f --- /dev/null +++ b/apct-tests/perftests/textclassifier/run.sh @@ -0,0 +1,4 @@ +set -e +make TextClassifierPerfTests +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 diff --git a/apct-tests/perftests/textclassifier/src/android/view/textclassifier/TextClassifierPerfTest.java b/apct-tests/perftests/textclassifier/src/android/view/textclassifier/TextClassifierPerfTest.java new file mode 100644 index 00000000000..14a121d60c2 --- /dev/null +++ b/apct-tests/perftests/textclassifier/src/android/view/textclassifier/TextClassifierPerfTest.java @@ -0,0 +1,110 @@ +/* + * 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 androidx.test.InstrumentationRegistry; +import androidx.test.filters.LargeTest; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Random; + +@RunWith(Parameterized.class) +@LargeTest +public class TextClassifierPerfTest { + /** Request contains meaning text, rather than garbled text. */ + private static final int ACTUAL_REQUEST = 0; + private static final String RANDOM_CHAR_SET = "abcdefghijklmnopqrstuvwxyz0123456789"; + + @Rule + public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); + + @Parameterized.Parameters(name = "size{0}") + public static Collection data() { + return Arrays.asList(new Object[][]{{ACTUAL_REQUEST}, {10}, {100}, {1000}}); + } + + private TextClassifier mTextClassifier; + private final int mSize; + + public TextClassifierPerfTest(int size) { + mSize = size; + } + + @Before + public void setUp() { + Context context = InstrumentationRegistry.getTargetContext(); + TextClassificationManager textClassificationManager = + context.getSystemService(TextClassificationManager.class); + mTextClassifier = textClassificationManager.getTextClassifier(TextClassifier.LOCAL); + } + + @Test + public void testSuggestConversationActions() { + String text = mSize == ACTUAL_REQUEST ? "Where are you?" : generateRandomString(mSize); + ConversationActions.Request request = createConversationActionsRequest(text); + BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + while (state.keepRunning()) { + mTextClassifier.suggestConversationActions(request); + } + } + + @Test + public void testDetectLanguage() { + String text = mSize == ACTUAL_REQUEST + ? "これは日本語のテキストです" : generateRandomString(mSize); + TextLanguage.Request request = createTextLanguageRequest(text); + BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + while (state.keepRunning()) { + mTextClassifier.detectLanguage(request); + } + } + + private static ConversationActions.Request createConversationActionsRequest(CharSequence text) { + ConversationActions.Message message = + new ConversationActions.Message.Builder( + ConversationActions.Message.PERSON_USER_OTHERS) + .setText(text) + .build(); + return new ConversationActions.Request.Builder(Collections.singletonList(message)) + .build(); + } + + private static TextLanguage.Request createTextLanguageRequest(CharSequence text) { + return new TextLanguage.Request.Builder(text).build(); + } + + private static String generateRandomString(int length) { + Random random = new Random(); + StringBuilder stringBuilder = new StringBuilder(length); + for (int i = 0; i < length; i++) { + int index = random.nextInt(RANDOM_CHAR_SET.length()); + stringBuilder.append(RANDOM_CHAR_SET.charAt(index)); + } + return stringBuilder.toString(); + } +} -- cgit v1.2.3