Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 433770fa authored by Arthur Eubanks's avatar Arthur Eubanks
Browse files

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
parent c04c265d
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -17,6 +17,10 @@
        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">
+55 −0
Original line number Diff line number Diff line
/*
 * 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;
    }
}
+70 −0
Original line number Diff line number Diff line
/*
 * 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;
        });
    }
}