diff options
author | Arthur Eubanks <aeubanks@google.com> | 2018-01-09 15:48:53 -0800 |
---|---|---|
committer | Arthur Eubanks <aeubanks@google.com> | 2018-02-02 08:42:21 -0800 |
commit | 433770fa0bacc897b2b6f00771a3f46f0889cc2e (patch) | |
tree | c2e99528817697f9bc69aedd3acaf6be62a17300 | |
parent | c04c265dd57e0fe2c880e529cc5cfc8164180009 (diff) |
Add ContentProvider perf tests
Add a stub ContentProvider in ActivityManagerPerfTestsTestApp.
Add two tests for
Context.getContentResolver().acquireContentProviderClient(PKG_NAME),
one when target package is running, one when it isn't.
Test: m ActivityManagerPerfTestsTestApp ActivityManagerPerfTests
Test: adb install \
$OUT/data/app/ActivityManagerPerfTestsTestApp/ActivityManagerPerfTestsTestApp.apk
Test: adb install \
$OUT/data/app/ActivityManagerPerfTests/ActivityManagerPerfTests.apk
Test: adb shell am instrument -w -e class \
com.android.frameworks.perftests.am.tests.ContentProviderPerfTest \
com.android.frameworks.perftests.amtests/android.support.test.runner.AndroidJUnitRunner
BUG: 67460485
Change-Id: Ia979832436a0d3923f6569bc52d22f17bb612a0e
3 files changed, 132 insertions, 3 deletions
diff --git a/tests/ActivityManagerPerfTests/test-app/AndroidManifest.xml b/tests/ActivityManagerPerfTests/test-app/AndroidManifest.xml index 71451101ac59..021e3861d882 100644 --- a/tests/ActivityManagerPerfTests/test-app/AndroidManifest.xml +++ b/tests/ActivityManagerPerfTests/test-app/AndroidManifest.xml @@ -14,12 +14,16 @@ limitations under the License. --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.android.frameworks.perftests.amteststestapp"> + package="com.android.frameworks.perftests.amteststestapp"> <application android:name=".TestApplication"> <activity android:name=".TestActivity" android:exported="true"/> + <provider + android:authorities="com.android.frameworks.perftests.amteststestapp" + android:name=".TestContentProvider" + android:exported="true" /> <receiver - android:name=".TestBroadcastReceiver" - android:exported="true"> + android:name=".TestBroadcastReceiver" + android:exported="true"> <intent-filter> <action android:name="com.android.frameworks.perftests.ACTION_BROADCAST_MANIFEST_RECEIVE" /> <category android:name="android.intent.category.DEFAULT" /> diff --git a/tests/ActivityManagerPerfTests/test-app/src/com/android/frameworks/perftests/amteststestapp/TestContentProvider.java b/tests/ActivityManagerPerfTests/test-app/src/com/android/frameworks/perftests/amteststestapp/TestContentProvider.java new file mode 100644 index 000000000000..0940578e4b28 --- /dev/null +++ b/tests/ActivityManagerPerfTests/test-app/src/com/android/frameworks/perftests/amteststestapp/TestContentProvider.java @@ -0,0 +1,55 @@ +/* + * 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 com.android.frameworks.perftests.amteststestapp; + +import android.content.ContentProvider; +import android.content.ContentValues; +import android.database.Cursor; +import android.net.Uri; + +public class TestContentProvider extends ContentProvider { + @Override + public Uri insert(Uri uri, ContentValues values) { + return null; + } + + @Override + public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, + String sortOrder) { + return null; + } + + @Override + public String getType(Uri uri) { + return null; + } + + @Override + public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { + return 0; + } + + @Override + public boolean onCreate() { + return false; + } + + @Override + public int delete(Uri uri, String selection, String[] selectionArgs) { + return 0; + } +} diff --git a/tests/ActivityManagerPerfTests/tests/src/com/android/frameworks/perftests/am/tests/ContentProviderPerfTest.java b/tests/ActivityManagerPerfTests/tests/src/com/android/frameworks/perftests/am/tests/ContentProviderPerfTest.java new file mode 100644 index 000000000000..3bf56ce8b085 --- /dev/null +++ b/tests/ActivityManagerPerfTests/tests/src/com/android/frameworks/perftests/am/tests/ContentProviderPerfTest.java @@ -0,0 +1,70 @@ +/* + * 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 com.android.frameworks.perftests.am.tests; + +import android.content.ContentProviderClient; +import android.support.test.filters.LargeTest; +import android.support.test.runner.AndroidJUnit4; + +import com.android.frameworks.perftests.am.util.TargetPackageUtils; + +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidJUnit4.class) +@LargeTest +public class ContentProviderPerfTest extends BasePerfTest { + /** + * Benchmark time to call ContentResolver.acquireContentProviderClient() when target package is + * running. + */ + @Test + public void contentProviderRunning() { + runPerfFunction(() -> { + startTargetPackage(); + + long startTimeNs = System.nanoTime(); + final ContentProviderClient contentProviderClient = + mContext.getContentResolver() + .acquireContentProviderClient(TargetPackageUtils.PACKAGE_NAME); + final long endTimeNs = System.nanoTime(); + + contentProviderClient.close(); + + return endTimeNs - startTimeNs; + }); + } + + /** + * Benchmark time to call ContentResolver.acquireContentProviderClient() when target package is + * not running. + */ + @Test + public void contentProviderNotRunning() { + runPerfFunction(() -> { + final long startTimeNs = System.nanoTime(); + final ContentProviderClient contentProviderClient = + mContext.getContentResolver().acquireContentProviderClient( + TargetPackageUtils.PACKAGE_NAME); + final long endTimeNs = System.nanoTime(); + + contentProviderClient.close(); + + return endTimeNs - startTimeNs; + }); + } +} |