blob: cc19107590eed468dd075d11c8ebab473d327e04 [file] [log] [blame]
Alex Light64ad14d2014-08-19 14:23:13 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Brian Carlstrombe6fa5e2014-12-09 20:15:42 -080017import java.lang.reflect.InvocationTargetException;
Brian Carlstrom31d8f522014-09-29 11:22:54 -070018import java.lang.reflect.Method;
19
Alex Light64ad14d2014-08-19 14:23:13 -070020public class Main {
Brian Carlstrom31d8f522014-09-29 11:22:54 -070021 public static void main(String[] args) throws Exception {
Mathieu Chartier031768a2015-08-27 10:25:02 -070022 System.loadLibrary(args[0]);
Alex Light64ad14d2014-08-19 14:23:13 -070023 boolean hasImage = hasImage();
Brian Carlstrom31d8f522014-09-29 11:22:54 -070024 String instructionSet = VMRuntime.getCurrentInstructionSet();
25 boolean isBootClassPathOnDisk = VMRuntime.isBootClassPathOnDisk(instructionSet);
Alex Light64ad14d2014-08-19 14:23:13 -070026 System.out.println(
27 "Has image is " + hasImage + ", is image dex2oat enabled is "
Brian Carlstrom31d8f522014-09-29 11:22:54 -070028 + isImageDex2OatEnabled() + ", is BOOTCLASSPATH on disk is "
29 + isBootClassPathOnDisk + ".");
Alex Light64ad14d2014-08-19 14:23:13 -070030
31 if (hasImage && !isImageDex2OatEnabled()) {
32 throw new Error("Image with dex2oat disabled runs with an oat file");
33 } else if (!hasImage && isImageDex2OatEnabled()) {
34 throw new Error("Image with dex2oat enabled runs without an oat file");
35 }
Brian Carlstrom31d8f522014-09-29 11:22:54 -070036 if (hasImage && !isBootClassPathOnDisk) {
37 throw new Error("Image with dex2oat disabled runs with an image file");
38 } else if (!hasImage && isBootClassPathOnDisk) {
39 throw new Error("Image with dex2oat enabled runs without an image file");
40 }
Brian Carlstrombe6fa5e2014-12-09 20:15:42 -080041
42 testB18485243();
Alex Light64ad14d2014-08-19 14:23:13 -070043 }
44
Alex Light64ad14d2014-08-19 14:23:13 -070045 private native static boolean hasImage();
46
47 private native static boolean isImageDex2OatEnabled();
Brian Carlstrom31d8f522014-09-29 11:22:54 -070048
49 private static class VMRuntime {
50 private static final Method getCurrentInstructionSetMethod;
51 private static final Method isBootClassPathOnDiskMethod;
52 static {
53 try {
Andreas Gampe166aaee2016-07-18 08:27:23 -070054 Class<?> c = Class.forName("dalvik.system.VMRuntime");
Brian Carlstrom31d8f522014-09-29 11:22:54 -070055 getCurrentInstructionSetMethod = c.getDeclaredMethod("getCurrentInstructionSet");
56 isBootClassPathOnDiskMethod = c.getDeclaredMethod("isBootClassPathOnDisk",
57 String.class);
58 } catch (Exception e) {
59 throw new RuntimeException(e);
60 }
61 }
62
63 public static String getCurrentInstructionSet() throws Exception {
64 return (String) getCurrentInstructionSetMethod.invoke(null);
65 }
66 public static boolean isBootClassPathOnDisk(String instructionSet) throws Exception {
67 return (boolean) isBootClassPathOnDiskMethod.invoke(null, instructionSet);
68 }
69 }
Brian Carlstrombe6fa5e2014-12-09 20:15:42 -080070
71 private static void testB18485243() throws Exception {
72 Class<?> k = Class.forName("B18485243");
73 Object o = k.newInstance();
74 Method m = k.getDeclaredMethod("run");
75 try {
76 m.invoke(o);
77 } catch (InvocationTargetException e) {
78 Throwable actual = e.getTargetException();
79 if (!(actual instanceof IncompatibleClassChangeError)) {
80 throw new AssertionError("Expected IncompatibleClassChangeError", actual);
81 }
82 }
83 System.out.println("testB18485243 PASS");
84 }
Alex Light64ad14d2014-08-19 14:23:13 -070085}