diff --git a/make/test/JtregNativeJdk.gmk b/make/test/JtregNativeJdk.gmk index 46eeb7684b674..f9bd67a693778 100644 --- a/make/test/JtregNativeJdk.gmk +++ b/make/test/JtregNativeJdk.gmk @@ -114,6 +114,8 @@ 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 9f1c12c8e2634..53cbf04d6366f 100644 --- a/test/jdk/java/nio/file/attribute/BasicFileAttributeView/CreationTime.java +++ b/test/jdk/java/nio/file/attribute/BasicFileAttributeView/CreationTime.java @@ -108,13 +108,8 @@ static void test(Path top) throws IOException { supportsCreationTimeWrite = true; } } else if (Platform.isLinux()) { - // Creation time read depends on statx system call support and on the file - // system storing the birth time. The tmpfs/nfs/ext3 etc. file system type does not store - // the birth time, that depends the linux kernel version. - boolean statxIsPresent = Linker.nativeLinker().defaultLookup().find("statx").isPresent(); - if (statxIsPresent && supportBirthTimeOnLinux(file)) { - supportsCreationTimeRead = true; - } + // Creation time read depends on statx system call support + supportsCreationTimeRead = CreationTimeHelper.linuxIsCreationTimeSupported(); // Creation time updates are not supported on Linux supportsCreationTimeWrite = false; } @@ -148,24 +143,6 @@ static void test(Path top) throws IOException { } } - /** - * read the output of linux command `stat -c "%w" file`, if the output is "-", - * then the file system doesn't support birth 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; - } - public static void main(String[] args) throws IOException { // create temporary directory to run tests Path dir; diff --git a/test/jdk/java/nio/file/attribute/BasicFileAttributeView/CreationTimeHelper.java b/test/jdk/java/nio/file/attribute/BasicFileAttributeView/CreationTimeHelper.java new file mode 100644 index 0000000000000..1b8d5bc47c80f --- /dev/null +++ b/test/jdk/java/nio/file/attribute/BasicFileAttributeView/CreationTimeHelper.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023, Red Hat, Inc. + * 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. + */ +public class CreationTimeHelper { + + static { + System.loadLibrary("CreationTimeHelper"); + } + + // Helper so as to determine 'statx' support on the runtime system + static native boolean linuxIsCreationTimeSupported(); +} diff --git a/test/jdk/java/nio/file/attribute/BasicFileAttributeView/libCreationTimeHelper.c b/test/jdk/java/nio/file/attribute/BasicFileAttributeView/libCreationTimeHelper.c new file mode 100644 index 0000000000000..6a2fc74ad5266 --- /dev/null +++ b/test/jdk/java/nio/file/attribute/BasicFileAttributeView/libCreationTimeHelper.c @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023, Red Hat, Inc. + * 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 "jni.h" +#if defined(__linux__) +#include +#endif + +// static native boolean linuxIsCreationTimeSupported() +JNIEXPORT jboolean JNICALL +Java_CreationTimeHelper_linuxIsCreationTimeSupported(JNIEnv *env, jclass cls) +{ +#if defined(__linux__) + void* statx_func = dlsym(RTLD_DEFAULT, "statx"); + return statx_func != NULL ? JNI_TRUE : JNI_FALSE; +#else + return JNI_FALSE; +#endif +}