1 // Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file 2 // for details. All rights reserved. Use of this source code is governed by a 3 // BSD-style license that can be found in the LICENSE file. 4 5 package com.android.tools.r8; 6 7 import com.android.tools.r8.ToolHelper.DexVm; 8 import com.android.tools.r8.dex.Constants; 9 import com.google.common.collect.ImmutableList; 10 import com.google.common.collect.ImmutableMap; 11 import java.nio.file.Path; 12 import java.nio.file.Paths; 13 import java.util.List; 14 import java.util.Map; 15 import java.util.concurrent.ExecutionException; 16 import java.util.function.UnaryOperator; 17 import org.junit.Test; 18 19 public class R8RunExamplesAndroidOTest extends RunExamplesAndroidOTest<R8Command.Builder> { 20 21 private static Map<DexVm, List<String>> alsoFailsOn = 22 ImmutableMap.of( 23 DexVm.ART_4_4_4, ImmutableList.of( 24 "invokecustom-with-shrinking" 25 ), 26 DexVm.ART_5_1_1, ImmutableList.of( 27 "invokecustom-with-shrinking" 28 ), 29 DexVm.ART_6_0_1, ImmutableList.of( 30 "invokecustom-with-shrinking" 31 ), 32 DexVm.ART_7_0_0, ImmutableList.of( 33 "invokecustom-with-shrinking" 34 ), 35 DexVm.ART_DEFAULT, ImmutableList.of( 36 ) 37 ); 38 39 @Test invokeCustomWithShrinking()40 public void invokeCustomWithShrinking() throws Throwable { 41 test("invokecustom-with-shrinking", "invokecustom", "InvokeCustom") 42 .withMinApiLevel(Constants.ANDROID_O_API) 43 .withBuilderTransformation(builder -> 44 builder.addProguardConfigurationFiles( 45 Paths.get(ToolHelper.EXAMPLES_ANDROID_O_DIR, "invokecustom/keep-rules.txt"))) 46 .run(); 47 } 48 49 class R8TestRunner extends TestRunner { 50 R8TestRunner(String testName, String packageName, String mainClass)51 R8TestRunner(String testName, String packageName, String mainClass) { 52 super(testName, packageName, mainClass); 53 } 54 55 @Override withMinApiLevel(int minApiLevel)56 TestRunner withMinApiLevel(int minApiLevel) { 57 return withBuilderTransformation(builder -> builder.setMinApiLevel(minApiLevel)); 58 } 59 60 @Override build(Path inputFile, Path out)61 void build(Path inputFile, Path out) throws Throwable { 62 try { 63 R8Command.Builder builder = R8Command.builder(); 64 for (UnaryOperator<R8Command.Builder> transformation : builderTransformations) { 65 builder = transformation.apply(builder); 66 } 67 R8Command command = builder.addProgramFiles(inputFile).setOutputPath(out).build(); 68 ToolHelper.runR8(command, this::combinedOptionConsumer); 69 } catch (ExecutionException e) { 70 throw e.getCause(); 71 } 72 } 73 } 74 75 @Override test(String testName, String packageName, String mainClass)76 TestRunner test(String testName, String packageName, String mainClass) { 77 return new R8TestRunner(testName, packageName, mainClass); 78 } 79 80 @Override expectedToFail(String name)81 boolean expectedToFail(String name) { 82 return super.expectedToFail(name) || failsOn(alsoFailsOn, name); 83 } 84 } 85