summaryrefslogtreecommitdiffstats
path: root/jack/tests/com/android/jack/ToolchainTest.java
blob: 8518559091a5b4969853665ae9a3fc4ff5187441 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.jack;

import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Tests that test different steps of the Jack toolchain.
 * These tests only rely on the Android tree for source lists.
 * They are supposed to be run in test-jack (ideally before each commit).
 */
@Ignore("Tree")
public class ToolchainTest {

  private static Sourcelist CORE_SOURCELIST;

  private static Sourcelist BOUNCY_SOURCELIST;

  private static Sourcelist JUNIT_SOURCELIST;

  private static File corePath;

  @BeforeClass
  public static void setup() throws Exception {
    CORE_SOURCELIST = TestTools.getTargetLibSourcelist("core");
    BOUNCY_SOURCELIST =
        TestTools.getTargetLibSourcelist("bouncycastle");
    JUNIT_SOURCELIST = TestTools.getHostLibSourcelist("junit4-jack");

    File coreOut = TestTools.createTempFile("core", ".zip");
    TestTools.compileSourceToJack(new Options(), CORE_SOURCELIST, null, coreOut, true);
    corePath = coreOut;
  }

  @Test
  public void shrobTestNoZip() throws Exception {
    File shrobTestJackOut = TestTools.createTempDir("shrobtest", "dir");
    String testName = "shrob/test001";
    String classpath = corePath.getAbsolutePath();
    File sourceDir = TestTools.getJackTestsWithJackFolder(testName);
    TestTools.compileSourceToJack(
        new Options(), sourceDir, classpath, shrobTestJackOut, false);

    File shrobTestShrunkOut = TestTools.createTempDir("shrobshrunk", "dir");
    List<ProguardFlags> flagFiles = new ArrayList<ProguardFlags>();
    File testFolder = TestTools.getJackTestFolder(testName);
    flagFiles.add(new ProguardFlags(testFolder, "proguard.flags001"));
    flagFiles.add(new ProguardFlags(testFolder, "proguard.flags004"));
    TestTools.shrobJackToJack(
        new Options(), shrobTestJackOut, classpath, shrobTestShrunkOut, flagFiles, false);

    File shrobTestDexOutFolder = TestTools.createTempDir("shrobbed", "dex");
    TestTools.compileJackToDex(new Options(), shrobTestShrunkOut, shrobTestDexOutFolder, false);
  }

  @Test
  public void shrobTestZip() throws Exception {
    File shrobTestJackOut = TestTools.createTempFile("shrobtest", ".zip");
    String testName = "shrob/test001";
    String classpath = corePath.getAbsolutePath();
    File sourceDir = TestTools.getJackTestsWithJackFolder(testName);
    TestTools.compileSourceToJack(
        new Options(), sourceDir, classpath, shrobTestJackOut, true);

    File shrobTestShrunkOut = TestTools.createTempFile("shrunk", ".zip");
    List<ProguardFlags> flagFiles = new ArrayList<ProguardFlags>();
    File testFolder = TestTools.getJackTestFolder(testName);
    flagFiles.add(new ProguardFlags(testFolder, "proguard.flags001"));
    flagFiles.add(new ProguardFlags(testFolder, "proguard.flags004"));
    TestTools.shrobJackToJack(
        new Options(), shrobTestJackOut, classpath, shrobTestShrunkOut, flagFiles, true);

    File shrobTestDexOut = TestTools.createTempFile("shrobbed", ".dex.zip");
    TestTools.compileJackToDex(new Options(), shrobTestShrunkOut, shrobTestDexOut, true);
  }

  @Test
  public void bouncyCastle() throws Exception {
    File bouncyCastleJack = TestTools.createTempFile("bouncyjack", ".zip");
    TestTools.compileSourceToJack(
        new Options(), BOUNCY_SOURCELIST, corePath.getAbsolutePath(), bouncyCastleJack, true);

    File bouncyCastleOutFolder = TestTools.createTempDir("bouncy", "dex");
    TestTools.compileJackToDex(new Options(), bouncyCastleJack, bouncyCastleOutFolder, false);
  }

  @Test
  public void core() throws Exception {
    File coreOutFolder = TestTools.createTempDir("core", "dex");
    TestTools.compileJackToDex(new Options(), corePath, coreOutFolder, false);
  }

  @Test
  public void junit() throws Exception {
    File junitJack = TestTools.createTempFile("junit", ".zip");
    TestTools.compileSourceToJack(
        new Options(), JUNIT_SOURCELIST, corePath.getAbsolutePath() + File.pathSeparator +
        TestTools.getFromAndroidTree(
            "out/host/common/obj/JAVA_LIBRARIES/hamcrest-core-hostdex-jack_intermediates/classes.jar"), junitJack, true);

    File junitOutFolder = TestTools.createTempDir("junit", "dex");
    TestTools.compileJackToDex(new Options(), junitJack, junitOutFolder, false);
  }

  @Test
  public void libOfLib() throws Exception {

    String corePathString = corePath.getAbsolutePath();
    File libOfLibOut = TestTools.createTempFile("libOfLibOut", ".zip");
    String testName = "liboflib/lib2";
    File sourceDir = TestTools.getJackTestsWithJackFolder(testName);
    TestTools.compileSourceToJack(
        new Options(), sourceDir, corePathString, libOfLibOut, true);

    File libOut = TestTools.createTempFile("libOut", ".zip");
    String testName2 = "liboflib/lib";
    String classpath = corePathString + File.pathSeparatorChar + libOfLibOut.getAbsolutePath();
    File sourceDir2 = TestTools.getJackTestsWithJackFolder(testName2);
    TestTools.compileSourceToJack(
        new Options(), sourceDir2, classpath, libOut, true);

    File mainOut = TestTools.createTempFile("mainOut", ".zip");
    String testName3 = "liboflib/main";
    classpath = corePathString + File.pathSeparatorChar + libOut.getAbsolutePath();
    File sourceDir3 = TestTools.getJackTestsWithJackFolder(testName3);
    TestTools.compileSourceToJack(
        new Options(), sourceDir3, classpath, mainOut, true);
  }

  @Test
  public void jarjarTest() throws Exception {
    File jarjarTestJackOut = TestTools.createTempFile("jarjartest", ".zip");
    String testName = "jarjar/test003";
    String classpath = corePath.getAbsolutePath();
    File sourceDir = TestTools.getJackTestsWithJackFolder(testName);
    TestTools.compileSourceToJack(
        new Options(), sourceDir, classpath, jarjarTestJackOut, true);

    File dalvikAnnotations = TestTools.getFromAndroidTree("libcore/dalvik/src/main/java/");
    File dalvikAnnotationsJackOut = TestTools.createTempFile("dalvikannotations", ".zip");
    TestTools.compileSourceToJack(
        new Options(), dalvikAnnotations, classpath, dalvikAnnotationsJackOut, true);

    File jarjarTestRenamedOut = TestTools.createTempFile("jarjartestrenamed", ".zip");
    File jarjarRules = new File(TestTools.getJackTestFolder(testName), "jarjar-rules.txt");
    TestTools.jarjarJackToJack(
        new Options(), jarjarTestJackOut, classpath, jarjarTestRenamedOut, jarjarRules, true);

    File jarjarTestDexOutFolder = TestTools.createTempDir("jarjared", "dex");
    TestTools.compileJackToDex(new Options(), jarjarTestRenamedOut, jarjarTestDexOutFolder, false);
  }
}