Skip to content

Commit 79adaec

Browse files
SendaoYanAlan Bateman
SendaoYan
authored and
Alan Bateman
committed
8334339: Test java/nio/file/attribute/BasicFileAttributeView/CreationTime.java fails on alinux3
Reviewed-by: alanb
1 parent 9901fc6 commit 79adaec

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

test/jdk/java/nio/file/attribute/BasicFileAttributeView/CreationTime.java

+29-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -21,15 +21,24 @@
2121
* questions.
2222
*/
2323

24-
/* @test
25-
* @bug 8011536 8151430 8316304
24+
/* @test id=tmp
25+
* @bug 8011536 8151430 8316304 8334339
2626
* @summary Basic test for creationTime attribute on platforms/file systems
27-
* that support it.
27+
* that support it, tests using /tmp directory.
2828
* @library ../.. /test/lib
2929
* @build jdk.test.lib.Platform
3030
* @run main CreationTime
3131
*/
3232

33+
/* @test id=cwd
34+
* @summary Basic test for creationTime attribute on platforms/file systems
35+
* that support it, tests using the test scratch directory, the test
36+
* scratch directory maybe at diff disk partition to /tmp on linux.
37+
* @library ../.. /test/lib
38+
* @build jdk.test.lib.Platform
39+
* @run main CreationTime .
40+
*/
41+
3342
import java.lang.foreign.Linker;
3443
import java.nio.file.Path;
3544
import java.nio.file.Files;
@@ -38,6 +47,7 @@
3847
import java.io.IOException;
3948

4049
import jdk.test.lib.Platform;
50+
import jtreg.SkippedException;
4151

4252
public class CreationTime {
4353

@@ -68,8 +78,14 @@ static void test(Path top) throws IOException {
6878
FileTime creationTime = creationTime(file);
6979
Instant now = Instant.now();
7080
if (Math.abs(creationTime.toMillis()-now.toEpochMilli()) > 10000L) {
71-
err.println("File creation time reported as: " + creationTime);
72-
throw new RuntimeException("Expected to be close to: " + now);
81+
System.out.println("creationTime.toMillis() == " + creationTime.toMillis());
82+
// If the file system doesn't support birth time, then skip this test
83+
if (creationTime.toMillis() == 0) {
84+
throw new SkippedException("birth time not support for: " + file);
85+
} else {
86+
err.println("File creation time reported as: " + creationTime);
87+
throw new RuntimeException("Expected to be close to: " + now);
88+
}
7389
}
7490

7591
/**
@@ -95,7 +111,7 @@ static void test(Path top) throws IOException {
95111
// Creation time updates are not supported on Linux
96112
supportsCreationTimeWrite = false;
97113
}
98-
System.out.println("supportsCreationTimeRead == " + supportsCreationTimeRead);
114+
System.out.println(top + " supportsCreationTimeRead == " + supportsCreationTimeRead);
99115

100116
/**
101117
* If the creation-time attribute is supported then change the file's
@@ -127,7 +143,12 @@ static void test(Path top) throws IOException {
127143

128144
public static void main(String[] args) throws IOException {
129145
// create temporary directory to run tests
130-
Path dir = TestUtil.createTemporaryDirectory();
146+
Path dir;
147+
if (args.length == 0) {
148+
dir = TestUtil.createTemporaryDirectory();
149+
} else {
150+
dir = TestUtil.createTemporaryDirectory(args[0]);
151+
}
131152
try {
132153
test(dir);
133154
} finally {

0 commit comments

Comments
 (0)