1 /*
 2  * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
 3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  *
 5  * This code is free software; you can redistribute it and/or modify it
 6  * under the terms of the GNU General Public License version 2 only, as
 7  * published by the Free Software Foundation.
 8  *
 9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 import java.io.File;
25 
26 import jdk.test.lib.JDKToolFinder;
27 import jdk.test.lib.Platform;
28 import jdk.test.lib.process.*;
29 
30 import tests.Helper;
31 
32 import jtreg.SkippedException;
33 
34 /* @test
35  * @bug 8264322
36  * @summary Test the --generate-cds-archive plugin
37  * @requires vm.cds
38  * @library ../../lib
39  * @library /test/lib
40  * @modules java.base/jdk.internal.jimage
41  *          jdk.jdeps/com.sun.tools.classfile
42  *          jdk.jlink/jdk.tools.jlink.internal
43  *          jdk.jlink/jdk.tools.jmod
44  *          jdk.jlink/jdk.tools.jimage
45  *          jdk.compiler
46  * @build tests.*
47  * @run main CDSPluginTest
48  */
49 
50 public class CDSPluginTest {
51 
52     public static void main(String[] args) throws Throwable {
53 
54         if (!Platform.isDefaultCDSArchiveSupported())
55             throw new SkippedException("not a supported platform");
56 
57         Helper helper = Helper.newHelper();
58         if (helper == null) {
59             System.err.println("Test not run");
60             return;
61         }
62 
63         var module = "cds";
64         helper.generateDefaultJModule(module);
65         var image = helper.generateDefaultImage(new String[] { "--generate-cds-archive" },
66                                                 module)
67             .assertSuccess();
68 
69         String subDir;
70         String sep = File.separator;
71         if (Platform.isWindows()) {
72             subDir = "bin" + sep;
73         } else {
74             subDir = "lib" + sep;
75         }
76         subDir += "server" + sep;
77 
78         if (Platform.isAArch64() || Platform.isX64()) {
79             helper.checkImage(image, module, null, null,
80                       new String[] { subDir + "classes.jsa", subDir + "classes_nocoops.jsa" });
81         } else {
82             helper.checkImage(image, module, null, null,
83                       new String[] { subDir + "classes.jsa" });
84         }
85     }
86 }