1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2014 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.InvocationTargetException; 18*795d594fSAndroid Build Coastguard Worker import java.lang.reflect.Method; 19*795d594fSAndroid Build Coastguard Worker import java.lang.reflect.Modifier; 20*795d594fSAndroid Build Coastguard Worker import java.util.LinkedList; 21*795d594fSAndroid Build Coastguard Worker import java.util.List; 22*795d594fSAndroid Build Coastguard Worker 23*795d594fSAndroid Build Coastguard Worker /** 24*795d594fSAndroid Build Coastguard Worker * Smali exercise. 25*795d594fSAndroid Build Coastguard Worker */ 26*795d594fSAndroid Build Coastguard Worker public class Main { 27*795d594fSAndroid Build Coastguard Worker 28*795d594fSAndroid Build Coastguard Worker private static class TestCase { TestCase(String testName, String testClass, String testMethodName, Object[] values, Throwable expectedException, Object expectedReturn, boolean checkCompiled)29*795d594fSAndroid Build Coastguard Worker public TestCase(String testName, String testClass, String testMethodName, Object[] values, 30*795d594fSAndroid Build Coastguard Worker Throwable expectedException, Object expectedReturn, 31*795d594fSAndroid Build Coastguard Worker boolean checkCompiled) { 32*795d594fSAndroid Build Coastguard Worker this.testName = testName; 33*795d594fSAndroid Build Coastguard Worker this.testClass = testClass; 34*795d594fSAndroid Build Coastguard Worker this.testMethodName = testMethodName; 35*795d594fSAndroid Build Coastguard Worker this.values = values; 36*795d594fSAndroid Build Coastguard Worker this.expectedException = expectedException; 37*795d594fSAndroid Build Coastguard Worker this.expectedReturn = expectedReturn; 38*795d594fSAndroid Build Coastguard Worker this.checkCompiled = checkCompiled; 39*795d594fSAndroid Build Coastguard Worker } 40*795d594fSAndroid Build Coastguard Worker TestCase(String testName, String testClass, String testMethodName, Object[] values, Throwable expectedException, Object expectedReturn)41*795d594fSAndroid Build Coastguard Worker public TestCase(String testName, String testClass, String testMethodName, Object[] values, 42*795d594fSAndroid Build Coastguard Worker Throwable expectedException, Object expectedReturn) { 43*795d594fSAndroid Build Coastguard Worker this(testName, testClass, testMethodName, values, expectedException, 44*795d594fSAndroid Build Coastguard Worker expectedReturn, false); 45*795d594fSAndroid Build Coastguard Worker } 46*795d594fSAndroid Build Coastguard Worker 47*795d594fSAndroid Build Coastguard Worker String testName; 48*795d594fSAndroid Build Coastguard Worker String testClass; 49*795d594fSAndroid Build Coastguard Worker String testMethodName; 50*795d594fSAndroid Build Coastguard Worker Object[] values; 51*795d594fSAndroid Build Coastguard Worker Throwable expectedException; 52*795d594fSAndroid Build Coastguard Worker Object expectedReturn; 53*795d594fSAndroid Build Coastguard Worker boolean checkCompiled; 54*795d594fSAndroid Build Coastguard Worker } 55*795d594fSAndroid Build Coastguard Worker 56*795d594fSAndroid Build Coastguard Worker private List<TestCase> testCases; 57*795d594fSAndroid Build Coastguard Worker Main()58*795d594fSAndroid Build Coastguard Worker public Main() { 59*795d594fSAndroid Build Coastguard Worker // Create the test cases. 60*795d594fSAndroid Build Coastguard Worker testCases = new LinkedList<TestCase>(); 61*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("PackedSwitch", "PackedSwitch", "packedSwitch", 62*795d594fSAndroid Build Coastguard Worker new Object[]{123}, null, 123)); 63*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("PackedSwitch key INT_MAX", "PackedSwitch", 64*795d594fSAndroid Build Coastguard Worker "packedSwitch_INT_MAX", new Object[]{123}, null, 123)); 65*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("PackedSwitch key overflow", "b_24399945", 66*795d594fSAndroid Build Coastguard Worker "packedSwitch_overflow", new Object[]{123}, new VerifyError(), null)); 67*795d594fSAndroid Build Coastguard Worker 68*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/17790197", "B17790197", "getInt", null, null, 100)); 69*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("FloatBadArgReg", "FloatBadArgReg", "getInt", 70*795d594fSAndroid Build Coastguard Worker new Object[]{100}, null, 100)); 71*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("negLong", "negLong", "negLong", null, null, 122142L)); 72*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("sameFieldNames", "sameFieldNames", "getInt", null, null, 7)); 73*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/18380491", "B18380491ConcreteClass", "foo", 74*795d594fSAndroid Build Coastguard Worker new Object[]{42}, null, 42)); 75*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("invoke-super abstract", "B18380491ConcreteClass", "foo", 76*795d594fSAndroid Build Coastguard Worker new Object[]{0}, new AbstractMethodError(), null)); 77*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("BadCaseInOpRegRegReg", "BadCaseInOpRegRegReg", "getInt", null, 78*795d594fSAndroid Build Coastguard Worker null, 2)); 79*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("CmpLong", "CmpLong", "run", null, null, 0)); 80*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("FloatIntConstPassing", "FloatIntConstPassing", "run", null, 81*795d594fSAndroid Build Coastguard Worker null, 2)); 82*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/18718277", "B18718277", "getInt", null, null, 0)); 83*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/18800943 (1)", "B18800943_1", "n_a", null, new VerifyError(), 84*795d594fSAndroid Build Coastguard Worker 0)); 85*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/18800943 (2)", "B18800943_2", "n_a", null, new VerifyError(), 86*795d594fSAndroid Build Coastguard Worker 0)); 87*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("MoveExc", "MoveExc", "run", null, new ArithmeticException(), 88*795d594fSAndroid Build Coastguard Worker null)); 89*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("MoveExceptionOnEntry", "MoveExceptionOnEntry", 90*795d594fSAndroid Build Coastguard Worker "moveExceptionOnEntry", new Object[]{0}, new VerifyError(), null)); 91*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("EmptySparseSwitch", "EmptySparseSwitch", "run", null, null, 92*795d594fSAndroid Build Coastguard Worker null)); 93*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/20224106", "B20224106", "run", null, new VerifyError(), 94*795d594fSAndroid Build Coastguard Worker 0)); 95*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/17410612", "B17410612", "run", null, new VerifyError(), 96*795d594fSAndroid Build Coastguard Worker 0)); 97*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/21863767", "B21863767", "run", null, null, 98*795d594fSAndroid Build Coastguard Worker null)); 99*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/21873167", "B21873167", "test", null, null, null)); 100*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/21614284", "B21614284", "test", new Object[] { null }, 101*795d594fSAndroid Build Coastguard Worker new NullPointerException(), null)); 102*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/21902684", "B21902684", "test", null, null, null)); 103*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/22045582", "B22045582", "run", null, new VerifyError(), 104*795d594fSAndroid Build Coastguard Worker 0)); 105*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/22045582 (int)", "B22045582Int", "run", null, 106*795d594fSAndroid Build Coastguard Worker new VerifyError(), 0)); 107*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/22045582 (wide)", "B22045582Wide", "run", null, 108*795d594fSAndroid Build Coastguard Worker new VerifyError(), 0)); 109*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/21886894", "B21886894", "test", null, new VerifyError(), 110*795d594fSAndroid Build Coastguard Worker null)); 111*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/22080519", "B22080519", "run", null, 112*795d594fSAndroid Build Coastguard Worker new NullPointerException(), null)); 113*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/21645819", "B21645819", "run", new Object[] { null }, 114*795d594fSAndroid Build Coastguard Worker null, null)); 115*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/22244733", "B22244733", "run", new Object[] { "abc" }, 116*795d594fSAndroid Build Coastguard Worker null, "abc")); 117*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/22331663", "B22331663", "run", new Object[] { false }, 118*795d594fSAndroid Build Coastguard Worker null, null)); 119*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/22331663 (pass)", "B22331663Pass", "run", 120*795d594fSAndroid Build Coastguard Worker new Object[] { false }, null, null)); 121*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/22331663 (fail)", "B22331663Fail", "run", 122*795d594fSAndroid Build Coastguard Worker new Object[] { false }, new VerifyError(), null)); 123*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/22411633 (1)", "B22411633_1", "run", new Object[] { false }, 124*795d594fSAndroid Build Coastguard Worker null, null)); 125*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/22411633 (2)", "B22411633_2", "run", new Object[] { false }, 126*795d594fSAndroid Build Coastguard Worker new VerifyError(), null)); 127*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/22411633 (3)", "B22411633_3", "run", new Object[] { false }, 128*795d594fSAndroid Build Coastguard Worker null, null)); 129*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/22411633 (4)", "B22411633_4", "run", new Object[] { false }, 130*795d594fSAndroid Build Coastguard Worker new VerifyError(), null)); 131*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/22411633 (5)", "B22411633_5", "run", new Object[] { false }, 132*795d594fSAndroid Build Coastguard Worker null, null)); 133*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/22777307", "B22777307", "run", null, new InstantiationError(), 134*795d594fSAndroid Build Coastguard Worker null)); 135*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/22881413", "B22881413", "run", null, null, null)); 136*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/20843113", "B20843113", "run", null, null, null)); 137*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/23201502 (float)", "B23201502", "runFloat", null, 138*795d594fSAndroid Build Coastguard Worker new NullPointerException(), null)); 139*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/23201502 (double)", "B23201502", "runDouble", null, 140*795d594fSAndroid Build Coastguard Worker new NullPointerException(), null)); 141*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/23300986", "B23300986", "runAliasAfterEnter", 142*795d594fSAndroid Build Coastguard Worker new Object[] { new Object() }, null, null)); 143*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/23300986 (2)", "B23300986", "runAliasBeforeEnter", 144*795d594fSAndroid Build Coastguard Worker new Object[] { new Object() }, null, null)); 145*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/23502994 (if-eqz)", "B23502994", "runIF_EQZ", 146*795d594fSAndroid Build Coastguard Worker new Object[] { new Object() }, null, null)); 147*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/23502994 (check-cast)", "B23502994", "runCHECKCAST", 148*795d594fSAndroid Build Coastguard Worker new Object[] { "abc" }, null, null)); 149*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/25494456", "B25494456", "run", null, new VerifyError(), 150*795d594fSAndroid Build Coastguard Worker null)); 151*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/21869691", "B21869691A", "run", null, 152*795d594fSAndroid Build Coastguard Worker new IncompatibleClassChangeError(), null)); 153*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/26143249", "B26143249", "run", null, 154*795d594fSAndroid Build Coastguard Worker new AbstractMethodError(), null)); 155*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/26579108", "B26579108", "run", null, new VerifyError(), 156*795d594fSAndroid Build Coastguard Worker null)); 157*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/26594149 (1)", "B26594149_1", "run", null, new VerifyError(), 158*795d594fSAndroid Build Coastguard Worker null)); 159*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/26594149 (2)", "B26594149_2", "run", null, new VerifyError(), 160*795d594fSAndroid Build Coastguard Worker null)); 161*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/26594149 (3)", "B26594149_3", "run", null, new VerifyError(), 162*795d594fSAndroid Build Coastguard Worker null)); 163*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/26594149 (4)", "B26594149_4", "run", null, new VerifyError(), 164*795d594fSAndroid Build Coastguard Worker null)); 165*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/26594149 (5)", "B26594149_5", "run", null, null, null)); 166*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/26594149 (6)", "B26594149_6", "run", null, new VerifyError(), 167*795d594fSAndroid Build Coastguard Worker null)); 168*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/26594149 (7)", "B26594149_7", "run", null, new VerifyError(), 169*795d594fSAndroid Build Coastguard Worker null)); 170*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/26594149 (8)", "B26594149_8", "run", null, new VerifyError(), 171*795d594fSAndroid Build Coastguard Worker null)); 172*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/27148248", "B27148248", "run", null, new VerifyError(), 173*795d594fSAndroid Build Coastguard Worker null)); 174*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/26965384", "B26965384", "run", null, new VerifyError(), 175*795d594fSAndroid Build Coastguard Worker null)); 176*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/27799205 (1)", "B27799205Helper", "run1", null, null, null)); 177*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/27799205 (2)", "B27799205Helper", "run2", null, 178*795d594fSAndroid Build Coastguard Worker new VerifyError(), null)); 179*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/27799205 (3)", "B27799205Helper", "run3", null, 180*795d594fSAndroid Build Coastguard Worker new VerifyError(), null)); 181*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/27799205 (4)", "B27799205Helper", "run4", null, 182*795d594fSAndroid Build Coastguard Worker new VerifyError(), null)); 183*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/27799205 (5)", "B27799205Helper", "run5", null, 184*795d594fSAndroid Build Coastguard Worker new VerifyError(), null)); 185*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/27799205 (6)", "B27799205Helper", "run6", null, null, null)); 186*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/28187158 (1)", "B28187158", "run", new Object[] { null }, 187*795d594fSAndroid Build Coastguard Worker new VerifyError(), null)); 188*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/28187158 (2)", "B28187158_2Helper", "run", null, 189*795d594fSAndroid Build Coastguard Worker new NullPointerException(), null)); 190*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/29778499 (1)", "B29778499_1", "run", null, 191*795d594fSAndroid Build Coastguard Worker new IncompatibleClassChangeError(), null)); 192*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/29778499 (2)", "B29778499_2", "run", null, 193*795d594fSAndroid Build Coastguard Worker new IncompatibleClassChangeError(), null)); 194*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/30458218", "B30458218", "run", null, null, null)); 195*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/31313170", "B31313170", "run", null, null, 0)); 196*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("ConstClassAliasing", "ConstClassAliasing", "run", null, null, 197*795d594fSAndroid Build Coastguard Worker null, true)); 198*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/121191566", "B121191566", "run", new Object[] { "a" }, null, 199*795d594fSAndroid Build Coastguard Worker true, false)); 200*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/122501785", "B122501785", "run", null, new VerifyError(), 201*795d594fSAndroid Build Coastguard Worker 0)); 202*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/134061982", "B134061982", "run", new Object[] { 0 }, 203*795d594fSAndroid Build Coastguard Worker new NullPointerException(), 0)); 204*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/134061982 (2)", "B134061982_2", "run", new Object[] { 0 }, 205*795d594fSAndroid Build Coastguard Worker new VerifyError(), 0)); 206*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/121245951", "B121245951", "run", new Object[] { true, 207*795d594fSAndroid Build Coastguard Worker new Object() }, new IllegalMonitorStateException(), 0)); 208*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/121245951 (2)", "B121245951_2", "run", new Object[] { true, 209*795d594fSAndroid Build Coastguard Worker new Object() }, new VerifyError(), 0)); 210*795d594fSAndroid Build Coastguard Worker testCases.add(new TestCase("b/121245951 (3)", "B121245951_3", "run", new Object[] { 211*795d594fSAndroid Build Coastguard Worker new Object() }, new IllegalMonitorStateException(), 0)); 212*795d594fSAndroid Build Coastguard Worker } 213*795d594fSAndroid Build Coastguard Worker runTests()214*795d594fSAndroid Build Coastguard Worker public void runTests() { 215*795d594fSAndroid Build Coastguard Worker for (TestCase tc : testCases) { 216*795d594fSAndroid Build Coastguard Worker System.out.println(tc.testName); 217*795d594fSAndroid Build Coastguard Worker try { 218*795d594fSAndroid Build Coastguard Worker runTest(tc); 219*795d594fSAndroid Build Coastguard Worker } catch (Exception exc) { 220*795d594fSAndroid Build Coastguard Worker exc.printStackTrace(System.out); 221*795d594fSAndroid Build Coastguard Worker } 222*795d594fSAndroid Build Coastguard Worker } 223*795d594fSAndroid Build Coastguard Worker } 224*795d594fSAndroid Build Coastguard Worker runTest(TestCase tc)225*795d594fSAndroid Build Coastguard Worker private void runTest(TestCase tc) throws Exception { 226*795d594fSAndroid Build Coastguard Worker Exception errorReturn = null; 227*795d594fSAndroid Build Coastguard Worker try { 228*795d594fSAndroid Build Coastguard Worker Class<?> c = Class.forName(tc.testClass); 229*795d594fSAndroid Build Coastguard Worker 230*795d594fSAndroid Build Coastguard Worker Method[] methods = c.getDeclaredMethods(); 231*795d594fSAndroid Build Coastguard Worker 232*795d594fSAndroid Build Coastguard Worker // For simplicity we assume that test methods are not overloaded. So searching by name 233*795d594fSAndroid Build Coastguard Worker // will give us the method we need to run. 234*795d594fSAndroid Build Coastguard Worker Method method = null; 235*795d594fSAndroid Build Coastguard Worker for (Method m : methods) { 236*795d594fSAndroid Build Coastguard Worker if (m.getName().equals(tc.testMethodName)) { 237*795d594fSAndroid Build Coastguard Worker method = m; 238*795d594fSAndroid Build Coastguard Worker break; 239*795d594fSAndroid Build Coastguard Worker } 240*795d594fSAndroid Build Coastguard Worker } 241*795d594fSAndroid Build Coastguard Worker 242*795d594fSAndroid Build Coastguard Worker if (method == null) { 243*795d594fSAndroid Build Coastguard Worker errorReturn = new IllegalArgumentException("Could not find test method " + 244*795d594fSAndroid Build Coastguard Worker tc.testMethodName + " in class " + 245*795d594fSAndroid Build Coastguard Worker tc.testClass + " for test " + 246*795d594fSAndroid Build Coastguard Worker tc.testName); 247*795d594fSAndroid Build Coastguard Worker } else { 248*795d594fSAndroid Build Coastguard Worker Object retValue; 249*795d594fSAndroid Build Coastguard Worker if (Modifier.isStatic(method.getModifiers())) { 250*795d594fSAndroid Build Coastguard Worker retValue = method.invoke(null, tc.values); 251*795d594fSAndroid Build Coastguard Worker } else { 252*795d594fSAndroid Build Coastguard Worker retValue = method.invoke(method.getDeclaringClass().newInstance(), tc.values); 253*795d594fSAndroid Build Coastguard Worker } 254*795d594fSAndroid Build Coastguard Worker if (tc.expectedException != null) { 255*795d594fSAndroid Build Coastguard Worker errorReturn = new IllegalStateException("Expected an exception in test " + 256*795d594fSAndroid Build Coastguard Worker tc.testName); 257*795d594fSAndroid Build Coastguard Worker } else if (tc.expectedReturn == null && retValue != null) { 258*795d594fSAndroid Build Coastguard Worker errorReturn = new IllegalStateException("Expected a null result in test " + 259*795d594fSAndroid Build Coastguard Worker tc.testName + " got " + retValue); 260*795d594fSAndroid Build Coastguard Worker } else if (tc.expectedReturn != null && 261*795d594fSAndroid Build Coastguard Worker (retValue == null || !tc.expectedReturn.equals(retValue))) { 262*795d594fSAndroid Build Coastguard Worker errorReturn = new IllegalStateException("Expected return " + 263*795d594fSAndroid Build Coastguard Worker tc.expectedReturn + 264*795d594fSAndroid Build Coastguard Worker ", but got " + retValue); 265*795d594fSAndroid Build Coastguard Worker } else if (tc.checkCompiled && compiledWithOptimizing() && !isAotVerified(c)) { 266*795d594fSAndroid Build Coastguard Worker errorReturn = new IllegalStateException("Expected method " + method.getName() + 267*795d594fSAndroid Build Coastguard Worker " of class " + c.getName() + 268*795d594fSAndroid Build Coastguard Worker " be verified in compile-time in test " + tc.testName); 269*795d594fSAndroid Build Coastguard Worker } else { 270*795d594fSAndroid Build Coastguard Worker // Expected result, do nothing. 271*795d594fSAndroid Build Coastguard Worker } 272*795d594fSAndroid Build Coastguard Worker } 273*795d594fSAndroid Build Coastguard Worker } catch (Throwable exc) { 274*795d594fSAndroid Build Coastguard Worker if (tc.expectedException == null) { 275*795d594fSAndroid Build Coastguard Worker errorReturn = new IllegalStateException("Did not expect exception", exc); 276*795d594fSAndroid Build Coastguard Worker } else if (exc instanceof InvocationTargetException && exc.getCause() != null && 277*795d594fSAndroid Build Coastguard Worker exc.getCause().getClass().equals(tc.expectedException.getClass())) { 278*795d594fSAndroid Build Coastguard Worker // Expected exception is wrapped in InvocationTargetException. 279*795d594fSAndroid Build Coastguard Worker } else if (!tc.expectedException.getClass().equals(exc.getClass())) { 280*795d594fSAndroid Build Coastguard Worker errorReturn = new IllegalStateException("Expected " + 281*795d594fSAndroid Build Coastguard Worker tc.expectedException.getClass().getName() + 282*795d594fSAndroid Build Coastguard Worker ", but got " + exc.getClass(), exc); 283*795d594fSAndroid Build Coastguard Worker } else { 284*795d594fSAndroid Build Coastguard Worker // Expected exception, do nothing. 285*795d594fSAndroid Build Coastguard Worker } 286*795d594fSAndroid Build Coastguard Worker } finally { 287*795d594fSAndroid Build Coastguard Worker if (errorReturn != null) { 288*795d594fSAndroid Build Coastguard Worker throw errorReturn; 289*795d594fSAndroid Build Coastguard Worker } 290*795d594fSAndroid Build Coastguard Worker } 291*795d594fSAndroid Build Coastguard Worker } 292*795d594fSAndroid Build Coastguard Worker main(String[] args)293*795d594fSAndroid Build Coastguard Worker public static void main(String[] args) throws Exception { 294*795d594fSAndroid Build Coastguard Worker System.loadLibrary(args[0]); 295*795d594fSAndroid Build Coastguard Worker 296*795d594fSAndroid Build Coastguard Worker Main main = new Main(); 297*795d594fSAndroid Build Coastguard Worker 298*795d594fSAndroid Build Coastguard Worker main.runTests(); 299*795d594fSAndroid Build Coastguard Worker 300*795d594fSAndroid Build Coastguard Worker System.out.println("Done!"); 301*795d594fSAndroid Build Coastguard Worker } 302*795d594fSAndroid Build Coastguard Worker isAotVerified(Class<?> cls)303*795d594fSAndroid Build Coastguard Worker private native static boolean isAotVerified(Class<?> cls); compiledWithOptimizing()304*795d594fSAndroid Build Coastguard Worker private native static boolean compiledWithOptimizing(); 305*795d594fSAndroid Build Coastguard Worker } 306