1*b7c941bbSAndroid Build Coastguard Worker /* 2*b7c941bbSAndroid Build Coastguard Worker * Copyright (C) 2008 The Android Open Source Project 3*b7c941bbSAndroid Build Coastguard Worker * 4*b7c941bbSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*b7c941bbSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*b7c941bbSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*b7c941bbSAndroid Build Coastguard Worker * 8*b7c941bbSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*b7c941bbSAndroid Build Coastguard Worker * 10*b7c941bbSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*b7c941bbSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*b7c941bbSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*b7c941bbSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*b7c941bbSAndroid Build Coastguard Worker * limitations under the License. 15*b7c941bbSAndroid Build Coastguard Worker */ 16*b7c941bbSAndroid Build Coastguard Worker 17*b7c941bbSAndroid Build Coastguard Worker package dot.junit; 18*b7c941bbSAndroid Build Coastguard Worker 19*b7c941bbSAndroid Build Coastguard Worker public class DxUtil { 20*b7c941bbSAndroid Build Coastguard Worker private static boolean isDalvik = false; 21*b7c941bbSAndroid Build Coastguard Worker 22*b7c941bbSAndroid Build Coastguard Worker static { 23*b7c941bbSAndroid Build Coastguard Worker /** 24*b7c941bbSAndroid Build Coastguard Worker * whether in case of a failure, also ClassNotFoundException is accepted. 25*b7c941bbSAndroid Build Coastguard Worker * this makes sense for invalid classes that got rejected by the dx tools 26*b7c941bbSAndroid Build Coastguard Worker * and thus do not exist in .dex format, so that this class missing means a 27*b7c941bbSAndroid Build Coastguard Worker * the expected verify error (though at the dx tool level) 28*b7c941bbSAndroid Build Coastguard Worker */ 29*b7c941bbSAndroid Build Coastguard Worker // String acnfS = System.getProperty("acceptCNF"); 30*b7c941bbSAndroid Build Coastguard Worker // isDalvik = (acnfS != null && acnfS.equals("true")); 31*b7c941bbSAndroid Build Coastguard Worker //System.out.println("@DX:DxUtil:isDalik="+isDalvik); 32*b7c941bbSAndroid Build Coastguard Worker } 33*b7c941bbSAndroid Build Coastguard Worker checkVerifyException(Throwable t)34*b7c941bbSAndroid Build Coastguard Worker public static void checkVerifyException(Throwable t) { 35*b7c941bbSAndroid Build Coastguard Worker // the dalvik vm and other vm handle verify errors differently (see the dalvik verifier) 36*b7c941bbSAndroid Build Coastguard Worker // the dalvik vm only throws a VerifyError, whereas other vm can throw all subclasses of 37*b7c941bbSAndroid Build Coastguard Worker // LinkageError: 38*b7c941bbSAndroid Build Coastguard Worker // - ClassCircularityError 39*b7c941bbSAndroid Build Coastguard Worker // - ClassFormatError 40*b7c941bbSAndroid Build Coastguard Worker // - ExceptionInInitializerError 41*b7c941bbSAndroid Build Coastguard Worker // - IncompatibleClassChangeError 42*b7c941bbSAndroid Build Coastguard Worker // - NoClassDefFoundError 43*b7c941bbSAndroid Build Coastguard Worker // - UnsatisfiedLinkError 44*b7c941bbSAndroid Build Coastguard Worker // - VerifyError 45*b7c941bbSAndroid Build Coastguard Worker 46*b7c941bbSAndroid Build Coastguard Worker // in case we are testing the dalvik, we also accept a ClassNotFoundException, 47*b7c941bbSAndroid Build Coastguard Worker // since that may happen when a verify error was thrown by the dx tool and thus no 48*b7c941bbSAndroid Build Coastguard Worker // classes.dex was written at all. 49*b7c941bbSAndroid Build Coastguard Worker //System.out.println("@dx:debug:isDalvik:"+isDalvik); 50*b7c941bbSAndroid Build Coastguard Worker /* 51*b7c941bbSAndroid Build Coastguard Worker if ((t instanceof VerifyError || 52*b7c941bbSAndroid Build Coastguard Worker (isDalvik && t instanceof ClassNotFoundException) || 53*b7c941bbSAndroid Build Coastguard Worker (!isDalvik && !(t instanceof NoClassDefFoundError) 54*b7c941bbSAndroid Build Coastguard Worker && t instanceof LinkageError))) { 55*b7c941bbSAndroid Build Coastguard Worker // ok, this is what we expected 56*b7c941bbSAndroid Build Coastguard Worker System.out.println("@dx:debug:vfe-ok: vfe was:"+t.getClass().getName()+", msg:"+t.getMessage()); 57*b7c941bbSAndroid Build Coastguard Worker return; 58*b7c941bbSAndroid Build Coastguard Worker } else { 59*b7c941bbSAndroid Build Coastguard Worker throw new RuntimeException("test did not cause the expected verify error, but:"+t.getClass().getName()+", msg:"+t.getMessage()); 60*b7c941bbSAndroid Build Coastguard Worker } 61*b7c941bbSAndroid Build Coastguard Worker */ 62*b7c941bbSAndroid Build Coastguard Worker if (t instanceof VerifyError || t instanceof java.lang.IncompatibleClassChangeError ||t instanceof ClassNotFoundException) { 63*b7c941bbSAndroid Build Coastguard Worker // ok, this is what we expected 64*b7c941bbSAndroid Build Coastguard Worker } else { 65*b7c941bbSAndroid Build Coastguard Worker throw new RuntimeException("VerifyError expected", t); 66*b7c941bbSAndroid Build Coastguard Worker } 67*b7c941bbSAndroid Build Coastguard Worker 68*b7c941bbSAndroid Build Coastguard Worker } 69*b7c941bbSAndroid Build Coastguard Worker } 70