xref: /aosp_15_r20/art/test/921-hello-failure/src/Main.java (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker  * Copyright (C) 2017 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 art.Redefinition;
18*795d594fSAndroid Build Coastguard Worker import java.util.Arrays;
19*795d594fSAndroid Build Coastguard Worker 
20*795d594fSAndroid Build Coastguard Worker public class Main {
21*795d594fSAndroid Build Coastguard Worker 
main(String[] args)22*795d594fSAndroid Build Coastguard Worker   public static void main(String[] args) {
23*795d594fSAndroid Build Coastguard Worker     Verification.doTest(new Transform());
24*795d594fSAndroid Build Coastguard Worker     NewName.doTest(new Transform());
25*795d594fSAndroid Build Coastguard Worker     DifferentAccess.doTest(new Transform());
26*795d594fSAndroid Build Coastguard Worker     NewInterface.doTest(new Transform2());
27*795d594fSAndroid Build Coastguard Worker     MissingInterface.doTest(new Transform2());
28*795d594fSAndroid Build Coastguard Worker     ReorderInterface.doTest(new Transform2());
29*795d594fSAndroid Build Coastguard Worker     MultiRedef.doTest(new Transform(), new Transform2());
30*795d594fSAndroid Build Coastguard Worker     MultiRetrans.doTest(new Transform(), new Transform2());
31*795d594fSAndroid Build Coastguard Worker     NewMethod.doTest(new Transform());
32*795d594fSAndroid Build Coastguard Worker     MissingMethod.doTest(new Transform3());
33*795d594fSAndroid Build Coastguard Worker     MethodChange.doTest(new Transform());
34*795d594fSAndroid Build Coastguard Worker     NewField.doTest(new Transform());
35*795d594fSAndroid Build Coastguard Worker     MissingField.doTest(new Transform4("there"));
36*795d594fSAndroid Build Coastguard Worker     FieldChange.doTest(new Transform4("there again"));
37*795d594fSAndroid Build Coastguard Worker     Unmodifiable.doTest(new Transform[] { new Transform(), });
38*795d594fSAndroid Build Coastguard Worker     Undefault.doTest(new Transform5());
39*795d594fSAndroid Build Coastguard Worker   }
40*795d594fSAndroid Build Coastguard Worker 
41*795d594fSAndroid Build Coastguard Worker   // TODO Replace this shim with a better re-write of this test.
mapCCD(CommonClassDefinition d)42*795d594fSAndroid Build Coastguard Worker   private static Redefinition.CommonClassDefinition mapCCD(CommonClassDefinition d) {
43*795d594fSAndroid Build Coastguard Worker     return new Redefinition.CommonClassDefinition(d.target, d.class_file_bytes, d.dex_file_bytes);
44*795d594fSAndroid Build Coastguard Worker   }
45*795d594fSAndroid Build Coastguard Worker 
toCCDA(CommonClassDefinition[] ds)46*795d594fSAndroid Build Coastguard Worker   private static Redefinition.CommonClassDefinition[] toCCDA(CommonClassDefinition[] ds) {
47*795d594fSAndroid Build Coastguard Worker     return Arrays.stream(ds).map(Main::mapCCD).toArray(Redefinition.CommonClassDefinition[]::new);
48*795d594fSAndroid Build Coastguard Worker   }
49*795d594fSAndroid Build Coastguard Worker 
doCommonClassRedefinition(Class<?> target, byte[] classfile, byte[] dexfile)50*795d594fSAndroid Build Coastguard Worker   public static void doCommonClassRedefinition(Class<?> target,
51*795d594fSAndroid Build Coastguard Worker                                                byte[] classfile,
52*795d594fSAndroid Build Coastguard Worker                                                byte[] dexfile) throws Exception {
53*795d594fSAndroid Build Coastguard Worker     Redefinition.doCommonClassRedefinition(target, classfile, dexfile);
54*795d594fSAndroid Build Coastguard Worker   }
doMultiClassRedefinition(CommonClassDefinition... defs)55*795d594fSAndroid Build Coastguard Worker   public static void doMultiClassRedefinition(CommonClassDefinition... defs) throws Exception {
56*795d594fSAndroid Build Coastguard Worker     Redefinition.doMultiClassRedefinition(toCCDA(defs));
57*795d594fSAndroid Build Coastguard Worker   }
addMultiTransformationResults(CommonClassDefinition... defs)58*795d594fSAndroid Build Coastguard Worker   public static void addMultiTransformationResults(CommonClassDefinition... defs) throws Exception {
59*795d594fSAndroid Build Coastguard Worker     Redefinition.addMultiTransformationResults(toCCDA(defs));
60*795d594fSAndroid Build Coastguard Worker   }
doCommonMultiClassRedefinition(Class<?>[] targets, byte[][] classfiles, byte[][] dexfiles)61*795d594fSAndroid Build Coastguard Worker   public static void doCommonMultiClassRedefinition(Class<?>[] targets,
62*795d594fSAndroid Build Coastguard Worker                                                     byte[][] classfiles,
63*795d594fSAndroid Build Coastguard Worker                                                     byte[][] dexfiles) throws Exception {
64*795d594fSAndroid Build Coastguard Worker     Redefinition.doCommonMultiClassRedefinition(targets, classfiles, dexfiles);
65*795d594fSAndroid Build Coastguard Worker   }
doCommonClassRetransformation(Class<?>.... target)66*795d594fSAndroid Build Coastguard Worker   public static void doCommonClassRetransformation(Class<?>... target) throws Exception {
67*795d594fSAndroid Build Coastguard Worker     Redefinition.doCommonClassRetransformation(target);
68*795d594fSAndroid Build Coastguard Worker   }
enableCommonRetransformation(boolean enable)69*795d594fSAndroid Build Coastguard Worker   public static void enableCommonRetransformation(boolean enable) {
70*795d594fSAndroid Build Coastguard Worker     Redefinition.enableCommonRetransformation(enable);
71*795d594fSAndroid Build Coastguard Worker   }
addCommonTransformationResult(String target_name, byte[] class_bytes, byte[] dex_bytes)72*795d594fSAndroid Build Coastguard Worker   public static void addCommonTransformationResult(String target_name,
73*795d594fSAndroid Build Coastguard Worker                                                    byte[] class_bytes,
74*795d594fSAndroid Build Coastguard Worker                                                    byte[] dex_bytes) {
75*795d594fSAndroid Build Coastguard Worker     Redefinition.addCommonTransformationResult(target_name, class_bytes, dex_bytes);
76*795d594fSAndroid Build Coastguard Worker   }
77*795d594fSAndroid Build Coastguard Worker }
78