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 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
/*
* Copyright (c) 2015, 2018, 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.
*/
/*
* @test
* @bug 8087112
* @library /lib/testlibrary/
* @modules java.net.http
* java.logging
* jdk.httpserver
* @build jdk.testlibrary.SimpleSSLContext jdk.testlibrary.Utils
* @compile ../../../../com/sun/net/httpserver/LogFilter.java
* @compile ../../../../com/sun/net/httpserver/FileServerHandler.java
* @compile ../ProxyServer.java
* @build Security
*
* @run main/othervm Driver
*/
/**
* driver required for allocating free portnumbers and putting this number
* into security policy file used in some tests.
*
* The tests are in Security.java and port number supplied in -Dport.number
* and -Dport.number1 for tests that require a second free port
*/
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import jdk.testlibrary.Utils;
/**
* Driver for tests
*/
public class Driver {
// change the default value to "true" to get the subprocess traces.
final static boolean DEBUG = Boolean.parseBoolean(System.getProperty("test.debug", "true"));
public static void main(String[] args) throws Throwable {
System.out.println("Starting Driver");
runtest("1.policy", "1");
runtest("10.policy", "10");
runtest("11.policy", "11");
runtest("12.policy", "12");
System.out.println("DONE");
}
static final Path CWD = Paths.get(".");
static class Logger extends Thread {
private final OutputStream ps;
private final InputStream stdout;
Logger(String cmdLine, Process p) throws IOException {
super();
setDaemon(true);
cmdLine = "Command line = [" + cmdLine + "]\n";
stdout = p.getInputStream();
File f = Files.createTempFile(CWD, "debug", ".txt").toFile();
ps = new FileOutputStream(f);
ps.write(cmdLine.getBytes());
ps.flush();
if (DEBUG) {
System.out.print(cmdLine);
System.out.flush();
}
}
public void run() {
try {
byte[] buf = new byte[128];
int c;
while ((c = stdout.read(buf)) != -1) {
if (DEBUG) {
System.out.write(buf, 0, c);
System.out.flush();
}
ps.write(buf, 0, c);
ps.flush();
}
ps.close();
} catch (Throwable e) {
e.printStackTrace();
}
}
}
public static void runtest(String policy, String testnum) throws Throwable {
String testJdk = System.getProperty("test.jdk", "?");
String testSrc = System.getProperty("test.src", "?");
String testClassPath = System.getProperty("test.class.path", "?");
String testClasses = System.getProperty("test.classes", "?");
String sep = System.getProperty("file.separator", "?");
String javaCmd = testJdk + sep + "bin" + sep + "java";
int retval = 10; // 10 is special exit code denoting a bind error
// in which case, we retry
while (retval == 10) {
List<String> cmd = new ArrayList<>();
cmd.add(javaCmd);
cmd.add("-ea");
cmd.add("-esa");
cmd.add("-Dtest.jdk=" + testJdk);
cmd.add("-Dtest.src=" + testSrc);
cmd.add("-Dtest.classes=" + testClasses);
cmd.add("-Djava.security.manager");
cmd.add("-Djava.security.policy=" + testSrc + sep + policy);
cmd.add("-Dport.number=" + Integer.toString(Utils.getFreePort()));
cmd.add("-Dport.number1=" + Integer.toString(Utils.getFreePort()));
cmd.add("-Djdk.httpclient.HttpClient.log=all,frames:all");
cmd.add("-cp");
cmd.add(testClassPath);
cmd.add("Security");
cmd.add(testnum);
ProcessBuilder processBuilder = new ProcessBuilder(cmd)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectErrorStream(true);
String cmdLine = cmd.stream().collect(Collectors.joining(" "));
long start = System.currentTimeMillis();
Process child = processBuilder.start();
Logger log = new Logger(cmdLine, child);
log.start();
retval = child.waitFor();
long elapsed = System.currentTimeMillis() - start;
System.out.println("Security " + testnum
+ ": retval = " + retval
+ ", duration=" + elapsed+" ms");
}
if (retval != 0) {
Thread.sleep(2000);
throw new RuntimeException("Non zero return value");
}
}
}
|