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

Commit 6320e514 authored by Winson Chiu's avatar Winson Chiu Committed by Android (Google) Code Review
Browse files

Merge "Include fonts as non asset file for CorePerfTests"

parents e544c0f0 6db9cdea
Loading
Loading
Loading
Loading
+18 −5
Original line number Diff line number Diff line
//
// Copyright (C) 2020 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: "CorePerfTests",

@@ -23,17 +39,14 @@ android_test {

    libs: ["android.test.base"],

    java_resources: [ ":GoogleFontDancingScript", ],

    data: [":perfetto_artifacts"],

    platform_apis: true,

    jni_libs: ["libperftestscore_jni"],

    // Use google-fonts/dancing-script for the performance metrics
    // ANDROIDMK TRANSLATION ERROR: Only $(LOCAL_PATH)/.. values are allowed
    // LOCAL_ASSET_DIR := $(TOP)/external/google-fonts/dancing-script

    test_suites: ["device-tests"],
    certificate: "platform",

}
+24 −2
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import androidx.test.InstrumentationRegistry;
import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.internal.util.Preconditions;
import com.android.perftests.core.R;

import org.junit.Rule;
@@ -73,10 +74,31 @@ public class TypefaceCreatePerfTest {
        final AssetManager am = context.getAssets();

        while (state.keepRunning()) {
            Typeface face = Typeface.createFromAsset(am, TEST_FONT_NAME);
            Typeface face = createFromNonAsset(am, TEST_FONT_NAME);
        }
    }

    /**
     * {@link AssetManager#openNonAsset(String)} variant of
     * {@link Typeface#createFromAsset(AssetManager, String)}.
     */
    private static Typeface createFromNonAsset(AssetManager mgr, String path) {
        Preconditions.checkNotNull(path); // for backward compatibility
        Preconditions.checkNotNull(mgr);

        Typeface typeface = new Typeface.Builder(mgr, path).build();
        if (typeface != null) return typeface;
        // check if the file exists, and throw an exception for backward compatibility
        //noinspection EmptyTryBlock
        try (InputStream inputStream = mgr.openNonAsset(path)) {
            // Purposely empty
        } catch (IOException e) {
            throw new RuntimeException("Font asset not found " + path);
        }

        return Typeface.DEFAULT;
    }

    @Test
    public void testCreate_fromFile() {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
@@ -90,7 +112,7 @@ public class TypefaceCreatePerfTest {
            throw new RuntimeException(e);
        }

        try (InputStream in = am.open(TEST_FONT_NAME);
        try (InputStream in = am.openNonAsset(TEST_FONT_NAME);
                OutputStream out = new FileOutputStream(outFile)) {
            byte[] buf = new byte[1024];
            int n = 0;