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