blob: 39ee0ce9f9517efd7c283610f88c07c67373f7d4 [file] [log] [blame]
Alexandre Ramesca0e3a02016-02-03 10:54:07 +00001/*
Roland Levillainfb7fc7b2016-02-24 15:41:20 +00002 * 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 Ramesca0e3a02016-02-03 10:54:07 +000016
Igor Murashkinf8c81922017-06-27 14:23:27 -070017import java.lang.reflect.Method;
18
Alexandre Ramesca0e3a02016-02-03 10:54:07 +000019public class Main {
20
Alexandre Ramesca0e3a02016-02-03 10:54:07 +000021 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 Murashkinf8c81922017-06-27 14:23:27 -070033 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 Murashkinf8c81922017-06-27 14:23:27 -070040 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 Kenez87547c92018-06-07 15:39:59 +020050 public static void main(String[] args) throws Exception {
51 assertIntEquals(~0xff, $noinline$runSmaliTest("$opt$noinline$andToOrV2", int.class, 0xf, 0xff));
Igor Murashkinf8c81922017-06-27 14:23:27 -070052 assertIntEquals(~0xff, $noinline$runSmaliTest("$opt$noinline$andToOr", int.class, 0xf, 0xff));
Tamas Kenez87547c92018-06-07 15:39:59 +020053 assertEquals(true, $noinline$runSmaliTest("$opt$noinline$booleanAndToOrV2", boolean.class, false, false));
Igor Murashkinf8c81922017-06-27 14:23:27 -070054 assertEquals(true, $noinline$runSmaliTest("$opt$noinline$booleanAndToOr", boolean.class, false, false));
Tamas Kenez87547c92018-06-07 15:39:59 +020055 assertLongEquals(~0xf, $noinline$runSmaliTest("$opt$noinline$orToAndV2", long.class, 0xfL, 0xffL));
Igor Murashkinf8c81922017-06-27 14:23:27 -070056 assertLongEquals(~0xf, $noinline$runSmaliTest("$opt$noinline$orToAnd", long.class, 0xfL, 0xffL));
Tamas Kenez87547c92018-06-07 15:39:59 +020057 assertEquals(false, $noinline$runSmaliTest("$opt$noinline$booleanOrToAndV2", boolean.class, true, true));
Igor Murashkinf8c81922017-06-27 14:23:27 -070058 assertEquals(false, $noinline$runSmaliTest("$opt$noinline$booleanOrToAnd", boolean.class, true, true));
Tamas Kenez87547c92018-06-07 15:39:59 +020059 assertIntEquals(-1, $noinline$runSmaliTest("$opt$noinline$regressInputsAwayV2", int.class, 0xf, 0xff));
Igor Murashkinf8c81922017-06-27 14:23:27 -070060 assertIntEquals(-1, $noinline$runSmaliTest("$opt$noinline$regressInputsAway", int.class, 0xf, 0xff));
Tamas Kenez87547c92018-06-07 15:39:59 +020061 assertIntEquals(0xf0, $noinline$runSmaliTest("$opt$noinline$notXorToXorV2", int.class, 0xf, 0xff));
Igor Murashkinf8c81922017-06-27 14:23:27 -070062 assertIntEquals(0xf0, $noinline$runSmaliTest("$opt$noinline$notXorToXor", int.class, 0xf, 0xff));
Tamas Kenez87547c92018-06-07 15:39:59 +020063 assertEquals(true, $noinline$runSmaliTest("$opt$noinline$booleanNotXorToXorV2", boolean.class, true, false));
Igor Murashkinf8c81922017-06-27 14:23:27 -070064 assertEquals(true, $noinline$runSmaliTest("$opt$noinline$booleanNotXorToXor", boolean.class, true, false));
Tamas Kenez87547c92018-06-07 15:39:59 +020065 assertIntEquals(~0xff, $noinline$runSmaliTest("$opt$noinline$notMultipleUsesV2", int.class, 0xf, 0xff));
Igor Murashkinf8c81922017-06-27 14:23:27 -070066 assertIntEquals(~0xff, $noinline$runSmaliTest("$opt$noinline$notMultipleUses", int.class, 0xf, 0xff));
Alexandre Ramesca0e3a02016-02-03 10:54:07 +000067 }
68}