Path: blob/master/test/jdk/tools/jimage/JImageToolTest.java
41144 views
/*1* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/*23* @test24* @library /test/lib25* @build jdk.test.lib.process.ProcessTools26* @summary Test to check if jimage tool exists and is working27* @run main/timeout=360 JImageToolTest28*/2930import java.nio.file.Files;31import java.nio.file.Path;32import java.nio.file.Paths;33import java.util.ArrayList;34import java.util.Arrays;3536import jdk.test.lib.process.ProcessTools;3738/**39* Basic test for jimage tool.40*/41public class JImageToolTest {42private static void jimage(String... jimageArgs) throws Exception {43ArrayList<String> args = new ArrayList<>();44args.add("-ms64m");45args.add("jdk.tools.jimage.Main");46args.addAll(Arrays.asList(jimageArgs));4748ProcessBuilder builder = ProcessTools.createJavaProcessBuilder(args.toArray(new String[args.size()]));49int res = builder.inheritIO().start().waitFor();5051if (res != 0) {52throw new RuntimeException("JImageToolTest FAILED");53}54}5556public static void main(String[] args) throws Exception {57String home = System.getProperty("java.home");58Path jimagePath = Paths.get(home, "bin", "jimage");59Path modulesimagePath = Paths.get(home, "lib", "modules");6061if (Files.exists(jimagePath) && Files.exists(modulesimagePath)) {62String jimage = jimagePath.toAbsolutePath().toString();63jimage("--version");64System.out.println("Test successful");65} else {66System.out.println("Test skipped, not an images build");67}68}69}707172