1 /*
  2  * Copyright (c) 2024, 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 
 25 import java.io.File;
 26 import java.nio.file.Path;
 27 import java.util.Map;
 28 import jdk.test.lib.StringArrayUtils;
 29 import jdk.test.lib.artifacts.Artifact;
 30 import jdk.test.lib.artifacts.ArtifactResolver;
 31 import jdk.test.lib.cds.CDSAppTester;
 32 import jdk.test.lib.process.OutputAnalyzer;
 33 
 34 /*
 35  * @test id=static
 36  * @key external-dep
 37  * @requires vm.cds
 38  * @summary run QuarkusGettingStarted with the classic static archive workflow
 39  * @library /test/lib
 40  * @run driver/timeout=120 QuarkusGettingStarted STATIC
 41  */
 42 
 43 /*
 44  * @test id=dynamic
 45  * @key external-dep
 46  * @requires vm.cds
 47  * @summary run QuarkusGettingStarted with the classic dynamic archive workflow
 48  * @library /test/lib
 49  * @run driver/timeout=120 QuarkusGettingStarted DYNAMIC
 50  */
 51 
 52 /*
 53  * @test id=leyden
 54  * @key external-dep
 55  * @requires vm.cds
 56  * @requires vm.cds.write.archived.java.heap
 57  * @summary un QuarkusGettingStarted with the Leyden workflow
 58  * @library /test/lib
 59  * @run driver/timeout=120 QuarkusGettingStarted LEYDEN
 60  */
 61 
 62 // Test CDS with the example program in https://quarkus.io/guides/getting-started
 63 //
 64 // NOTE: if you have not set up an artifactory, you can create quarkus-getting-started-1.0.0b.zip by:
 65 //
 66 // - Make a clone of https://github.com/openjdk/leyden/tree/premain
 67 // - Change to the directory test/hotspot/jtreg/premain/quarkus-getting-started
 68 // - Edit the Makefile and ../lib/DemoSupport.gmk as necessary
 69 // - Run the command "make artifact"
 70 //
 71 // Then, you can add the following to your jtreg command-line to run the test cases in this directory:
 72 // -vmoption:-Djdk.test.lib.artifacts.quarkus-getting-started=/my/repo/test/hotspot/jtreg/premain/quarkus-getting-started/getting-started/target
 73 
 74 @Artifact(organization = "io.quarkus", name = "quarkus-getting-started", revision = "1.0.0b", extension = "zip")
 75 public class QuarkusGettingStarted {
 76     public static void main(String args[]) throws Exception {
 77         String cp = getArtifact();
 78         QuarkusGettingStartedTester tester = new QuarkusGettingStartedTester(cp);
 79         tester.run(args);
 80         System.out.println(cp);
 81     }
 82 
 83     private static String getArtifact() throws Exception {
 84         Map<String, Path> artifacts = ArtifactResolver.resolve(QuarkusGettingStarted.class);
 85         Path path = artifacts.get("io.quarkus.quarkus-getting-started-1.0.0b");
 86         return path.toString() + File.separator + "getting-started-1.0.0-SNAPSHOT-runner.jar";
 87     }
 88 
 89     static class QuarkusGettingStartedTester extends CDSAppTester {
 90         String cp;
 91 
 92         QuarkusGettingStartedTester(String cp) {
 93             super("QuarkusGettingStarted");
 94             this.cp = cp;
 95         }
 96 
 97         @Override
 98         public String[] vmArgs(RunMode runMode) {
 99             return new String[] {
100                 "-DautoQuit=true",
101                 "-Dquarkus.http.port=0", // use system-assigned port
102 
103                 // This program may run very slowly in debug builds if VerifyDependencies is enabled.
104                 "-XX:+IgnoreUnrecognizedVMOptions", "-XX:-VerifyDependencies",
105             };
106         }
107 
108         @Override
109         public String classpath(RunMode runMode) {
110             return cp;
111         }
112 
113         @Override
114         public String[] appCommandLine(RunMode runMode) {
115             String cmdLine[] = new String[] {
116                 "Main", 
117             };
118 
119             if (runMode.isProductionRun()) {
120                 cmdLine = StringArrayUtils.concat("-Xlog:scc=error", cmdLine);
121             }
122             return cmdLine;
123         }
124 
125         @Override
126         public void checkExecution(OutputAnalyzer out, RunMode runMode) {
127             if (!runMode.isStaticDump()) {
128                 out.shouldContain("Booted and returned in ");
129             }
130         }
131     }
132 }