提交 d363c21d 编写于 作者: A alanb

6962419: TEST_BUG: java_io tests fails in samevm mode

Reviewed-by: ohair, sherman
上级 47d4546f
...@@ -187,73 +187,6 @@ java/beans/XMLEncoder/6329581/Test6329581.java generic-all ...@@ -187,73 +187,6 @@ java/beans/XMLEncoder/6329581/Test6329581.java generic-all
############################################################################ ############################################################################
# jdk_io
# Many of these tests have a tendency to leave input streams open, which
# will cause following tests to be failures when used in samevm mode.
# Should be othervm, or corrected for samevm, fails with samevm:
java/io/BufferedReader/BigMark.java generic-all
java/io/BufferedReader/ReadLineSync.java generic-all
# Windows samevm issues? triggers other tests to fail, missing close() on f.txt?
java/io/DataInputStream/OpsAfterClose.java generic-all
# Windows 32bit samevm failure: RuntimeException: File.getFreeSpace() failed
java/io/File/MaxPathLength.java generic-all
# Should be othervm, or corrected for samevm, fails with samevm:
java/io/File/DeleteOnExit.java generic-all
java/io/File/DeleteOnExitLong.java generic-all
java/io/File/DeleteOnExitNPE.java generic-all
java/io/File/IsHidden.java generic-all
java/io/FileDescriptor/FileChannelFDTest.java generic-all
java/io/FileDescriptor/Finalize.java generic-all
java/io/FileInputStream/FinalizeShdCallClose.java generic-all
# Known to cause samevm issues on windows, other tests fail, missing close()?
java/io/FileInputStream/OpsAfterClose.java generic-all
# Should be othervm, or corrected for samevm, fails with samevm:
java/io/FileOutputStream/FinalizeShdCallClose.java generic-all
# Known to cause samevm issues on windows, other tests fail, missing close()?
java/io/FileOutputStream/OpsAfterClose.java generic-all
# Windows samevm issues? triggers other tests to fail, missing close() on f.txt?
java/io/InputStream/OpsAfterClose.java generic-all
# Missing close() on x.ReadBounds file? Windows samevm issues
java/io/InputStream/ReadParams.java generic-all
# Known to cause samevm issues on windows, other tests fail, missing close()?
java/io/InputStreamReader/GrowAfterEOF.java generic-all
# Should be othervm, or corrected for samevm, fails with samevm:
java/io/ObjectInputStream/ResolveProxyClass.java generic-all
# Not doing a close() on x.ParameterCheck file? windows samevm cascade error
java/io/RandomAccessFile/ParameterCheck.java generic-all
# Not doing a close on x.ReadLine file? windows cascade samevm problems
java/io/RandomAccessFile/ReadLine.java generic-all
# Not doing close on file input x.WriteByteChars, windows samevm problems
java/io/RandomAccessFile/WriteBytesChars.java generic-all
# Not doing close on file input x.WriteUTF, windows samevm problems
java/io/RandomAccessFile/WriteUTF.java generic-all
# Possibly, not doing a close() on input.txt, windows samevm issues.
java/io/RandomAccessFile/skipBytes/SkipBytes.java generic-all
java/io/readBytes/MemoryLeak.java generic-all
java/io/readBytes/ReadBytesBounds.java generic-all
# Possibly not doing a close() on input.txt, windows samevm issues.
java/io/StreamTokenizer/Comment.java generic-all
############################################################################
# jdk_lang # jdk_lang
# Times out on solaris 10 sparc # Times out on solaris 10 sparc
...@@ -593,10 +526,6 @@ java/nio/channels/Selector/Wakeup.java windows-all ...@@ -593,10 +526,6 @@ java/nio/channels/Selector/Wakeup.java windows-all
com/sun/nio/sctp/SctpChannel/Send.java generic-all com/sun/nio/sctp/SctpChannel/Send.java generic-all
com/sun/nio/sctp/SctpChannel/Shutdown.java generic-all com/sun/nio/sctp/SctpChannel/Shutdown.java generic-all
# Fails on Windows 2000, Can't delete test directory .\x.SetLastModified.dir
# at SetLastModified.main(SetLastModified.java:107)
java/io/File/SetLastModified.java generic-all
# Fails on Windows 2000, times out # Fails on Windows 2000, times out
java/nio/channels/FileChannel/Transfer.java generic-all java/nio/channels/FileChannel/Transfer.java generic-all
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
@summary BufferedReader should throw an OutOfMemoryError when the @summary BufferedReader should throw an OutOfMemoryError when the
read-ahead limit is very large read-ahead limit is very large
@bug 6350733 @bug 6350733
@build BigMark
@run main/othervm BigMark
*/ */
import java.io.*; import java.io.*;
......
...@@ -46,6 +46,7 @@ public class ReadLineSync { ...@@ -46,6 +46,7 @@ public class ReadLineSync {
BufferedReader reader = new BufferedReader( BufferedReader reader = new BufferedReader(
new FileReader(f)); new FileReader(f));
try {
int threadCount = 2; int threadCount = 2;
ExecutorService es = Executors.newFixedThreadPool(threadCount); ExecutorService es = Executors.newFixedThreadPool(threadCount);
...@@ -56,6 +57,9 @@ public class ReadLineSync { ...@@ -56,6 +57,9 @@ public class ReadLineSync {
// Wait for the tasks to complete // Wait for the tasks to complete
es.shutdown(); es.shutdown();
while (!es.awaitTermination(60, TimeUnit.SECONDS)); while (!es.awaitTermination(60, TimeUnit.SECONDS));
} finally {
reader.close();
}
} }
static class BufferedReaderConsumer extends Thread { static class BufferedReaderConsumer extends Thread {
......
...@@ -244,13 +244,19 @@ public enum OpsAfterClose { ...@@ -244,13 +244,19 @@ public enum OpsAfterClose {
f.deleteOnExit(); f.deleteOnExit();
FileInputStream fis = new FileInputStream(f); FileInputStream fis = new FileInputStream(f);
try {
DataInputStream dis = new DataInputStream( DataInputStream dis = new DataInputStream(
new FileInputStream(f)); new FileInputStream(f));
try {
if (testDataInputStream(dis)) { if (testDataInputStream(dis)) {
failed = true; failed = true;
} }
} finally {
dis.close();
}
} finally {
fis.close();
}
} }
private static boolean testDataInputStream(DataInputStream is) private static boolean testDataInputStream(DataInputStream is)
......
...@@ -43,6 +43,7 @@ public class ReadFully { ...@@ -43,6 +43,7 @@ public class ReadFully {
} catch (IndexOutOfBoundsException ie) { } catch (IndexOutOfBoundsException ie) {
caughtException = true; caughtException = true;
} finally { } finally {
dis.close();
if (!caughtException) if (!caughtException)
throw new RuntimeException("Test failed"); throw new RuntimeException("Test failed");
} }
......
...@@ -48,7 +48,9 @@ public class DeleteOnExit { ...@@ -48,7 +48,9 @@ public class DeleteOnExit {
public static void main (String args[]) throws Exception{ public static void main (String args[]) throws Exception{
if (args.length == 0) { if (args.length == 0) {
Runtime.getRuntime().exec(java + " DeleteOnExit -test").waitFor(); String cmd = java + " -classpath " + System.getProperty("test.classes")
+ " DeleteOnExit -test";
Runtime.getRuntime().exec(cmd).waitFor();
if (file1.exists() || file2.exists() || file3.exists() || if (file1.exists() || file2.exists() || file3.exists() ||
dir.exists() || file4.exists() || file5.exists() || dir.exists() || file4.exists() || file5.exists() ||
file6.exists() || file7.exists()) { file6.exists() || file7.exists()) {
......
...@@ -45,7 +45,8 @@ public class DeleteOnExitNPE implements Runnable ...@@ -45,7 +45,8 @@ public class DeleteOnExitNPE implements Runnable
public static void runTest() throws Exception { public static void runTest() throws Exception {
String cmd = System.getProperty("java.home") + File.separator + String cmd = System.getProperty("java.home") + File.separator +
"bin" + File.separator + "java"; "bin" + File.separator + "java" +
" -classpath " + System.getProperty("test.classes");
Process process = Runtime.getRuntime().exec(cmd + " DeleteOnExitNPE -test"); Process process = Runtime.getRuntime().exec(cmd + " DeleteOnExitNPE -test");
BufferedReader isReader = new BufferedReader(new InputStreamReader(process.getInputStream())); BufferedReader isReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader esReader = new BufferedReader(new InputStreamReader(process.getErrorStream())); BufferedReader esReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
*/ */
import java.io.*; import java.io.*;
import java.nio.file.attribute.DosFileAttributeView;
public class IsHidden { public class IsHidden {
...@@ -41,15 +41,20 @@ public class IsHidden { ...@@ -41,15 +41,20 @@ public class IsHidden {
System.err.println(path + " ==> " + x); System.err.println(path + " ==> " + x);
} }
private static void setHidden(File f, boolean value) throws IOException {
f.toPath().getFileAttributeView(DosFileAttributeView.class).setHidden(value);
}
private static void testWin32() throws Exception { private static void testWin32() throws Exception {
File f = new File(dir, "test"); File f = new File(dir, "test");
f.deleteOnExit(); f.deleteOnExit();
f.createNewFile(); f.createNewFile();
String name = f.getCanonicalPath(); setHidden(f, true);
Process p = Runtime.getRuntime().exec("cmd.exe /c attrib +H " + name); try {
p.waitFor(); ck(f.getPath(), true);
ck(name, true); } finally {
setHidden(f, false);
}
ck(".foo", false); ck(".foo", false);
ck("foo", false); ck("foo", false);
} }
......
...@@ -36,8 +36,8 @@ public class LeadingSlash { ...@@ -36,8 +36,8 @@ public class LeadingSlash {
File file = null; File file = null;
try { try {
file = File.createTempFile("bug", "4487368"); file = File.createTempFile("bug", "4487368");
new FileInputStream("\\" + file.getPath()); new FileInputStream("\\" + file.getPath()).close();
new FileOutputStream("\\" + file.getPath()); new FileOutputStream("\\" + file.getPath()).close();
} finally { } finally {
if (file != null) if (file != null)
file.delete(); file.delete();
......
...@@ -125,24 +125,36 @@ public enum OpsAfterClose { ...@@ -125,24 +125,36 @@ public enum OpsAfterClose {
f.deleteOnExit(); f.deleteOnExit();
FileInputStream fis = new FileInputStream(f); FileInputStream fis = new FileInputStream(f);
try {
if (testInputStream(fis)) { if (testInputStream(fis)) {
failed = true; failed = true;
} }
if (testFileInputStream(fis)) { if (testFileInputStream(fis)) {
failed = true; failed = true;
} }
} finally {
fis.close();
}
BufferedInputStream bs = new BufferedInputStream( BufferedInputStream bs = new BufferedInputStream(
new FileInputStream(f)); new FileInputStream(f));
try {
if (testInputStream(bs)) { if (testInputStream(bs)) {
failed = true; failed = true;
} }
} finally {
bs.close();
}
DataInputStream dis = new DataInputStream( DataInputStream dis = new DataInputStream(
new FileInputStream(f)); new FileInputStream(f));
try {
if (testInputStream(dis)) { if (testInputStream(dis)) {
failed = true; failed = true;
} }
} finally {
dis.close();
}
PushbackInputStream pbis = new PushbackInputStream( PushbackInputStream pbis = new PushbackInputStream(
new ByteArrayInputStream(new byte[20])); new ByteArrayInputStream(new byte[20]));
......
...@@ -137,6 +137,7 @@ public class ReadParams { ...@@ -137,6 +137,7 @@ public class ReadParams {
oos.writeInt(12345); oos.writeInt(12345);
oos.writeObject("Today"); oos.writeObject("Today");
oos.writeObject(new Integer(32)); oos.writeObject(new Integer(32));
oos.close();
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fn)); ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fn));
doTest(ois); doTest(ois);
doTest1(ois); doTest1(ois);
......
...@@ -33,9 +33,10 @@ public class GrowAfterEOF { ...@@ -33,9 +33,10 @@ public class GrowAfterEOF {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
File input = new File(".", "TestEOFInput.txt"); File input = new File(".", "TestEOFInput.txt");
RandomAccessFile rf = new RandomAccessFile(input, "rw"); RandomAccessFile rf = new RandomAccessFile(input, "rw");
try {
BufferedReader r = new BufferedReader BufferedReader r = new BufferedReader
(new InputStreamReader(new FileInputStream(input))); (new InputStreamReader(new FileInputStream(input)));
try {
// write something // write something
rf.writeBytes("a line"); rf.writeBytes("a line");
...@@ -57,5 +58,11 @@ public class GrowAfterEOF { ...@@ -57,5 +58,11 @@ public class GrowAfterEOF {
} else { } else {
input.delete(); input.delete();
} }
} finally {
r.close();
}
} finally {
rf.close();
}
} }
} }
...@@ -79,7 +79,7 @@ public class ResolveProxyClass { ...@@ -79,7 +79,7 @@ public class ResolveProxyClass {
* code, and it should be the first loader on the stack when * code, and it should be the first loader on the stack when
* ObjectInputStream.resolveProxyClass gets executed. * ObjectInputStream.resolveProxyClass gets executed.
*/ */
ClassLoader expectedLoader = ClassLoader.getSystemClassLoader(); ClassLoader expectedLoader = ResolveProxyClass.class.getClassLoader();
TestObjectInputStream in = new TestObjectInputStream(); TestObjectInputStream in = new TestObjectInputStream();
Class proxyClass = in.resolveProxyClass( Class proxyClass = in.resolveProxyClass(
......
...@@ -35,12 +35,16 @@ public class EOF { ...@@ -35,12 +35,16 @@ public class EOF {
int n; int n;
String dir = System.getProperty("test.src", "."); String dir = System.getProperty("test.src", ".");
RandomAccessFile raf = new RandomAccessFile(new File(dir, "EOF.java"), "r"); RandomAccessFile raf = new RandomAccessFile(new File(dir, "EOF.java"), "r");
try {
for (;;) { for (;;) {
n = raf.read(buf, 0, buf.length); n = raf.read(buf, 0, buf.length);
if (n <= 0) break; if (n <= 0) break;
} }
if (n != -1) if (n != -1)
throw new RuntimeException("Expected -1 for EOF, got " + n); throw new RuntimeException("Expected -1 for EOF, got " + n);
} finally {
raf.close();
}
} }
} }
...@@ -44,6 +44,7 @@ public class ParameterCheck { ...@@ -44,6 +44,7 @@ public class ParameterCheck {
private static void doTest(String method) throws Exception { private static void doTest(String method) throws Exception {
File fn = new File("x.ParameterCheck"); File fn = new File("x.ParameterCheck");
RandomAccessFile raf = null;
try { try {
byte b[] = new byte[32]; byte b[] = new byte[32];
...@@ -55,7 +56,7 @@ public class ParameterCheck { ...@@ -55,7 +56,7 @@ public class ParameterCheck {
fout.write(i); fout.write(i);
} }
fout.close(); fout.close();
RandomAccessFile raf = new RandomAccessFile(fn , "rw"); raf = new RandomAccessFile(fn , "rw");
System.err.println("-----------------------------" + System.err.println("-----------------------------" +
"-----------------------------"); "-----------------------------");
...@@ -125,6 +126,8 @@ public class ParameterCheck { ...@@ -125,6 +126,8 @@ public class ParameterCheck {
System.err.println("-----------------------------" + System.err.println("-----------------------------" +
"-----------------------------"); "-----------------------------");
} finally { } finally {
if (raf != null)
raf.close();
fn.delete(); fn.delete();
} }
......
...@@ -33,6 +33,7 @@ public class ReadLine { ...@@ -33,6 +33,7 @@ public class ReadLine {
public static void main(String args[]) throws Exception { public static void main(String args[]) throws Exception {
File fn = new File("x.ReadLine"); File fn = new File("x.ReadLine");
RandomAccessFile raf = new RandomAccessFile(fn,"rw"); RandomAccessFile raf = new RandomAccessFile(fn,"rw");
try {
String line; String line;
int ctr = 1; int ctr = 1;
String expected; String expected;
...@@ -54,6 +55,9 @@ public class ReadLine { ...@@ -54,6 +55,9 @@ public class ReadLine {
} }
ctr++; ctr++;
} }
} finally {
raf.close();
}
System.err.println("Successfully completed test!"); System.err.println("Successfully completed test!");
} }
......
...@@ -44,6 +44,8 @@ public class Seek ...@@ -44,6 +44,8 @@ public class Seek
throw new Exception throw new Exception
("Should have thrown an IOException when seek offset is < 0"); ("Should have thrown an IOException when seek offset is < 0");
} catch (IOException e) { } catch (IOException e) {
} finally {
raf.close();
} }
} }
} }
...@@ -37,8 +37,8 @@ public class WriteBytesChars { ...@@ -37,8 +37,8 @@ public class WriteBytesChars {
byte[] b = new byte[80]; byte[] b = new byte[80];
File fn = new File("x.WriteBytesChars"); File fn = new File("x.WriteBytesChars");
try{
RandomAccessFile raf = new RandomAccessFile(fn , "rw");; RandomAccessFile raf = new RandomAccessFile(fn , "rw");;
try {
for (int i = 0; i < 80; i++) { for (int i = 0; i < 80; i++) {
buf[i] = 'a'; buf[i] = 'a';
} }
...@@ -71,6 +71,7 @@ public class WriteBytesChars { ...@@ -71,6 +71,7 @@ public class WriteBytesChars {
RuntimeException("RandomAccessFile.writeChars, wrong result"); RuntimeException("RandomAccessFile.writeChars, wrong result");
} }
} finally { } finally {
raf.close();
fn.delete(); fn.delete();
} }
} }
......
...@@ -42,8 +42,8 @@ public class WriteUTF { ...@@ -42,8 +42,8 @@ public class WriteUTF {
s += s; s += s;
System.err.println("String length " + s.length()); System.err.println("String length " + s.length());
try {
f = new RandomAccessFile(fn, "rw"); f = new RandomAccessFile(fn, "rw");
try {
try { try {
f.writeUTF(s); f.writeUTF(s);
} }
...@@ -53,6 +53,7 @@ public class WriteUTF { ...@@ -53,6 +53,7 @@ public class WriteUTF {
throw new RuntimeException("UTFDataFormatException not thrown"); throw new RuntimeException("UTFDataFormatException not thrown");
} }
finally { finally {
f.close();
fn.delete(); fn.delete();
} }
......
...@@ -96,6 +96,7 @@ public class SkipBytes{ ...@@ -96,6 +96,7 @@ public class SkipBytes{
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
RandomAccessFile raf = new RandomAccessFile("input.txt" , "rw"); RandomAccessFile raf = new RandomAccessFile("input.txt" , "rw");
try {
int length = (int)raf.length(); int length = (int)raf.length();
doTest(raf , 0 , 2*length); doTest(raf , 0 , 2*length);
...@@ -104,6 +105,9 @@ public class SkipBytes{ ...@@ -104,6 +105,9 @@ public class SkipBytes{
doTest(raf , length/2 , -2); doTest(raf , length/2 , -2);
doTest(raf , length , 0); doTest(raf , length , 0);
doTest(raf , 0 , -1); doTest(raf , 0 , -1);
} finally{
raf.close();
}
} }
......
...@@ -35,6 +35,7 @@ public class Skip { ...@@ -35,6 +35,7 @@ public class Skip {
File f = new File(System.getProperty("test.src", "."), File f = new File(System.getProperty("test.src", "."),
"SkipInput.txt"); "SkipInput.txt");
FileReader fr = new FileReader(f); FileReader fr = new FileReader(f);
try {
long nchars = 8200; long nchars = 8200;
long actual = fr.skip(nchars); long actual = fr.skip(nchars);
...@@ -42,5 +43,8 @@ public class Skip { ...@@ -42,5 +43,8 @@ public class Skip {
throw new Exception throw new Exception
("Should skip " + nchars + ", but skipped " +actual+" chars"); ("Should skip " + nchars + ", but skipped " +actual+" chars");
} }
} finally {
fr.close();
}
} }
} }
...@@ -41,6 +41,8 @@ public class SkipNegative { ...@@ -41,6 +41,8 @@ public class SkipNegative {
} catch(IllegalArgumentException e){ } catch(IllegalArgumentException e){
// Negative argument caught // Negative argument caught
return; return;
} finally {
fr.close();
} }
throw new Exception("Skip should not accept negative values"); throw new Exception("Skip should not accept negative values");
} }
......
...@@ -41,7 +41,9 @@ public class Comment { ...@@ -41,7 +41,9 @@ public class Comment {
int slashStarComment = 4; int slashStarComment = 4;
for (int i = 0; i < 8 ; i++) { for (int i = 0; i < 8 ; i++) {
StreamTokenizer st = new StreamTokenizer(new FileReader(f)); FileReader reader = new FileReader(f);
try {
StreamTokenizer st = new StreamTokenizer(reader);
/* decide the state of this run */ /* decide the state of this run */
boolean slashCommentFlag = ((i & slashIsCommentStart) != 0); boolean slashCommentFlag = ((i & slashIsCommentStart) != 0);
...@@ -76,6 +78,9 @@ public class Comment { ...@@ -76,6 +78,9 @@ public class Comment {
} }
} }
} }
} finally {
reader.close();
}
} }
} }
} }
...@@ -57,7 +57,7 @@ public class ReadBytesBounds { ...@@ -57,7 +57,7 @@ public class ReadBytesBounds {
} }
public static void main(String argv[]) throws Throwable { public static void main(String argv[]) throws Throwable {
byte b[] = new byte[32]; try {
testRead(-1, -1, false); testRead(-1, -1, false);
testRead(-1, 0, false); testRead(-1, 0, false);
testRead( 0, -1, false); testRead( 0, -1, false);
...@@ -75,6 +75,10 @@ public class ReadBytesBounds { ...@@ -75,6 +75,10 @@ public class ReadBytesBounds {
testRead(-1, Integer.MAX_VALUE, false); testRead(-1, Integer.MAX_VALUE, false);
testRead(-4, Integer.MIN_VALUE, false); testRead(-4, Integer.MIN_VALUE, false);
testRead( 0, Integer.MIN_VALUE, false); testRead( 0, Integer.MIN_VALUE, false);
} finally {
fis.close();
raf.close();
}
} }
static void testRead(int off, int len, boolean expected) throws Throwable { static void testRead(int off, int len, boolean expected) throws Throwable {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册