1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
/*
* Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import jdk.test.lib.Platform;
import jdk.test.lib.Utils;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jtreg.SkippedException;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class SigTestDriver {
public static void main(String[] args) {
// No signal tests on Windows yet; so setting to no-op
if (Platform.isWindows()) {
throw new SkippedException("no signal tests on Windows");
}
// At least one argument should be specified
if ((args == null) || (args.length < 1)) {
throw new IllegalArgumentException("At lease one argument should be specified, the signal name");
}
String signame = args[0];
switch (signame) {
case "SIGWAITING":
case "SIGKILL":
case "SIGSTOP": {
throw new SkippedException("signals SIGWAITING, SIGKILL and SIGSTOP can't be tested");
}
case "SIGUSR2": {
if (Platform.isLinux()) {
throw new SkippedException("SIGUSR2 can't be tested on Linux");
} else if (Platform.isOSX()) {
throw new SkippedException("SIGUSR2 can't be tested on OS X");
}
}
}
Path test = Paths.get(Utils.TEST_NATIVE_PATH)
.resolve("sigtest")
.toAbsolutePath();
String envVar = Platform.sharedLibraryPathVariableName();
List<String> cmd = new ArrayList<>();
Collections.addAll(cmd,
test.toString(),
"-sig",
signame,
"-mode",
null, // modeIdx
"-scenario",
null // scenarioIdx
);
int modeIdx = 4;
int scenarioIdx = 6;
// add external flags
cmd.addAll(vmargs());
// add test specific arguments w/o signame
var argList = Arrays.asList(args)
.subList(1, args.length);
cmd.addAll(argList);
boolean passed = true;
for (String mode : new String[] {"sigset", "sigaction"}) {
for (String scenario : new String[] {"nojvm", "prepre", "prepost", "postpre", "postpost"}) {
cmd.set(modeIdx, mode);
cmd.set(scenarioIdx, scenario);
System.out.printf("START TESTING: SIGNAL = %s, MODE = %s, SCENARIO=%s%n", signame, mode, scenario);
System.out.printf("Do execute: %s%n", cmd.toString());
ProcessBuilder pb = new ProcessBuilder(cmd);
pb.environment().merge(envVar, Platform.jvmLibDir().toString(),
(x, y) -> y + File.pathSeparator + x);
pb.environment().put("CLASSPATH", Utils.TEST_CLASS_PATH);
switch (scenario) {
case "postpre":
case "postpost": {
pb.environment().merge("LD_PRELOAD", libjsig().toString(),
(x, y) -> y + File.pathSeparator + x);
}
}
try {
OutputAnalyzer oa = ProcessTools.executeProcess(pb);
oa.reportDiagnosticSummary();
int exitCode = oa.getExitValue();
if (exitCode == 0) {
System.out.println("PASSED with exit code 0");
} else {
System.out.println("FAILED with exit code " + exitCode);
passed = false;
}
} catch (Exception e) {
throw new Error("execution failed", e);
}
}
}
if (!passed) {
throw new Error("test failed");
}
}
private static List<String> vmargs() {
return Stream.concat(Arrays.stream(Utils.VM_OPTIONS.split(" ")),
Arrays.stream(Utils.JAVA_OPTIONS.split(" ")))
.filter(s -> !s.isEmpty())
.filter(s -> s.startsWith("-X"))
.flatMap(arg -> Stream.of("-vmopt", arg))
.collect(Collectors.toList());
}
private static Path libjsig() {
return Platform.jvmLibDir().resolve((Platform.isWindows() ? "" : "lib")
+ "jsig." + Platform.sharedLibraryExt());
}
}
|