--- old/test/jdk/java/io/File/GetXSpace.java 2020-08-05 11:33:10.000000000 -0700 +++ new/test/jdk/java/io/File/GetXSpace.java 2020-08-05 11:33:09.000000000 -0700 @@ -24,11 +24,9 @@ /** * @test * @bug 4057701 6286712 6364377 - * @requires (os.family == "linux" | os.family == "mac" | os.family == "windows") - * @run build GetXSpace - * @run shell GetXSpace.sh + * @requires (os.family == "linux" | os.family == "mac" | + * os.family == "windows") * @summary Basic functionality of File.get-X-Space methods. - * @key randomness */ import java.io.BufferedReader; @@ -37,11 +35,13 @@ import java.io.InputStreamReader; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.security.Permission; import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static java.lang.System.err; import static java.lang.System.out; public class GetXSpace { @@ -60,6 +60,12 @@ private static int pass = 0; private static Throwable first; + static void reset() { + fail = 0; + pass = 0; + first = null; + } + static void pass() { pass++; } @@ -331,7 +337,8 @@ } } - private static void testFile(String dirName) { + private static int testFile(Path dir) { + String dirName = dir.toString(); out.format("--- Testing %s%n", dirName); ArrayList l; try { @@ -340,9 +347,18 @@ throw new RuntimeException(dirName + " can't get file system information", x); } compare(l.get(0)); + + if (fail != 0) { + err.format("%d tests: %d failure(s); first: %s%n", + fail + pass, fail, first); + } else { + out.format("all %d tests passed%n", fail + pass); + } + + return fail != 0 ? 1 : 0; } - private static void testDF() { + private static int testDF() { out.println("--- Testing df"); // Find all of the partitions on the machine and verify that the size // returned by "df" is equivalent to File.getXSpace() values. @@ -374,20 +390,51 @@ } } } - } - public static void main(String [] args) { - if (args.length > 0) { - testFile(args[0]); - } else { - testDF(); - } + System.setSecurityManager(null); if (fail != 0) { - throw new RuntimeException((fail + pass) + " tests: " - + fail + " failure(s), first", first); + err.format("%d tests: %d failure(s); first: %s%n", + fail + pass, fail, first); } else { out.format("all %d tests passed%n", fail + pass); } + + return fail != 0 ? 1 : 0; + } + + private static void perms(File file, boolean allow) throws IOException { + file.setExecutable(allow, false); + file.setReadable(allow, false); + file.setWritable(allow, false); + } + + private static void deny(Path path) throws IOException { + perms(path.toFile(), false); + } + + private static void allow(Path path) throws IOException { + perms(path.toFile(), true); + } + + public static void main(String[] args) throws Exception { + int failedTests = testDF(); + reset(); + + Path tmpDir = Files.createTempDirectory(null); + Path tmpSubdir = Files.createTempDirectory(tmpDir, null); + Path tmpFile = Files.createTempFile(tmpSubdir, "foo", null); + + deny(tmpSubdir); + failedTests += testFile(tmpFile); + + allow(tmpSubdir); + Files.delete(tmpFile); + Files.delete(tmpSubdir); + Files.delete(tmpDir); + + if (failedTests > 0) { + throw new RuntimeException(failedTests + " test(s) failed"); + } } } --- old/test/jdk/java/io/File/GetXSpace.sh 2020-08-05 11:33:10.000000000 -0700 +++ /dev/null 2020-08-05 11:33:10.000000000 -0700 @@ -1,82 +0,0 @@ -# -# Copyright (c) 2006, 2020, 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 -# 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. -# - -# - -# set platform-dependent variable -OS=`uname -s` -case "$OS" in - Linux | Darwin ) TMP=/tmp ;; - Windows_98 ) return ;; - CYGWIN_* ) TMP="c:/temp" ;; - Windows* ) SID=`sid`; TMP="c:/temp" ;; - * ) - echo "Unrecognized system! ${OS}" - exit 1 - ;; -esac - -TMP1=${TMP}/tmp1_$$ -FAIL=0; - -deny() { - case "$OS" in - Windows* ) chacl -d ${SID}:f $* ;; - * ) chmod 000 $* ;; - esac -} - -allow() { - case "$OS" in - Windows* ) chacl -g ${SID}:f $* ;; - * ) chmod 777 $* ;; - esac -} - -runTest() { - ${TESTJAVA}/bin/java ${TESTVMOPTS} -cp ${TESTCLASSES} GetXSpace $* - if [ $? -eq 0 ] - then echo "Passed" - else - echo "FAILED" - FAIL=`expr ${FAIL} + 1` - fi -} - -# df output -runTest - -# readable file in an unreadable directory -mkdir -p ${TMP1} -touch ${TMP1}/foo -deny ${TMP1} -runTest ${TMP1}/foo -allow ${TMP1} -rm -rf ${TMP1} - -if [ ${FAIL} -ne 0 ] -then - echo "" - echo "${FAIL} test(s) failed" - exit 1 -fi