diff options
Diffstat (limited to 'test/846-multidex-data-image')
| -rw-r--r-- | test/846-multidex-data-image/expected-stderr.txt | 0 | ||||
| -rw-r--r-- | test/846-multidex-data-image/expected-stdout.txt | 2 | ||||
| -rw-r--r-- | test/846-multidex-data-image/info.txt | 2 | ||||
| -rw-r--r-- | test/846-multidex-data-image/run.py | 23 | ||||
| -rw-r--r-- | test/846-multidex-data-image/src-art/Main.java | 98 | ||||
| -rw-r--r-- | test/846-multidex-data-image/src-multidex/Foo.java | 18 |
6 files changed, 143 insertions, 0 deletions
diff --git a/test/846-multidex-data-image/expected-stderr.txt b/test/846-multidex-data-image/expected-stderr.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/846-multidex-data-image/expected-stderr.txt diff --git a/test/846-multidex-data-image/expected-stdout.txt b/test/846-multidex-data-image/expected-stdout.txt new file mode 100644 index 0000000000..8db7853696 --- /dev/null +++ b/test/846-multidex-data-image/expected-stdout.txt @@ -0,0 +1,2 @@ +JNI_OnLoad called +JNI_OnLoad called diff --git a/test/846-multidex-data-image/info.txt b/test/846-multidex-data-image/info.txt new file mode 100644 index 0000000000..3b83d2c460 --- /dev/null +++ b/test/846-multidex-data-image/info.txt @@ -0,0 +1,2 @@ +Test the generation of app image at runtime, when the primary APK contains +multiple dex files. diff --git a/test/846-multidex-data-image/run.py b/test/846-multidex-data-image/run.py new file mode 100644 index 0000000000..3976af2b17 --- /dev/null +++ b/test/846-multidex-data-image/run.py @@ -0,0 +1,23 @@ +# Copyright (C) 2022 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. + +import sys + +# We run the tests by disabling compilation with app image. +# Run the test twice: one run for generating the image, a second run for using +# the image. +def run(ctx, args): + ctx.default_run(args, app_image=False) + # Pass another argument to let the test know it should now expect an image. + ctx.default_run(args, app_image=False, test_args=["--second-run"]) diff --git a/test/846-multidex-data-image/src-art/Main.java b/test/846-multidex-data-image/src-art/Main.java new file mode 100644 index 0000000000..aea92a46a7 --- /dev/null +++ b/test/846-multidex-data-image/src-art/Main.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2022 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. + */ + +import dalvik.system.DexFile; +import dalvik.system.VMRuntime; +import java.io.File; +import java.io.IOException; + +public class Main { + public static void main(String[] args) throws Exception { + System.loadLibrary(args[0]); + + // Register the dex file so that the runtime can pick up which + // dex file to compile for the image. + File file = null; + try { + file = createTempFile(); + String codePath = DEX_LOCATION + "/846-multidex-data-image.jar"; + VMRuntime.registerAppInfo( + "test.app", + file.getPath(), + file.getPath(), + new String[] {codePath}, + VMRuntime.CODE_PATH_TYPE_PRIMARY_APK); + } finally { + if (file != null) { + file.delete(); + } + } + + if (!hasOatFile() || !hasImage()) { + // We only generate an app image if there is at least a vdex file and a boot image. + return; + } + + if (args.length == 2 && "--second-run".equals(args[1])) { + DexFile.OptimizationInfo info = VMRuntime.getBaseApkOptimizationInfo(); + if (!info.isOptimized()) { + throw new Error("Expected image to be loaded"); + } + } + + VMRuntime runtime = VMRuntime.getRuntime(); + runtime.notifyStartupCompleted(); + + String filter = getCompilerFilter(Main.class); + if ("speed-profile".equals(filter) || "speed".equals(filter)) { + // We only generate an app image for filters that don't compile. + return; + } + + String instructionSet = VMRuntime.getCurrentInstructionSet(); + // Wait for the file to be generated. + File image = new File(DEX_LOCATION + "/" + instructionSet + "/846-multidex-data-image.art"); + while (!image.exists()) { + Thread.yield(); + } + + // Test that we can load a class from the other dex file. We do this after creating the image to + // check that the runtime can deal with a missing dex cache. + Class.forName("Foo"); + } + + private static native boolean hasOatFile(); + private static native boolean hasImage(); + private static native String getCompilerFilter(Class<?> cls); + + private static final String TEMP_FILE_NAME_PREFIX = "temp"; + private static final String TEMP_FILE_NAME_SUFFIX = "-file"; + private static final String DEX_LOCATION = System.getenv("DEX_LOCATION"); + + private static File createTempFile() throws Exception { + try { + return File.createTempFile(TEMP_FILE_NAME_PREFIX, TEMP_FILE_NAME_SUFFIX); + } catch (IOException e) { + System.setProperty("java.io.tmpdir", "/data/local/tmp"); + try { + return File.createTempFile(TEMP_FILE_NAME_PREFIX, TEMP_FILE_NAME_SUFFIX); + } catch (IOException e2) { + System.setProperty("java.io.tmpdir", "/sdcard"); + return File.createTempFile(TEMP_FILE_NAME_PREFIX, TEMP_FILE_NAME_SUFFIX); + } + } + } +} diff --git a/test/846-multidex-data-image/src-multidex/Foo.java b/test/846-multidex-data-image/src-multidex/Foo.java new file mode 100644 index 0000000000..4e36e88e9a --- /dev/null +++ b/test/846-multidex-data-image/src-multidex/Foo.java @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2022 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. + */ + +public class Foo { +} |