From 6f684dceee62732d0b932880475b43eb5653b435 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Mon, 6 Mar 2023 19:24:51 +0100 Subject: [PATCH 01/12] allow up to unsigned int maximum when setting values in statvfs --- .../cryptomator/jfuse/mac/StatvfsImpl.java | 14 +- .../jfuse/mac/StatvfsImplTest.java | 123 ++++++++++++++++++ 2 files changed, 131 insertions(+), 6 deletions(-) create mode 100644 jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java diff --git a/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java b/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java index c1a047f7..8e5f51fe 100644 --- a/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java +++ b/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java @@ -9,6 +9,8 @@ record StatvfsImpl(MemorySegment segment) implements Statvfs { + private static final long MAX_UINT = 0xFFFFFFFF; + public StatvfsImpl(MemoryAddress address, MemorySession scope) { this(statvfs.ofAddress(address, scope)); } @@ -40,8 +42,8 @@ public long getBlocks() { @Override public void setBlocks(long blocks) { - if (blocks > Integer.MAX_VALUE) { - throw new IllegalArgumentException("Max supported number of blocks: " + Integer.MAX_VALUE); + if (blocks > MAX_UINT){ + throw new IllegalArgumentException("Max supported number of blocks: " + MAX_UINT); } else { statvfs.f_blocks$set(segment, (int) blocks); } @@ -54,8 +56,8 @@ public long getBfree() { @Override public void setBfree(long bfree) { - if (bfree > Integer.MAX_VALUE) { - throw new IllegalArgumentException("Max supported number of blocks: " + Integer.MAX_VALUE); + if (bfree > MAX_UINT){ + throw new IllegalArgumentException("Max supported number of blocks: " + MAX_UINT); } else { statvfs.f_bfree$set(segment, (int) bfree); } @@ -68,8 +70,8 @@ public long getBavail() { @Override public void setBavail(long bavail) { - if (bavail > Integer.MAX_VALUE) { - throw new IllegalArgumentException("Max supported number of blocks: " + Integer.MAX_VALUE); + if (bavail > MAX_UINT){ + throw new IllegalArgumentException("Max supported number of blocks: " + MAX_UINT); } else { statvfs.f_bavail$set(segment, (int) bavail); } diff --git a/jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java b/jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java new file mode 100644 index 00000000..6469e2ef --- /dev/null +++ b/jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java @@ -0,0 +1,123 @@ +package org.cryptomator.jfuse.mac; + +import org.cryptomator.jfuse.api.Statvfs; +import org.cryptomator.jfuse.mac.extr.statvfs; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Named; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.lang.foreign.MemorySegment; +import java.lang.foreign.MemorySession; +import java.util.function.BiConsumer; +import java.util.function.Function; +import java.util.stream.Stream; + +public class StatvfsImplTest { + + @DisplayName("test getters") + @ParameterizedTest(name = "{1}") + @MethodSource + public void testGetters(SetInMemorySegment setter, GetInStatvfs getter, Number value) { + try (var scope = MemorySession.openConfined()) { + var segment = statvfs.allocate(scope); + var statvfs = new StatvfsImpl(segment.address(), scope); + + setter.accept(segment, value); + + Assertions.assertEquals(value.longValue(), getter.apply(statvfs).longValue()); + } + } + + public static Stream testGetters() { + return Stream.of( + Arguments.arguments((SetInMemorySegment) statvfs::f_bsize$set, Named.of("getBsize()", (GetInStatvfs) Statvfs::getBsize), 42L), + Arguments.arguments((SetInMemorySegment) statvfs::f_frsize$set, Named.of("getFrsize()", (GetInStatvfs) Statvfs::getFrsize), 42L), + Arguments.arguments((SetInMemorySegment) statvfs::f_blocks$set, Named.of("getBlocks()", (GetInStatvfs) Statvfs::getBlocks), 42), + Arguments.arguments((SetInMemorySegment) statvfs::f_bfree$set, Named.of("getBfree()", (GetInStatvfs) Statvfs::getBfree), 42), + Arguments.arguments((SetInMemorySegment) statvfs::f_bavail$set, Named.of("getBavail()", (GetInStatvfs) Statvfs::getBavail), 42), + Arguments.arguments((SetInMemorySegment) statvfs::f_namemax$set, Named.of("getNameMax()", (GetInStatvfs) Statvfs::getNameMax), 42) + ); + } + + private interface SetInMemorySegment extends BiConsumer { + } + + private interface GetInStatvfs extends Function { + } + + @DisplayName("test setters") + @ParameterizedTest(name = "{0}") + @MethodSource + public void testSetters(SetInStatvfs setter, GetInMemorySegment getter, Number value) { + try (var scope = MemorySession.openConfined()) { + var segment = statvfs.allocate(scope); + var statvfs = new StatvfsImpl(segment.address(), scope); + + setter.accept(statvfs, value); + + Assertions.assertEquals(value.longValue(), getter.apply(segment).longValue()); + } + } + + public static Stream testSetters() { + return Stream.of( + Arguments.arguments(Named.of("setBsize()", (SetInStatvfs) Statvfs::setBsize), (GetInMemorySegment) statvfs::f_bsize$get, 42L), + Arguments.arguments(Named.of("setFrsize()", (SetInStatvfs) Statvfs::setFrsize), (GetInMemorySegment) statvfs::f_frsize$get, 42L), + Arguments.arguments(Named.of("setBlocks()", (SetInStatvfs) Statvfs::setBlocks), (GetInMemorySegment) statvfs::f_blocks$get, 42), + Arguments.arguments(Named.of("setBfree()", (SetInStatvfs) Statvfs::setBfree), (GetInMemorySegment) statvfs::f_bfree$get, 42), + Arguments.arguments(Named.of("setBavail()", (SetInStatvfs) Statvfs::setBavail), (GetInMemorySegment) statvfs::f_bavail$get, 42), + Arguments.arguments(Named.of("setNameMax()", (SetInStatvfs) Statvfs::setNameMax), (GetInMemorySegment) statvfs::f_namemax$get, 42L) + ); + } + + @DisplayName("test setters casting") + @ParameterizedTest(name = "{0}") + @MethodSource + public void testSettersCasting(SetInStatvfs setter, GetInMemorySegment getter, Number value) { + try (var scope = MemorySession.openConfined()) { + var segment = statvfs.allocate(scope); + var statvfs = new StatvfsImpl(segment.address(), scope); + + setter.accept(statvfs, value); + + Assertions.assertEquals(value.byteValue(), getter.apply(segment).byteValue()); + } + } + + public static Stream testSettersCasting() { + return Stream.of( + Arguments.arguments(Named.of("setBlocks()", (SetInStatvfs) Statvfs::setBlocks), (GetInMemorySegment) statvfs::f_blocks$get, -42), + Arguments.arguments(Named.of("setBfree()", (SetInStatvfs) Statvfs::setBfree), (GetInMemorySegment) statvfs::f_bfree$get, -42), + Arguments.arguments(Named.of("setBavail()", (SetInStatvfs) Statvfs::setBavail), (GetInMemorySegment) statvfs::f_bavail$get, -42) + ); + } + + @DisplayName("test setters out-of-range") + @ParameterizedTest(name = "{0}") + @MethodSource + public void testSettersOutOfRange(SetInStatvfs setter, Number value) { + try (var scope = MemorySession.openConfined()) { + var segment = statvfs.allocate(scope); + var statvfs = new StatvfsImpl(segment.address(), scope); + + Assertions.assertThrows(IllegalArgumentException.class, () -> setter.accept(statvfs, value)); + } + } + + public static Stream testSettersOutOfRange() { + return Stream.of( + Arguments.arguments(Named.of("setBlocks()", (SetInStatvfs) Statvfs::setBlocks), 0x100000000L), + Arguments.arguments(Named.of("setBfree()", (SetInStatvfs) Statvfs::setBfree), 0x100000000L), + Arguments.arguments(Named.of("setBavail()", (SetInStatvfs) Statvfs::setBavail), 0x100000000L) + ); + } + + private interface SetInStatvfs extends BiConsumer { + } + + private interface GetInMemorySegment extends Function { + } +} From 94924ce1a91a89d12b0a2ac8072f52fce7dd5e10 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Mon, 6 Mar 2023 19:50:04 +0100 Subject: [PATCH 02/12] never return negative values in statvfs --- .../main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java b/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java index 8e5f51fe..c7d09216 100644 --- a/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java +++ b/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java @@ -37,7 +37,7 @@ public void setFrsize(long frsize) { @Override public long getBlocks() { - return statvfs.f_blocks$get(segment); + return Integer.toUnsignedLong(statvfs.f_blocks$get(segment)); } @Override @@ -51,7 +51,7 @@ public void setBlocks(long blocks) { @Override public long getBfree() { - return statvfs.f_bfree$get(segment); + return Integer.toUnsignedLong(statvfs.f_bfree$get(segment)); } @Override @@ -65,7 +65,7 @@ public void setBfree(long bfree) { @Override public long getBavail() { - return statvfs.f_bavail$get(segment); + return Integer.toUnsignedLong(statvfs.f_bavail$get(segment)); } @Override From 75a9261ac25b54a80675eb4c672b16e6a648b83f Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Fri, 10 Mar 2023 12:43:33 +0100 Subject: [PATCH 03/12] fix unit tests --- .../jfuse/mac/StatvfsImplTest.java | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java b/jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java index 6469e2ef..040d825b 100644 --- a/jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java +++ b/jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java @@ -38,7 +38,7 @@ public static Stream testGetters() { Arguments.arguments((SetInMemorySegment) statvfs::f_blocks$set, Named.of("getBlocks()", (GetInStatvfs) Statvfs::getBlocks), 42), Arguments.arguments((SetInMemorySegment) statvfs::f_bfree$set, Named.of("getBfree()", (GetInStatvfs) Statvfs::getBfree), 42), Arguments.arguments((SetInMemorySegment) statvfs::f_bavail$set, Named.of("getBavail()", (GetInStatvfs) Statvfs::getBavail), 42), - Arguments.arguments((SetInMemorySegment) statvfs::f_namemax$set, Named.of("getNameMax()", (GetInStatvfs) Statvfs::getNameMax), 42) + Arguments.arguments((SetInMemorySegment) statvfs::f_namemax$set, Named.of("getNameMax()", (GetInStatvfs) Statvfs::getNameMax), 42L) ); } @@ -48,28 +48,47 @@ private interface SetInMemorySegment extends BiConsumer { private interface GetInStatvfs extends Function { } - @DisplayName("test setters") + @DisplayName("test setters with long type") @ParameterizedTest(name = "{0}") @MethodSource - public void testSetters(SetInStatvfs setter, GetInMemorySegment getter, Number value) { + public void testSettersLong(SetInStatvfs setter, GetInMemorySegment getter, Number value) { try (var scope = MemorySession.openConfined()) { var segment = statvfs.allocate(scope); var statvfs = new StatvfsImpl(segment.address(), scope); - setter.accept(statvfs, value); + setter.accept(statvfs, value.longValue()); Assertions.assertEquals(value.longValue(), getter.apply(segment).longValue()); } } - public static Stream testSetters() { + public static Stream testSettersLong() { return Stream.of( Arguments.arguments(Named.of("setBsize()", (SetInStatvfs) Statvfs::setBsize), (GetInMemorySegment) statvfs::f_bsize$get, 42L), Arguments.arguments(Named.of("setFrsize()", (SetInStatvfs) Statvfs::setFrsize), (GetInMemorySegment) statvfs::f_frsize$get, 42L), + Arguments.arguments(Named.of("setNameMax()", (SetInStatvfs) Statvfs::setNameMax), (GetInMemorySegment) statvfs::f_namemax$get, 42L) + ); + } + + @DisplayName("test setters with int type") + @ParameterizedTest(name = "{0}") + @MethodSource + public void testSettersInt(SetInStatvfs setter, GetInMemorySegment getter, Number value) { + try (var scope = MemorySession.openConfined()) { + var segment = statvfs.allocate(scope); + var statvfs = new StatvfsImpl(segment.address(), scope); + + setter.accept(statvfs, value.longValue()); + + Assertions.assertEquals(value.longValue(), getter.apply(segment).intValue()); + } + } + + public static Stream testSettersInt() { + return Stream.of( Arguments.arguments(Named.of("setBlocks()", (SetInStatvfs) Statvfs::setBlocks), (GetInMemorySegment) statvfs::f_blocks$get, 42), Arguments.arguments(Named.of("setBfree()", (SetInStatvfs) Statvfs::setBfree), (GetInMemorySegment) statvfs::f_bfree$get, 42), - Arguments.arguments(Named.of("setBavail()", (SetInStatvfs) Statvfs::setBavail), (GetInMemorySegment) statvfs::f_bavail$get, 42), - Arguments.arguments(Named.of("setNameMax()", (SetInStatvfs) Statvfs::setNameMax), (GetInMemorySegment) statvfs::f_namemax$get, 42L) + Arguments.arguments(Named.of("setBavail()", (SetInStatvfs) Statvfs::setBavail), (GetInMemorySegment) statvfs::f_bavail$get, 42) ); } @@ -81,7 +100,7 @@ public void testSettersCasting(SetInStatvfs setter, GetInMemorySegment Date: Fri, 10 Mar 2023 12:47:16 +0100 Subject: [PATCH 04/12] ensure MAX_UINT is long --- .../src/main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java b/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java index c7d09216..f30a7e28 100644 --- a/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java +++ b/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java @@ -9,7 +9,7 @@ record StatvfsImpl(MemorySegment segment) implements Statvfs { - private static final long MAX_UINT = 0xFFFFFFFF; + private static final long MAX_UINT = 0xFFFFFFFFL; public StatvfsImpl(MemoryAddress address, MemorySession scope) { this(statvfs.ofAddress(address, scope)); From b1af02021f28c4087c2f3ccfc5a6cac4d8e4394f Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Fri, 10 Mar 2023 12:54:12 +0100 Subject: [PATCH 05/12] Replace unchecked excpetions with setting to max value --- .../cryptomator/jfuse/mac/StatvfsImpl.java | 18 ++----- .../jfuse/mac/StatvfsImplTest.java | 50 +++++++++---------- 2 files changed, 27 insertions(+), 41 deletions(-) diff --git a/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java b/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java index f30a7e28..65f8a346 100644 --- a/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java +++ b/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java @@ -42,11 +42,7 @@ public long getBlocks() { @Override public void setBlocks(long blocks) { - if (blocks > MAX_UINT){ - throw new IllegalArgumentException("Max supported number of blocks: " + MAX_UINT); - } else { - statvfs.f_blocks$set(segment, (int) blocks); - } + statvfs.f_blocks$set(segment,(int) Math.min(MAX_UINT, blocks)); } @Override @@ -56,11 +52,7 @@ public long getBfree() { @Override public void setBfree(long bfree) { - if (bfree > MAX_UINT){ - throw new IllegalArgumentException("Max supported number of blocks: " + MAX_UINT); - } else { - statvfs.f_bfree$set(segment, (int) bfree); - } + statvfs.f_blocks$set(segment,(int) Math.min(MAX_UINT, bfree)); } @Override @@ -70,11 +62,7 @@ public long getBavail() { @Override public void setBavail(long bavail) { - if (bavail > MAX_UINT){ - throw new IllegalArgumentException("Max supported number of blocks: " + MAX_UINT); - } else { - statvfs.f_bavail$set(segment, (int) bavail); - } + statvfs.f_blocks$set(segment,(int) Math.min(MAX_UINT, bavail)); } @Override diff --git a/jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java b/jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java index 040d825b..a4dede18 100644 --- a/jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java +++ b/jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java @@ -17,10 +17,10 @@ public class StatvfsImplTest { - @DisplayName("test getters") + @DisplayName("test getters with native long type") @ParameterizedTest(name = "{1}") @MethodSource - public void testGetters(SetInMemorySegment setter, GetInStatvfs getter, Number value) { + public void testGettersLong(SetInMemorySegment setter, GetInStatvfs getter, Number value) { try (var scope = MemorySession.openConfined()) { var segment = statvfs.allocate(scope); var statvfs = new StatvfsImpl(segment.address(), scope); @@ -31,17 +31,35 @@ public void testGetters(SetInMemorySegment setter, GetInStatvfs } } - public static Stream testGetters() { + public static Stream testGettersLong() { return Stream.of( Arguments.arguments((SetInMemorySegment) statvfs::f_bsize$set, Named.of("getBsize()", (GetInStatvfs) Statvfs::getBsize), 42L), Arguments.arguments((SetInMemorySegment) statvfs::f_frsize$set, Named.of("getFrsize()", (GetInStatvfs) Statvfs::getFrsize), 42L), - Arguments.arguments((SetInMemorySegment) statvfs::f_blocks$set, Named.of("getBlocks()", (GetInStatvfs) Statvfs::getBlocks), 42), - Arguments.arguments((SetInMemorySegment) statvfs::f_bfree$set, Named.of("getBfree()", (GetInStatvfs) Statvfs::getBfree), 42), - Arguments.arguments((SetInMemorySegment) statvfs::f_bavail$set, Named.of("getBavail()", (GetInStatvfs) Statvfs::getBavail), 42), Arguments.arguments((SetInMemorySegment) statvfs::f_namemax$set, Named.of("getNameMax()", (GetInStatvfs) Statvfs::getNameMax), 42L) ); } + @DisplayName("test getters with native int type") + @ParameterizedTest(name = "{1}") + @MethodSource + public void testGettersInt(SetInMemorySegment setter, GetInStatvfs getter, Number value) { + try (var scope = MemorySession.openConfined()) { + var segment = statvfs.allocate(scope); + var statvfs = new StatvfsImpl(segment.address(), scope); + + setter.accept(segment, value.intValue()); + Assertions.assertEquals(Integer.toUnsignedLong(value.intValue()), getter.apply(statvfs).longValue()); + } + } + + public static Stream testGettersInt() { + return Stream.of( + Arguments.arguments((SetInMemorySegment) statvfs::f_blocks$set, Named.of("getBlocks()", (GetInStatvfs) Statvfs::getBlocks), -42), + Arguments.arguments((SetInMemorySegment) statvfs::f_bfree$set, Named.of("getBfree()", (GetInStatvfs) Statvfs::getBfree), -42), + Arguments.arguments((SetInMemorySegment) statvfs::f_bavail$set, Named.of("getBavail()", (GetInStatvfs) Statvfs::getBavail), -42) + ); + } + private interface SetInMemorySegment extends BiConsumer { } @@ -114,26 +132,6 @@ public static Stream testSettersCasting() { ); } - @DisplayName("test setters out-of-range") - @ParameterizedTest(name = "{0}") - @MethodSource - public void testSettersOutOfRange(SetInStatvfs setter, Number value) { - try (var scope = MemorySession.openConfined()) { - var segment = statvfs.allocate(scope); - var statvfs = new StatvfsImpl(segment.address(), scope); - - Assertions.assertThrows(IllegalArgumentException.class, () -> setter.accept(statvfs, value)); - } - } - - public static Stream testSettersOutOfRange() { - return Stream.of( - Arguments.arguments(Named.of("setBlocks()", (SetInStatvfs) Statvfs::setBlocks), 0x100000000L), - Arguments.arguments(Named.of("setBfree()", (SetInStatvfs) Statvfs::setBfree), 0x100000000L), - Arguments.arguments(Named.of("setBavail()", (SetInStatvfs) Statvfs::setBavail), 0x100000000L) - ); - } - private interface SetInStatvfs extends BiConsumer { } From 40edc6ab79466c1ec8585ae626a617d73e875a98 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Fri, 10 Mar 2023 13:07:58 +0100 Subject: [PATCH 06/12] write to correct memory region --- .../src/main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java b/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java index 65f8a346..243041cb 100644 --- a/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java +++ b/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java @@ -52,7 +52,7 @@ public long getBfree() { @Override public void setBfree(long bfree) { - statvfs.f_blocks$set(segment,(int) Math.min(MAX_UINT, bfree)); + statvfs.f_bfree$set(segment,(int) Math.min(MAX_UINT, bfree)); } @Override @@ -62,7 +62,7 @@ public long getBavail() { @Override public void setBavail(long bavail) { - statvfs.f_blocks$set(segment,(int) Math.min(MAX_UINT, bavail)); + statvfs.f_bavail$set(segment,(int) Math.min(MAX_UINT, bavail)); } @Override From b0c66e917cb481a0134f7e1c4e374ed61c9a210e Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Fri, 10 Mar 2023 13:44:17 +0100 Subject: [PATCH 07/12] compare complete number in assertion --- .../test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java b/jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java index a4dede18..3183230f 100644 --- a/jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java +++ b/jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java @@ -120,7 +120,7 @@ public void testSettersCasting(SetInStatvfs setter, GetInMemorySegment Date: Fri, 10 Mar 2023 13:47:32 +0100 Subject: [PATCH 08/12] add test cases when value exceeds unsinged int range --- .../jfuse/mac/StatvfsImplTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java b/jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java index 3183230f..785bb23e 100644 --- a/jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java +++ b/jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java @@ -132,6 +132,29 @@ public static Stream testSettersCasting() { ); } + @DisplayName("test setters out-of-range") + @ParameterizedTest(name = "{0}") + @MethodSource + public void testSettersOutOfRange(SetInStatvfs setter, GetInMemorySegment getter, Number value) { + try (var scope = MemorySession.openConfined()) { + var segment = statvfs.allocate(scope); + var statvfs = new StatvfsImpl(segment.address(), scope); + + setter.accept(statvfs, value.longValue()); + + Assertions.assertEquals(0xFFFFFFFF, getter.apply(segment).intValue()); + } + } + + public static Stream testSettersOutOfRange() { + return Stream.of( + Arguments.arguments(Named.of("setBlocks()", (SetInStatvfs) Statvfs::setBlocks), (GetInMemorySegment) statvfs::f_blocks$get, 0x01234567_89abcdefL), + Arguments.arguments(Named.of("setBfree()", (SetInStatvfs) Statvfs::setBfree), (GetInMemorySegment) statvfs::f_bfree$get, 0x01234567_89abcdefL), + Arguments.arguments(Named.of("setBavail()", (SetInStatvfs) Statvfs::setBavail), (GetInMemorySegment) statvfs::f_bavail$get, 0x01234567_89abcdefL) + ); + } + + private interface SetInStatvfs extends BiConsumer { } From 69444f472fcebcbae50f6d9f79a02822cda37ca4 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Fri, 10 Mar 2023 14:32:03 +0100 Subject: [PATCH 09/12] consolidated test cases --- .../jfuse/mac/StatvfsImplTest.java | 125 ++++-------------- 1 file changed, 29 insertions(+), 96 deletions(-) diff --git a/jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java b/jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java index 785bb23e..909f2930 100644 --- a/jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java +++ b/jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java @@ -17,46 +17,33 @@ public class StatvfsImplTest { - @DisplayName("test getters with native long type") + @DisplayName("test getters") @ParameterizedTest(name = "{1}") @MethodSource - public void testGettersLong(SetInMemorySegment setter, GetInStatvfs getter, Number value) { + public void testGetters(SetInMemorySegment setter, GetInStatvfs getter, Number value, long expected) { try (var scope = MemorySession.openConfined()) { var segment = statvfs.allocate(scope); var statvfs = new StatvfsImpl(segment.address(), scope); setter.accept(segment, value); - Assertions.assertEquals(value.longValue(), getter.apply(statvfs).longValue()); + Assertions.assertEquals(expected, getter.apply(statvfs).longValue()); } } - public static Stream testGettersLong() { + public static Stream testGetters() { return Stream.of( - Arguments.arguments((SetInMemorySegment) statvfs::f_bsize$set, Named.of("getBsize()", (GetInStatvfs) Statvfs::getBsize), 42L), - Arguments.arguments((SetInMemorySegment) statvfs::f_frsize$set, Named.of("getFrsize()", (GetInStatvfs) Statvfs::getFrsize), 42L), - Arguments.arguments((SetInMemorySegment) statvfs::f_namemax$set, Named.of("getNameMax()", (GetInStatvfs) Statvfs::getNameMax), 42L) - ); - } - - @DisplayName("test getters with native int type") - @ParameterizedTest(name = "{1}") - @MethodSource - public void testGettersInt(SetInMemorySegment setter, GetInStatvfs getter, Number value) { - try (var scope = MemorySession.openConfined()) { - var segment = statvfs.allocate(scope); - var statvfs = new StatvfsImpl(segment.address(), scope); + Arguments.arguments((SetInMemorySegment) statvfs::f_bsize$set, Named.of("getBsize()", (GetInStatvfs) Statvfs::getBsize), 42L, 42L), + Arguments.arguments((SetInMemorySegment) statvfs::f_frsize$set, Named.of("getFrsize()", (GetInStatvfs) Statvfs::getFrsize), 42L, 42L), + Arguments.arguments((SetInMemorySegment) statvfs::f_namemax$set, Named.of("getNameMax()", (GetInStatvfs) Statvfs::getNameMax), 42L, 42L), - setter.accept(segment, value.intValue()); - Assertions.assertEquals(Integer.toUnsignedLong(value.intValue()), getter.apply(statvfs).longValue()); - } - } + Arguments.arguments((SetInMemorySegment) statvfs::f_blocks$set, Named.of("getBlocks() with memory containing value < INT32", (GetInStatvfs) Statvfs::getBlocks), 42, 42L), + Arguments.arguments((SetInMemorySegment) statvfs::f_bfree$set, Named.of("getBfree() with memory containing value < INT32", (GetInStatvfs) Statvfs::getBfree), 42, 42L), + Arguments.arguments((SetInMemorySegment) statvfs::f_bavail$set, Named.of("getBavail() with memory containing value < INT32", (GetInStatvfs) Statvfs::getBavail), 42, 42L), - public static Stream testGettersInt() { - return Stream.of( - Arguments.arguments((SetInMemorySegment) statvfs::f_blocks$set, Named.of("getBlocks()", (GetInStatvfs) Statvfs::getBlocks), -42), - Arguments.arguments((SetInMemorySegment) statvfs::f_bfree$set, Named.of("getBfree()", (GetInStatvfs) Statvfs::getBfree), -42), - Arguments.arguments((SetInMemorySegment) statvfs::f_bavail$set, Named.of("getBavail()", (GetInStatvfs) Statvfs::getBavail), -42) + Arguments.arguments((SetInMemorySegment) statvfs::f_blocks$set, Named.of("getBlocks() with memory containing value < UINT32", (GetInStatvfs) Statvfs::getBlocks), 0xFFFFFFD6, 0x00000000_FFFFFFD6L), + Arguments.arguments((SetInMemorySegment) statvfs::f_bfree$set, Named.of("getBfree() with memory containing value < UINT32", (GetInStatvfs) Statvfs::getBfree), 0xFFFFFFD6, 0x00000000_FFFFFFD6L), + Arguments.arguments((SetInMemorySegment) statvfs::f_bavail$set, Named.of("getBavail() with memory containing value < UINT32", (GetInStatvfs) Statvfs::getBavail), 0xFFFFFFD6, 0x00000000_FFFFFFD6L) ); } @@ -66,91 +53,37 @@ private interface SetInMemorySegment extends BiConsumer { private interface GetInStatvfs extends Function { } - @DisplayName("test setters with long type") + @DisplayName("test setters") @ParameterizedTest(name = "{0}") @MethodSource - public void testSettersLong(SetInStatvfs setter, GetInMemorySegment getter, Number value) { + public void testSetters(SetInStatvfs setter, GetInMemorySegment getter, Number value, long expected) { try (var scope = MemorySession.openConfined()) { var segment = statvfs.allocate(scope); var statvfs = new StatvfsImpl(segment.address(), scope); setter.accept(statvfs, value.longValue()); - Assertions.assertEquals(value.longValue(), getter.apply(segment).longValue()); + Assertions.assertEquals(expected, getter.apply(segment).longValue()); } } - public static Stream testSettersLong() { + public static Stream testSetters() { return Stream.of( - Arguments.arguments(Named.of("setBsize()", (SetInStatvfs) Statvfs::setBsize), (GetInMemorySegment) statvfs::f_bsize$get, 42L), - Arguments.arguments(Named.of("setFrsize()", (SetInStatvfs) Statvfs::setFrsize), (GetInMemorySegment) statvfs::f_frsize$get, 42L), - Arguments.arguments(Named.of("setNameMax()", (SetInStatvfs) Statvfs::setNameMax), (GetInMemorySegment) statvfs::f_namemax$get, 42L) - ); - } + Arguments.arguments(Named.of("setBsize()", (SetInStatvfs) Statvfs::setBsize), (GetInMemorySegment) statvfs::f_bsize$get, 42L, 42L), + Arguments.arguments(Named.of("setFrsize()", (SetInStatvfs) Statvfs::setFrsize), (GetInMemorySegment) statvfs::f_frsize$get, 42L, 42L), + Arguments.arguments(Named.of("setNameMax()", (SetInStatvfs) Statvfs::setNameMax), (GetInMemorySegment) statvfs::f_namemax$get, 42L, 42L), - @DisplayName("test setters with int type") - @ParameterizedTest(name = "{0}") - @MethodSource - public void testSettersInt(SetInStatvfs setter, GetInMemorySegment getter, Number value) { - try (var scope = MemorySession.openConfined()) { - var segment = statvfs.allocate(scope); - var statvfs = new StatvfsImpl(segment.address(), scope); + Arguments.arguments(Named.of("setBlocks(i) with i < INT32", (SetInStatvfs) Statvfs::setBlocks), (GetInMemorySegment) statvfs::f_blocks$get, 42, 42), + Arguments.arguments(Named.of("setBfree(i) with i < INT32", (SetInStatvfs) Statvfs::setBfree), (GetInMemorySegment) statvfs::f_bfree$get, 42, 42), + Arguments.arguments(Named.of("setBavail(i) with i < INT32", (SetInStatvfs) Statvfs::setBavail), (GetInMemorySegment) statvfs::f_bavail$get, 42, 42), - setter.accept(statvfs, value.longValue()); + Arguments.arguments(Named.of("setBlocks(i) with i > INT32", (SetInStatvfs) Statvfs::setBlocks), (GetInMemorySegment) statvfs::f_blocks$get, 0xFFFFFFD6, 0xFFFFFFD6), + Arguments.arguments(Named.of("setBfree(i) with i > INT32", (SetInStatvfs) Statvfs::setBfree), (GetInMemorySegment) statvfs::f_bfree$get, 0xFFFFFFD6, 0xFFFFFFD6), + Arguments.arguments(Named.of("setBavail(i) with i > INT32", (SetInStatvfs) Statvfs::setBavail), (GetInMemorySegment) statvfs::f_bavail$get, 0xFFFFFFD6, 0xFFFFFFD6), - Assertions.assertEquals(value.longValue(), getter.apply(segment).intValue()); - } - } - - public static Stream testSettersInt() { - return Stream.of( - Arguments.arguments(Named.of("setBlocks()", (SetInStatvfs) Statvfs::setBlocks), (GetInMemorySegment) statvfs::f_blocks$get, 42), - Arguments.arguments(Named.of("setBfree()", (SetInStatvfs) Statvfs::setBfree), (GetInMemorySegment) statvfs::f_bfree$get, 42), - Arguments.arguments(Named.of("setBavail()", (SetInStatvfs) Statvfs::setBavail), (GetInMemorySegment) statvfs::f_bavail$get, 42) - ); - } - - @DisplayName("test setters casting") - @ParameterizedTest(name = "{0}") - @MethodSource - public void testSettersCasting(SetInStatvfs setter, GetInMemorySegment getter, Number value) { - try (var scope = MemorySession.openConfined()) { - var segment = statvfs.allocate(scope); - var statvfs = new StatvfsImpl(segment.address(), scope); - - setter.accept(statvfs, value.longValue()); - - Assertions.assertEquals(value.intValue(), getter.apply(segment).intValue()); - } - } - - public static Stream testSettersCasting() { - return Stream.of( - Arguments.arguments(Named.of("setBlocks()", (SetInStatvfs) Statvfs::setBlocks), (GetInMemorySegment) statvfs::f_blocks$get, -42), - Arguments.arguments(Named.of("setBfree()", (SetInStatvfs) Statvfs::setBfree), (GetInMemorySegment) statvfs::f_bfree$get, -42), - Arguments.arguments(Named.of("setBavail()", (SetInStatvfs) Statvfs::setBavail), (GetInMemorySegment) statvfs::f_bavail$get, -42) - ); - } - - @DisplayName("test setters out-of-range") - @ParameterizedTest(name = "{0}") - @MethodSource - public void testSettersOutOfRange(SetInStatvfs setter, GetInMemorySegment getter, Number value) { - try (var scope = MemorySession.openConfined()) { - var segment = statvfs.allocate(scope); - var statvfs = new StatvfsImpl(segment.address(), scope); - - setter.accept(statvfs, value.longValue()); - - Assertions.assertEquals(0xFFFFFFFF, getter.apply(segment).intValue()); - } - } - - public static Stream testSettersOutOfRange() { - return Stream.of( - Arguments.arguments(Named.of("setBlocks()", (SetInStatvfs) Statvfs::setBlocks), (GetInMemorySegment) statvfs::f_blocks$get, 0x01234567_89abcdefL), - Arguments.arguments(Named.of("setBfree()", (SetInStatvfs) Statvfs::setBfree), (GetInMemorySegment) statvfs::f_bfree$get, 0x01234567_89abcdefL), - Arguments.arguments(Named.of("setBavail()", (SetInStatvfs) Statvfs::setBavail), (GetInMemorySegment) statvfs::f_bavail$get, 0x01234567_89abcdefL) + Arguments.arguments(Named.of("setBlocks(i) with i > UINT32", (SetInStatvfs) Statvfs::setBlocks), (GetInMemorySegment) statvfs::f_blocks$get, 0x01234567_89ABCDEFL, 0xFFFFFFFF), + Arguments.arguments(Named.of("setBfree(i) with i > UINT32", (SetInStatvfs) Statvfs::setBfree), (GetInMemorySegment) statvfs::f_bfree$get, 0x01234567_89ABCDEFL, 0xFFFFFFFF), + Arguments.arguments(Named.of("setBavail(i) with i > UINT32", (SetInStatvfs) Statvfs::setBavail), (GetInMemorySegment) statvfs::f_bavail$get, 0x01234567_89ABCDEFL, 0xFFFFFFFF) ); } From 424215fd401aa2ec9dcf4d08fee3facd61da2451 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Sun, 12 Mar 2023 12:43:04 +0100 Subject: [PATCH 10/12] add `--enable-native-access` flags to JUnit Run Template [ci skip] --- .idea/runConfigurations/_template__of_JUnit.xml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .idea/runConfigurations/_template__of_JUnit.xml diff --git a/.idea/runConfigurations/_template__of_JUnit.xml b/.idea/runConfigurations/_template__of_JUnit.xml new file mode 100644 index 00000000..cde359ec --- /dev/null +++ b/.idea/runConfigurations/_template__of_JUnit.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file From 05f10be2339d420f0c0ad7ffd291e2c61467ce25 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Mon, 13 Mar 2023 09:23:37 +0100 Subject: [PATCH 11/12] update IDE files --- .idea/vcs.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7f..63c9ab20 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,5 +2,9 @@ + + + + \ No newline at end of file From cc4d679d7599847a604bd617b42792732e6a75f9 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Mon, 13 Mar 2023 09:26:17 +0100 Subject: [PATCH 12/12] prepare 0.4.1 --- jfuse-api/pom.xml | 2 +- jfuse-examples/pom.xml | 2 +- jfuse-linux-aarch64/pom.xml | 2 +- jfuse-linux-amd64/pom.xml | 2 +- jfuse-mac/pom.xml | 2 +- jfuse-tests/pom.xml | 2 +- jfuse-win/pom.xml | 2 +- jfuse/pom.xml | 2 +- pom.xml | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/jfuse-api/pom.xml b/jfuse-api/pom.xml index b982b7fe..3dc7fbc0 100644 --- a/jfuse-api/pom.xml +++ b/jfuse-api/pom.xml @@ -5,7 +5,7 @@ org.cryptomator jfuse-parent - 0.5.0-SNAPSHOT + 0.4.1 4.0.0 jfuse-api diff --git a/jfuse-examples/pom.xml b/jfuse-examples/pom.xml index 1096434b..be015173 100644 --- a/jfuse-examples/pom.xml +++ b/jfuse-examples/pom.xml @@ -5,7 +5,7 @@ org.cryptomator jfuse-parent - 0.5.0-SNAPSHOT + 0.4.1 4.0.0 jfuse-examples diff --git a/jfuse-linux-aarch64/pom.xml b/jfuse-linux-aarch64/pom.xml index 2c2133a3..0aa75f6e 100644 --- a/jfuse-linux-aarch64/pom.xml +++ b/jfuse-linux-aarch64/pom.xml @@ -5,7 +5,7 @@ jfuse-parent org.cryptomator - 0.5.0-SNAPSHOT + 0.4.1 4.0.0 jfuse-linux-aarch64 diff --git a/jfuse-linux-amd64/pom.xml b/jfuse-linux-amd64/pom.xml index 0e7ba6a1..b124c530 100644 --- a/jfuse-linux-amd64/pom.xml +++ b/jfuse-linux-amd64/pom.xml @@ -5,7 +5,7 @@ org.cryptomator jfuse-parent - 0.5.0-SNAPSHOT + 0.4.1 4.0.0 jfuse-linux-amd64 diff --git a/jfuse-mac/pom.xml b/jfuse-mac/pom.xml index 2fdc893a..77453e67 100644 --- a/jfuse-mac/pom.xml +++ b/jfuse-mac/pom.xml @@ -5,7 +5,7 @@ org.cryptomator jfuse-parent - 0.5.0-SNAPSHOT + 0.4.1 4.0.0 jfuse-mac diff --git a/jfuse-tests/pom.xml b/jfuse-tests/pom.xml index 4a016e94..683a628a 100644 --- a/jfuse-tests/pom.xml +++ b/jfuse-tests/pom.xml @@ -5,7 +5,7 @@ org.cryptomator jfuse-parent - 0.5.0-SNAPSHOT + 0.4.1 4.0.0 jfuse-tests diff --git a/jfuse-win/pom.xml b/jfuse-win/pom.xml index 8f836716..d8707f30 100644 --- a/jfuse-win/pom.xml +++ b/jfuse-win/pom.xml @@ -5,7 +5,7 @@ org.cryptomator jfuse-parent - 0.5.0-SNAPSHOT + 0.4.1 4.0.0 jfuse-win diff --git a/jfuse/pom.xml b/jfuse/pom.xml index 6f0c755a..f72c304a 100644 --- a/jfuse/pom.xml +++ b/jfuse/pom.xml @@ -5,7 +5,7 @@ org.cryptomator jfuse-parent - 0.5.0-SNAPSHOT + 0.4.1 4.0.0 jfuse diff --git a/pom.xml b/pom.xml index 60439f66..3e8a0160 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.cryptomator jfuse-parent pom - 0.5.0-SNAPSHOT + 0.4.1 jFUSE Java bindings for FUSE using foreign functions & memory API https://github.com/cryptomator/jfuse