langtools/test/tools/sjavac/ParallelCompilations.java
author alundblad
Wed, 26 Aug 2015 09:02:02 +0200
changeset 32337 c9d3ab9f601c
parent 30730 d3ce7619db2c
child 32799 ee577901f4bb
permissions -rw-r--r--
8133671: langtools tests have bad license Summary: Dropped classpath exception from copyright notice in tests. Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28799
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
     1
/*
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
     4
 *
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
32337
c9d3ab9f601c 8133671: langtools tests have bad license
alundblad
parents: 30730
diff changeset
     7
 * published by the Free Software Foundation.
28799
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
     8
 *
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    13
 * accompanied this code).
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    14
 *
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    18
 *
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    21
 * questions.
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    22
 */
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    23
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    24
/*
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    25
 * @test
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    26
 * @summary Test to check that -j option works with more than one value
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    27
 * @bug 8071629
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    28
 * @author sogoel
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    29
 * @library /tools/lib
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 28799
diff changeset
    30
 * @modules jdk.compiler/com.sun.tools.javac.api
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 28799
diff changeset
    31
 *          jdk.compiler/com.sun.tools.javac.file
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 28799
diff changeset
    32
 *          jdk.compiler/com.sun.tools.javac.main
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 28799
diff changeset
    33
 *          jdk.compiler/com.sun.tools.sjavac
28799
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    34
 * @build Wrapper ToolBox
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    35
 * @run main Wrapper ParallelCompilations
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    36
 */
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    37
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    38
import java.io.*;
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    39
import java.nio.file.*;
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    40
import com.sun.tools.sjavac.Main;
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    41
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    42
class ParallelCompilations extends SJavacTester {
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    43
  public static void main(String[] args) throws Exception {
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    44
    new ParallelCompilations().run();
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    45
  }
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    46
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    47
  public void run() throws Exception {
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    48
    ToolBox tb = new ToolBox();
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    49
    final String SERVER_ARG = "--server:"
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    50
            + "portfile=testportfile,"
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    51
            + "background=false";
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    52
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    53
    // Generate 10 files
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    54
    for (int i = 0; i < 10; i++) {
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    55
      String fileName = "Test" + i;
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    56
      String content = "package foo"+ i + ";\n" +
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    57
                       "public class "+ fileName + "{\n" +
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    58
                       "  public static void main(String[] args) {}\n" +
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    59
                       "\n}";
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    60
      Path srcDir = Paths.get("src");
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    61
      tb.writeJavaFiles(srcDir,content);
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    62
    }
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    63
    //Method will throw an exception if compilation fails
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    64
    compile("src", "-d", "classes", "-j", "10", SERVER_ARG, "--log=debug");
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    65
  }
19f1ace44dab 8071629: Write new test to test -j switch
sogoel
parents:
diff changeset
    66
}