1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2016 The Android Open Source Project 3*795d594fSAndroid Build Coastguard Worker * 4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*795d594fSAndroid Build Coastguard Worker * 8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*795d594fSAndroid Build Coastguard Worker * 10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*795d594fSAndroid Build Coastguard Worker * limitations under the License. 15*795d594fSAndroid Build Coastguard Worker */ 16*795d594fSAndroid Build Coastguard Worker 17*795d594fSAndroid Build Coastguard Worker import java.lang.reflect.Method; 18*795d594fSAndroid Build Coastguard Worker 19*795d594fSAndroid Build Coastguard Worker public class Main { 20*795d594fSAndroid Build Coastguard Worker assertIntEquals(int expected, int result)21*795d594fSAndroid Build Coastguard Worker public static void assertIntEquals(int expected, int result) { 22*795d594fSAndroid Build Coastguard Worker if (expected != result) { 23*795d594fSAndroid Build Coastguard Worker throw new Error("Expected: " + expected + ", found: " + result); 24*795d594fSAndroid Build Coastguard Worker } 25*795d594fSAndroid Build Coastguard Worker } 26*795d594fSAndroid Build Coastguard Worker assertLongEquals(long expected, long result)27*795d594fSAndroid Build Coastguard Worker public static void assertLongEquals(long expected, long result) { 28*795d594fSAndroid Build Coastguard Worker if (expected != result) { 29*795d594fSAndroid Build Coastguard Worker throw new Error("Expected: " + expected + ", found: " + result); 30*795d594fSAndroid Build Coastguard Worker } 31*795d594fSAndroid Build Coastguard Worker } 32*795d594fSAndroid Build Coastguard Worker assertEquals(boolean expected, boolean result)33*795d594fSAndroid Build Coastguard Worker public static void assertEquals(boolean expected, boolean result) { 34*795d594fSAndroid Build Coastguard Worker if (expected != result) { 35*795d594fSAndroid Build Coastguard Worker throw new Error("Expected: " + expected + ", found: " + result); 36*795d594fSAndroid Build Coastguard Worker } 37*795d594fSAndroid Build Coastguard Worker } 38*795d594fSAndroid Build Coastguard Worker $noinline$runSmaliTest(String name, Class<T> klass, T input1, T input2)39*795d594fSAndroid Build Coastguard Worker public static <T> T $noinline$runSmaliTest(String name, Class<T> klass, T input1, T input2) { 40*795d594fSAndroid Build Coastguard Worker Class<T> inputKlass = (Class<T>)input1.getClass(); 41*795d594fSAndroid Build Coastguard Worker try { 42*795d594fSAndroid Build Coastguard Worker Class<?> c = Class.forName("SmaliTests"); 43*795d594fSAndroid Build Coastguard Worker Method m = c.getMethod(name, klass, klass); 44*795d594fSAndroid Build Coastguard Worker return inputKlass.cast(m.invoke(null, input1, input2)); 45*795d594fSAndroid Build Coastguard Worker } catch (Exception ex) { 46*795d594fSAndroid Build Coastguard Worker throw new Error(ex); 47*795d594fSAndroid Build Coastguard Worker } 48*795d594fSAndroid Build Coastguard Worker } 49*795d594fSAndroid Build Coastguard Worker main(String[] args)50*795d594fSAndroid Build Coastguard Worker public static void main(String[] args) throws Exception { 51*795d594fSAndroid Build Coastguard Worker assertIntEquals(~0xff, $noinline$runSmaliTest("$opt$noinline$andToOrV2", int.class, 0xf, 0xff)); 52*795d594fSAndroid Build Coastguard Worker assertIntEquals(~0xff, $noinline$runSmaliTest("$opt$noinline$andToOr", int.class, 0xf, 0xff)); 53*795d594fSAndroid Build Coastguard Worker assertEquals(true, $noinline$runSmaliTest("$opt$noinline$booleanAndToOrV2", boolean.class, false, false)); 54*795d594fSAndroid Build Coastguard Worker assertEquals(true, $noinline$runSmaliTest("$opt$noinline$booleanAndToOr", boolean.class, false, false)); 55*795d594fSAndroid Build Coastguard Worker assertLongEquals(~0xf, $noinline$runSmaliTest("$opt$noinline$orToAndV2", long.class, 0xfL, 0xffL)); 56*795d594fSAndroid Build Coastguard Worker assertLongEquals(~0xf, $noinline$runSmaliTest("$opt$noinline$orToAnd", long.class, 0xfL, 0xffL)); 57*795d594fSAndroid Build Coastguard Worker assertEquals(false, $noinline$runSmaliTest("$opt$noinline$booleanOrToAndV2", boolean.class, true, true)); 58*795d594fSAndroid Build Coastguard Worker assertEquals(false, $noinline$runSmaliTest("$opt$noinline$booleanOrToAnd", boolean.class, true, true)); 59*795d594fSAndroid Build Coastguard Worker assertIntEquals(-1, $noinline$runSmaliTest("$opt$noinline$regressInputsAwayV2", int.class, 0xf, 0xff)); 60*795d594fSAndroid Build Coastguard Worker assertIntEquals(-1, $noinline$runSmaliTest("$opt$noinline$regressInputsAway", int.class, 0xf, 0xff)); 61*795d594fSAndroid Build Coastguard Worker assertIntEquals(0xf0, $noinline$runSmaliTest("$opt$noinline$notXorToXorV2", int.class, 0xf, 0xff)); 62*795d594fSAndroid Build Coastguard Worker assertIntEquals(0xf0, $noinline$runSmaliTest("$opt$noinline$notXorToXor", int.class, 0xf, 0xff)); 63*795d594fSAndroid Build Coastguard Worker assertEquals(true, $noinline$runSmaliTest("$opt$noinline$booleanNotXorToXorV2", boolean.class, true, false)); 64*795d594fSAndroid Build Coastguard Worker assertEquals(true, $noinline$runSmaliTest("$opt$noinline$booleanNotXorToXor", boolean.class, true, false)); 65*795d594fSAndroid Build Coastguard Worker assertIntEquals(~0xff, $noinline$runSmaliTest("$opt$noinline$notMultipleUsesV2", int.class, 0xf, 0xff)); 66*795d594fSAndroid Build Coastguard Worker assertIntEquals(~0xff, $noinline$runSmaliTest("$opt$noinline$notMultipleUses", int.class, 0xf, 0xff)); 67*795d594fSAndroid Build Coastguard Worker } 68*795d594fSAndroid Build Coastguard Worker } 69