Include fonts as non asset file for CorePerfTests
Android.bp migration broke this as the external folder should no longer be referenced directly. See b/169071405 for request for assets_dir filegroup support to avoid openNonAsset. Bug: 168845570 Test: atest android.graphics.perftests.TypefaceCreatePerfTest Change-Id: If1ee2cadbff02ac85c60dea49de50da2e98c1b39
This commit is contained in:
@@ -1,3 +1,19 @@
|
||||
//
|
||||
// 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",
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user