From 42fec73f2cf6ebe7cd0f4f9e1eb3ac4e9a91d310 Mon Sep 17 00:00:00 2001 From: sendaoYan Date: Sun, 16 Jun 2024 16:12:01 +0800 Subject: [PATCH] 8334339: CreationTime.java fails on alinux3 --- .../BasicFileAttributeView/CreationTime.java | 53 ++++++++++++++++--- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/test/jdk/java/nio/file/attribute/BasicFileAttributeView/CreationTime.java b/test/jdk/java/nio/file/attribute/BasicFileAttributeView/CreationTime.java index 1898f584bcd63..7d36843f0e9e9 100644 --- a/test/jdk/java/nio/file/attribute/BasicFileAttributeView/CreationTime.java +++ b/test/jdk/java/nio/file/attribute/BasicFileAttributeView/CreationTime.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -21,23 +21,36 @@ * questions. */ -/* @test - * @bug 8011536 8151430 8316304 +/* @test id=tmp + * @bug 8011536 8151430 8316304 8334339 * @summary Basic test for creationTime attribute on platforms/file systems - * that support it. + * that support it, test directory is /tmp. * @library ../.. /test/lib * @build jdk.test.lib.Platform * @run main CreationTime */ + /* @test id=cwd + * @bug 8011536 8151430 8316304 8334339 + * @summary Basic test for creationTime attribute on platforms/file systems + * that support it, test directory is JTwork/scratch. The JTwork/scratch + * directory maybe at diff disk partition to /tmp on linux + * @library ../.. /test/lib + * @build jdk.test.lib.Platform + * @run main CreationTime . + */ + import java.lang.foreign.Linker; import java.nio.file.Path; import java.nio.file.Files; import java.nio.file.attribute.*; import java.time.Instant; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStreamReader; import jdk.test.lib.Platform; +import jtreg.SkippedException; public class CreationTime { @@ -59,6 +72,20 @@ private static void setCreationTime(Path file, FileTime time) throws IOException view.setTimes(null, null, time); } + public static boolean supportBirthTimeOnLinux(Path file) { + try { + String filePath = file.toAbsolutePath().toString(); + ProcessBuilder pb = new ProcessBuilder("stat", "-c", "%w", filePath); + pb.redirectErrorStream(true); + Process p = pb.start(); + BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream())); + String l = b.readLine(); + if (l != null && l.equals("-")) { return false; } + } catch(Exception e) { + } + return true; + } + static void test(Path top) throws IOException { Path file = Files.createFile(top.resolve("foo")); @@ -68,8 +95,13 @@ static void test(Path top) throws IOException { FileTime creationTime = creationTime(file); Instant now = Instant.now(); if (Math.abs(creationTime.toMillis()-now.toEpochMilli()) > 10000L) { - err.println("File creation time reported as: " + creationTime); - throw new RuntimeException("Expected to be close to: " + now); + System.out.println("creationTime.toMillis() == " + creationTime.toMillis()); + if(0 == creationTime.toMillis() && Platform.isLinux() && !supportBirthTimeOnLinux(file) ) { + throw new SkippedException("birth time not support for: " + file); + } else { + err.println("File creation time reported as: " + creationTime); + throw new RuntimeException("Expected to be close to: " + now); + } } /** @@ -95,7 +127,7 @@ static void test(Path top) throws IOException { // Creation time updates are not supported on Linux supportsCreationTimeWrite = false; } - System.out.println("supportsCreationTimeRead == " + supportsCreationTimeRead); + System.out.println(top + " supportsCreationTimeRead == " + supportsCreationTimeRead); /** * If the creation-time attribute is supported then change the file's @@ -127,7 +159,12 @@ static void test(Path top) throws IOException { public static void main(String[] args) throws IOException { // create temporary directory to run tests - Path dir = TestUtil.createTemporaryDirectory(); + Path dir; + if(0 == args.length) { + dir = TestUtil.createTemporaryDirectory(); + } else { + dir = TestUtil.createTemporaryDirectory(args[0]); + } try { test(dir); } finally {