Alexandre Rames | ca0e3a0 | 2016-02-03 10:54:07 +0000 | [diff] [blame] | 1 | /* |
Roland Levillain | fb7fc7b | 2016-02-24 15:41:20 +0000 | [diff] [blame] | 2 | * Copyright (C) 2016 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 | */ |
Alexandre Rames | ca0e3a0 | 2016-02-03 10:54:07 +0000 | [diff] [blame] | 16 | |
Igor Murashkin | f8c8192 | 2017-06-27 14:23:27 -0700 | [diff] [blame] | 17 | import java.lang.reflect.Method; |
| 18 | |
Alexandre Rames | ca0e3a0 | 2016-02-03 10:54:07 +0000 | [diff] [blame] | 19 | public class Main { |
| 20 | |
Alexandre Rames | ca0e3a0 | 2016-02-03 10:54:07 +0000 | [diff] [blame] | 21 | public static void assertIntEquals(int expected, int result) { |
| 22 | if (expected != result) { |
| 23 | throw new Error("Expected: " + expected + ", found: " + result); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | public static void assertLongEquals(long expected, long result) { |
| 28 | if (expected != result) { |
| 29 | throw new Error("Expected: " + expected + ", found: " + result); |
| 30 | } |
| 31 | } |
| 32 | |
Igor Murashkin | f8c8192 | 2017-06-27 14:23:27 -0700 | [diff] [blame] | 33 | public static void assertEquals(boolean expected, boolean result) { |
| 34 | if (expected != result) { |
| 35 | throw new Error("Expected: " + expected + ", found: " + result); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | public static <T> T $noinline$runSmaliTest(String name, Class<T> klass, T input1, T input2) { |
Igor Murashkin | f8c8192 | 2017-06-27 14:23:27 -0700 | [diff] [blame] | 40 | Class<T> inputKlass = (Class<T>)input1.getClass(); |
| 41 | try { |
| 42 | Class<?> c = Class.forName("SmaliTests"); |
| 43 | Method m = c.getMethod(name, klass, klass); |
| 44 | return inputKlass.cast(m.invoke(null, input1, input2)); |
| 45 | } catch (Exception ex) { |
| 46 | throw new Error(ex); |
| 47 | } |
| 48 | } |
| 49 | |
Tamas Kenez | 87547c9 | 2018-06-07 15:39:59 +0200 | [diff] [blame] | 50 | public static void main(String[] args) throws Exception { |
| 51 | assertIntEquals(~0xff, $noinline$runSmaliTest("$opt$noinline$andToOrV2", int.class, 0xf, 0xff)); |
Igor Murashkin | f8c8192 | 2017-06-27 14:23:27 -0700 | [diff] [blame] | 52 | assertIntEquals(~0xff, $noinline$runSmaliTest("$opt$noinline$andToOr", int.class, 0xf, 0xff)); |
Tamas Kenez | 87547c9 | 2018-06-07 15:39:59 +0200 | [diff] [blame] | 53 | assertEquals(true, $noinline$runSmaliTest("$opt$noinline$booleanAndToOrV2", boolean.class, false, false)); |
Igor Murashkin | f8c8192 | 2017-06-27 14:23:27 -0700 | [diff] [blame] | 54 | assertEquals(true, $noinline$runSmaliTest("$opt$noinline$booleanAndToOr", boolean.class, false, false)); |
Tamas Kenez | 87547c9 | 2018-06-07 15:39:59 +0200 | [diff] [blame] | 55 | assertLongEquals(~0xf, $noinline$runSmaliTest("$opt$noinline$orToAndV2", long.class, 0xfL, 0xffL)); |
Igor Murashkin | f8c8192 | 2017-06-27 14:23:27 -0700 | [diff] [blame] | 56 | assertLongEquals(~0xf, $noinline$runSmaliTest("$opt$noinline$orToAnd", long.class, 0xfL, 0xffL)); |
Tamas Kenez | 87547c9 | 2018-06-07 15:39:59 +0200 | [diff] [blame] | 57 | assertEquals(false, $noinline$runSmaliTest("$opt$noinline$booleanOrToAndV2", boolean.class, true, true)); |
Igor Murashkin | f8c8192 | 2017-06-27 14:23:27 -0700 | [diff] [blame] | 58 | assertEquals(false, $noinline$runSmaliTest("$opt$noinline$booleanOrToAnd", boolean.class, true, true)); |
Tamas Kenez | 87547c9 | 2018-06-07 15:39:59 +0200 | [diff] [blame] | 59 | assertIntEquals(-1, $noinline$runSmaliTest("$opt$noinline$regressInputsAwayV2", int.class, 0xf, 0xff)); |
Igor Murashkin | f8c8192 | 2017-06-27 14:23:27 -0700 | [diff] [blame] | 60 | assertIntEquals(-1, $noinline$runSmaliTest("$opt$noinline$regressInputsAway", int.class, 0xf, 0xff)); |
Tamas Kenez | 87547c9 | 2018-06-07 15:39:59 +0200 | [diff] [blame] | 61 | assertIntEquals(0xf0, $noinline$runSmaliTest("$opt$noinline$notXorToXorV2", int.class, 0xf, 0xff)); |
Igor Murashkin | f8c8192 | 2017-06-27 14:23:27 -0700 | [diff] [blame] | 62 | assertIntEquals(0xf0, $noinline$runSmaliTest("$opt$noinline$notXorToXor", int.class, 0xf, 0xff)); |
Tamas Kenez | 87547c9 | 2018-06-07 15:39:59 +0200 | [diff] [blame] | 63 | assertEquals(true, $noinline$runSmaliTest("$opt$noinline$booleanNotXorToXorV2", boolean.class, true, false)); |
Igor Murashkin | f8c8192 | 2017-06-27 14:23:27 -0700 | [diff] [blame] | 64 | assertEquals(true, $noinline$runSmaliTest("$opt$noinline$booleanNotXorToXor", boolean.class, true, false)); |
Tamas Kenez | 87547c9 | 2018-06-07 15:39:59 +0200 | [diff] [blame] | 65 | assertIntEquals(~0xff, $noinline$runSmaliTest("$opt$noinline$notMultipleUsesV2", int.class, 0xf, 0xff)); |
Igor Murashkin | f8c8192 | 2017-06-27 14:23:27 -0700 | [diff] [blame] | 66 | assertIntEquals(~0xff, $noinline$runSmaliTest("$opt$noinline$notMultipleUses", int.class, 0xf, 0xff)); |
Alexandre Rames | ca0e3a0 | 2016-02-03 10:54:07 +0000 | [diff] [blame] | 67 | } |
| 68 | } |