--- /dev/null 2015-10-28 19:12:34.000000000 +0300 +++ new/runtime/ThreadSignalMask/ThreadSignalMask.java 2015-10-28 19:12:34.000000000 +0300 @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + */ + +import java.io.File; +import java.lang.ProcessBuilder.Redirect; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.Arrays; +import java.util.List; + +/* + * @test + * @key cte_test + * @bug 4345157 + * @summary JDK 1.3.0 alters thread signal mask + * @requires (os.simpleArch == "sparcv9" & vm.flavor == "server") + * @compile Prog.java + * @run main/native ThreadSignalMask + */ +public class ThreadSignalMask { + + public static void main(String args[]) throws Exception { + + String testClasses = getSystemProperty("test.classes"); + + String testNativePath = getSystemProperty("test.nativepath"); + + String testJdk = getSystemProperty("test.jdk"); + + String currentDirPath = Paths.get(".") + .toAbsolutePath().normalize().toString(); + + File classFile + = new File(testClasses + File.separator + + Prog.class.getSimpleName()); + + //copy Prog.class file to be invoked from native + Files.copy(classFile.toPath(), (new File(currentDirPath + + File.separator + classFile.getName())) + .toPath(), StandardCopyOption.REPLACE_EXISTING); + + //copy compiled native executable + File executableFile = new File(testNativePath + File.separator + + ThreadSignalMask.class.getSimpleName()); + File executableFileLocal = new File(currentDirPath + File.separator + + executableFile.getName()); + Files.copy(executableFile.toPath(), executableFileLocal.toPath(), + StandardCopyOption.REPLACE_EXISTING); + + executableFileLocal.setExecutable(true); + + long[] intervalsArray = {2000, 5000, 10000, 2000}; + + List processArgs = Arrays.asList(executableFileLocal.getPath(), + testJdk + ); + ProcessBuilder pb = new ProcessBuilder(processArgs); + pb.redirectOutput(Redirect.INHERIT); + pb.redirectError(Redirect.INHERIT); + int result = 0; + for (int i = 0; i < intervalsArray.length; i++) { + Process p = pb.start(); + + //sleep for a specified period of time to let native run + sleep(intervalsArray[i]); + p.destroy(); + //sleep for a specified period of time to let native exit + sleep(intervalsArray[i]); + + //get exit value and validate it + result = p.exitValue(); + System.out.println("Result = " + result); + if (result == 0) { + break; + } + } + + if (result != 0) { + throw new Exception("Test Failed"); + } + + System.out.println("Test Passed"); + + } + + /** + * Utility method to handle Thread.sleep + * @param millis to specify sleep period + */ + private static void sleep(long millis) { + try { + System.out.println("Sleep for " + millis); + Thread.sleep(millis); + } catch (InterruptedException ex) { + System.err.println("Interrupted"); + } + } + + /** + * Utility method to retrieve and validate system properties + * @param propertyName system property to retrieve + * @return retrieved system property + * @throws Exception if system property is empty + */ + private static String getSystemProperty(String propertyName) throws Exception { + String systemProperty = System.getProperty(propertyName, "").trim(); + System.out.println(propertyName + " = " + systemProperty); + if (systemProperty.isEmpty()) { + throw new Exception("Property " + propertyName + " is empty"); + } + return systemProperty; + } +}