• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2016, 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 package com.android.tools.r8.jar.UnicodeSetRegression;
5 
6 import com.android.tools.r8.CompilationException;
7 import com.android.tools.r8.ToolHelper;
8 import com.android.tools.r8.shaking.ProguardRuleParserException;
9 import com.android.tools.r8.utils.AndroidApp;
10 import com.android.tools.r8.utils.ArtErrorParser;
11 import com.android.tools.r8.utils.ArtErrorParser.ArtErrorInfo;
12 import com.android.tools.r8.utils.ArtErrorParser.ArtErrorParserException;
13 import com.android.tools.r8.utils.DexInspector;
14 import java.io.IOException;
15 import java.nio.file.Path;
16 import java.util.List;
17 import java.util.concurrent.ExecutionException;
18 import org.junit.ComparisonFailure;
19 import org.junit.Rule;
20 import org.junit.Test;
21 import org.junit.rules.TemporaryFolder;
22 
23 public class UnicodeSetRegressionTest {
24 
25   private static final String JAR_FILE =
26       "src/test/java/com/android/tools/r8/jar/UnicodeSetRegression/UnicodeSet.jar";
27 
28   @Rule
29   public TemporaryFolder temp = ToolHelper.getTemporaryFolderForTest();
30 
dexFromDX()31   private AndroidApp dexFromDX() throws IOException {
32     return ToolHelper.runDexer(JAR_FILE, temp.newFolder("dx-dex").getPath());
33   }
34 
35   @Test
testUnicodeSetFromDex()36   public void testUnicodeSetFromDex()
37       throws ExecutionException, IOException, ProguardRuleParserException, CompilationException {
38     Path combinedInput = temp.getRoot().toPath().resolve("all.zip");
39     Path oatFile = temp.getRoot().toPath().resolve("all.oat");
40     ToolHelper.runR8(dexFromDX(), combinedInput);
41     ToolHelper.runDex2Oat(combinedInput, oatFile);
42   }
43 
44   @Test
testUnicodeSetFromJar()45   public void testUnicodeSetFromJar()
46       throws ExecutionException, IOException, ProguardRuleParserException, CompilationException {
47     Path combinedInput = temp.getRoot().toPath().resolve("all.zip");
48     Path oatFile = temp.getRoot().toPath().resolve("all.oat");
49     AndroidApp result = ToolHelper.runR8(JAR_FILE, combinedInput.toString());
50     try {
51       ToolHelper.runDex2Oat(combinedInput, oatFile);
52     } catch (AssertionError e) {
53       AndroidApp fromDexApp = ToolHelper.runR8(dexFromDX());
54       DexInspector fromDex = new DexInspector(fromDexApp);
55       DexInspector fromJar = new DexInspector(result);
56       List<ArtErrorInfo> errors;
57       try {
58         errors = ArtErrorParser.parse(e.getMessage());
59       } catch (ArtErrorParserException parserException) {
60         System.err.println(parserException.toString());
61         throw e;
62       }
63       if (errors.isEmpty()) {
64         throw e;
65       }
66       for (ArtErrorInfo error : errors.subList(0, errors.size() - 1)) {
67         System.err.println(new ComparisonFailure(error.getMessage(),
68             "REFERENCE\n" + error.dump(fromDex, false) + "\nEND REFERENCE",
69             "PROCESSED\n" + error.dump(fromJar, true) + "\nEND PROCESSED").toString());
70       }
71       ArtErrorInfo error = errors.get(errors.size() - 1);
72       throw new ComparisonFailure(error.getMessage(),
73           "REFERENCE\n" + error.dump(fromDex, false) + "\nEND REFERENCE",
74           "PROCESSED\n" + error.dump(fromJar, true) + "\nEND PROCESSED");
75     }
76   }
77 }
78