1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
21
21
* questions.
22
22
*/
23
23
24
- /* @test
25
- * @bug 8011536 8151430 8316304
24
+ /* @test id=tmp
25
+ * @bug 8011536 8151430 8316304 8334339
26
26
* @summary Basic test for creationTime attribute on platforms/file systems
27
- * that support it.
27
+ * that support it, tests using /tmp directory .
28
28
* @library ../.. /test/lib
29
29
* @build jdk.test.lib.Platform
30
30
* @run main CreationTime
31
31
*/
32
32
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
+
33
42
import java .lang .foreign .Linker ;
34
43
import java .nio .file .Path ;
35
44
import java .nio .file .Files ;
38
47
import java .io .IOException ;
39
48
40
49
import jdk .test .lib .Platform ;
50
+ import jtreg .SkippedException ;
41
51
42
52
public class CreationTime {
43
53
@@ -68,8 +78,14 @@ static void test(Path top) throws IOException {
68
78
FileTime creationTime = creationTime (file );
69
79
Instant now = Instant .now ();
70
80
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
+ }
73
89
}
74
90
75
91
/**
@@ -95,7 +111,7 @@ static void test(Path top) throws IOException {
95
111
// Creation time updates are not supported on Linux
96
112
supportsCreationTimeWrite = false ;
97
113
}
98
- System .out .println (" supportsCreationTimeRead == " + supportsCreationTimeRead );
114
+ System .out .println (top + " supportsCreationTimeRead == " + supportsCreationTimeRead );
99
115
100
116
/**
101
117
* If the creation-time attribute is supported then change the file's
@@ -127,7 +143,12 @@ static void test(Path top) throws IOException {
127
143
128
144
public static void main (String [] args ) throws IOException {
129
145
// 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
+ }
131
152
try {
132
153
test (dir );
133
154
} finally {
0 commit comments