1 /*
2 * Copyright (c) 2007, 2019, 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 */
83 int modeIdx = 4;
84 int scenarioIdx = 6;
85
86 // add external flags
87 cmd.addAll(vmargs());
88
89 // add test specific arguments w/o signame
90 cmd.addAll(Arrays.asList(args)
91 .subList(1, args.length));
92
93 boolean passed = true;
94
95 for (String mode : new String[]{"sigset", "sigaction"}) {
96 for (String scenario : new String[] {"nojvm", "prepre", "prepost", "postpre", "postpost"}) {
97 cmd.set(modeIdx, mode);
98 cmd.set(scenarioIdx, scenario);
99 System.out.printf("START TESTING: SIGNAL = %s, MODE = %s, SCENARIO=%s%n",signame, mode, scenario);
100 System.out.printf("Do execute: %s%n", cmd.toString());
101
102 ProcessBuilder pb = new ProcessBuilder(cmd);
103 pb.environment().merge(envVar, jvmLibDir().toString(),
104 (x, y) -> y + File.pathSeparator + x);
105 pb.environment().put("CLASSPATH", Utils.TEST_CLASS_PATH);
106
107 switch (scenario) {
108 case "postpre":
109 case "postpost": {
110 pb.environment().merge("LD_PRELOAD", libjsig().toString(),
111 (x, y) -> y + File.pathSeparator + x);
112 }
113 }
114
115 try {
116 OutputAnalyzer oa = ProcessTools.executeProcess(pb);
117 oa.reportDiagnosticSummary();
118 int exitCode = oa.getExitValue();
119 if (exitCode == 0) {
120 System.out.println("PASSED with exit code 0");
121 } else {
122 System.out.println("FAILED with exit code " + exitCode);
123 passed = false;
126 throw new Error("execution failed", e);
127 }
128 }
129 }
130
131 if (!passed) {
132 throw new Error("test failed");
133 }
134 }
135
136 private static List<String> vmargs() {
137 return Stream.concat(Arrays.stream(Utils.VM_OPTIONS.split(" ")),
138 Arrays.stream(Utils.JAVA_OPTIONS.split(" ")))
139 .filter(s -> !s.isEmpty())
140 .filter(s -> s.startsWith("-X"))
141 .flatMap(arg -> Stream.of("-vmopt", arg))
142 .collect(Collectors.toList());
143 }
144
145 private static Path libjsig() {
146 return jvmLibDir().resolve((Platform.isWindows() ? "" : "lib")
147 + "jsig." + Platform.sharedLibraryExt());
148 }
149
150 private static Path jvmLibDir() {
151 Path dir = Paths.get(Utils.TEST_JDK);
152 if (Platform.isWindows()) {
153 return dir.resolve("bin")
154 .resolve(variant())
155 .toAbsolutePath();
156 } else {
157 return dir.resolve("lib")
158 .resolve(variant())
159 .toAbsolutePath();
160 }
161 }
162
163 private static String variant() {
164 if (Platform.isServer()) {
165 return "server";
166 } else if (Platform.isClient()) {
167 return "client";
168 } else if (Platform.isMinimal()) {
169 return "minimal";
170 } else {
171 throw new Error("TESTBUG: unsupported vm variant");
172 }
173 }
174 }
|
1 /*
2 * Copyright (c) 2007, 2020, 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 */
83 int modeIdx = 4;
84 int scenarioIdx = 6;
85
86 // add external flags
87 cmd.addAll(vmargs());
88
89 // add test specific arguments w/o signame
90 cmd.addAll(Arrays.asList(args)
91 .subList(1, args.length));
92
93 boolean passed = true;
94
95 for (String mode : new String[]{"sigset", "sigaction"}) {
96 for (String scenario : new String[] {"nojvm", "prepre", "prepost", "postpre", "postpost"}) {
97 cmd.set(modeIdx, mode);
98 cmd.set(scenarioIdx, scenario);
99 System.out.printf("START TESTING: SIGNAL = %s, MODE = %s, SCENARIO=%s%n",signame, mode, scenario);
100 System.out.printf("Do execute: %s%n", cmd.toString());
101
102 ProcessBuilder pb = new ProcessBuilder(cmd);
103 pb.environment().merge(envVar, Platform.jvmLibDir().toString(),
104 (x, y) -> y + File.pathSeparator + x);
105 pb.environment().put("CLASSPATH", Utils.TEST_CLASS_PATH);
106
107 switch (scenario) {
108 case "postpre":
109 case "postpost": {
110 pb.environment().merge("LD_PRELOAD", libjsig().toString(),
111 (x, y) -> y + File.pathSeparator + x);
112 }
113 }
114
115 try {
116 OutputAnalyzer oa = ProcessTools.executeProcess(pb);
117 oa.reportDiagnosticSummary();
118 int exitCode = oa.getExitValue();
119 if (exitCode == 0) {
120 System.out.println("PASSED with exit code 0");
121 } else {
122 System.out.println("FAILED with exit code " + exitCode);
123 passed = false;
126 throw new Error("execution failed", e);
127 }
128 }
129 }
130
131 if (!passed) {
132 throw new Error("test failed");
133 }
134 }
135
136 private static List<String> vmargs() {
137 return Stream.concat(Arrays.stream(Utils.VM_OPTIONS.split(" ")),
138 Arrays.stream(Utils.JAVA_OPTIONS.split(" ")))
139 .filter(s -> !s.isEmpty())
140 .filter(s -> s.startsWith("-X"))
141 .flatMap(arg -> Stream.of("-vmopt", arg))
142 .collect(Collectors.toList());
143 }
144
145 private static Path libjsig() {
146 return Platform.jvmLibDir().resolve((Platform.isWindows() ? "" : "lib")
147 + "jsig." + Platform.sharedLibraryExt());
148 }
149 }
|