jdk/test/tools/jimage/JImageToolTest.java
author jlaskey
Mon, 25 Apr 2016 09:57:55 -0300
changeset 37615 d4486cdacf4e
parent 36511 9d0388c6b336
child 39762 935ffb4260ba
permissions -rw-r--r--
8154090: Remove support for jimage recreate Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    23
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    24
 * @test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
 * @library /lib/testlibrary
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
 * @build jdk.testlibrary.*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
 * @summary Test to see if jimage tool extracts and recreates correctly.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
 * @run main/timeout=360 JImageToolTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import java.nio.file.Files;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import java.nio.file.Path;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.nio.file.Paths;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import java.util.ArrayList;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import java.util.Arrays;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import jdk.testlibrary.ProcessTools;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
 * Basic test for jimage tool.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
public class JImageToolTest {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
    private static void jimage(String... jimageArgs) throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
        ArrayList<String> args = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
        args.add("-ms8m");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
        args.add("jdk.tools.jimage.Main");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
        args.addAll(Arrays.asList(jimageArgs));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
        ProcessBuilder builder = ProcessTools.createJavaProcessBuilder(args.toArray(new String[args.size()]));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
        int res = builder.inheritIO().start().waitFor();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
        if (res != 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
            throw new RuntimeException("JImageToolTest FAILED");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
    public static void main(String[] args) throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
        String home = System.getProperty("java.home");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
        Path jimagePath = Paths.get(home, "bin", "jimage");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        Path modulesimagePath = Paths.get(home, "lib", "modules");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
        if (Files.exists(jimagePath) && Files.exists(modulesimagePath)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
            String jimage = jimagePath.toAbsolutePath().toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
            String bootimage = modulesimagePath.toAbsolutePath().toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
            String extractDir = Paths.get(".", "extract").toAbsolutePath().toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
            jimage("extract", "--dir", extractDir, bootimage);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
            System.out.println("Test successful");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
         } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
            System.out.println("Test skipped, not an images build");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
         }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
}