1 /*
2 * Copyright (c) 2015, 2017, 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 *
52 String source = "package javax.naming.spi; " +
53 "public class NamingManager { " +
54 " static { " +
55 " System.out.println(\"I pass!\"); " +
56 " } " +
57 "}";
58 ClassFileInstaller.writeClassToDisk("javax/naming/spi/NamingManager",
59 InMemoryJavaCompiler.compile("javax.naming.spi.NamingManager", source, "--patch-module=java.naming"),
60 "mods/java.naming");
61
62 JarBuilder.build("hello", "Hello");
63 JarBuilder.build("hello_more", "HelloMore");
64
65 (new JigsawOptionsCombo()).runTests();
66 }
67
68
69 private ArrayList<TestCase> testCaseTable = new ArrayList<TestCase>();
70
71 public static String infoDuringDump(String option) {
72 return "Info: the " + option +
73 " option is ignored when dumping the shared archive";
74 }
75
76 public void runTests() throws Exception {
77
78 testCaseTable.add(new TestCase(
79 "basic: Basic dump and execute, to verify the test plumbing works",
80 "", "", 0,
81 "", "", 0) );
82
83 String bcpArg = "-Xbootclasspath/a:" +
84 TestCommon.getTestJar("hello_more.jar");
85
86 testCaseTable.add(new TestCase(
87 "Xbootclasspath/a: is OK for both dump and run time",
88 bcpArg, "", 0,
89 bcpArg, "", 0) );
90
91 testCaseTable.add(new TestCase(
92 "module-path-01: --module-path is ignored for dump time",
93 "--module-path mods",
94 infoDuringDump("--module-path"), 0,
95 null, null, 0) );
96
97 testCaseTable.add(new TestCase(
98 "module-path-02: --module-path is ok for run time",
99 "", "", 0,
100 "--module-path mods", "", 0) );
101
102 testCaseTable.add(new TestCase(
103 "add-modules-01: --add-modules is ok at dump time",
104 "--add-modules java.management",
105 "", 0,
106 null, null, 0) );
107
108 testCaseTable.add(new TestCase(
109 "add-modules-02: --add-modules is ok at run time",
110 "", "", 0,
111 "--add-modules java.management", "", 0) );
112
113 testCaseTable.add(new TestCase(
114 "limit-modules-01: --limit-modules is ignored at dump time",
115 "--limit-modules java.base",
116 infoDuringDump("--limit-modules"), 0,
117 null, null, 0) );
118
119 testCaseTable.add(new TestCase(
120 "limit-modules-02: --limit-modules is ok at run time",
121 "", "", 0,
122 "--limit-modules java.base", "", 0) );
123
124 testCaseTable.add(new TestCase(
125 "upgrade-module-path-01: --upgrade-module-path is ignored at dump time",
126 "--upgrade-module-path mods",
127 infoDuringDump("--upgrade-module-path"), 0,
128 null, null, 0) );
129
130 testCaseTable.add(new TestCase(
131 "-upgrade-module-path-module-path-02: --upgrade-module-path is ok at run time",
132 "", "", 0,
133 "--upgrade-module-path mods", "", 0) );
134
135 for (TestCase tc : testCaseTable) tc.execute();
136 }
137
138
139 // class representing a singe test case
140 public class TestCase {
141 String description;
142 String dumpTimeArgs;
143 String dumpTimeExpectedOutput;
144 int dumpTimeExpectedExitValue;
145 String runTimeArgs;
146 String runTimeExpectedOutput;
147 int runTimeExpectedExitValue;
148
149 private String appJar = TestCommon.getTestJar("hello.jar");
150 private String appClasses[] = {"Hello"};
151
152
153 public TestCase(String description,
154 String dumpTimeArgs, String dumpTimeExpectedOutput, int dumpTimeExpectedExitValue,
155 String runTimeArgs, String runTimeExpectedOutput, int runTimeExpectedExitValue) {
156
157 this.description = description;
158 this.dumpTimeArgs = dumpTimeArgs;
159 this.dumpTimeExpectedOutput = dumpTimeExpectedOutput;
160 this.dumpTimeExpectedExitValue = dumpTimeExpectedExitValue;
161 this.runTimeArgs = runTimeArgs;
162 this.runTimeExpectedOutput = runTimeExpectedOutput;
163 this.runTimeExpectedExitValue = runTimeExpectedExitValue;
164 }
165
166
167 public void execute() throws Exception {
168 System.out.println("Description: " + description);
169
170 // ===== dump step - create the archive
171 OutputAnalyzer dumpOutput = TestCommon.dump(
172 appJar, appClasses, getDumpOptions());
173
174 if (dumpTimeExpectedExitValue == 0) {
175 TestCommon.checkDump(dumpOutput, dumpTimeExpectedOutput);
176 } else {
177 dumpOutput.shouldMatch(dumpTimeExpectedOutput);
178 dumpOutput.shouldHaveExitValue(dumpTimeExpectedExitValue);
179 }
180
181 // ===== exec step - use the archive
182 if (runTimeArgs != null) {
183 OutputAnalyzer execOutput = TestCommon.exec(appJar, getRunOptions());
184
185 if (runTimeExpectedExitValue == 0) {
186 TestCommon.checkExec(execOutput, runTimeExpectedOutput, "Hello World");
187 } else {
188 execOutput.shouldMatch(dumpTimeExpectedOutput);
189 execOutput.shouldHaveExitValue(dumpTimeExpectedExitValue);
190 }
191 }
192 }
193
194
195 // dump command line options can be separated by a space
196 private String[] getDumpOptions() {
197 return dumpTimeArgs.split(" ");
198 }
199
200
201 // run command line options can be separated by a space
202 private String[] getRunOptions() {
203 ArrayList<String> result = new ArrayList<>();
204
205 if (runTimeArgs != "") {
206 String splitArgs[] = runTimeArgs.split(" ");
|
1 /*
2 * Copyright (c) 2015, 2018, 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 *
52 String source = "package javax.naming.spi; " +
53 "public class NamingManager { " +
54 " static { " +
55 " System.out.println(\"I pass!\"); " +
56 " } " +
57 "}";
58 ClassFileInstaller.writeClassToDisk("javax/naming/spi/NamingManager",
59 InMemoryJavaCompiler.compile("javax.naming.spi.NamingManager", source, "--patch-module=java.naming"),
60 "mods/java.naming");
61
62 JarBuilder.build("hello", "Hello");
63 JarBuilder.build("hello_more", "HelloMore");
64
65 (new JigsawOptionsCombo()).runTests();
66 }
67
68
69 private ArrayList<TestCase> testCaseTable = new ArrayList<TestCase>();
70
71 public static String infoDuringDump(String option) {
72 return "Cannot use the following option when dumping the shared archive: " + option;
73 }
74
75 public void runTests() throws Exception {
76
77 testCaseTable.add(new TestCase(
78 "basic: Basic dump and execute, to verify the test plumbing works",
79 "", "", 0,
80 "", "", 0, true) );
81
82 String bcpArg = "-Xbootclasspath/a:" +
83 TestCommon.getTestJar("hello_more.jar");
84
85 testCaseTable.add(new TestCase(
86 "Xbootclasspath/a: is OK for both dump and run time",
87 bcpArg, "", 0,
88 bcpArg, "", 0, true) );
89
90 testCaseTable.add(new TestCase(
91 "module-path-01: --module-path is ignored for dump time",
92 "--module-path mods", "", 0,
93 null, null, 0, true) );
94
95 testCaseTable.add(new TestCase(
96 "module-path-02: --module-path is ok for run time",
97 "", "", 0,
98 "--module-path mods", "", 0, true) );
99
100 testCaseTable.add(new TestCase(
101 "add-modules-01: --add-modules is ok at dump time",
102 "--add-modules java.management",
103 "", 0,
104 null, null, 0, true) );
105
106 testCaseTable.add(new TestCase(
107 "add-modules-02: --add-modules is ok at run time",
108 "", "", 0,
109 "--add-modules java.management", "", 0, true) );
110
111 testCaseTable.add(new TestCase(
112 "limit-modules-01: --limit-modules is ignored at dump time",
113 "--limit-modules java.base",
114 infoDuringDump("--limit-modules"), 1,
115 null, null, 0, true) );
116
117 testCaseTable.add(new TestCase(
118 "limit-modules-02: --limit-modules is ok at run time",
119 "", "", 0,
120 "--limit-modules java.base", "", 0, false) );
121
122 testCaseTable.add(new TestCase(
123 "upgrade-module-path-01: --upgrade-module-path is ignored at dump time",
124 "--upgrade-module-path mods",
125 infoDuringDump("--upgrade-module-path"), 1,
126 null, null, 0, true) );
127
128 testCaseTable.add(new TestCase(
129 "-upgrade-module-path-module-path-02: --upgrade-module-path is ok at run time",
130 "", "", 0,
131 "--upgrade-module-path mods", "", 0, false) );
132
133 for (TestCase tc : testCaseTable) tc.execute();
134 }
135
136
137 // class representing a singe test case
138 public class TestCase {
139 String description;
140 String dumpTimeArgs;
141 String dumpTimeExpectedOutput;
142 int dumpTimeExpectedExitValue;
143 String runTimeArgs;
144 String runTimeExpectedOutput;
145 int runTimeExpectedExitValue;
146 boolean sharingOn;
147
148 private String appJar = TestCommon.getTestJar("hello.jar");
149 private String appClasses[] = {"Hello"};
150
151
152 public TestCase(String description,
153 String dumpTimeArgs, String dumpTimeExpectedOutput, int dumpTimeExpectedExitValue,
154 String runTimeArgs, String runTimeExpectedOutput, int runTimeExpectedExitValue,
155 boolean sharingOn) {
156
157 this.description = description;
158 this.dumpTimeArgs = dumpTimeArgs;
159 this.dumpTimeExpectedOutput = dumpTimeExpectedOutput;
160 this.dumpTimeExpectedExitValue = dumpTimeExpectedExitValue;
161 this.runTimeArgs = runTimeArgs;
162 this.runTimeExpectedOutput = runTimeExpectedOutput;
163 this.runTimeExpectedExitValue = runTimeExpectedExitValue;
164 this.sharingOn = sharingOn;
165 }
166
167
168 public void execute() throws Exception {
169 System.out.println("Description: " + description);
170
171 // ===== dump step - create the archive
172 OutputAnalyzer dumpOutput = TestCommon.dump(
173 appJar, appClasses, getDumpOptions());
174
175 if (dumpTimeExpectedExitValue == 0) {
176 TestCommon.checkDump(dumpOutput, dumpTimeExpectedOutput);
177 } else {
178 dumpOutput.shouldMatch(dumpTimeExpectedOutput);
179 dumpOutput.shouldHaveExitValue(dumpTimeExpectedExitValue);
180 }
181
182 // ===== exec step - use the archive
183 if (runTimeArgs != null) {
184 OutputAnalyzer execOutput = TestCommon.exec(appJar, getRunOptions());
185
186 if (runTimeExpectedExitValue == 0) {
187 if (sharingOn) {
188 TestCommon.checkExec(execOutput, runTimeExpectedOutput, "Hello World");
189 } else {
190 execOutput.shouldHaveExitValue(0)
191 .shouldContain(runTimeExpectedOutput)
192 .shouldContain("Hello World");
193 }
194 } else {
195 execOutput.shouldMatch(dumpTimeExpectedOutput);
196 execOutput.shouldHaveExitValue(dumpTimeExpectedExitValue);
197 }
198 }
199 }
200
201
202 // dump command line options can be separated by a space
203 private String[] getDumpOptions() {
204 return dumpTimeArgs.split(" ");
205 }
206
207
208 // run command line options can be separated by a space
209 private String[] getRunOptions() {
210 ArrayList<String> result = new ArrayList<>();
211
212 if (runTimeArgs != "") {
213 String splitArgs[] = runTimeArgs.split(" ");
|