Loading apct-tests/perftests/core/Android.bp +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", Loading @@ -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", } apct-tests/perftests/core/src/android/graphics/perftests/TypefaceCreatePerfTest.java +24 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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(); Loading @@ -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; Loading Loading
apct-tests/perftests/core/Android.bp +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", Loading @@ -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", }
apct-tests/perftests/core/src/android/graphics/perftests/TypefaceCreatePerfTest.java +24 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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(); Loading @@ -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; Loading