From a258ec39492ff00af8f5198485950105590a41d4 Mon Sep 17 00:00:00 2001 From: Victor Chang Date: Thu, 24 Dec 2020 14:57:44 +0000 Subject: [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) --- .../java/org/apache/harmony/tests/java/io/FileTest.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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 9f397f4f5f..2bf5660ac1 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 @@ public class FileTest extends TestCase { // 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; } -- cgit v1.2.3