From 36fca5d19d6c0eb0391b4a36db689d9c3aae09b1 Mon Sep 17 00:00:00 2001 From: Christian Hagedorn Date: Thu, 10 Oct 2024 06:40:55 +0000 Subject: [PATCH] 8341882: [BACKOUT] java/nio/file/attribute/BasicFileAttributeView/CreationTime.java#tmp fails on alinux3 Reviewed-by: thartmann --- make/test/JtregNativeJdk.gmk | 2 - .../BasicFileAttributeView/CreationTime.java | 38 +++--- .../CreationTimeHelper.java | 61 --------- .../libCreationTimeHelper.c | 117 ------------------ 4 files changed, 18 insertions(+), 200 deletions(-) delete mode 100644 test/jdk/java/nio/file/attribute/BasicFileAttributeView/CreationTimeHelper.java delete mode 100644 test/jdk/java/nio/file/attribute/BasicFileAttributeView/libCreationTimeHelper.c diff --git a/make/test/JtregNativeJdk.gmk b/make/test/JtregNativeJdk.gmk index 90055cb5c01..d9f1e334a5c 100644 --- a/make/test/JtregNativeJdk.gmk +++ b/make/test/JtregNativeJdk.gmk @@ -115,8 +115,6 @@ ifeq ($(call isTargetOs, linux), true) # stripping during the test libraries' build. BUILD_JDK_JTREG_LIBRARIES_CFLAGS_libFib := -g BUILD_JDK_JTREG_LIBRARIES_STRIP_SYMBOLS_libFib := false - # nio tests' libCreationTimeHelper native needs -ldl linker flag - BUILD_JDK_JTREG_LIBRARIES_LDFLAGS_libCreationTimeHelper := -ldl endif ifeq ($(ASAN_ENABLED), true) diff --git a/test/jdk/java/nio/file/attribute/BasicFileAttributeView/CreationTime.java b/test/jdk/java/nio/file/attribute/BasicFileAttributeView/CreationTime.java index 65e801b0a9f..ad85da7ae63 100644 --- a/test/jdk/java/nio/file/attribute/BasicFileAttributeView/CreationTime.java +++ b/test/jdk/java/nio/file/attribute/BasicFileAttributeView/CreationTime.java @@ -1,6 +1,5 @@ /* * Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2024 Alibaba Group Holding Limited. 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 @@ -26,18 +25,18 @@ * @bug 8011536 8151430 8316304 8334339 * @summary Basic test for creationTime attribute on platforms/file systems * that support it, tests using /tmp directory. - * @library ../.. /test/lib /java/foreign - * @build jdk.test.lib.Platform NativeTestHelper - * @run main/othervm/native --enable-native-access=ALL-UNNAMED CreationTime + * @library ../.. /test/lib + * @build jdk.test.lib.Platform + * @run main CreationTime */ /* @test id=cwd * @summary Basic test for creationTime attribute on platforms/file systems * that support it, tests using the test scratch directory, the test * scratch directory maybe at diff disk partition to /tmp on linux. - * @library ../.. /test/lib /java/foreign - * @build jdk.test.lib.Platform NativeTestHelper - * @run main/othervm/native --enable-native-access=ALL-UNNAMED CreationTime . + * @library ../.. /test/lib + * @build jdk.test.lib.Platform + * @run main CreationTime . */ import java.lang.foreign.Linker; @@ -52,6 +51,8 @@ import jtreg.SkippedException; public class CreationTime { + private static final java.io.PrintStream err = System.err; + /** * Reads the creationTime attribute */ @@ -77,9 +78,14 @@ public class CreationTime { FileTime creationTime = creationTime(file); Instant now = Instant.now(); if (Math.abs(creationTime.toMillis()-now.toEpochMilli()) > 10000L) { - System.err.println("creationTime.toMillis() == " + creationTime.toMillis()); - System.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 the file system doesn't support birth time, then skip this test + if (creationTime.toMillis() == 0) { + 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); + } } /** @@ -101,12 +107,7 @@ public class CreationTime { } } else if (Platform.isLinux()) { // Creation time read depends on statx system call support - try { - supportsCreationTimeRead = CreationTimeHelper. - linuxIsCreationTimeSupported(file.toAbsolutePath().toString()); - } catch (Throwable e) { - supportsCreationTimeRead = false; - } + supportsCreationTimeRead = Linker.nativeLinker().defaultLookup().find("statx").isPresent(); // Creation time updates are not supported on Linux supportsCreationTimeWrite = false; } @@ -121,11 +122,8 @@ public class CreationTime { Instant plusHour = Instant.now().plusSeconds(60L * 60L); Files.setLastModifiedTime(file, FileTime.from(plusHour)); FileTime current = creationTime(file); - if (!current.equals(creationTime)) { - System.err.println("current = " + current); - System.err.println("creationTime = " + creationTime); + if (!current.equals(creationTime)) throw new RuntimeException("Creation time should not have changed"); - } } /** diff --git a/test/jdk/java/nio/file/attribute/BasicFileAttributeView/CreationTimeHelper.java b/test/jdk/java/nio/file/attribute/BasicFileAttributeView/CreationTimeHelper.java deleted file mode 100644 index 592aeba322d..00000000000 --- a/test/jdk/java/nio/file/attribute/BasicFileAttributeView/CreationTimeHelper.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2024 Alibaba Group Holding Limited. 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import java.lang.foreign.Arena; -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.Linker; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SymbolLookup; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; - -public class CreationTimeHelper extends NativeTestHelper { - - static { - System.loadLibrary("CreationTimeHelper"); - } - - final static Linker abi = Linker.nativeLinker(); - static final SymbolLookup lookup = SymbolLookup.loaderLookup(); - final static MethodHandle methodHandle = abi. - downcallHandle(lookup.findOrThrow("linuxIsCreationTimeSupported"), - FunctionDescriptor.of(C_BOOL, C_POINTER)); - - // Helper so as to determine birth time support or not on Linux. - // Support is determined in a two-step process: - // 1. Determine if `statx` system call is available. If available proceed, - // otherwise return false. - // 2. Perform an actual `statx` call on the given file and check for birth - // time support in the mask returned from the call. This is needed, - // since some file systems, like nfs/tmpfs etc., don't support birth - // time even though the `statx` system call is available. - static boolean linuxIsCreationTimeSupported(String file) throws Throwable { - if (!abi.defaultLookup().find("statx").isPresent()) { - return false; - } - try (var arena = Arena.ofConfined()) { - MemorySegment s = arena.allocateFrom(file); - return (boolean)methodHandle.invokeExact(s); - } - } -} diff --git a/test/jdk/java/nio/file/attribute/BasicFileAttributeView/libCreationTimeHelper.c b/test/jdk/java/nio/file/attribute/BasicFileAttributeView/libCreationTimeHelper.c deleted file mode 100644 index d4c41d8cf91..00000000000 --- a/test/jdk/java/nio/file/attribute/BasicFileAttributeView/libCreationTimeHelper.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2024 Alibaba Group Holding Limited. 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -#include "export.h" -#include -#if defined(__linux__) -#include -#include -#include -#include -#include -#include -#ifndef STATX_BASIC_STATS -#define STATX_BASIC_STATS 0x000007ffU -#endif -#ifndef STATX_BTIME -#define STATX_BTIME 0x00000800U -#endif -#ifndef RTLD_DEFAULT -#define RTLD_DEFAULT RTLD_LOCAL -#endif - -/* - * Timestamp structure for the timestamps in struct statx. - */ -struct my_statx_timestamp { - __int64_t tv_sec; - __uint32_t tv_nsec; - __int32_t __reserved; -}; - -/* - * struct statx used by statx system call on >= glibc 2.28 - * systems - */ -struct my_statx -{ - __uint32_t stx_mask; - __uint32_t stx_blksize; - __uint64_t stx_attributes; - __uint32_t stx_nlink; - __uint32_t stx_uid; - __uint32_t stx_gid; - __uint16_t stx_mode; - __uint16_t __statx_pad1[1]; - __uint64_t stx_ino; - __uint64_t stx_size; - __uint64_t stx_blocks; - __uint64_t stx_attributes_mask; - struct my_statx_timestamp stx_atime; - struct my_statx_timestamp stx_btime; - struct my_statx_timestamp stx_ctime; - struct my_statx_timestamp stx_mtime; - __uint32_t stx_rdev_major; - __uint32_t stx_rdev_minor; - __uint32_t stx_dev_major; - __uint32_t stx_dev_minor; - __uint64_t __statx_pad2[14]; -}; - -typedef int statx_func(int dirfd, const char *restrict pathname, int flags, - unsigned int mask, struct my_statx *restrict statxbuf); - -static statx_func* my_statx_func = NULL; -#endif //#defined(__linux__) - -// static boolean linuxIsCreationTimeSupported(char* file) -EXPORT bool linuxIsCreationTimeSupported(char* file) { -#if defined(__linux__) - struct my_statx stx = {0}; - int ret, atflag = AT_SYMLINK_NOFOLLOW; - unsigned int mask = STATX_BASIC_STATS | STATX_BTIME; - - my_statx_func = (statx_func*) dlsym(RTLD_DEFAULT, "statx"); - if (my_statx_func == NULL) { - return false; - } - - if (file == NULL) { - printf("input file error!\n"); - return false; - } - - ret = my_statx_func(AT_FDCWD, file, atflag, mask, &stx); - if (ret != 0) { - return false; - } - // On some systems where statx is available but birth time might still not - // be supported as it's file system specific. The only reliable way to - // check for supported or not is looking at the filled in STATX_BTIME bit - // in the returned statx buffer mask. - if ((stx.stx_mask & STATX_BTIME) != 0) - return true; - return false; -#else - return false; -#endif -}