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
This commit is contained in:
Arthur Eubanks
2018-01-09 15:48:53 -08:00
parent c04c265dd5
commit 433770fa0b
3 changed files with 132 additions and 3 deletions

View File

@@ -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" />

View File

@@ -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;
}
}

View File

@@ -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;
});
}
}