提交 bf3ca964 编写于 作者: J jbachorik

8230448: [test] JFRSecurityTestSuite.java is failing on Windows

Reviewed-by: neugens
上级 eb332e67
......@@ -63,9 +63,13 @@ import jdk.jfr.Name;
import jdk.jfr.Recording;
import jdk.jfr.ValueDescriptor;
import jdk.test.lib.Platform;
/*
* @test
* @requires (jdk.version.major >= 8)
* @library /lib /
* @key jfr
* @run main/othervm/timeout=30 -XX:+FlightRecorder -XX:StartFlightRecording JFRSecurityTestSuite
* @author Martin Balao (mbalao@redhat.com)
*/
......@@ -77,6 +81,7 @@ public class JFRSecurityTestSuite {
private static String failureMessage = null;
private static Path jfrTmpDirPath = null;
private static Path recFilePath = null;
private static String protectedLocationPath;
interface F {
void call() throws Exception;
......@@ -136,6 +141,8 @@ public class JFRSecurityTestSuite {
jfrTmpDirPath = Files.createTempDirectory("jfr_test");
try {
setProtectedLocation();
File recFile = new File(jfrTmpDirPath.toString(), "rec");
recFile.createNewFile();
recFilePath = recFile.toPath();
......@@ -219,10 +226,19 @@ public class JFRSecurityTestSuite {
}
}
private static void doInConstrainedEnvironment() throws Throwable {
final String testPath = "/etc";
private static void setProtectedLocation() {
if (Platform.isWindows()) {
protectedLocationPath = System.getenv("%WINDIR%");
if (protectedLocationPath == null) {
// fallback
protectedLocationPath = "c:\\windows";
}
} else {
protectedLocationPath = "/etc";
}
}
private static void doInConstrainedEnvironment() throws Throwable {
checkNoDirectAccess();
assertPermission(() -> {
......@@ -258,8 +274,8 @@ public class JFRSecurityTestSuite {
}, FlightRecorderPermission.class, "registerEvent", true);
assertPermission(() -> {
Configuration.create(Paths.get(testPath));
}, FilePermission.class, testPath, false);
Configuration.create(Paths.get(protectedLocationPath));
}, FilePermission.class, protectedLocationPath, false);
assertPermission(() -> {
EventFactory.create(new ArrayList<AnnotationElement>(),
......@@ -280,12 +296,12 @@ public class JFRSecurityTestSuite {
}, FlightRecorderPermission.class, "accessFlightRecorder", false);
assertPermission(() -> {
new RecordingFile(Paths.get(testPath));
}, FilePermission.class, testPath, false);
new RecordingFile(Paths.get(protectedLocationPath));
}, FilePermission.class, protectedLocationPath, false);
assertPermission(() -> {
RecordingFile.readAllEvents(Paths.get(testPath));
}, FilePermission.class, testPath, false);
RecordingFile.readAllEvents(Paths.get(protectedLocationPath));
}, FilePermission.class, protectedLocationPath, false);
assertPermission(() -> {
EventType.getEventType(MyEvent2.class);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册