Alex Light | 9dcc457 | 2014-08-14 14:16:26 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | public class Main { |
| 18 | public static void main(String[] args) { |
Mathieu Chartier | 031768a | 2015-08-27 10:25:02 -0700 | [diff] [blame] | 19 | System.loadLibrary(args[0]); |
| 20 | |
Alex Light | 22cbec4 | 2015-09-18 17:09:43 -0700 | [diff] [blame] | 21 | // With a relocationDelta of 0, the runtime has no way to determine if the oat file in |
| 22 | // ANDROID_DATA has been relocated, since a non-relocated oat file always has a 0 delta. |
| 23 | // Hitting this condition should be rare and ideally we would prevent it from happening but |
| 24 | // there is no way to do so without major changes to the run-test framework. |
Igor Murashkin | 96e8393 | 2014-10-29 19:45:42 -0700 | [diff] [blame] | 25 | boolean executable_correct = (isPic() ? |
Alex Light | 22cbec4 | 2015-09-18 17:09:43 -0700 | [diff] [blame] | 26 | hasExecutableOat() == true : |
| 27 | hasExecutableOat() == (isDex2OatEnabled() || isRelocationDeltaZero())); |
Igor Murashkin | 96e8393 | 2014-10-29 19:45:42 -0700 | [diff] [blame] | 28 | |
Alex Light | 9dcc457 | 2014-08-14 14:16:26 -0700 | [diff] [blame] | 29 | System.out.println( |
| 30 | "dex2oat & patchoat are " + ((isDex2OatEnabled()) ? "enabled" : "disabled") + |
Andreas Gampe | 0b15f67 | 2015-09-30 17:25:15 -0700 | [diff] [blame] | 31 | ", has oat is " + hasOatFile() + ", has executable oat is " + ( |
Igor Murashkin | 96e8393 | 2014-10-29 19:45:42 -0700 | [diff] [blame] | 32 | executable_correct ? "expected" : "not expected") + "."); |
Alex Light | 9dcc457 | 2014-08-14 14:16:26 -0700 | [diff] [blame] | 33 | |
Andreas Gampe | 0b15f67 | 2015-09-30 17:25:15 -0700 | [diff] [blame] | 34 | if (!hasOatFile() && isDex2OatEnabled()) { |
Alex Light | 9dcc457 | 2014-08-14 14:16:26 -0700 | [diff] [blame] | 35 | throw new Error("Application with dex2oat enabled runs without an oat file"); |
| 36 | } |
| 37 | |
| 38 | System.out.println(functionCall()); |
| 39 | } |
| 40 | |
| 41 | public static String functionCall() { |
| 42 | String arr[] = {"This", "is", "a", "function", "call"}; |
| 43 | String ret = ""; |
| 44 | for (int i = 0; i < arr.length; i++) { |
| 45 | ret = ret + arr[i] + " "; |
| 46 | } |
| 47 | return ret.substring(0, ret.length() - 1); |
| 48 | } |
| 49 | |
Alex Light | 9dcc457 | 2014-08-14 14:16:26 -0700 | [diff] [blame] | 50 | private native static boolean isDex2OatEnabled(); |
| 51 | |
Igor Murashkin | 96e8393 | 2014-10-29 19:45:42 -0700 | [diff] [blame] | 52 | private native static boolean isPic(); |
| 53 | |
Andreas Gampe | 0b15f67 | 2015-09-30 17:25:15 -0700 | [diff] [blame] | 54 | private native static boolean hasOatFile(); |
Alex Light | 9dcc457 | 2014-08-14 14:16:26 -0700 | [diff] [blame] | 55 | |
| 56 | private native static boolean hasExecutableOat(); |
Alex Light | 22cbec4 | 2015-09-18 17:09:43 -0700 | [diff] [blame] | 57 | |
| 58 | private native static boolean isRelocationDeltaZero(); |
Alex Light | 9dcc457 | 2014-08-14 14:16:26 -0700 | [diff] [blame] | 59 | } |