Navigation Menu

Skip to content

Commit

Permalink
8291911: java/io/File/GetXSpace.java fails with "53687091200 != 16105…
Browse files Browse the repository at this point in the history
…1996160"

Reviewed-by: rriggs
  • Loading branch information
Brian Burkhalter committed Nov 14, 2022
1 parent 95b8405 commit 749335d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 18 deletions.
1 change: 0 additions & 1 deletion test/jdk/ProblemList.txt
Expand Up @@ -507,7 +507,6 @@ java/lang/instrument/RetransformBigClass.sh 8065756 generic-

java/io/pathNames/GeneralWin32.java 8180264 windows-all
java/io/File/createTempFile/SpecialTempFile.java 8274122 windows11
java/io/File/GetXSpace.java 8291911 windows-all

############################################################################

Expand Down
73 changes: 56 additions & 17 deletions test/jdk/java/io/File/GetXSpace.java
Expand Up @@ -57,7 +57,7 @@ public class GetXSpace {
new DenyRead() };

// FileSystem Total Used Available Use% MountedOn
private static final Pattern DF_PATTERN = Pattern.compile("([^\\s]+)\\s+(\\d+)\\s+\\d+\\s+(\\d+)\\s+\\d+%\\s+([^\\s].*)\n");
private static final Pattern DF_PATTERN = Pattern.compile("([^\\s]+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+\\d+%\\s+([^\\s].*)\n");

private static int fail = 0;
private static int pass = 0;
Expand Down Expand Up @@ -103,29 +103,52 @@ private static class Space {
private static final long KSIZE = 1024;
private final String name;
private final long total;
private final long free;
private final long used;
private final long available;

Space(String total, String free, String name) {
Space(String name, String total, String used, String available) {
this.name = name;
try {
this.total = Long.parseLong(total) * KSIZE;
this.free = Long.parseLong(free) * KSIZE;
this.used = Long.parseLong(used) * KSIZE;
this.available = Long.parseLong(available) * KSIZE;
} catch (NumberFormatException x) {
throw new RuntimeException("the regex should have caught this", x);
}
this.name = name;
}

String name() { return name; }
long total() { return total; }
long free() { return free; }
long used() { return used; }
long available() { return available; }
long free() { return total - used; }
boolean woomFree(long freeSpace) {
return ((freeSpace >= (free / 10)) && (freeSpace <= (free * 10)));
return ((freeSpace >= (available / 10)) &&
(freeSpace <= (available * 10)));
}
public String toString() {
return String.format("%s (%d/%d)", name, free, total);
return String.format("%s (%d/%d/%d)", name, total, used, available);
}
}

private static void diskFree() throws IOException {
ArrayList<Space> al = new ArrayList<>();

String cmd = "fsutil volume diskFree C:\\";
StringBuilder sb = new StringBuilder();
Process p = Runtime.getRuntime().exec(cmd);
try (BufferedReader in = p.inputReader()) {
String s;
int i = 0;
while ((s = in.readLine()) != null) {
// skip header
if (i++ == 0) continue;
sb.append(s).append("\n");
}
}
out.println(sb);
}

private static ArrayList<Space> space(String f) throws IOException {
ArrayList<Space> al = new ArrayList<>();

Expand All @@ -152,9 +175,9 @@ private static ArrayList<Space> space(String f) throws IOException {
String name = f;
if (name == null) {
// cygwin's df lists windows path as FileSystem (1st group)
name = Platform.isWindows() ? m.group(1) : m.group(4);
name = Platform.isWindows() ? m.group(1) : m.group(5);
}
al.add(new Space(m.group(2), m.group(3), name));
al.add(new Space(name, m.group(2), m.group(3), m.group(4)));
}
j = m.end();
} else {
Expand All @@ -167,7 +190,7 @@ private static ArrayList<Space> space(String f) throws IOException {
if (al.size() == 0) {
// df did not produce output
String name = (f == null ? "" : f);
al.add(new Space("0", "0", name));
al.add(new Space(name, "0", "0", "0"));
}
return al;
}
Expand Down Expand Up @@ -209,8 +232,8 @@ private static void compare(Space s) {
long us = f.getUsableSpace();

out.format("%s:%n", s.name());
String fmt = " %-4s total= %12d free = %12d usable = %12d%n";
out.format(fmt, "df", s.total(), 0, s.free());
String fmt = " %-4s total = %12d free = %12d usable = %12d%n";
out.format(fmt, "df", s.total(), s.free(), s.available());
out.format(fmt, "getX", ts, fs, us);

// If the file system can dynamically change size, this check will fail.
Expand All @@ -236,9 +259,22 @@ private static void compare(Space s) {
// calculated by 'df' using integer division by 2 of the number of
// 512 byte blocks, resulting in a size smaller than the actual
// value when the number of blocks is odd.
if (!Platform.isOSX() || blockSize != 512 || numBlocks % 2 == 0
|| ts - s.total() != 512) {
fail(s.name(), s.total(), "!=", ts);
if (!Platform.isOSX() || blockSize != 512 || numBlocks % 2 == 0 ||
ts - s.total() != 512) {
if (Platform.isWindows()) {
//
// In Cygwin, 'df' has been observed to account for quotas
// when reporting the total disk size, but the total size
// reported by GetDiskFreeSpaceExW() has been observed not
// to account for the quota in which case the latter value
// should be larger.
//
if (s.total() > ts) {
fail(s.name() + " total space", s.total(), ">", ts);
}
} else {
fail(s.name() + " total space", s.total(), "!=", ts);
}
}
} else {
pass();
Expand All @@ -247,7 +283,7 @@ private static void compare(Space s) {
// unix df returns statvfs.f_bavail
long tsp = (!Platform.isWindows() ? us : fs);
if (!s.woomFree(tsp)) {
fail(s.name(), s.free(), "??", tsp);
fail(s.name(), s.available(), "??", tsp);
} else {
pass();
}
Expand Down Expand Up @@ -380,6 +416,9 @@ private static int testDF() {
ArrayList<Space> l;
try {
l = space(null);
if (Platform.isWindows()) {
diskFree();
}
} catch (IOException x) {
throw new RuntimeException("can't get file system information", x);
}
Expand Down

2 comments on commit 749335d

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@openjdk
Copy link

@openjdk openjdk bot commented on 749335d Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SoniaZaldana Could not automatically backport 749335d3 to openjdk/jdk17u-dev due to conflicts in the following files:

  • test/jdk/java/io/File/GetXSpace.java

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk17u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk17u-dev.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b SoniaZaldana-backport-749335d3

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk.git 749335d34ac570760279ac81308d5d323aba4067

# Backport the commit
$ git cherry-pick --no-commit 749335d34ac570760279ac81308d5d323aba4067
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 749335d34ac570760279ac81308d5d323aba4067'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk17u-dev with the title Backport 749335d34ac570760279ac81308d5d323aba4067.

Please sign in to comment.