[RESTRICT AUTOMERGE] Modify FileTest#test_createNewFile to match the behavior change on kernel version 5.7+
Cherry-picking this to pie-cts-dev to fix an Android P CtsLibcore
failure when using the 5.10 kernel.
Original change description:
Relax the test expection on new File("/..").createNewFile().
File.createNewFile() with other illegal paths, e.g. "", "/a/../../", still throws
IOException on kernel 5.4 and 5.10.
Bug: 176057454
Bug: 179621021
Test: atest CtsLibcoreTestCases:org.apache.harmony.tests.java.io.FileTest on kernel 5.10
Test: atest CtsLibcoreTestCases:org.apache.harmony.tests.java.io.FileTest on kernel 5.4
Change-Id: I91455d09853c1e2e9b7dcd9c0c7ecfc9e537160e
(cherry picked from commit f2d9613d33d8f8f12df573b405814b0f7184bfba)
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileTest.java
index 9f397f4..2bf5660 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/FileTest.java
@@ -410,17 +410,22 @@
// Test create an illegal file
String sep = File.separator;
- f1 = new File(sep + "..");
+ f1 = new File(sep + "a" + sep + ".." + sep + ".." + sep);
try {
f1.createNewFile();
fail("should throw IOE");
} catch (IOException e) {
// expected;
}
- f1 = new File(sep + "a" + sep + ".." + sep + ".." + sep);
+
+ // Prior to kernel version 5.7, creating "/.." returns EISDIR, and in 5.7 or later,
+ // such syscall returns EEXIST. In the first case, IOException is thrown. In the second
+ // case, false is returned. The below test is modified to accept both of them.
+ // See http://b/176057454 for details.
+ f1 = new File(sep + "..");
try {
- f1.createNewFile();
- fail("should throw IOE");
+ boolean result = f1.createNewFile();
+ assertFalse(result);
} catch (IOException e) {
// expected;
}