diff --git a/test/jdk/java/foreign/CallGeneratorHelper.java b/test/jdk/java/foreign/CallGeneratorHelper.java index 6fd32eac41095..360c7540b4f45 100644 --- a/test/jdk/java/foreign/CallGeneratorHelper.java +++ b/test/jdk/java/foreign/CallGeneratorHelper.java @@ -37,8 +37,10 @@ import java.util.stream.Stream; import jdk.internal.foreign.Utils; -import org.testng.annotations.*; +import org.junit.jupiter.api.TestInstance; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class CallGeneratorHelper extends NativeTestHelper { static final List STACK_PREFIX_LAYOUTS = Stream.concat( @@ -151,7 +153,6 @@ static void generateTest(int i, Stack combo, Z[] elems, List> res } } - @DataProvider(name = "functions") public static Object[][] functions() { int functions = 0; List downcalls = new ArrayList<>(); diff --git a/test/jdk/java/foreign/CompositeLookupTest.java b/test/jdk/java/foreign/CompositeLookupTest.java index 1cc0b35950d38..7c0c3498ef830 100644 --- a/test/jdk/java/foreign/CompositeLookupTest.java +++ b/test/jdk/java/foreign/CompositeLookupTest.java @@ -21,36 +21,39 @@ * questions. */ -import org.testng.annotations.Test; import java.lang.foreign.*; import java.util.List; import java.util.Optional; import java.util.Set; -import org.testng.annotations.*; - -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; /* * @test - * @run testng CompositeLookupTest + * @run junit CompositeLookupTest */ +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class CompositeLookupTest { - @Test(dataProvider = "testCases") + @ParameterizedTest + @MethodSource("testCases") public void testLookups(SymbolLookup lookup, List results) { for (Result result : results) { switch (result) { case Success(String name, long expectedLookupId) -> { Optional symbol = lookup.find(name); assertTrue(symbol.isPresent()); - assertEquals(symbol.get().address(), expectedLookupId); + assertEquals(expectedLookupId, symbol.get().address()); } case Failure(String name) -> { Optional symbol = lookup.find(name); assertFalse(symbol.isPresent()); } + } } } @@ -76,7 +79,6 @@ sealed interface Result { } record Success(String name, long expectedLookupId) implements Result { } record Failure(String name) implements Result { } - @DataProvider(name = "testCases") public Object[][] testCases() { return new Object[][]{ { diff --git a/test/jdk/java/foreign/LibraryLookupTest.java b/test/jdk/java/foreign/LibraryLookupTest.java index ad2f02c5df3f9..847336c91d339 100644 --- a/test/jdk/java/foreign/LibraryLookupTest.java +++ b/test/jdk/java/foreign/LibraryLookupTest.java @@ -21,7 +21,6 @@ * questions. */ -import org.testng.annotations.Test; import java.io.IOException; import java.lang.foreign.*; @@ -37,11 +36,12 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; /* * @test id=specialized - * @run testng/othervm/native + * @run junit/othervm/native * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=true * --enable-native-access=ALL-UNNAMED * LibraryLookupTest @@ -49,7 +49,7 @@ /* * @test id=interpreted - * @run testng/othervm/native + * @run junit/othervm/native * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=false * --enable-native-access=ALL-UNNAMED * LibraryLookupTest @@ -73,19 +73,23 @@ void testLoadLibraryConfined() { } } - @Test(expectedExceptions = IllegalStateException.class) + @Test void testLoadLibraryConfinedClosed() { MemorySegment addr; try (Arena arena = Arena.ofConfined()) { addr = loadLibrary(arena); } - callFunc(addr); + assertThrows(IllegalStateException.class, () -> { + callFunc(addr); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test void testLoadLibraryBadName() { try (Arena arena = Arena.ofConfined()) { - SymbolLookup.libraryLookup(LIB_PATH.toString() + "\u0000", arena); + assertThrows(IllegalArgumentException.class, () -> { + SymbolLookup.libraryLookup(LIB_PATH.toString() + "\u0000", arena); + }); } } @@ -99,7 +103,7 @@ void testLoadLibraryBadLookupName() { @Test void testLoadLibraryNonDefaultFileSystem() throws URISyntaxException, IOException { - try (FileSystem customFs = fsFromJarOfClass(org.testng.annotations.Test.class)) { + try (FileSystem customFs = fsFromJarOfClass(Test.class)) { try (Arena arena = Arena.ofConfined()) { Path p = customFs.getPath("."); try { @@ -131,7 +135,7 @@ private static FileSystem fsFromJarOfClass(Class clazz) throws URISyntaxExcep private static MemorySegment loadLibrary(Arena session) { SymbolLookup lib = SymbolLookup.libraryLookup(LIB_PATH, session); MemorySegment addr = lib.find("inc").get(); - assertEquals(addr.scope(), session.scope()); + assertEquals(session.scope(), addr.scope()); return addr; } @@ -149,14 +153,18 @@ private static void callFunc(MemorySegment addr) { static final int MAX_EXECUTOR_WAIT_SECONDS = 20; static final int NUM_ACCESSORS = Math.min(10, Runtime.getRuntime().availableProcessors()); - @Test(expectedExceptions = IllegalArgumentException.class) + @Test void testBadLibraryLookupName() { - SymbolLookup.libraryLookup("nonExistent", Arena.global()); + assertThrows(IllegalArgumentException.class, () -> { + SymbolLookup.libraryLookup("nonExistent", Arena.global()); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test void testBadLibraryLookupPath() { - SymbolLookup.libraryLookup(Path.of("nonExistent"), Arena.global()); + assertThrows(IllegalArgumentException.class, () -> { + SymbolLookup.libraryLookup(Path.of("nonExistent"), Arena.global()); + }); } @Test diff --git a/test/jdk/java/foreign/MemoryLayoutPrincipalTotalityTest.java b/test/jdk/java/foreign/MemoryLayoutPrincipalTotalityTest.java index c304a1390148a..345619355bfbc 100644 --- a/test/jdk/java/foreign/MemoryLayoutPrincipalTotalityTest.java +++ b/test/jdk/java/foreign/MemoryLayoutPrincipalTotalityTest.java @@ -23,15 +23,16 @@ /* * @test - * @run testng/othervm MemoryLayoutPrincipalTotalityTest + * @run junit/othervm MemoryLayoutPrincipalTotalityTest */ -import org.testng.annotations.*; import java.lang.foreign.*; import static java.lang.foreign.ValueLayout.*; -import static org.testng.Assert.*; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class MemoryLayoutPrincipalTotalityTest { @@ -43,7 +44,7 @@ public void testBasicTotality() { int v0 = switch (memoryLayout) { case MemoryLayout ml -> 1; }; - assertEquals(v0, 1); + assertEquals(1, v0); } @Test @@ -55,7 +56,7 @@ public void testMLRemovedTotality() { case SequenceLayout sl -> 0; // leaf case ValueLayout vl -> 1; }; - assertEquals(v1, 1); + assertEquals(1, v1); } @Test @@ -68,7 +69,7 @@ public void testMLGLRemovedTotality() { case StructLayout sl -> 0; // leaf case UnionLayout ul -> 0; // leaf }; - assertEquals(v2, 1); + assertEquals(1, v2); } @Test @@ -89,7 +90,7 @@ public void testMLGLVLRemovedTotality() { case OfLong ol -> 0; // leaf case OfShort os -> 0; // leaf }; - assertEquals(v3, 1); + assertEquals(1, v3); } @Test @@ -109,7 +110,7 @@ public void testMLVLRemovedTotality() { case OfLong ol -> 0; // leaf case OfShort os -> 0; // leaf }; - assertEquals(v4, 1); + assertEquals(1, v4); } private static MemoryLayout javaIntMemoryLayout() { diff --git a/test/jdk/java/foreign/MemoryLayoutTypeRetentionTest.java b/test/jdk/java/foreign/MemoryLayoutTypeRetentionTest.java index ecfc4b0da38a5..86e383f6d4442 100644 --- a/test/jdk/java/foreign/MemoryLayoutTypeRetentionTest.java +++ b/test/jdk/java/foreign/MemoryLayoutTypeRetentionTest.java @@ -23,16 +23,17 @@ /* * @test - * @run testng/othervm MemoryLayoutTypeRetentionTest + * @run junit/othervm MemoryLayoutTypeRetentionTest */ -import org.testng.annotations.*; import java.lang.foreign.*; import java.nio.ByteOrder; import static java.lang.foreign.ValueLayout.*; -import static org.testng.Assert.*; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class MemoryLayoutTypeRetentionTest { @@ -144,12 +145,12 @@ public void testAddressLayout() { .withoutTargetLayout() .withOrder(BYTE_ORDER); check(v); - assertEquals(v.order(), BYTE_ORDER); + assertEquals(BYTE_ORDER, v.order()); assertFalse(v.targetLayout().isPresent()); AddressLayout v2 = v.withTargetLayout(JAVA_INT); assertTrue(v2.targetLayout().isPresent()); - assertEquals(v2.targetLayout().get(), JAVA_INT); + assertEquals(JAVA_INT, v2.targetLayout().get()); assertTrue(v2.withoutTargetLayout().targetLayout().isEmpty()); } @@ -197,15 +198,15 @@ public void testUnionLayout() { public void check(ValueLayout v) { check((MemoryLayout) v); - assertEquals(v.order(), BYTE_ORDER); + assertEquals(BYTE_ORDER, v.order()); } public void check(MemoryLayout v) { // Check name properties - assertEquals(v.name().orElseThrow(), NAME); + assertEquals(NAME, v.name().orElseThrow()); assertTrue(v.withoutName().name().isEmpty()); - assertEquals(v.byteAlignment(), BYTE_ALIGNMENT); + assertEquals(BYTE_ALIGNMENT, v.byteAlignment()); } } diff --git a/test/jdk/java/foreign/SafeFunctionAccessTest.java b/test/jdk/java/foreign/SafeFunctionAccessTest.java index 658a0bfc78486..e22b86dd7ca9e 100644 --- a/test/jdk/java/foreign/SafeFunctionAccessTest.java +++ b/test/jdk/java/foreign/SafeFunctionAccessTest.java @@ -23,7 +23,7 @@ /* * @test id=specialized - * @run testng/othervm/native + * @run junit/othervm/native * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=true * --enable-native-access=ALL-UNNAMED * SafeFunctionAccessTest @@ -31,7 +31,7 @@ /* * @test id=interpreted - * @run testng/othervm/native + * @run junit/othervm/native * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=false * --enable-native-access=ALL-UNNAMED * SafeFunctionAccessTest @@ -49,9 +49,8 @@ import java.util.stream.Stream; -import org.testng.annotations.*; - -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class SafeFunctionAccessTest extends NativeTestHelper { static { @@ -62,18 +61,18 @@ public class SafeFunctionAccessTest extends NativeTestHelper { C_INT, C_INT ); - @Test(expectedExceptions = IllegalStateException.class) + @Test public void testClosedStruct() throws Throwable { MemorySegment segment; try (Arena arena = Arena.ofConfined()) { segment = arena.allocate(POINT); - } - assertFalse(segment.scope().isAlive()); + } assertFalse(segment.scope().isAlive()); MethodHandle handle = Linker.nativeLinker().downcallHandle( findNativeOrThrow("struct_func"), FunctionDescriptor.ofVoid(POINT)); - - handle.invokeExact(segment); + assertThrows(IllegalStateException.class, () -> { + handle.invokeExact(segment); + }); } @Test @@ -119,19 +118,19 @@ static Allocation of(MemoryLayout layout) { } } - @Test(expectedExceptions = IllegalStateException.class) + @Test public void testClosedUpcall() throws Throwable { MemorySegment upcall; try (Arena arena = Arena.ofConfined()) { MethodHandle dummy = MethodHandles.lookup().findStatic(SafeFunctionAccessTest.class, "dummy", MethodType.methodType(void.class)); upcall = Linker.nativeLinker().upcallStub(dummy, FunctionDescriptor.ofVoid(), arena); - } - assertFalse(upcall.scope().isAlive()); + } assertFalse(upcall.scope().isAlive()); MethodHandle handle = Linker.nativeLinker().downcallHandle( findNativeOrThrow("addr_func"), FunctionDescriptor.ofVoid(C_POINTER)); - - handle.invokeExact(upcall); + assertThrows(IllegalStateException.class, () -> { + handle.invokeExact(upcall); + }); } static void dummy() { } diff --git a/test/jdk/java/foreign/Test4BAlignedDouble.java b/test/jdk/java/foreign/Test4BAlignedDouble.java index ce3bf6c5f2f89..ab6b5a02c63b8 100644 --- a/test/jdk/java/foreign/Test4BAlignedDouble.java +++ b/test/jdk/java/foreign/Test4BAlignedDouble.java @@ -26,17 +26,18 @@ * @test * @summary Test passing of a structure which contains a double with 4 Byte alignment on AIX. * - * @run testng/othervm/native --enable-native-access=ALL-UNNAMED Test4BAlignedDouble + * @run junit/othervm/native --enable-native-access=ALL-UNNAMED Test4BAlignedDouble */ import java.lang.foreign.*; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; -import org.testng.annotations.Test; import static java.lang.foreign.ValueLayout.*; +import org.junit.jupiter.api.Test; + public class Test4BAlignedDouble { static { @@ -82,7 +83,7 @@ public class Test4BAlignedDouble { FunctionDescriptor.of(platform_S_IDFLayout, ADDRESS, platform_S_IDFLayout)); @Test - public static void testDowncall() { + public void testDowncall() { int p0 = 0; double p1 = 0.0d; float p2 = 0.0f; @@ -113,7 +114,7 @@ public static MemorySegment S_IDF_fun(MemorySegment p) { } @Test - public static void testUpcall() { + public void testUpcall() { int p0 = 0; double p1 = 0.0d; float p2 = 0.0f; diff --git a/test/jdk/java/foreign/TestAccessModes.java b/test/jdk/java/foreign/TestAccessModes.java index e54d4f1ae9ed1..da9e6a9149098 100644 --- a/test/jdk/java/foreign/TestAccessModes.java +++ b/test/jdk/java/foreign/TestAccessModes.java @@ -23,10 +23,10 @@ /* * @test - * @run testng/othervm/timeout=480 -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false -Xverify:all TestAccessModes - * @run testng/othervm/timeout=480 -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true -Xverify:all TestAccessModes - * @run testng/othervm/timeout=480 -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false -Xverify:all TestAccessModes - * @run testng/othervm/timeout=480 -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true -Xverify:all TestAccessModes + * @run junit/othervm/timeout=480 -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false -Xverify:all TestAccessModes + * @run junit/othervm/timeout=480 -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true -Xverify:all TestAccessModes + * @run junit/othervm/timeout=480 -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false -Xverify:all TestAccessModes + * @run junit/othervm/timeout=480 -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true -Xverify:all TestAccessModes */ import java.lang.foreign.*; @@ -40,12 +40,15 @@ import java.util.List; import java.util.Set; -import org.testng.annotations.*; - -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestAccessModes { - @Test(dataProvider = "segmentsAndLayoutsAndModes") + @ParameterizedTest + @MethodSource("segmentsAndLayoutsAndModes") public void testAccessModes(MemorySegment segment, MemoryLayout layout, AccessMode mode) throws Throwable { VarHandle varHandle = layout instanceof ValueLayout ? layout.varHandle() : @@ -61,7 +64,7 @@ public void testAccessModes(MemorySegment segment, MemoryLayout layout, AccessMo // access is unaligned assertTrue(segment.maxByteAlignment() < layout.byteAlignment()); } - assertEquals(varHandle.isAccessModeSupported(mode), compatible); + assertEquals(compatible, varHandle.isAccessModeSupported(mode)); } static ValueLayout accessLayout(MemoryLayout layout) { @@ -171,7 +174,6 @@ static MemorySegment[] segments() { }; } - @DataProvider(name = "segmentsAndLayoutsAndModes") static Object[][] segmentsAndLayoutsAndModes() { List segmentsAndLayouts = new ArrayList<>(); for (MemorySegment segment : segments()) { diff --git a/test/jdk/java/foreign/TestAdaptVarHandles.java b/test/jdk/java/foreign/TestAdaptVarHandles.java index ebbef0ffb6bcb..ce08e46c08444 100644 --- a/test/jdk/java/foreign/TestAdaptVarHandles.java +++ b/test/jdk/java/foreign/TestAdaptVarHandles.java @@ -24,16 +24,15 @@ /* * @test - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false -Xverify:all TestAdaptVarHandles - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true -Xverify:all TestAdaptVarHandles - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false -Xverify:all TestAdaptVarHandles - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true -Xverify:all TestAdaptVarHandles + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false -Xverify:all TestAdaptVarHandles + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true -Xverify:all TestAdaptVarHandles + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false -Xverify:all TestAdaptVarHandles + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true -Xverify:all TestAdaptVarHandles */ import java.lang.foreign.*; -import org.testng.annotations.*; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; @@ -41,6 +40,8 @@ import java.lang.invoke.VarHandle; import java.util.List; +import org.junit.jupiter.api.Test; + public class TestAdaptVarHandles { static MethodHandle S2I; @@ -98,15 +99,15 @@ public void testFilterValue() throws Throwable { VarHandle i2SHandle = MethodHandles.filterValue(intHandle, S2I, I2S); i2SHandle.set(segment, 0L, "1"); String oldValue = (String)i2SHandle.getAndAdd(segment, 0L, "42"); - assertEquals(oldValue, "1"); + assertEquals("1", oldValue); String value = (String)i2SHandle.get(segment, 0L); - assertEquals(value, "43"); + assertEquals("43", value); boolean swapped = (boolean)i2SHandle.compareAndSet(segment, 0L, "43", "12"); assertTrue(swapped); oldValue = (String)i2SHandle.compareAndExchange(segment, 0L, "12", "42"); - assertEquals(oldValue, "12"); + assertEquals("12", oldValue); value = (String)i2SHandle.toMethodHandle(VarHandle.AccessMode.GET).invokeExact(segment, 0L); - assertEquals(value, "42"); + assertEquals("42", value); } @Test @@ -120,15 +121,15 @@ public void testFilterValueComposite() throws Throwable { i2SHandle = MethodHandles.insertCoordinates(i2SHandle, 2, "a", "b"); i2SHandle.set(segment, 0L, "1"); String oldValue = (String)i2SHandle.getAndAdd(segment, 0L, "42"); - assertEquals(oldValue, "ab1"); + assertEquals("ab1", oldValue); String value = (String)i2SHandle.get(segment, 0L); - assertEquals(value, "ab43"); + assertEquals("ab43", value); boolean swapped = (boolean)i2SHandle.compareAndSet(segment, 0L, "43", "12"); assertTrue(swapped); oldValue = (String)i2SHandle.compareAndExchange(segment, 0L, "12", "42"); - assertEquals(oldValue, "ab12"); + assertEquals("ab12", oldValue); value = (String)i2SHandle.toMethodHandle(VarHandle.AccessMode.GET).invokeExact(segment, 0L); - assertEquals(value, "ab42"); + assertEquals("ab42", value); } @Test @@ -140,72 +141,88 @@ public void testFilterValueLoose() throws Throwable { VarHandle i2SHandle = MethodHandles.filterValue(intHandle, O2I, I2O); i2SHandle.set(segment, 0L, "1"); String oldValue = (String)i2SHandle.getAndAdd(segment, 0L, "42"); - assertEquals(oldValue, "1"); + assertEquals("1", oldValue); String value = (String)i2SHandle.get(segment, 0L); - assertEquals(value, "43"); + assertEquals("43", value); boolean swapped = (boolean)i2SHandle.compareAndSet(segment, 0L, "43", "12"); assertTrue(swapped); oldValue = (String)i2SHandle.compareAndExchange(segment, 0L, "12", "42"); - assertEquals(oldValue, "12"); + assertEquals("12", oldValue); value = (String)(Object)i2SHandle.toMethodHandle(VarHandle.AccessMode.GET).invokeExact(segment, 0L); - assertEquals(value, "42"); + assertEquals("42", value); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadFilterCarrier() { - MethodHandles.filterValue(floatHandle, S2I, I2S); + assertThrows(IllegalArgumentException.class, () -> { + MethodHandles.filterValue(floatHandle, S2I, I2S); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadFilterUnboxArity() { VarHandle floatHandle = ValueLayout.JAVA_INT.varHandle(); - MethodHandles.filterValue(floatHandle, S2I.bindTo(""), I2S); + assertThrows(IllegalArgumentException.class, () -> { + MethodHandles.filterValue(floatHandle, S2I.bindTo(""), I2S); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadFilterBoxArity() { VarHandle intHandle = ValueLayout.JAVA_INT.varHandle(); - MethodHandles.filterValue(intHandle, S2I, I2S.bindTo(42)); + assertThrows(IllegalArgumentException.class, () -> { + MethodHandles.filterValue(intHandle, S2I, I2S.bindTo(42)); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadFilterBoxPrefixCoordinates() { VarHandle intHandle = ValueLayout.JAVA_INT.varHandle(); - MethodHandles.filterValue(intHandle, - MethodHandles.dropArguments(S2I, 1, int.class), - MethodHandles.dropArguments(I2S, 1, long.class)); + assertThrows(IllegalArgumentException.class, () -> { + MethodHandles.filterValue(intHandle, + MethodHandles.dropArguments(S2I, 1, int.class), + MethodHandles.dropArguments(I2S, 1, long.class)); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadFilterBoxException() { VarHandle intHandle = ValueLayout.JAVA_INT.varHandle(); - MethodHandles.filterValue(intHandle, I2S, S2L_EX); + assertThrows(IllegalArgumentException.class, () -> { + MethodHandles.filterValue(intHandle, I2S, S2L_EX); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadFilterUnboxException() { VarHandle intHandle = ValueLayout.JAVA_INT.varHandle(); - MethodHandles.filterValue(intHandle, S2L_EX, I2S); + assertThrows(IllegalArgumentException.class, () -> { + MethodHandles.filterValue(intHandle, S2L_EX, I2S); + }); } - @Test(expectedExceptions = IllegalStateException.class) + @Test public void testBadFilterBoxHandleException() { VarHandle intHandle = ValueLayout.JAVA_INT.varHandle(); VarHandle vh = MethodHandles.filterValue(intHandle, S2I, I2S_EX); try (Arena arena = Arena.ofConfined()) { MemorySegment seg = arena.allocate(ValueLayout.JAVA_INT); vh.set(seg, 0L, "42"); - String x = (String) vh.get(seg, 0L); // should throw + assertThrows(IllegalStateException.class, () -> { + String x = (String) vh.get(seg, 0L); + }); } } - @Test(expectedExceptions = IllegalStateException.class) + @Test public void testBadFilterUnboxHandleException() { VarHandle intHandle = ValueLayout.JAVA_INT.varHandle(); VarHandle vh = MethodHandles.filterValue(intHandle, S2I_EX, I2S); try (Arena arena = Arena.ofConfined()) { MemorySegment seg = arena.allocate(ValueLayout.JAVA_INT); - vh.set(seg, 0L, "42"); // should throw + assertThrows(IllegalStateException.class, () -> { + vh.set(seg, 0L, "42"); // should throw + }); } } @@ -217,40 +234,50 @@ public void testFilterCoordinates() throws Throwable { VarHandle intHandle_longIndex = MethodHandles.filterCoordinates(intHandleIndexed, 0, BASE_ADDR, S2L); intHandle_longIndex.set(segment, "0", 1); int oldValue = (int)intHandle_longIndex.getAndAdd(segment, "0", 42); - assertEquals(oldValue, 1); + assertEquals(1, oldValue); int value = (int)intHandle_longIndex.get(segment, "0"); - assertEquals(value, 43); + assertEquals(43, value); boolean swapped = (boolean)intHandle_longIndex.compareAndSet(segment, "0", 43, 12); assertTrue(swapped); oldValue = (int)intHandle_longIndex.compareAndExchange(segment, "0", 12, 42); - assertEquals(oldValue, 12); + assertEquals(12, oldValue); value = (int)intHandle_longIndex.toMethodHandle(VarHandle.AccessMode.GET).invokeExact(segment, "0"); - assertEquals(value, 42); + assertEquals(42, value); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadFilterCoordinatesNegativePos() { - MethodHandles.filterCoordinates(intHandle, -1, SUM_OFFSETS); + assertThrows(IllegalArgumentException.class, () -> { + MethodHandles.filterCoordinates(intHandle, -1, SUM_OFFSETS); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadFilterCoordinatesPosTooBig() { - MethodHandles.filterCoordinates(intHandle, 1, SUM_OFFSETS); + assertThrows(IllegalArgumentException.class, () -> { + MethodHandles.filterCoordinates(intHandle, 1, SUM_OFFSETS); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadFilterCoordinatesWrongFilterType() { - MethodHandles.filterCoordinates(intHandleIndexed, 1, S2I); + assertThrows(IllegalArgumentException.class, () -> { + MethodHandles.filterCoordinates(intHandleIndexed, 1, S2I); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadFilterCoordinatesWrongFilterException() { - MethodHandles.filterCoordinates(intHandleIndexed, 1, S2L_EX); + assertThrows(IllegalArgumentException.class, () -> { + MethodHandles.filterCoordinates(intHandleIndexed, 1, S2L_EX); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadFilterCoordinatesTooManyFilters() { - MethodHandles.filterCoordinates(intHandleIndexed, 1, S2L, S2L); + assertThrows(IllegalArgumentException.class, () -> { + MethodHandles.filterCoordinates(intHandleIndexed, 1, S2L, S2L); + }); } @Test @@ -261,35 +288,43 @@ public void testInsertCoordinates() throws Throwable { VarHandle intHandle_longIndex = MethodHandles.insertCoordinates(intHandleIndexed, 0, segment, 0L); intHandle_longIndex.set(1); int oldValue = (int)intHandle_longIndex.getAndAdd(42); - assertEquals(oldValue, 1); + assertEquals(1, oldValue); int value = (int)intHandle_longIndex.get(); - assertEquals(value, 43); + assertEquals(43, value); boolean swapped = (boolean)intHandle_longIndex.compareAndSet(43, 12); assertTrue(swapped); oldValue = (int)intHandle_longIndex.compareAndExchange(12, 42); - assertEquals(oldValue, 12); + assertEquals(12, oldValue); value = (int)intHandle_longIndex.toMethodHandle(VarHandle.AccessMode.GET).invokeExact(); - assertEquals(value, 42); + assertEquals(42, value); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadInsertCoordinatesNegativePos() { - MethodHandles.insertCoordinates(intHandle, -1, 42); + assertThrows(IllegalArgumentException.class, () -> { + MethodHandles.insertCoordinates(intHandle, -1, 42); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadInsertCoordinatesPosTooBig() { - MethodHandles.insertCoordinates(intHandle, 1, 42); + assertThrows(IllegalArgumentException.class, () -> { + MethodHandles.insertCoordinates(intHandle, 1, 42); + }); } - @Test(expectedExceptions = ClassCastException.class) + @Test public void testBadInsertCoordinatesWrongCoordinateType() { - MethodHandles.insertCoordinates(intHandleIndexed, 1, "Hello"); + assertThrows(ClassCastException.class, () -> { + MethodHandles.insertCoordinates(intHandleIndexed, 1, "Hello"); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadInsertCoordinatesTooManyValues() { - MethodHandles.insertCoordinates(intHandleIndexed, 1, 0L, 0L); + assertThrows(IllegalArgumentException.class, () -> { + MethodHandles.insertCoordinates(intHandleIndexed, 1, 0L, 0L); + }); } @Test @@ -301,35 +336,43 @@ public void testPermuteCoordinates() throws Throwable { List.of(long.class, MemorySegment.class), 1, 0); intHandle_swap.set(0L, segment, 1); int oldValue = (int)intHandle_swap.getAndAdd(0L, segment, 42); - assertEquals(oldValue, 1); + assertEquals(1, oldValue); int value = (int)intHandle_swap.get(0L, segment); - assertEquals(value, 43); + assertEquals(43, value); boolean swapped = (boolean)intHandle_swap.compareAndSet(0L, segment, 43, 12); assertTrue(swapped); oldValue = (int)intHandle_swap.compareAndExchange(0L, segment, 12, 42); - assertEquals(oldValue, 12); + assertEquals(12, oldValue); value = (int)intHandle_swap.toMethodHandle(VarHandle.AccessMode.GET).invokeExact(0L, segment); - assertEquals(value, 42); + assertEquals(42, value); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadPermuteCoordinatesTooManyCoordinates() { - MethodHandles.permuteCoordinates(intHandle, List.of(int.class, int.class), new int[2]); + assertThrows(IllegalArgumentException.class, () -> { + MethodHandles.permuteCoordinates(intHandle, List.of(int.class, int.class), new int[2]); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadPermuteCoordinatesTooFewCoordinates() { - MethodHandles.permuteCoordinates(intHandle, List.of()); + assertThrows(IllegalArgumentException.class, () -> { + MethodHandles.permuteCoordinates(intHandle, List.of()); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadPermuteCoordinatesIndexTooBig() { - MethodHandles.permuteCoordinates(intHandle, List.of(int.class, int.class), 3); + assertThrows(IllegalArgumentException.class, () -> { + MethodHandles.permuteCoordinates(intHandle, List.of(int.class, int.class), 3); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadPermuteCoordinatesIndexTooSmall() { - MethodHandles.permuteCoordinates(intHandle, List.of(int.class, int.class), -1); + assertThrows(IllegalArgumentException.class, () -> { + MethodHandles.permuteCoordinates(intHandle, List.of(int.class, int.class), -1); + }); } @Test @@ -340,41 +383,49 @@ public void testCollectCoordinates() throws Throwable { VarHandle intHandle_sum = MethodHandles.collectCoordinates(intHandleIndexed, 1, SUM_OFFSETS); intHandle_sum.set(segment, -2L, 2L, 1); int oldValue = (int)intHandle_sum.getAndAdd(segment, -2L, 2L, 42); - assertEquals(oldValue, 1); + assertEquals(1, oldValue); int value = (int)intHandle_sum.get(segment, -2L, 2L); - assertEquals(value, 43); + assertEquals(43, value); boolean swapped = (boolean)intHandle_sum.compareAndSet(segment, -2L, 2L, 43, 12); assertTrue(swapped); oldValue = (int)intHandle_sum.compareAndExchange(segment, -2L, 2L, 12, 42); - assertEquals(oldValue, 12); + assertEquals(12, oldValue); value = (int)intHandle_sum.toMethodHandle(VarHandle.AccessMode.GET).invokeExact(segment, -2L, 2L); - assertEquals(value, 42); + assertEquals(42, value); } @Test public void testCollectCoordinatesVoidFilterType() { VarHandle handle = MethodHandles.collectCoordinates(intHandle, 0, VOID_FILTER); - assertEquals(handle.coordinateTypes(), List.of(String.class, MemorySegment.class)); + assertEquals(List.of(String.class, MemorySegment.class), handle.coordinateTypes()); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadCollectCoordinatesNegativePos() { - MethodHandles.collectCoordinates(intHandle, -1, SUM_OFFSETS); + assertThrows(IllegalArgumentException.class, () -> { + MethodHandles.collectCoordinates(intHandle, -1, SUM_OFFSETS); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadCollectCoordinatesPosTooBig() { - MethodHandles.collectCoordinates(intHandle, 1, SUM_OFFSETS); + assertThrows(IllegalArgumentException.class, () -> { + MethodHandles.collectCoordinates(intHandle, 1, SUM_OFFSETS); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadCollectCoordinatesWrongFilterType() { - MethodHandles.collectCoordinates(intHandle, 0, SUM_OFFSETS); + assertThrows(IllegalArgumentException.class, () -> { + MethodHandles.collectCoordinates(intHandle, 0, SUM_OFFSETS); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadCollectCoordinatesWrongFilterException() { - MethodHandles.collectCoordinates(intHandle, 0, S2L_EX); + assertThrows(IllegalArgumentException.class, () -> { + MethodHandles.collectCoordinates(intHandle, 0, S2L_EX); + }); } @Test @@ -385,25 +436,29 @@ public void testDropCoordinates() throws Throwable { VarHandle intHandle_dummy = MethodHandles.dropCoordinates(intHandleIndexed, 1, float.class, String.class); intHandle_dummy.set(segment, 1f, "hello", 0L, 1); int oldValue = (int)intHandle_dummy.getAndAdd(segment, 1f, "hello", 0L, 42); - assertEquals(oldValue, 1); + assertEquals(1, oldValue); int value = (int)intHandle_dummy.get(segment, 1f, "hello", 0L); - assertEquals(value, 43); + assertEquals(43, value); boolean swapped = (boolean)intHandle_dummy.compareAndSet(segment, 1f, "hello", 0L, 43, 12); assertTrue(swapped); oldValue = (int)intHandle_dummy.compareAndExchange(segment, 1f, "hello", 0L, 12, 42); - assertEquals(oldValue, 12); + assertEquals(12, oldValue); value = (int)intHandle_dummy.toMethodHandle(VarHandle.AccessMode.GET).invokeExact(segment, 1f, "hello", 0L); - assertEquals(value, 42); + assertEquals(42, value); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadDropCoordinatesNegativePos() { - MethodHandles.dropCoordinates(intHandle, -1); + assertThrows(IllegalArgumentException.class, () -> { + MethodHandles.dropCoordinates(intHandle, -1); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadDropCoordinatesPosTooBig() { - MethodHandles.dropCoordinates(intHandle, 2); + assertThrows(IllegalArgumentException.class, () -> { + MethodHandles.dropCoordinates(intHandle, 2); + }); } //helper methods diff --git a/test/jdk/java/foreign/TestAddressDereference.java b/test/jdk/java/foreign/TestAddressDereference.java index 76ab0086eb93f..d83241169a13d 100644 --- a/test/jdk/java/foreign/TestAddressDereference.java +++ b/test/jdk/java/foreign/TestAddressDereference.java @@ -24,7 +24,7 @@ /* * @test * @library ../ /test/lib - * @run testng/othervm/native --enable-native-access=ALL-UNNAMED TestAddressDereference + * @run junit/othervm/native --enable-native-access=ALL-UNNAMED TestAddressDereference */ import java.lang.foreign.Arena; @@ -41,10 +41,12 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.testng.annotations.*; - -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestAddressDereference extends UpcallTestHelper { static final Linker LINKER = Linker.nativeLinker(); @@ -65,7 +67,8 @@ public class TestAddressDereference extends UpcallTestHelper { } } - @Test(dataProvider = "layoutsAndAlignments") + @ParameterizedTest + @MethodSource("layoutsAndAlignments") public void testGetAddress(long alignment, ValueLayout layout) { boolean badAlign = layout.byteAlignment() > alignment; try (Arena arena = Arena.ofConfined()) { @@ -73,14 +76,15 @@ public void testGetAddress(long alignment, ValueLayout layout) { segment.set(ValueLayout.ADDRESS, 0, MemorySegment.ofAddress(alignment)); MemorySegment deref = segment.get(ValueLayout.ADDRESS.withTargetLayout(layout), 0); assertFalse(badAlign); - assertEquals(deref.byteSize(), layout.byteSize()); + assertEquals(layout.byteSize(), deref.byteSize()); } catch (IllegalArgumentException ex) { assertTrue(badAlign); assertTrue(ex.getMessage().contains("alignment constraint for address")); } } - @Test(dataProvider = "layoutsAndAlignments") + @ParameterizedTest + @MethodSource("layoutsAndAlignments") public void testGetAddressIndex(long alignment, ValueLayout layout) { boolean badAlign = layout.byteAlignment() > alignment; try (Arena arena = Arena.ofConfined()) { @@ -88,14 +92,15 @@ public void testGetAddressIndex(long alignment, ValueLayout layout) { segment.set(ValueLayout.ADDRESS, 0, MemorySegment.ofAddress(alignment)); MemorySegment deref = segment.getAtIndex(ValueLayout.ADDRESS.withTargetLayout(layout), 0); assertFalse(badAlign); - assertEquals(deref.byteSize(), layout.byteSize()); + assertEquals(layout.byteSize(), deref.byteSize()); } catch (IllegalArgumentException ex) { assertTrue(badAlign); assertTrue(ex.getMessage().contains("alignment constraint for address")); } } - @Test(dataProvider = "layoutsAndAlignments") + @ParameterizedTest + @MethodSource("layoutsAndAlignments") public void testNativeReturn(long alignment, ValueLayout layout) throws Throwable { boolean badAlign = layout.byteAlignment() > alignment; try { @@ -103,14 +108,15 @@ public void testNativeReturn(long alignment, ValueLayout layout) throws Throwabl FunctionDescriptor.of(ValueLayout.ADDRESS.withTargetLayout(layout), ValueLayout.ADDRESS)); MemorySegment deref = (MemorySegment)get_addr_handle.invokeExact(MemorySegment.ofAddress(alignment)); assertFalse(badAlign); - assertEquals(deref.byteSize(), layout.byteSize()); + assertEquals(layout.byteSize(), deref.byteSize()); } catch (IllegalArgumentException ex) { assertTrue(badAlign); assertTrue(ex.getMessage().contains("alignment constraint for address")); } } - @Test(dataProvider = "layoutsAndAlignments") + @ParameterizedTest + @MethodSource("layoutsAndAlignments") public void testNativeUpcallArgPos(long alignment, ValueLayout layout) throws Throwable { boolean badAlign = layout.byteAlignment() > alignment; if (badAlign) return; // this will crash the JVM (exception occurs when going into the upcall stub) @@ -122,7 +128,8 @@ public void testNativeUpcallArgPos(long alignment, ValueLayout layout) throws Th } } - @Test(dataProvider = "layoutsAndAlignments") + @ParameterizedTest + @MethodSource("layoutsAndAlignments") public void testNativeUpcallArgNeg(long alignment, ValueLayout layout) throws Throwable { boolean badAlign = layout.byteAlignment() > alignment; if (!badAlign) return; @@ -154,10 +161,9 @@ static ValueLayout parseLayout(String s) { } static void testArg(MemorySegment deref, long expectedSize) { - assertEquals(deref.byteSize(), expectedSize); + assertEquals(expectedSize, deref.byteSize()); } - @DataProvider(name = "layoutsAndAlignments") static Object[][] layoutsAndAlignments() { List layoutsAndAlignments = new ArrayList<>(); for (LayoutKind lk : LayoutKind.values()) { diff --git a/test/jdk/java/foreign/TestArrayCopy.java b/test/jdk/java/foreign/TestArrayCopy.java index 9a1c48a394e09..cc82002df110f 100644 --- a/test/jdk/java/foreign/TestArrayCopy.java +++ b/test/jdk/java/foreign/TestArrayCopy.java @@ -23,7 +23,7 @@ /* * @test - * @run testng TestArrayCopy + * @run junit TestArrayCopy */ import java.lang.foreign.MemorySegment; @@ -33,13 +33,15 @@ import java.nio.ByteOrder; import java.util.ArrayList; import java.util.List; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import static java.lang.foreign.ValueLayout.JAVA_BYTE; import static java.lang.foreign.ValueLayout.JAVA_INT; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.fail; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; /** * These tests exercise the MemoryCopy copyFromArray(...) and copyToArray(...). @@ -51,6 +53,7 @@ * the copy of the overlapping region is performed as if the data in the overlapping region * were first copied into a temporary segment before being copied to the destination.

*/ +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestArrayCopy { private static final ByteOrder NATIVE_ORDER = ByteOrder.nativeOrder(); private static final ByteOrder NON_NATIVE_ORDER = NATIVE_ORDER == ByteOrder.LITTLE_ENDIAN @@ -59,7 +62,8 @@ public class TestArrayCopy { private static final int SEG_LENGTH_BYTES = 32; private static final int SEG_OFFSET_BYTES = 8; - @Test(dataProvider = "copyModesAndHelpers") + @ParameterizedTest + @MethodSource("copyModesAndHelpers") public void testSelfCopy(CopyMode mode, CopyHelper helper, String helperDebugString) { int bytesPerElement = (int)helper.elementLayout.byteSize(); int indexShifts = SEG_OFFSET_BYTES / bytesPerElement; @@ -73,7 +77,7 @@ public void testSelfCopy(CopyMode mode, CopyHelper helper, MemorySegment dstSeg = helper.fromArray(srcArr); long dstOffsetBytes = mode.direction ? SEG_OFFSET_BYTES : 0; helper.copyFromArray(srcArr, srcIndex, srcCopyLen, dstSeg, dstOffsetBytes, bo); - assertEquals(truth.mismatch(dstSeg), -1); + assertEquals(-1, truth.mismatch(dstSeg)); //CopyTo long srcOffsetBytes = mode.direction ? 0 : SEG_OFFSET_BYTES; Object dstArr = helper.toArray(base); @@ -82,10 +86,11 @@ public void testSelfCopy(CopyMode mode, CopyHelper helper, int dstCopyLen = helper.length(dstArr) - indexShifts; helper.copyToArray(srcSeg, srcOffsetBytes, dstArr, dstIndex, dstCopyLen, bo); MemorySegment result = helper.fromArray(dstArr); - assertEquals(truth.mismatch(result), -1); + assertEquals(-1, truth.mismatch(result)); } - @Test(dataProvider = "copyModesAndHelpers") + @ParameterizedTest + @MethodSource("copyModesAndHelpers") public void testUnalignedCopy(CopyMode mode, CopyHelper helper, String helperDebugString) { int bytesPerElement = (int)helper.elementLayout.byteSize(); int indexShifts = SEG_OFFSET_BYTES / bytesPerElement; @@ -107,7 +112,8 @@ public void testUnalignedCopy(CopyMode mode, CopyHelper hel helper.copyToArray(srcSeg, srcOffsetBytes, dstArr, dstIndex, dstCopyLen, bo); } - @Test(dataProvider = "copyModesAndHelpers") + @ParameterizedTest + @MethodSource("copyModesAndHelpers") public void testCopyOobLength(CopyMode mode, CopyHelper helper, String helperDebugString) { int bytesPerElement = (int)helper.elementLayout.byteSize(); MemorySegment base = srcSegment(SEG_LENGTH_BYTES); @@ -131,7 +137,8 @@ public void testCopyOobLength(CopyMode mode, CopyHelper hel } } - @Test(dataProvider = "copyModesAndHelpers") + @ParameterizedTest + @MethodSource("copyModesAndHelpers") public void testCopyNegativeIndices(CopyMode mode, CopyHelper helper, String helperDebugString) { int bytesPerElement = (int)helper.elementLayout.byteSize(); MemorySegment base = srcSegment(SEG_LENGTH_BYTES); @@ -155,7 +162,8 @@ public void testCopyNegativeIndices(CopyMode mode, CopyHelper helper, String helperDebugString) { int bytesPerElement = (int)helper.elementLayout.byteSize(); MemorySegment base = srcSegment(SEG_LENGTH_BYTES); @@ -179,7 +187,8 @@ public void testCopyNegativeOffsets(CopyMode mode, CopyHelper helper, String helperDebugString) { int bytesPerElement = (int)helper.elementLayout.byteSize(); MemorySegment base = srcSegment(SEG_LENGTH_BYTES); @@ -203,7 +212,8 @@ public void testCopyOobIndices(CopyMode mode, CopyHelper he } } - @Test(dataProvider = "copyModesAndHelpers") + @ParameterizedTest + @MethodSource("copyModesAndHelpers") public void testCopyOobOffsets(CopyMode mode, CopyHelper helper, String helperDebugString) { int bytesPerElement = (int)helper.elementLayout.byteSize(); MemorySegment base = srcSegment(SEG_LENGTH_BYTES); @@ -227,7 +237,8 @@ public void testCopyOobOffsets(CopyMode mode, CopyHelper he } } - @Test(dataProvider = "copyModesAndHelpers") + @ParameterizedTest + @MethodSource("copyModesAndHelpers") public void testCopyReadOnlyDest(CopyMode mode, CopyHelper helper, String helperDebugString) { int bytesPerElement = (int)helper.elementLayout.byteSize(); MemorySegment base = srcSegment(SEG_LENGTH_BYTES); @@ -242,40 +253,52 @@ public void testCopyReadOnlyDest(CopyMode mode, CopyHelper } } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testNotAnArraySrc() { MemorySegment segment = MemorySegment.ofArray(new int[] {1, 2, 3, 4}); - MemorySegment.copy(segment, JAVA_BYTE, 0, new String[] { "hello" }, 0, 4); + assertThrows(IllegalArgumentException.class, () -> { + MemorySegment.copy(segment, JAVA_BYTE, 0, new String[] { "hello" }, 0, 4); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testNotAnArrayDst() { MemorySegment segment = MemorySegment.ofArray(new int[] {1, 2, 3, 4}); - MemorySegment.copy(new String[] { "hello" }, 0, segment, JAVA_BYTE, 0, 4); + assertThrows(IllegalArgumentException.class, () -> { + MemorySegment.copy(new String[] { "hello" }, 0, segment, JAVA_BYTE, 0, 4); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testCarrierMismatchSrc() { MemorySegment segment = MemorySegment.ofArray(new int[] {1, 2, 3, 4}); - MemorySegment.copy(segment, JAVA_INT, 0, new byte[] { 1, 2, 3, 4 }, 0, 4); + assertThrows(IllegalArgumentException.class, () -> { + MemorySegment.copy(segment, JAVA_INT, 0, new byte[] { 1, 2, 3, 4 }, 0, 4); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testCarrierMismatchDst() { MemorySegment segment = MemorySegment.ofArray(new int[] {1, 2, 3, 4}); - MemorySegment.copy(new byte[] { 1, 2, 3, 4 }, 0, segment, JAVA_INT, 0, 4); + assertThrows(IllegalArgumentException.class, () -> { + MemorySegment.copy(new byte[] { 1, 2, 3, 4 }, 0, segment, JAVA_INT, 0, 4); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testHyperAlignedSrc() { MemorySegment segment = MemorySegment.ofArray(new byte[] {1, 2, 3, 4}); - MemorySegment.copy(new byte[] { 1, 2, 3, 4 }, 0, segment, JAVA_BYTE.withByteAlignment(2), 0, 4); + assertThrows(IllegalArgumentException.class, () -> { + MemorySegment.copy(new byte[] { 1, 2, 3, 4 }, 0, segment, JAVA_BYTE.withByteAlignment(2), 0, 4); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testHyperAlignedDst() { MemorySegment segment = MemorySegment.ofArray(new byte[] {1, 2, 3, 4}); - MemorySegment.copy(segment, JAVA_BYTE.withByteAlignment(2), 0, new byte[] { 1, 2, 3, 4 }, 0, 4); + assertThrows(IllegalArgumentException.class, () -> { + MemorySegment.copy(segment, JAVA_BYTE.withByteAlignment(2), 0, new byte[] { 1, 2, 3, 4 }, 0, 4); + }); } /***** Utilities *****/ @@ -555,7 +578,6 @@ int length(double[] arr) { }; } - @DataProvider Object[][] copyModesAndHelpers() { CopyHelper[] helpers = { CopyHelper.BYTE, CopyHelper.CHAR, CopyHelper.SHORT, CopyHelper.INT, CopyHelper.FLOAT, CopyHelper.LONG, CopyHelper.DOUBLE }; diff --git a/test/jdk/java/foreign/TestArrays.java b/test/jdk/java/foreign/TestArrays.java index 4406db36750d6..e84fc8c8a8cb4 100644 --- a/test/jdk/java/foreign/TestArrays.java +++ b/test/jdk/java/foreign/TestArrays.java @@ -24,7 +24,7 @@ /* * @test - * @run testng/othervm --enable-native-access=ALL-UNNAMED TestArrays + * @run junit/othervm --enable-native-access=ALL-UNNAMED TestArrays */ import java.lang.foreign.*; @@ -39,7 +39,6 @@ import java.util.function.Consumer; import java.util.function.Function; -import org.testng.annotations.*; import static java.lang.foreign.ValueLayout.JAVA_BYTE; import static java.lang.foreign.ValueLayout.JAVA_CHAR; @@ -48,8 +47,13 @@ import static java.lang.foreign.ValueLayout.JAVA_INT; import static java.lang.foreign.ValueLayout.JAVA_LONG; import static java.lang.foreign.ValueLayout.JAVA_SHORT; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestArrays { static SequenceLayout bytes = MemoryLayout.sequenceLayout(100, @@ -104,7 +108,8 @@ static void checkBytes(MemorySegment base, SequenceLayout layout, Function init, Consumer checker, MemoryLayout layout) { Arena scope = Arena.ofAuto(); MemorySegment segment = scope.allocate(layout); @@ -113,37 +118,42 @@ public void testArrays(Consumer init, Consumer che checker.accept(segment); } - @Test(dataProvider = "elemLayouts", - expectedExceptions = IllegalStateException.class) + @ParameterizedTest + @MethodSource("elemLayouts") public void testTooBigForArray(MemoryLayout layout, Function arrayFactory) { MemoryLayout seq = MemoryLayout.sequenceLayout((Integer.MAX_VALUE * layout.byteSize()) + 1, layout); //do not really allocate here, as it's way too much memory MemorySegment segment = MemorySegment.NULL.reinterpret(seq.byteSize()); - arrayFactory.apply(segment); + assertThrows(IllegalStateException.class, () -> { + arrayFactory.apply(segment); + }); } - @Test(dataProvider = "elemLayouts", - expectedExceptions = IllegalStateException.class) + @ParameterizedTest + @MethodSource("elemLayouts") public void testBadSize(MemoryLayout layout, Function arrayFactory) { - if (layout.byteSize() == 1) throw new IllegalStateException(); //make it fail + if (layout.byteSize() == 1) return; // skip try (Arena arena = Arena.ofConfined()) { long byteSize = layout.byteSize() + 1; long byteAlignment = layout.byteSize(); MemorySegment segment = arena.allocate(byteSize, byteAlignment); - arrayFactory.apply(segment); + assertThrows(IllegalStateException.class, () -> { + arrayFactory.apply(segment); + }); } } - @Test(dataProvider = "elemLayouts", - expectedExceptions = IllegalStateException.class) + @ParameterizedTest + @MethodSource("elemLayouts") public void testArrayFromClosedSegment(MemoryLayout layout, Function arrayFactory) { Arena arena = Arena.ofConfined(); MemorySegment segment = arena.allocate(layout); arena.close(); - arrayFactory.apply(segment); + assertThrows(IllegalStateException.class, () -> { + arrayFactory.apply(segment); + }); } - @DataProvider(name = "arrays") public Object[][] nativeAccessOps() { Consumer byteInitializer = (base) -> initBytes(base, bytes, (addr, pos) -> byteHandle.set(addr, 0L, pos, (byte)(long)pos)); @@ -186,7 +196,6 @@ public Object[][] nativeAccessOps() { }; } - @DataProvider(name = "elemLayouts") public Object[][] elemLayouts() { return new Object[][] { { JAVA_BYTE, (Function)s -> s.toArray(JAVA_BYTE)}, diff --git a/test/jdk/java/foreign/TestByteBuffer.java b/test/jdk/java/foreign/TestByteBuffer.java index e45bb3fdbf0d3..61c752bd98496 100644 --- a/test/jdk/java/foreign/TestByteBuffer.java +++ b/test/jdk/java/foreign/TestByteBuffer.java @@ -24,7 +24,7 @@ /* * @test * @modules java.base/sun.nio.ch java.base/jdk.internal.foreign - * @run testng/othervm/timeout=600 --enable-native-access=ALL-UNNAMED TestByteBuffer + * @run junit/othervm/timeout=600 --enable-native-access=ALL-UNNAMED TestByteBuffer */ import java.lang.foreign.*; @@ -67,13 +67,19 @@ import java.util.function.Supplier; import java.util.stream.Stream; -import org.testng.SkipException; -import org.testng.annotations.*; import sun.nio.ch.DirectBuffer; import static java.lang.foreign.ValueLayout.*; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assumptions.assumeFalse; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestByteBuffer { static final Path tempPath; @@ -125,9 +131,9 @@ static void checkTuples(MemorySegment base, ByteBuffer bb, long count) { for (long i = 0; i < count ; i++) { int index; float value; - assertEquals(index = bb.getInt(), (int)indexHandle.get(base, 0L, i)); - assertEquals(value = bb.getFloat(), (float)valueHandle.get(base, 0L, i)); - assertEquals(value, index / 500f); + assertEquals((int)indexHandle.get(base, 0L, i), index = bb.getInt()); + assertEquals((float)valueHandle.get(base, 0L, i), value = bb.getFloat()); + assertEquals(index / 500f, value); } } @@ -154,13 +160,13 @@ static void checkBytes(MemorySegment base, SequenceLayout lay Object bufferValue = bufferExtractor.apply(z); Object handleViewValue = handleExtractor.apply(segmentBufferView, j - i); if (handleValue instanceof Number) { - assertEquals(((Number)handleValue).longValue(), j); - assertEquals(((Number)bufferValue).longValue(), j); - assertEquals(((Number)handleViewValue).longValue(), j); + assertEquals(j, ((Number)handleValue).longValue()); + assertEquals(j, ((Number)bufferValue).longValue()); + assertEquals(j, ((Number)handleViewValue).longValue()); } else { - assertEquals((long)(char)handleValue, j); - assertEquals((long)(char)bufferValue, j); - assertEquals((long)(char)handleViewValue, j); + assertEquals(j, (long)(char)handleValue); + assertEquals(j, (long)(char)bufferValue); + assertEquals(j, (long)(char)handleViewValue); } } } @@ -248,19 +254,21 @@ public void testMappedSegment() throws Throwable { } } - @Test(dataProvider = "mappedOps", expectedExceptions = IllegalStateException.class) + @ParameterizedTest + @MethodSource("mappedOps") public void testMappedSegmentOperations(MappedSegmentOp mappedBufferOp) throws Throwable { File f = new File("test3.out"); f.createNewFile(); f.deleteOnExit(); - Arena arena = Arena.ofConfined(); try (FileChannel fileChannel = FileChannel.open(f.toPath(), StandardOpenOption.READ, StandardOpenOption.WRITE)) { MemorySegment segment = fileChannel.map(FileChannel.MapMode.READ_WRITE, 0L, 8L, arena); assertTrue(segment.isMapped()); assertTrue(segment.toString().contains("mapped")); arena.close(); - mappedBufferOp.apply(segment); + assertThrows(IllegalStateException.class, () -> { + mappedBufferOp.apply(segment); + }); } } @@ -294,7 +302,8 @@ public void testMappedSegmentOffset() throws Throwable { } } - @Test(dataProvider = "fromArrays") + @ParameterizedTest + @MethodSource("fromArrays") public void testAsByteBufferFromNonByteArray(MemorySegment segment) { if (!segment.heapBase().map(a -> a instanceof byte[]).get()) { // This should not work as the segment is not backed by a byte array @@ -318,12 +327,12 @@ public void testMappedSegmentAsByteBuffer() throws Throwable { segment.isLoaded(); segment.unload(); ByteBuffer byteBuffer = segment.asByteBuffer(); - assertEquals(byteBuffer.capacity(), segment.byteSize()); - assertEquals(byteBuffer.isReadOnly(), segment.isReadOnly()); + assertEquals(segment.byteSize(), byteBuffer.capacity()); + assertEquals(segment.isReadOnly(), byteBuffer.isReadOnly()); assertTrue(byteBuffer.isDirect()); } catch (IOException e) { - if (e.getMessage().equals("Function not implemented")) - throw new SkipException(e.getMessage(), e); + assumeFalse(e.getMessage().equals("Function not implemented"), + e.getMessage()); } finally { if (arena.scope() != Arena.global().scope()) { arena.close(); @@ -337,9 +346,7 @@ public void testMappedSegmentAsByteBuffer() throws Throwable { @Test public void testLargeMappedSegment() throws Throwable { - if (System.getProperty("sun.arch.data.model").equals("32")) { - throw new SkipException("large mapped files not supported on 32-bit systems"); - } + assumeFalse(System.getProperty("sun.arch.data.model").equals("32"), "large mapped files not supported on 32-bit systems"); File f = new File("testLargeMappedSegment.out"); f.createNewFile(); @@ -356,8 +363,8 @@ public void testLargeMappedSegment() throws Throwable { segment.unload(); segment.isLoaded(); } catch(IOException e) { - if (e.getMessage().equals("Function not implemented")) - throw new SkipException(e.getMessage(), e); + assumeFalse(e.getMessage().equals("Function not implemented"), + e.getMessage()); } } @@ -374,14 +381,13 @@ static void withMappedBuffer(FileChannel channel, FileChannel.MapMode mode, long } static void checkByteArrayAlignment(MemoryLayout layout) { - if (layout.byteSize() > 4 - && System.getProperty("sun.arch.data.model").equals("32")) { - throw new SkipException("avoid unaligned access on 32-bit system"); - } + assumeFalse(layout.byteSize() > 4 + && System.getProperty("sun.arch.data.model").equals("32"), "avoid unaligned access on 32-bit system"); } - @Test(dataProvider = "bufferOps") - public void testScopedBuffer(Function bufferFactory, @NoInjection Method method, Object[] args) { + @ParameterizedTest + @MethodSource("bufferOps") + public void testScopedBuffer(Function bufferFactory, Method method, Object[] args) { Buffer bb; try (Arena arena = Arena.ofConfined()) { MemorySegment segment = arena.allocate(bytes); @@ -406,7 +412,8 @@ public void testScopedBuffer(Function bufferFactory, @NoInje } } - @Test(dataProvider = "bufferHandleOps") + @ParameterizedTest + @MethodSource("bufferHandleOps") public void testScopedBufferAndVarHandle(VarHandle bufferHandle) { ByteBuffer bb; try (Arena arena = Arena.ofConfined()) { @@ -441,20 +448,22 @@ public void testScopedBufferAndVarHandle(VarHandle bufferHandle) { } } - @Test(dataProvider = "bufferOps") - public void testDirectBuffer(Function bufferFactory, @NoInjection Method method, Object[] args) { + @ParameterizedTest + @MethodSource("bufferOps") + public void testDirectBuffer(Function bufferFactory, Method method, Object[] args) { try (Arena arena = Arena.ofConfined()) { MemorySegment segment = arena.allocate(bytes); Buffer bb = bufferFactory.apply(segment.asByteBuffer()); assertTrue(bb.isDirect()); DirectBuffer directBuffer = ((DirectBuffer)bb); - assertEquals(directBuffer.address(), segment.address()); + assertEquals(segment.address(), directBuffer.address()); assertTrue((directBuffer.attachment() == null) == (bb instanceof ByteBuffer)); assertTrue(directBuffer.cleaner() == null); } } - @Test(dataProvider="resizeOps") + @ParameterizedTest + @MethodSource("resizeOps") public void testResizeOffheap(Consumer checker, Consumer initializer, SequenceLayout seq) { try (Arena arena = Arena.ofConfined()) { MemorySegment segment = arena.allocate(seq); @@ -463,7 +472,8 @@ public void testResizeOffheap(Consumer checker, Consumer checker, Consumer initializer, SequenceLayout seq) { checkByteArrayAlignment(seq.elementLayout()); int capacity = (int)seq.byteSize(); @@ -472,7 +482,8 @@ public void testResizeHeap(Consumer checker, Consumer checker, Consumer initializer, SequenceLayout seq) { checkByteArrayAlignment(seq.elementLayout()); int capacity = (int)seq.byteSize(); @@ -481,7 +492,8 @@ public void testResizeBuffer(Consumer checker, Consumer checker, Consumer initializer, SequenceLayout seq) { checkByteArrayAlignment(seq.elementLayout()); int capacity = (int)seq.byteSize(); @@ -492,7 +504,8 @@ public void testResizeRoundtripHeap(Consumer checker, Consumer checker, Consumer initializer, SequenceLayout seq) { try (Arena arena = Arena.ofConfined()) { MemorySegment segment = arena.allocate(seq); @@ -502,39 +515,47 @@ public void testResizeRoundtripNative(Consumer checker, Consumer< } } - @Test(expectedExceptions = IllegalStateException.class) + @Test public void testBufferOnClosedSession() { MemorySegment leaked; try (Arena arena = Arena.ofConfined()) { leaked = arena.allocate(bytes); } ByteBuffer byteBuffer = leaked.asByteBuffer(); // ok - byteBuffer.get(); // should throw + assertThrows(IllegalStateException.class, () -> { + byteBuffer.get(); + }); } - @Test(expectedExceptions = IllegalStateException.class) + @Test public void testTooBigForByteBuffer() { MemorySegment segment = MemorySegment.NULL.reinterpret(Integer.MAX_VALUE + 10L); - segment.asByteBuffer(); + assertThrows(IllegalStateException.class, () -> { + segment.asByteBuffer(); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadMapNegativeSize() throws IOException { File f = new File("testNeg1.out"); f.createNewFile(); f.deleteOnExit(); try (FileChannel fileChannel = FileChannel.open(f.toPath(), StandardOpenOption.READ, StandardOpenOption.WRITE)) { - fileChannel.map(FileChannel.MapMode.READ_WRITE, 0L, -1L, Arena.ofAuto()); + assertThrows(IllegalArgumentException.class, () -> { + fileChannel.map(FileChannel.MapMode.READ_WRITE, 0L, -1L, Arena.ofAuto()); + }); } } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadMapNegativeOffset() throws IOException { File f = new File("testNeg2.out"); f.createNewFile(); f.deleteOnExit(); try (FileChannel fileChannel = FileChannel.open(f.toPath(), StandardOpenOption.READ, StandardOpenOption.WRITE)) { - fileChannel.map(FileChannel.MapMode.READ_WRITE, -1L, 1L, Arena.ofAuto()); + assertThrows(IllegalArgumentException.class, () -> { + fileChannel.map(FileChannel.MapMode.READ_WRITE, -1L, 1L, Arena.ofAuto()); + }); } } @@ -559,7 +580,7 @@ public void testMapOffset() throws IOException { try (Arena arena = Arena.ofConfined(); FileChannel fileChannel = FileChannel.open(f.toPath(), StandardOpenOption.READ)) { MemorySegment segment = fileChannel.map(FileChannel.MapMode.READ_ONLY, offset, SIZE - offset, arena); - assertEquals(segment.get(JAVA_BYTE, 0), offset); + assertEquals(offset, segment.get(JAVA_BYTE, 0)); } } } @@ -573,30 +594,30 @@ public void testMapZeroSize() throws IOException { try (Arena arena = Arena.ofConfined(); FileChannel fileChannel = FileChannel.open(f.toPath(), StandardOpenOption.READ, StandardOpenOption.WRITE)) { MemorySegment segment = fileChannel.map(FileChannel.MapMode.READ_WRITE, 0L, 0L, arena); - assertEquals(segment.byteSize(), 0); - assertEquals(segment.isMapped(), true); + assertEquals(0, segment.byteSize()); + assertEquals(true, segment.isMapped()); assertFalse(segment.isReadOnly()); segment.force(); segment.load(); segment.isLoaded(); segment.unload(); ByteBuffer byteBuffer = segment.asByteBuffer(); - assertEquals(byteBuffer.capacity(), 0); + assertEquals(0, byteBuffer.capacity()); assertFalse(byteBuffer.isReadOnly()); } //RO try (Arena arena = Arena.ofConfined(); FileChannel fileChannel = FileChannel.open(f.toPath(), StandardOpenOption.READ)) { MemorySegment segment = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0L, 0L, arena); - assertEquals(segment.byteSize(), 0); - assertEquals(segment.isMapped(), true); + assertEquals(0, segment.byteSize()); + assertEquals(true, segment.isMapped()); assertTrue(segment.isReadOnly()); segment.force(); segment.load(); segment.isLoaded(); segment.unload(); ByteBuffer byteBuffer = segment.asByteBuffer(); - assertEquals(byteBuffer.capacity(), 0); + assertEquals(0, byteBuffer.capacity()); assertTrue(byteBuffer.isReadOnly()); } } @@ -622,7 +643,8 @@ public void testMapCustomPath() throws IOException { } } - @Test(dataProvider="resizeOps") + @ParameterizedTest + @MethodSource("resizeOps") public void testCopyHeapToNative(Consumer checker, Consumer initializer, SequenceLayout seq) { checkByteArrayAlignment(seq.elementLayout()); int bytes = (int)seq.byteSize(); @@ -635,7 +657,8 @@ public void testCopyHeapToNative(Consumer checker, Consumer checker, Consumer initializer, SequenceLayout seq) { checkByteArrayAlignment(seq.elementLayout()); int bytes = (int)seq.byteSize(); @@ -685,28 +708,30 @@ public void testOfBufferScopeReachable() throws InterruptedException { } } - @Test(dataProvider="bufferSources") + @ParameterizedTest + @MethodSource("bufferSources") public void testBufferToSegment(ByteBuffer bb, Predicate segmentChecker) { MemorySegment segment = MemorySegment.ofBuffer(bb); - assertEquals(segment.isReadOnly(), bb.isReadOnly()); + assertEquals(bb.isReadOnly(), segment.isReadOnly()); assertTrue(segmentChecker.test(segment)); assertTrue(segmentChecker.test(segment.asSlice(0, segment.byteSize()))); - assertEquals(bb.capacity(), segment.byteSize()); + assertEquals(segment.byteSize(), bb.capacity()); //another round trip segment = MemorySegment.ofBuffer(segment.asByteBuffer()); - assertEquals(segment.isReadOnly(), bb.isReadOnly()); + assertEquals(bb.isReadOnly(), segment.isReadOnly()); assertTrue(segmentChecker.test(segment)); assertTrue(segmentChecker.test(segment.asSlice(0, segment.byteSize()))); - assertEquals(bb.capacity(), segment.byteSize()); + assertEquals(segment.byteSize(), bb.capacity()); } - @Test(dataProvider="bufferSources") + @ParameterizedTest + @MethodSource("bufferSources") public void bufferProperties(ByteBuffer bb, Predicate _unused) { MemorySegment segment = MemorySegment.ofBuffer(bb); ByteBuffer buffer = segment.asByteBuffer(); - assertEquals(buffer.position(), 0); - assertEquals(buffer.capacity(), segment.byteSize()); - assertEquals(buffer.limit(), segment.byteSize()); + assertEquals(0, buffer.position()); + assertEquals(segment.byteSize(), buffer.capacity()); + assertEquals(segment.byteSize(), buffer.limit()); } @Test @@ -715,27 +740,28 @@ public void testRoundTripAccess() { MemorySegment ms = arena.allocate(4, 1); MemorySegment msNoAccess = ms.asReadOnly(); MemorySegment msRoundTrip = MemorySegment.ofBuffer(msNoAccess.asByteBuffer()); - assertEquals(msRoundTrip.scope(), ms.scope()); - assertEquals(msNoAccess.isReadOnly(), msRoundTrip.isReadOnly()); + assertEquals(ms.scope(), msRoundTrip.scope()); + assertEquals(msRoundTrip.isReadOnly(), msNoAccess.isReadOnly()); } } - @Test(dataProvider = "bufferFactories") + @ParameterizedTest + @MethodSource("bufferFactories") public void testDerivedBufferScopes(Supplier bufferFactory) { MemorySegment segment = MemorySegment.ofBuffer(bufferFactory.get()); assertEquals(segment.scope(), segment.scope()); // one level - assertEquals(segment.asSlice(0).scope(), segment.scope()); - assertEquals(segment.asReadOnly().scope(), segment.scope()); + assertEquals(segment.scope(), segment.asSlice(0).scope()); + assertEquals(segment.scope(), segment.asReadOnly().scope()); // two levels - assertEquals(segment.asSlice(0).asReadOnly().scope(), segment.scope()); - assertEquals(segment.asReadOnly().asSlice(0).scope(), segment.scope()); + assertEquals(segment.scope(), segment.asSlice(0).asReadOnly().scope()); + assertEquals(segment.scope(), segment.asReadOnly().asSlice(0).scope()); // check fresh every time MemorySegment another = MemorySegment.ofBuffer(bufferFactory.get()); - assertNotEquals(segment.scope(), another.scope()); + assertNotEquals(another.scope(), segment.scope()); } - @Test(expectedExceptions = IllegalStateException.class) + @Test public void testDeadAccessOnClosedBufferSegment() { Arena arena = Arena.ofConfined(); MemorySegment s1 = arena.allocate(JAVA_INT); @@ -743,11 +769,13 @@ public void testDeadAccessOnClosedBufferSegment() { // memory freed arena.close(); - - s2.set(JAVA_INT, 0, 10); // Dead access! + assertThrows(IllegalStateException.class, () -> { + s2.set(JAVA_INT, 0, 10); // Dead access! + }); } - @Test(dataProvider = "closeableArenas") + @ParameterizedTest + @MethodSource("closeableArenas") public void closeableArenas(Supplier arenaSupplier) throws IOException { File tmp = File.createTempFile("tmp", "txt"); tmp.deleteOnExit(); @@ -758,17 +786,18 @@ public void closeableArenas(Supplier arenaSupplier) throws IOException { segment.set(JAVA_BYTE, i, (byte) i); } ByteBuffer bb = segment.asByteBuffer(); - assertEquals(channel.write(bb), 10); + assertEquals(10, channel.write(bb)); segment.fill((byte)0x00); - assertEquals(bb.clear(), ByteBuffer.wrap(new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0})); - assertEquals(channel.position(0).read(bb.clear()), 10); - assertEquals(bb.flip(), ByteBuffer.wrap(new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9})); + assertEquals(ByteBuffer.wrap(new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}), bb.clear()); + assertEquals(10, channel.position(0).read(bb.clear())); + assertEquals(ByteBuffer.wrap(new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}), bb.flip()); } } static final Class ISE = IllegalStateException.class; - @Test(dataProvider = "closeableArenas") + @ParameterizedTest + @MethodSource("closeableArenas") public void testIOOnClosedSegmentBuffer(Supplier arenaSupplier) throws IOException { File tmp = File.createTempFile("tmp", "txt"); tmp.deleteOnExit(); @@ -797,13 +826,13 @@ public void buffersAndArraysFromSlices() { var slice = segment.asSlice(4, newSize); var bytes = slice.toArray(JAVA_BYTE); - assertEquals(newSize, bytes.length); + assertEquals(bytes.length, newSize); var buffer = slice.asByteBuffer(); // Fails for heap segments, but passes for native segments: assertEquals(0, buffer.position()); - assertEquals(newSize, buffer.limit()); - assertEquals(newSize, buffer.capacity()); + assertEquals(buffer.limit(), newSize); + assertEquals(buffer.capacity(), newSize); } } @@ -817,7 +846,6 @@ public void viewsFromSharedSegment() { } } - @DataProvider(name = "segments") public static Object[][] segments() throws Throwable { return new Object[][] { { (Supplier) () -> Arena.ofAuto().allocate(16, 1)}, @@ -826,7 +854,6 @@ public static Object[][] segments() throws Throwable { }; } - @DataProvider(name = "closeableArenas") public static Object[][] closeableArenas() { return new Object[][] { { (Supplier) Arena::ofConfined}, @@ -834,7 +861,6 @@ public static Object[][] closeableArenas() { }; } - @DataProvider(name = "bufferOps") public static Object[][] bufferOps() throws Throwable { List args = new ArrayList<>(); bufferOpsArgs(args, bb -> bb, ByteBuffer.class); @@ -861,7 +887,6 @@ static void bufferOpsArgs(List argsList, Function } } - @DataProvider(name = "bufferHandleOps") public static Object[][] bufferHandleOps() throws Throwable { return new Object[][]{ { MethodHandles.byteBufferViewVarHandle(char[].class, ByteOrder.nativeOrder()) }, @@ -889,7 +914,6 @@ static Map varHandleMembers(ByteBuffer bb, VarHandle han return members; } - @DataProvider(name = "resizeOps") public Object[][] resizeOps() { Consumer byteInitializer = (base) -> initBytes(base, bytes, (addr, pos) -> addr.set(JAVA_BYTE, pos, (byte)(long)pos)); @@ -994,7 +1018,6 @@ static Object defaultValue(Class c) { } } - @DataProvider(name = "bufferSources") public static Object[][] bufferSources() { Predicate heapTest = segment -> !segment.isNative() && !segment.isMapped(); Predicate nativeTest = segment -> segment.isNative() && !segment.isMapped(); @@ -1038,14 +1061,12 @@ void apply(MemorySegment segment) { } } - @DataProvider(name = "mappedOps") public static Object[][] mappedOps() { return Stream.of(MappedSegmentOp.values()) .map(op -> new Object[] { op }) .toArray(Object[][]::new); } - @DataProvider(name = "bufferFactories") public static Object[][] bufferFactories() { List> l = List.of( () -> ByteBuffer.allocate(10), @@ -1066,7 +1087,6 @@ public static Object[][] bufferFactories() { return l.stream().map(s -> new Object[] { s }).toArray(Object[][]::new); } - @DataProvider(name = "fromArrays") public static Object[][] fromArrays() { int len = 16; return Stream.of( diff --git a/test/jdk/java/foreign/TestClassLoaderFindNative.java b/test/jdk/java/foreign/TestClassLoaderFindNative.java index 9d04a7f83af17..eee3b54516239 100644 --- a/test/jdk/java/foreign/TestClassLoaderFindNative.java +++ b/test/jdk/java/foreign/TestClassLoaderFindNative.java @@ -23,17 +23,18 @@ /* * @test - * @run testng/othervm/native --enable-native-access=ALL-UNNAMED TestClassLoaderFindNative + * @run junit/othervm/native --enable-native-access=ALL-UNNAMED TestClassLoaderFindNative */ import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; import java.lang.foreign.SymbolLookup; import java.nio.ByteOrder; -import org.testng.annotations.Test; import static java.lang.foreign.ValueLayout.JAVA_INT; -import static org.testng.Assert.*; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; // FYI this test is run on 64-bit platforms only for now, // since the windows 32-bit linker fails and there @@ -58,7 +59,7 @@ public void testInvalidSymbolLookup() { @Test public void testVariableSymbolLookup() { MemorySegment segment = SymbolLookup.loaderLookup().find("c").get().reinterpret(4); - assertEquals(segment.get(JAVA_INT, 0), 42); + assertEquals(42, segment.get(JAVA_INT, 0)); } @Test diff --git a/test/jdk/java/foreign/TestConcurrentClose.java b/test/jdk/java/foreign/TestConcurrentClose.java index 74f0ca2a87745..1d2b02ed8e04b 100644 --- a/test/jdk/java/foreign/TestConcurrentClose.java +++ b/test/jdk/java/foreign/TestConcurrentClose.java @@ -31,7 +31,7 @@ * @build jdk.test.whitebox.WhiteBox * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox * - * @run testng/othervm/timeout=480 + * @run junit/othervm/timeout=480 * -Xbootclasspath/a:. * -XX:+UnlockDiagnosticVMOptions * -XX:+WhiteBoxAPI @@ -41,7 +41,6 @@ */ import jdk.test.whitebox.WhiteBox; -import org.testng.annotations.Test; import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; @@ -53,7 +52,9 @@ import java.util.concurrent.atomic.AtomicLong; import static java.lang.foreign.ValueLayout.JAVA_BYTE; -import static org.testng.Assert.assertFalse; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import org.junit.jupiter.api.Test; public class TestConcurrentClose { static final WhiteBox WB = WhiteBox.getWhiteBox(); diff --git a/test/jdk/java/foreign/TestDereferencePath.java b/test/jdk/java/foreign/TestDereferencePath.java index e2281cde235eb..d4ae5ace4ce16 100644 --- a/test/jdk/java/foreign/TestDereferencePath.java +++ b/test/jdk/java/foreign/TestDereferencePath.java @@ -24,7 +24,7 @@ /* * @test - * @run testng TestDereferencePath + * @run junit TestDereferencePath */ import java.lang.foreign.Arena; @@ -34,10 +34,11 @@ import java.lang.foreign.ValueLayout; -import org.testng.annotations.*; import java.lang.invoke.VarHandle; -import static org.testng.Assert.*; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class TestDereferencePath { @@ -73,7 +74,7 @@ public void testSingle() { c.set(ValueLayout.JAVA_INT, 0, 42); // dereference int val = (int) abcx.get(a, 0L); - assertEquals(val, 42); + assertEquals(42, val); } } @@ -109,13 +110,13 @@ public void testMulti() { c.setAtIndex(ValueLayout.JAVA_INT, 3, 4); // dereference int val00 = (int) abcx_multi.get(a, 0L, 0, 0); // a->b[0]->c[0] = 1 - assertEquals(val00, 1); + assertEquals(1, val00); int val10 = (int) abcx_multi.get(a, 0L, 1, 0); // a->b[1]->c[0] = 3 - assertEquals(val10, 3); + assertEquals(3, val10); int val01 = (int) abcx_multi.get(a, 0L, 0, 1); // a->b[0]->c[1] = 2 - assertEquals(val01, 2); + assertEquals(2, val01); int val11 = (int) abcx_multi.get(a, 0L, 1, 1); // a->b[1]->c[1] = 4 - assertEquals(val11, 4); + assertEquals(4, val11); } } @@ -138,44 +139,53 @@ public void testDerefValue() { b.set(ValueLayout.JAVA_INT, 0, 42); // dereference int val = (int) a_value.get(a, 0L); - assertEquals(val, 42); + assertEquals(42, val); } } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test void testBadDerefInSelect() { - A.select(PathElement.groupElement("b"), PathElement.dereferenceElement()); + assertThrows(IllegalArgumentException.class, () -> { + A.select(PathElement.groupElement("b"), PathElement.dereferenceElement()); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test void testBadDerefInOffset() { - A.byteOffset(PathElement.groupElement("b"), PathElement.dereferenceElement()); + assertThrows(IllegalArgumentException.class, () -> { + A.byteOffset(PathElement.groupElement("b"), PathElement.dereferenceElement()); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test void testBadDerefInSlice() { - A.sliceHandle(PathElement.groupElement("b"), PathElement.dereferenceElement()); + assertThrows(IllegalArgumentException.class, () -> { + A.sliceHandle(PathElement.groupElement("b"), PathElement.dereferenceElement()); + }); } static final MemoryLayout A_MULTI_NO_TARGET = MemoryLayout.structLayout( ValueLayout.ADDRESS.withName("bs") ); - @Test(expectedExceptions = IllegalArgumentException.class) + @Test void badDerefAddressNoTarget() { - A_MULTI_NO_TARGET.varHandle(PathElement.groupElement("bs"), PathElement.dereferenceElement()); + assertThrows(IllegalArgumentException.class, () -> { + A_MULTI_NO_TARGET.varHandle(PathElement.groupElement("bs"), PathElement.dereferenceElement()); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test void badDerefMisAligned() { MemoryLayout struct = MemoryLayout.structLayout( - ValueLayout.ADDRESS.withTargetLayout(ValueLayout.JAVA_INT).withName("x")); - + ValueLayout.ADDRESS.withTargetLayout(ValueLayout.JAVA_INT).withName("x")); try (Arena arena = Arena.ofConfined()) { MemorySegment segment = arena.allocate(struct.byteSize() + 1, struct.byteAlignment()).asSlice(1); VarHandle vhX = struct.varHandle(PathElement.groupElement("x"), PathElement.dereferenceElement()); - vhX.set(segment, 0L, 42); // should throw + assertThrows(IllegalArgumentException.class, () -> { + vhX.set(segment, 0L, 42); + }); } } } diff --git a/test/jdk/java/foreign/TestDowncallBase.java b/test/jdk/java/foreign/TestDowncallBase.java index ace8867000f0d..e62b0bc40acdb 100644 --- a/test/jdk/java/foreign/TestDowncallBase.java +++ b/test/jdk/java/foreign/TestDowncallBase.java @@ -33,6 +33,9 @@ import java.util.function.Consumer; import java.util.stream.Stream; +import org.junit.jupiter.api.TestInstance; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestDowncallBase extends CallGeneratorHelper { Object doCall(MemorySegment symbol, SegmentAllocator allocator, FunctionDescriptor descriptor, Object[] args) throws Throwable { diff --git a/test/jdk/java/foreign/TestDowncallScope.java b/test/jdk/java/foreign/TestDowncallScope.java index 860fa74b533e4..7d8bd9ec1a887 100644 --- a/test/jdk/java/foreign/TestDowncallScope.java +++ b/test/jdk/java/foreign/TestDowncallScope.java @@ -26,31 +26,35 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestDowncallBase * - * @run testng/othervm/native -Xcheck:jni -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies + * @run junit/othervm/native -Xcheck:jni -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies * --enable-native-access=ALL-UNNAMED -Dgenerator.sample.factor=17 * TestDowncallScope * - * @run testng/othervm/native -Xint -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies + * @run junit/othervm/native -Xint -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies * --enable-native-access=ALL-UNNAMED -Dgenerator.sample.factor=100000 * TestDowncallScope */ -import org.testng.annotations.Test; import java.lang.foreign.*; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; -import static org.testng.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestDowncallScope extends TestDowncallBase { static { System.loadLibrary("TestDowncall"); } - @Test(dataProvider="functions", dataProviderClass=CallGeneratorHelper.class) + @ParameterizedTest + @MethodSource("functions") public void testDowncall(int count, String fName, CallGeneratorHelper.Ret ret, List paramTypes, List fields) throws Throwable { @@ -68,7 +72,7 @@ public void testDowncall(int count, String fName, CallGeneratorHelper.Ret ret, checks.forEach(c -> c.accept(res)); if (needsScope) { // check that return struct has indeed been allocated in the native scope - assertEquals(((MemorySegment)res).scope(), arena.scope()); + assertEquals(arena.scope(), ((MemorySegment)res).scope()); } } } diff --git a/test/jdk/java/foreign/TestDowncallStack.java b/test/jdk/java/foreign/TestDowncallStack.java index 516a8a7e958cd..28b8a18fa3e41 100644 --- a/test/jdk/java/foreign/TestDowncallStack.java +++ b/test/jdk/java/foreign/TestDowncallStack.java @@ -26,27 +26,31 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestDowncallBase * - * @run testng/othervm/native -Xcheck:jni -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies + * @run junit/othervm/native -Xcheck:jni -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies * --enable-native-access=ALL-UNNAMED -Dgenerator.sample.factor=17 * TestDowncallStack */ -import org.testng.annotations.Test; import java.lang.foreign.*; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; -import static org.testng.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestDowncallStack extends TestDowncallBase { static { System.loadLibrary("TestDowncallStack"); } - @Test(dataProvider="functions", dataProviderClass=CallGeneratorHelper.class) + @ParameterizedTest + @MethodSource("functions") public void testDowncallStack(int count, String fName, CallGeneratorHelper.Ret ret, List paramTypes, List fields) throws Throwable { @@ -64,7 +68,7 @@ public void testDowncallStack(int count, String fName, CallGeneratorHelper.Ret r checks.forEach(c -> c.accept(res)); if (needsScope) { // check that return struct has indeed been allocated in the native scope - assertEquals(((MemorySegment)res).scope(), arena.scope()); + assertEquals(arena.scope(), ((MemorySegment)res).scope()); } } } diff --git a/test/jdk/java/foreign/TestFallbackLookup.java b/test/jdk/java/foreign/TestFallbackLookup.java index 5cc78bf747cac..12534592644cb 100644 --- a/test/jdk/java/foreign/TestFallbackLookup.java +++ b/test/jdk/java/foreign/TestFallbackLookup.java @@ -23,14 +23,15 @@ /* * @test - * @run testng/othervm -Dos.name=Windows --enable-native-access=ALL-UNNAMED TestFallbackLookup + * @run junit/othervm -Dos.name=Windows --enable-native-access=ALL-UNNAMED TestFallbackLookup */ -import org.testng.annotations.*; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.lang.foreign.Linker; +import org.junit.jupiter.api.Test; + public class TestFallbackLookup { @Test void testBadSystemLookupRequest() { diff --git a/test/jdk/java/foreign/TestFree.java b/test/jdk/java/foreign/TestFree.java index 31e9d9906e161..4c8e9d24e3e4a 100644 --- a/test/jdk/java/foreign/TestFree.java +++ b/test/jdk/java/foreign/TestFree.java @@ -25,12 +25,12 @@ * @test * @bug 8248421 * @summary SystemCLinker should have a way to free memory allocated outside Java - * @run testng/othervm --enable-native-access=ALL-UNNAMED TestFree + * @run junit/othervm --enable-native-access=ALL-UNNAMED TestFree */ import java.lang.foreign.MemorySegment; -import static org.testng.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class TestFree extends NativeTestHelper { public void test() throws Throwable { @@ -38,7 +38,7 @@ public void test() throws Throwable { MemorySegment addr = allocateMemory(str.length() + 1); addr.copyFrom(MemorySegment.ofArray(str.getBytes())); addr.set(C_CHAR, str.length(), (byte)0); - assertEquals(str, addr.getString(0)); + assertEquals(addr.getString(0), str); freeMemory(addr); } } diff --git a/test/jdk/java/foreign/TestFunctionDescriptor.java b/test/jdk/java/foreign/TestFunctionDescriptor.java index ef06f1048b20e..9f7d8c67b5079 100644 --- a/test/jdk/java/foreign/TestFunctionDescriptor.java +++ b/test/jdk/java/foreign/TestFunctionDescriptor.java @@ -23,7 +23,7 @@ /* * @test - * @run testng/othervm --enable-native-access=ALL-UNNAMED TestFunctionDescriptor + * @run junit/othervm --enable-native-access=ALL-UNNAMED TestFunctionDescriptor */ import java.lang.foreign.FunctionDescriptor; @@ -32,9 +32,9 @@ import java.lang.invoke.MethodType; import java.util.List; import java.util.Optional; -import org.testng.annotations.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class TestFunctionDescriptor extends NativeTestHelper { @@ -44,17 +44,17 @@ public class TestFunctionDescriptor extends NativeTestHelper { public void testOf() { FunctionDescriptor fd = FunctionDescriptor.of(C_INT, C_DOUBLE, C_LONG_LONG); - assertEquals(fd.argumentLayouts(), List.of(C_DOUBLE, C_LONG_LONG)); + assertEquals(List.of(C_DOUBLE, C_LONG_LONG), fd.argumentLayouts()); Optional returnLayoutOp = fd.returnLayout(); assertTrue(returnLayoutOp.isPresent()); - assertEquals(returnLayoutOp.get(), C_INT); + assertEquals(C_INT, returnLayoutOp.get()); } @Test public void testOfVoid() { FunctionDescriptor fd = FunctionDescriptor.ofVoid(C_DOUBLE, C_LONG_LONG); - assertEquals(fd.argumentLayouts(), List.of(C_DOUBLE, C_LONG_LONG)); + assertEquals(List.of(C_DOUBLE, C_LONG_LONG), fd.argumentLayouts()); Optional returnLayoutOp = fd.returnLayout(); assertFalse(returnLayoutOp.isPresent()); } @@ -64,10 +64,10 @@ public void testAppendArgumentLayouts() { FunctionDescriptor fd = FunctionDescriptor.of(C_INT, C_DOUBLE, C_LONG_LONG); fd = fd.appendArgumentLayouts(C_POINTER); - assertEquals(fd.argumentLayouts(), List.of(C_DOUBLE, C_LONG_LONG, C_POINTER)); + assertEquals(List.of(C_DOUBLE, C_LONG_LONG, C_POINTER), fd.argumentLayouts()); Optional returnLayoutOp = fd.returnLayout(); assertTrue(returnLayoutOp.isPresent()); - assertEquals(returnLayoutOp.get(), C_INT); + assertEquals(C_INT, returnLayoutOp.get()); } @Test @@ -75,10 +75,10 @@ public void testChangeReturnLayout() { FunctionDescriptor fd = FunctionDescriptor.of(C_INT, C_DOUBLE, C_LONG_LONG); fd = fd.changeReturnLayout(C_INT); - assertEquals(fd.argumentLayouts(), List.of(C_DOUBLE, C_LONG_LONG)); + assertEquals(List.of(C_DOUBLE, C_LONG_LONG), fd.argumentLayouts()); Optional returnLayoutOp = fd.returnLayout(); assertTrue(returnLayoutOp.isPresent()); - assertEquals(returnLayoutOp.get(), C_INT); + assertEquals(C_INT, returnLayoutOp.get()); } @Test @@ -86,7 +86,7 @@ public void testDropReturnLayout() { FunctionDescriptor fd = FunctionDescriptor.of(C_INT, C_DOUBLE, C_LONG_LONG); fd = fd.dropReturnLayout(); - assertEquals(fd.argumentLayouts(), List.of(C_DOUBLE, C_LONG_LONG)); + assertEquals(List.of(C_DOUBLE, C_LONG_LONG), fd.argumentLayouts()); Optional returnLayoutOp = fd.returnLayout(); assertFalse(returnLayoutOp.isPresent()); } @@ -110,44 +110,58 @@ public void testCarrierMethodType() { MemoryLayout.structLayout(C_INT, C_INT), MemoryLayout.sequenceLayout(3, C_INT)); MethodType cmt = fd.toMethodType(); - assertEquals(cmt, MethodType.methodType(int.class, int.class, MemorySegment.class, MemorySegment.class)); + assertEquals(MethodType.methodType(int.class, int.class, MemorySegment.class, MemorySegment.class), cmt); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testIllegalInsertArgNegIndex() { FunctionDescriptor fd = FunctionDescriptor.of(C_INT); - fd.insertArgumentLayouts(-1, C_INT); + assertThrows(IllegalArgumentException.class, () -> { + fd.insertArgumentLayouts(-1, C_INT); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testIllegalInsertArgOutOfBounds() { FunctionDescriptor fd = FunctionDescriptor.of(C_INT); - fd.insertArgumentLayouts(2, C_INT); + assertThrows(IllegalArgumentException.class, () -> { + fd.insertArgumentLayouts(2, C_INT); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadPaddingInVoidFunction() { - FunctionDescriptor.ofVoid(MemoryLayout.paddingLayout(1)); + assertThrows(IllegalArgumentException.class, () -> { + FunctionDescriptor.ofVoid(MemoryLayout.paddingLayout(1)); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadPaddingInNonVoidFunction() { - FunctionDescriptor.of(MemoryLayout.paddingLayout(1)); + assertThrows(IllegalArgumentException.class, () -> { + FunctionDescriptor.of(MemoryLayout.paddingLayout(1)); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadPaddingInAppendArgLayouts() { - FunctionDescriptor.ofVoid().appendArgumentLayouts(MemoryLayout.paddingLayout(1)); + assertThrows(IllegalArgumentException.class, () -> { + FunctionDescriptor.ofVoid().appendArgumentLayouts(MemoryLayout.paddingLayout(1)); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadPaddingInInsertArgLayouts() { - FunctionDescriptor.ofVoid().insertArgumentLayouts(0, MemoryLayout.paddingLayout(1)); + assertThrows(IllegalArgumentException.class, () -> { + FunctionDescriptor.ofVoid().insertArgumentLayouts(0, MemoryLayout.paddingLayout(1)); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadPaddingInChangeRetLayout() { - FunctionDescriptor.ofVoid().changeReturnLayout(MemoryLayout.paddingLayout(1)); + assertThrows(IllegalArgumentException.class, () -> { + FunctionDescriptor.ofVoid().changeReturnLayout(MemoryLayout.paddingLayout(1)); + }); } } diff --git a/test/jdk/java/foreign/TestHFA.java b/test/jdk/java/foreign/TestHFA.java index 40f2bf2f305cf..a3d4b460cf6f3 100644 --- a/test/jdk/java/foreign/TestHFA.java +++ b/test/jdk/java/foreign/TestHFA.java @@ -26,17 +26,18 @@ * @test * @summary Test passing of Homogeneous Float Aggregates. * - * @run testng/othervm/native --enable-native-access=ALL-UNNAMED TestHFA + * @run junit/othervm/native --enable-native-access=ALL-UNNAMED TestHFA */ import java.lang.foreign.*; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; -import org.testng.annotations.Test; import static java.lang.foreign.ValueLayout.*; +import org.junit.jupiter.api.Test; + public class TestHFA { static { @@ -108,7 +109,7 @@ public class TestHFA { fdpass_large_struct_after_structs); @Test - public static void testAddFloatStructs() { + public void testAddFloatStructs() { float p0 = 0.0f, p1 = 0.0f, p2 = 0.0f, p3 = 0.0f, p4 = 0.0f, p5 = 0.0f, p6 = 0.0f; try (Arena arena = Arena.ofConfined()) { MemorySegment s = arena.allocate(S_FFFFFFFLayout); @@ -136,7 +137,7 @@ public static void testAddFloatStructs() { } @Test - public static void testAddFloatToStructAfterFloats() { + public void testAddFloatToStructAfterFloats() { float p0 = 0.0f, p1 = 0.0f; try (Arena arena = Arena.ofConfined()) { MemorySegment s = arena.allocate(S_FFLayout); @@ -156,7 +157,7 @@ public static void testAddFloatToStructAfterFloats() { } @Test - public static void testAddFloatToStructAfterStructs() { + public void testAddFloatToStructAfterStructs() { float p0 = 0.0f, p1 = 0.0f; try (Arena arena = Arena.ofConfined()) { MemorySegment s = arena.allocate(S_FFLayout); @@ -175,7 +176,7 @@ public static void testAddFloatToStructAfterStructs() { } @Test - public static void testAddDoubleToStructAfterStructs() { + public void testAddDoubleToStructAfterStructs() { float p0 = 0.0f, p1 = 0.0f; try (Arena arena = Arena.ofConfined()) { MemorySegment s = arena.allocate(S_FFLayout); @@ -194,7 +195,7 @@ public static void testAddDoubleToStructAfterStructs() { } @Test - public static void testAddFloatToLargeStructAfterStructs() { + public void testAddFloatToLargeStructAfterStructs() { float p0 = 0.0f, p1 = 0.0f, p2 = 0.0f, p3 = 0.0f, p4 = 0.0f, p5 = 0.0f, p6 = 0.0f; try (Arena arena = Arena.ofConfined()) { MemorySegment s = arena.allocate(S_FFFFFFFLayout); @@ -270,7 +271,7 @@ public static MemorySegment addDoubleToStructAfterStructs( } @Test - public static void testAddFloatStructsUpcall() { + public void testAddFloatStructsUpcall() { float p0 = 0.0f, p1 = 0.0f, p2 = 0.0f, p3 = 0.0f, p4 = 0.0f, p5 = 0.0f, p6 = 0.0f; try (Arena arena = Arena.ofConfined()) { MemorySegment s = arena.allocate(S_FFFFFFFLayout); @@ -302,7 +303,7 @@ public static void testAddFloatStructsUpcall() { } @Test - public static void testAddFloatToStructAfterFloatsUpcall() { + public void testAddFloatToStructAfterFloatsUpcall() { float p0 = 0.0f, p1 = 0.0f; try (Arena arena = Arena.ofConfined()) { MemorySegment s = arena.allocate(S_FFLayout); @@ -326,7 +327,7 @@ public static void testAddFloatToStructAfterFloatsUpcall() { } @Test - public static void testAddFloatToStructAfterStructsUpcall() { + public void testAddFloatToStructAfterStructsUpcall() { float p0 = 0.0f, p1 = 0.0f; try (Arena arena = Arena.ofConfined()) { MemorySegment s = arena.allocate(S_FFLayout); @@ -349,7 +350,7 @@ public static void testAddFloatToStructAfterStructsUpcall() { } @Test - public static void testAddDoubleToStructAfterStructsUpcall() { + public void testAddDoubleToStructAfterStructsUpcall() { float p0 = 0.0f, p1 = 0.0f; try (Arena arena = Arena.ofConfined()) { MemorySegment s = arena.allocate(S_FFLayout); @@ -372,7 +373,7 @@ public static void testAddDoubleToStructAfterStructsUpcall() { } @Test - public static void testAddFloatToLargeStructAfterStructsUpcall() { + public void testAddFloatToLargeStructAfterStructsUpcall() { float p0 = 0.0f, p1 = 0.0f, p2 = 0.0f, p3 = 0.0f, p4 = 0.0f, p5 = 0.0f, p6 = 0.0f; try (Arena arena = Arena.ofConfined()) { MemorySegment s = arena.allocate(S_FFFFFFFLayout); diff --git a/test/jdk/java/foreign/TestHandshake.java b/test/jdk/java/foreign/TestHandshake.java index 86200b0e7d691..727af389f66a7 100644 --- a/test/jdk/java/foreign/TestHandshake.java +++ b/test/jdk/java/foreign/TestHandshake.java @@ -26,10 +26,10 @@ * @requires vm.flavor != "zero" * @modules java.base/jdk.internal.vm.annotation java.base/jdk.internal.misc * @key randomness - * @run testng/othervm TestHandshake - * @run testng/othervm -Xint TestHandshake - * @run testng/othervm -XX:TieredStopAtLevel=1 TestHandshake - * @run testng/othervm -XX:-TieredCompilation TestHandshake + * @run junit/othervm TestHandshake + * @run junit/othervm -Xint TestHandshake + * @run junit/othervm -XX:TieredStopAtLevel=1 TestHandshake + * @run junit/othervm -XX:-TieredCompilation TestHandshake */ import java.lang.foreign.Arena; @@ -46,13 +46,16 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import static java.lang.foreign.ValueLayout.JAVA_BYTE; import static java.lang.foreign.ValueLayout.JAVA_INT; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestHandshake { static final int ITERATIONS = 5; @@ -66,7 +69,8 @@ public class TestHandshake { static final AtomicLong start = new AtomicLong(); static final AtomicBoolean started = new AtomicBoolean(); - @Test(dataProvider = "accessors") + @ParameterizedTest + @MethodSource("accessors") public void testHandshake(String testName, AccessorFactory accessorFactory) throws InterruptedException { for (int it = 0 ; it < ITERATIONS ; it++) { Arena arena = Arena.ofShared(); @@ -286,7 +290,6 @@ interface AccessorFactory { AbstractSegmentAccessor make(int id, MemorySegment segment, Arena arena); } - @DataProvider static Object[][] accessors() { return new Object[][] { { "SegmentAccessor", (AccessorFactory)SegmentAccessor::new }, diff --git a/test/jdk/java/foreign/TestHeapAlignment.java b/test/jdk/java/foreign/TestHeapAlignment.java index cc8a95465108c..cbe7a59ce1474 100644 --- a/test/jdk/java/foreign/TestHeapAlignment.java +++ b/test/jdk/java/foreign/TestHeapAlignment.java @@ -23,7 +23,7 @@ /* * @test - * @run testng/othervm --enable-native-access=ALL-UNNAMED TestHeapAlignment + * @run junit/othervm --enable-native-access=ALL-UNNAMED TestHeapAlignment */ import java.lang.foreign.AddressLayout; @@ -34,14 +34,17 @@ import java.util.ArrayList; import java.util.List; import java.util.function.Function; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import static org.testng.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestHeapAlignment { - @Test(dataProvider = "layouts") + @ParameterizedTest + @MethodSource("layouts") public void testHeapAlignment(MemorySegment segment, int align, Object val, Object arr, ValueLayout layout, Function segmentFactory) { assertAligned(align, layout, () -> layout.varHandle().get(segment, 0L)); assertAligned(align, layout, () -> layout.varHandle().set(segment, 0L, val)); @@ -101,7 +104,6 @@ enum SegmentAndAlignment { } } - @DataProvider public static Object[][] layouts() { List layouts = new ArrayList<>(); for (SegmentAndAlignment testCase : SegmentAndAlignment.values()) { diff --git a/test/jdk/java/foreign/TestIllegalLink.java b/test/jdk/java/foreign/TestIllegalLink.java index 45239e3cb458b..dc0ab294c3d29 100644 --- a/test/jdk/java/foreign/TestIllegalLink.java +++ b/test/jdk/java/foreign/TestIllegalLink.java @@ -24,7 +24,7 @@ /* * @test * @modules java.base/jdk.internal.foreign - * @run testng/othervm --enable-native-access=ALL-UNNAMED TestIllegalLink + * @run junit/othervm --enable-native-access=ALL-UNNAMED TestIllegalLink */ import java.lang.foreign.Arena; @@ -42,14 +42,17 @@ import java.util.List; import jdk.internal.foreign.CABI; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import static java.lang.foreign.ValueLayout.*; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assumptions.assumeFalse; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestIllegalLink extends NativeTestHelper { private static final boolean IS_SYSV = CABI.current() == CABI.SYS_V; @@ -59,7 +62,8 @@ public class TestIllegalLink extends NativeTestHelper { private static final MethodHandle DUMMY_TARGET_MH = MethodHandles.empty(MethodType.methodType(void.class)); private static final Linker ABI = Linker.nativeLinker(); - @Test(dataProvider = "types") + @ParameterizedTest + @MethodSource("types") public void testIllegalLayouts(FunctionDescriptor desc, Linker.Option[] options, String expectedExceptionMessage) { try { ABI.downcallHandle(DUMMY_TARGET, desc, options); @@ -70,34 +74,32 @@ public void testIllegalLayouts(FunctionDescriptor desc, Linker.Option[] options, } } - @Test(dataProvider = "downcallOnlyOptions", - expectedExceptions = IllegalArgumentException.class, - expectedExceptionsMessageRegExp = ".*Not supported for upcall.*") + @ParameterizedTest + @MethodSource("downcallOnlyOptions") public void testIllegalUpcallOptions(Linker.Option downcallOnlyOption) { - ABI.upcallStub(DUMMY_TARGET_MH, FunctionDescriptor.ofVoid(), Arena.ofAuto(), downcallOnlyOption); + assertThrows(IllegalArgumentException.class, () -> { + ABI.upcallStub(DUMMY_TARGET_MH, FunctionDescriptor.ofVoid(), Arena.ofAuto(), downcallOnlyOption); + }); } - @Test(dataProvider = "illegalCaptureState", - expectedExceptions = IllegalArgumentException.class, - expectedExceptionsMessageRegExp = ".*Unknown name.*") + @ParameterizedTest + @MethodSource("illegalCaptureState") public void testIllegalCaptureState(String name) { - Linker.Option.captureCallState(name); + assumeFalse(IS_WINDOWS); + assertThrows(IllegalArgumentException.class, () -> { + Linker.Option.captureCallState(name); + }); } // where - @DataProvider public static Object[][] illegalCaptureState() { - if (!IS_WINDOWS) { - return new Object[][]{ - { "GetLastError" }, - { "WSAGetLastError" }, - }; - } - return new Object[][]{}; + return new Object[][]{ + { "GetLastError" }, + { "WSAGetLastError" }, + }; } - @DataProvider public static Object[][] downcallOnlyOptions() { return new Object[][]{ { Linker.Option.firstVariadicArg(0) }, @@ -106,7 +108,6 @@ public static Object[][] downcallOnlyOptions() { }; } - @DataProvider public static Object[][] types() { Linker.Option[] NO_OPTIONS = new Linker.Option[0]; List cases = new ArrayList<>(Arrays.asList(new Object[][]{ diff --git a/test/jdk/java/foreign/TestIntrinsics.java b/test/jdk/java/foreign/TestIntrinsics.java index 5024a90949712..856f57170b827 100644 --- a/test/jdk/java/foreign/TestIntrinsics.java +++ b/test/jdk/java/foreign/TestIntrinsics.java @@ -23,7 +23,7 @@ /* * @test - * @run testng/othervm/native + * @run junit/othervm/native * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=true * --enable-native-access=ALL-UNNAMED * -Xbatch @@ -39,13 +39,17 @@ import java.util.List; import java.lang.foreign.MemoryLayout; -import org.testng.annotations.*; import static java.lang.foreign.Linker.Option.firstVariadicArg; import static java.lang.invoke.MethodType.methodType; import static java.lang.foreign.ValueLayout.JAVA_CHAR; -import static org.testng.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestIntrinsics extends NativeTestHelper { static final Linker abi = Linker.nativeLinker(); @@ -57,14 +61,14 @@ private interface RunnableX { void run() throws Throwable; } - @Test(dataProvider = "tests") + @ParameterizedTest + @MethodSource("tests") public void testIntrinsics(RunnableX test) throws Throwable { for (int i = 0; i < 20_000; i++) { test.run(); } } - @DataProvider public Object[][] tests() { List testsList = new ArrayList<>(); @@ -74,7 +78,7 @@ interface AddTest { AddTest tests = (mh, expectedResult, args) -> testsList.add(() -> { Object actual = mh.invokeWithArguments(args); - assertEquals(actual, expectedResult); + assertEquals(expectedResult, actual); }); interface AddIdentity { diff --git a/test/jdk/java/foreign/TestLargeSegmentCopy.java b/test/jdk/java/foreign/TestLargeSegmentCopy.java index c1508e592c3d0..4d0913567b45a 100644 --- a/test/jdk/java/foreign/TestLargeSegmentCopy.java +++ b/test/jdk/java/foreign/TestLargeSegmentCopy.java @@ -26,16 +26,17 @@ * @test * @requires sun.arch.data.model == "64" * @bug 8292851 - * @run testng/othervm -Xmx4G TestLargeSegmentCopy + * @run junit/othervm -Xmx4G TestLargeSegmentCopy */ -import org.testng.annotations.Test; import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; import static java.lang.foreign.ValueLayout.JAVA_LONG; +import org.junit.jupiter.api.Test; + public class TestLargeSegmentCopy { @Test diff --git a/test/jdk/java/foreign/TestLayoutPaths.java b/test/jdk/java/foreign/TestLayoutPaths.java index 6729fbf823682..aa1b56f31ec07 100644 --- a/test/jdk/java/foreign/TestLayoutPaths.java +++ b/test/jdk/java/foreign/TestLayoutPaths.java @@ -24,13 +24,12 @@ /* * @test - * @run testng TestLayoutPaths + * @run junit TestLayoutPaths */ import java.lang.foreign.*; import java.lang.foreign.MemoryLayout.PathElement; -import org.testng.annotations.*; import java.lang.invoke.MethodHandle; import java.lang.invoke.VarHandle; @@ -46,84 +45,116 @@ import static java.lang.foreign.MemoryLayout.PathElement.sequenceElement; import static java.lang.foreign.ValueLayout.JAVA_INT; import static java.lang.foreign.ValueLayout.JAVA_SHORT; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestLayoutPaths { - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadByteSelectFromSeq() { SequenceLayout seq = MemoryLayout.sequenceLayout(5, JAVA_INT); - seq.byteOffset(groupElement("foo")); + assertThrows(IllegalArgumentException.class, () -> { + seq.byteOffset(groupElement("foo")); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadByteSelectFromStruct() { GroupLayout g = MemoryLayout.structLayout(JAVA_INT); - g.byteOffset(sequenceElement()); + assertThrows(IllegalArgumentException.class, () -> { + g.byteOffset(sequenceElement()); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadByteSelectFromValue() { SequenceLayout seq = MemoryLayout.sequenceLayout(5, JAVA_INT); - seq.byteOffset(sequenceElement(), sequenceElement()); + assertThrows(IllegalArgumentException.class, () -> { + seq.byteOffset(sequenceElement(), sequenceElement()); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testUnknownByteStructField() { GroupLayout g = MemoryLayout.structLayout(JAVA_INT); - g.byteOffset(groupElement("foo")); + assertThrows(IllegalArgumentException.class, () -> { + g.byteOffset(groupElement("foo")); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testTooBigGroupElementIndex() { GroupLayout g = MemoryLayout.structLayout(JAVA_INT); - g.byteOffset(groupElement(1)); + assertThrows(IllegalArgumentException.class, () -> { + g.byteOffset(groupElement(1)); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testNegativeGroupElementIndex() { GroupLayout g = MemoryLayout.structLayout(JAVA_INT); - g.byteOffset(groupElement(-1)); + assertThrows(IllegalArgumentException.class, () -> { + g.byteOffset(groupElement(-1)); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testByteOutOfBoundsSeqIndex() { SequenceLayout seq = MemoryLayout.sequenceLayout(5, JAVA_INT); - seq.byteOffset(sequenceElement(6)); + assertThrows(IllegalArgumentException.class, () -> { + seq.byteOffset(sequenceElement(6)); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testNegativeSeqIndex() { - sequenceElement(-2); + assertThrows(IllegalArgumentException.class, () -> { + sequenceElement(-2); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testByteNegativeSeqIndex() { SequenceLayout seq = MemoryLayout.sequenceLayout(5, JAVA_INT); - seq.byteOffset(sequenceElement(-2)); + assertThrows(IllegalArgumentException.class, () -> { + seq.byteOffset(sequenceElement(-2)); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testOutOfBoundsSeqRange() { SequenceLayout seq = MemoryLayout.sequenceLayout(5, JAVA_INT); - seq.byteOffset(sequenceElement(6, 2)); + assertThrows(IllegalArgumentException.class, () -> { + seq.byteOffset(sequenceElement(6, 2)); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testNegativeSeqRange() { - sequenceElement(-2, 2); + assertThrows(IllegalArgumentException.class, () -> { + sequenceElement(-2, 2); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testByteNegativeSeqRange() { SequenceLayout seq = MemoryLayout.sequenceLayout(5, JAVA_INT); - seq.byteOffset(sequenceElement(-2, 2)); + assertThrows(IllegalArgumentException.class, () -> { + seq.byteOffset(sequenceElement(-2, 2)); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testIncompleteAccess() { SequenceLayout seq = MemoryLayout.sequenceLayout(5, MemoryLayout.structLayout(JAVA_INT)); - seq.varHandle(sequenceElement()); + assertThrows(IllegalArgumentException.class, () -> { + seq.varHandle(sequenceElement()); + }); } @Test @@ -132,10 +163,12 @@ public void testByteOffsetHandleRange() { seq.byteOffsetHandle(sequenceElement(0, 1)); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testByteOffsetHandleBadRange() { SequenceLayout seq = MemoryLayout.sequenceLayout(5, MemoryLayout.structLayout(JAVA_INT)); - seq.byteOffsetHandle(sequenceElement(5, 1)); // invalid range (starting position is outside the sequence) + assertThrows(IllegalArgumentException.class, () -> { + seq.byteOffsetHandle(sequenceElement(5, 1)); // invalid range (starting position is outside the sequence) + }); } @Test @@ -143,23 +176,23 @@ public void testBadAlignmentOfRoot() { MemoryLayout struct = MemoryLayout.structLayout( JAVA_INT.withOrder(ByteOrder.LITTLE_ENDIAN), JAVA_SHORT.withOrder(ByteOrder.LITTLE_ENDIAN).withName("x")); - assertEquals(struct.byteAlignment(), 4); + assertEquals(4, struct.byteAlignment()); try (Arena arena = Arena.ofConfined()) { MemorySegment seg = arena.allocate(struct.byteSize() + 2, struct.byteAlignment()).asSlice(2); - assertEquals(seg.address() % JAVA_SHORT.byteAlignment(), 0); // should be aligned - assertNotEquals(seg.address() % struct.byteAlignment(), 0); // should not be aligned + assertEquals(0, seg.address() % JAVA_SHORT.byteAlignment()); // should be aligned + assertNotEquals(0, seg.address() % struct.byteAlignment()); // should not be aligned String expectedMessage = "Target offset 0 is incompatible with alignment constraint " + struct.byteAlignment() + " (of [i4s2(x)]) for segment MemorySegment"; VarHandle vhX = struct.varHandle(groupElement("x")); - IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> { + IllegalArgumentException iae = assertThrows(IllegalArgumentException.class, () -> { vhX.set(seg, 0L, (short) 42); }); assertTrue(iae.getMessage().startsWith(expectedMessage)); MethodHandle sliceX = struct.sliceHandle(groupElement("x")); - iae = expectThrows(IllegalArgumentException.class, () -> { + iae = assertThrows(IllegalArgumentException.class, () -> { MemorySegment slice = (MemorySegment) sliceX.invokeExact(seg, 0L); }); assertTrue(iae.getMessage().startsWith(expectedMessage)); @@ -175,9 +208,9 @@ public void testWrongTypeRoot() { var expectedMessage = "Bad layout path: attempting to select a sequence element from a non-sequence layout: [i4i4]"; - IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> + IllegalArgumentException iae = assertThrows(IllegalArgumentException.class, () -> struct.select(PathElement.sequenceElement())); - assertEquals(iae.getMessage(), expectedMessage); + assertEquals(expectedMessage, iae.getMessage()); } @Test @@ -195,11 +228,11 @@ public void testWrongTypeEnclosing() { "[2:[i4(3a)i4(3b)](2)](1), selected from: " + "[[2:[i4(3a)i4(3b)](2)](1)](0)"; - IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> + IllegalArgumentException iae = assertThrows(IllegalArgumentException.class, () -> struct.select(PathElement.groupElement("1"), PathElement.sequenceElement(), PathElement.sequenceElement())); - assertEquals(iae.getMessage(), expectedMessage); + assertEquals(expectedMessage, iae.getMessage()); } @Test @@ -229,7 +262,8 @@ public void testBadSequencePathInSelect() { } } - @Test(dataProvider = "groupSelectors") + @ParameterizedTest + @MethodSource("groupSelectors") public void testStructPaths(IntFunction groupSelector) { long[] offsets = { 0, 1, 3, 7 }; GroupLayout g = MemoryLayout.structLayout( @@ -250,11 +284,12 @@ public void testStructPaths(IntFunction groupSelector) { for (int i = 0 ; i < 4 ; i++) { long byteOffset = g.byteOffset(groupSelector.apply(i)); - assertEquals(offsets[i], byteOffset); + assertEquals(byteOffset, offsets[i]); } } - @Test(dataProvider = "groupSelectors") + @ParameterizedTest + @MethodSource("groupSelectors") public void testUnionPaths(IntFunction groupSelector) { long[] offsets = { 0, 0, 0, 0 }; GroupLayout g = MemoryLayout.unionLayout( @@ -275,11 +310,10 @@ public void testUnionPaths(IntFunction groupSelector) { for (int i = 0 ; i < 4 ; i++) { long byteOffset = g.byteOffset(groupSelector.apply(i)); - assertEquals(offsets[i], byteOffset); + assertEquals(byteOffset, offsets[i]); } } - @DataProvider public static Object[][] groupSelectors() { return new Object[][] { { (IntFunction) PathElement::groupElement }, // by index @@ -301,20 +335,22 @@ public void testSequencePaths() { for (int i = 0 ; i < 4 ; i++) { long byteOffset = g.byteOffset(sequenceElement(i)); - assertEquals(offsets[i], byteOffset); + assertEquals(byteOffset, offsets[i]); } } - @Test(dataProvider = "testLayouts") + @ParameterizedTest + @MethodSource("testLayouts") public void testOffsetHandle(MemoryLayout layout, PathElement[] pathElements, long[] indexes, long expectedByteOffset) throws Throwable { MethodHandle byteOffsetHandle = layout.byteOffsetHandle(pathElements); byteOffsetHandle = byteOffsetHandle.asSpreader(long[].class, indexes.length); long actualByteOffset = (long) byteOffsetHandle.invokeExact(0L, indexes); - assertEquals(actualByteOffset, expectedByteOffset); + assertEquals(expectedByteOffset, actualByteOffset); } - @Test(dataProvider = "testLayouts") + @ParameterizedTest + @MethodSource("testLayouts") public void testOffsetHandleOOBIndex(MemoryLayout layout, PathElement[] pathElements, long[] indexes, long expectedByteOffset) throws Throwable { int[] badIndices = { -1, 10 }; @@ -332,15 +368,19 @@ public void testOffsetHandleOOBIndex(MemoryLayout layout, PathElement[] pathElem } } - @Test(dataProvider = "testLayouts", expectedExceptions = ArithmeticException.class) + @ParameterizedTest + @MethodSource("testLayouts") public void testOffsetHandleOverflow(MemoryLayout layout, PathElement[] pathElements, long[] indexes, long expectedByteOffset) throws Throwable { MethodHandle byteOffsetHandle = layout.byteOffsetHandle(pathElements); - byteOffsetHandle = byteOffsetHandle.asSpreader(long[].class, indexes.length); - byteOffsetHandle.invoke(Long.MAX_VALUE, indexes); + MethodHandle finalHandle = byteOffsetHandle.asSpreader(long[].class, indexes.length); + assertThrows(ArithmeticException.class, () -> { + finalHandle.invoke(Long.MAX_VALUE, indexes); + }); } - @Test(dataProvider = "testLayouts") + @ParameterizedTest + @MethodSource("testLayouts") public void testVarHandleBadSegment(MemoryLayout layout, PathElement[] pathElements, long[] indexes, long expectedByteOffset) throws Throwable { MemoryLayout seqLayout = MemoryLayout.sequenceLayout(10, layout); @@ -357,7 +397,8 @@ public void testVarHandleBadSegment(MemoryLayout layout, PathElement[] pathEleme assertThrows(IndexOutOfBoundsException.class, () -> getter_handle.invoke(segment, 0L, seqIndexes)); } - @Test(dataProvider = "testLayouts") + @ParameterizedTest + @MethodSource("testLayouts") public void testSliceHandleBadSegment(MemoryLayout layout, PathElement[] pathElements, long[] indexes, long expectedByteOffset) throws Throwable { MemoryLayout seqLayout = MemoryLayout.sequenceLayout(10, layout); @@ -373,7 +414,8 @@ public void testSliceHandleBadSegment(MemoryLayout layout, PathElement[] pathEle assertThrows(IndexOutOfBoundsException.class, () -> getter_handle.invoke(segment, 0L, seqIndexes)); } - @Test(dataProvider = "testLayouts") + @ParameterizedTest + @MethodSource("testLayouts") public void testArrayElementVarHandleBadSegment(MemoryLayout layout, PathElement[] pathElements, long[] indexes, long expectedByteOffset) throws Throwable { MemoryLayout seqLayout = MemoryLayout.sequenceLayout(10, layout); @@ -395,46 +437,45 @@ public void testArrayElementVarHandleBadSegment(MemoryLayout layout, PathElement public void testHashCodeCollision() { PathElement sequenceElement = PathElement.sequenceElement(); PathElement dereferenceElement = PathElement.dereferenceElement(); - assertNotEquals(sequenceElement.hashCode(), dereferenceElement.hashCode()); + assertNotEquals(dereferenceElement.hashCode(), sequenceElement.hashCode()); } @Test public void testGroupElementIndexToString() { PathElement e = PathElement.groupElement(2); - assertEquals(e.toString(), "groupElement(2)"); + assertEquals("groupElement(2)", e.toString()); } @Test public void testGroupElementNameToString() { PathElement e = PathElement.groupElement("x"); - assertEquals(e.toString(), "groupElement(\"x\")"); + assertEquals("groupElement(\"x\")", e.toString()); } @Test public void testSequenceElementToString() { PathElement e = PathElement.sequenceElement(); - assertEquals(e.toString(), "sequenceElement()"); + assertEquals("sequenceElement()", e.toString()); } @Test public void testSequenceElementIndexToString() { PathElement e = PathElement.sequenceElement(2); - assertEquals(e.toString(), "sequenceElement(2)"); + assertEquals("sequenceElement(2)", e.toString()); } @Test public void testSequenceElementRangeToString() { PathElement e = PathElement.sequenceElement(2, 4); - assertEquals(e.toString(), "sequenceElement(2, 4)"); + assertEquals("sequenceElement(2, 4)", e.toString()); } @Test public void testDerefereceElementToString() { PathElement e = PathElement.dereferenceElement(); - assertEquals(e.toString(), "dereferenceElement()"); + assertEquals("dereferenceElement()", e.toString()); } - @DataProvider public static Object[][] testLayouts() { List testCases = new ArrayList<>(); @@ -510,7 +551,8 @@ public static Object[][] testLayouts() { return testCases.toArray(Object[][]::new); } - @Test(dataProvider = "testLayouts") + @ParameterizedTest + @MethodSource("testLayouts") public void testSliceHandle(MemoryLayout layout, PathElement[] pathElements, long[] indexes, long expectedByteOffset) throws Throwable { MemoryLayout selected = layout.select(pathElements); @@ -520,8 +562,8 @@ public void testSliceHandle(MemoryLayout layout, PathElement[] pathElements, lon try (Arena arena = Arena.ofConfined()) { MemorySegment segment = arena.allocate(layout); MemorySegment slice = (MemorySegment) sliceHandle.invokeExact(segment, 0L, indexes); - assertEquals(slice.address() - segment.address(), expectedByteOffset); - assertEquals(slice.byteSize(), selected.byteSize()); + assertEquals(expectedByteOffset, slice.address() - segment.address()); + assertEquals(selected.byteSize(), slice.byteSize()); } } diff --git a/test/jdk/java/foreign/TestLayouts.java b/test/jdk/java/foreign/TestLayouts.java index 2606e0481b322..64984eb7268c7 100644 --- a/test/jdk/java/foreign/TestLayouts.java +++ b/test/jdk/java/foreign/TestLayouts.java @@ -23,7 +23,7 @@ /* * @test - * @run testng TestLayouts + * @run junit TestLayouts */ import java.lang.foreign.*; @@ -36,19 +36,28 @@ import java.util.function.LongFunction; import java.util.stream.Stream; -import org.testng.annotations.*; import static java.lang.foreign.ValueLayout.*; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestLayouts { - @Test(dataProvider = "badAlignments", expectedExceptions = IllegalArgumentException.class) + @ParameterizedTest + @MethodSource("layoutsAndBadAlignments") public void testBadLayoutAlignment(MemoryLayout layout, long alignment) { - layout.withByteAlignment(alignment); + assertThrows(IllegalArgumentException.class, () -> { + layout.withByteAlignment(alignment); + }); } - @Test(dataProvider = "basicLayoutsAndAddressAndGroups") + @ParameterizedTest + @MethodSource("basicLayoutsAndAddressAndGroups") public void testEqualities(MemoryLayout layout) { // Use another Type @@ -110,26 +119,36 @@ public void testIndexedSequencePath() { } } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadBoundSequenceLayoutResize() { SequenceLayout seq = MemoryLayout.sequenceLayout(10, ValueLayout.JAVA_INT); - seq.withElementCount(-1); + assertThrows(IllegalArgumentException.class, () -> { + seq.withElementCount(-1); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testReshape() { SequenceLayout layout = MemoryLayout.sequenceLayout(10, JAVA_INT); - layout.reshape(); + assertThrows(IllegalArgumentException.class, () -> { + layout.reshape(); + }); } - @Test(dataProvider = "basicLayoutsAndAddressAndGroups", expectedExceptions = IllegalArgumentException.class) + @ParameterizedTest + @MethodSource("basicLayoutsAndAddressAndGroups") public void testGroupIllegalAlignmentNotPowerOfTwo(MemoryLayout layout) { - layout.withByteAlignment(9); + assertThrows(IllegalArgumentException.class, () -> { + layout.withByteAlignment(9); + }); } - @Test(dataProvider = "basicLayoutsAndAddressAndGroups", expectedExceptions = IllegalArgumentException.class) + @ParameterizedTest + @MethodSource("basicLayoutsAndAddressAndGroups") public void testGroupIllegalAlignmentNotGreaterOrEqualTo1(MemoryLayout layout) { - layout.withByteAlignment(0); + assertThrows(IllegalArgumentException.class, () -> { + layout.withByteAlignment(0); + }); } @Test @@ -137,18 +156,18 @@ public void testEqualsPadding() { PaddingLayout paddingLayout = MemoryLayout.paddingLayout(2); testEqualities(paddingLayout); PaddingLayout paddingLayout2 = MemoryLayout.paddingLayout(4); - assertNotEquals(paddingLayout, paddingLayout2); + assertNotEquals(paddingLayout2, paddingLayout); } @Test public void testEmptyGroup() { MemoryLayout struct = MemoryLayout.structLayout(); - assertEquals(struct.byteSize(), 0); - assertEquals(struct.byteAlignment(), 1); + assertEquals(0, struct.byteSize()); + assertEquals(1, struct.byteAlignment()); MemoryLayout union = MemoryLayout.unionLayout(); - assertEquals(union.byteSize(), 0); - assertEquals(union.byteAlignment(), 1); + assertEquals(0, union.byteSize()); + assertEquals(1, union.byteAlignment()); } @Test @@ -160,27 +179,30 @@ public void testStructSizeAndAlign() { ValueLayout.JAVA_INT, ValueLayout.JAVA_LONG ); - assertEquals(struct.byteSize(), 1 + 1 + 2 + 4 + 8); - assertEquals(struct.byteAlignment(), 8); + assertEquals(1 + 1 + 2 + 4 + 8, struct.byteSize()); + assertEquals(8, struct.byteAlignment()); } - @Test(dataProvider="basicLayouts") + @ParameterizedTest + @MethodSource("basicLayouts") public void testPaddingNoAlign(MemoryLayout layout) { - assertEquals(MemoryLayout.paddingLayout(layout.byteSize()).byteAlignment(), 1); + assertEquals(1, MemoryLayout.paddingLayout(layout.byteSize()).byteAlignment()); } - @Test(dataProvider="basicLayouts") + @ParameterizedTest + @MethodSource("basicLayouts") public void testStructPaddingAndAlign(MemoryLayout layout) { MemoryLayout struct = MemoryLayout.structLayout( layout, MemoryLayout.paddingLayout(16 - layout.byteSize())); - assertEquals(struct.byteAlignment(), layout.byteAlignment()); + assertEquals(layout.byteAlignment(), struct.byteAlignment()); } - @Test(dataProvider="basicLayouts") + @ParameterizedTest + @MethodSource("basicLayouts") public void testUnionPaddingAndAlign(MemoryLayout layout) { MemoryLayout struct = MemoryLayout.unionLayout( layout, MemoryLayout.paddingLayout(16 - layout.byteSize())); - assertEquals(struct.byteAlignment(), layout.byteAlignment()); + assertEquals(layout.byteAlignment(), struct.byteAlignment()); } @Test @@ -191,8 +213,8 @@ public void testUnionSizeAndAlign() { ValueLayout.JAVA_INT, ValueLayout.JAVA_LONG ); - assertEquals(struct.byteSize(), 8); - assertEquals(struct.byteAlignment(), 8); + assertEquals(8, struct.byteSize()); + assertEquals(8, struct.byteAlignment()); } @Test @@ -220,16 +242,16 @@ public void testSequenceOverflow() { @Test public void testSequenceLayoutWithZeroLength() { SequenceLayout layout = MemoryLayout.sequenceLayout(0, JAVA_INT); - assertEquals(layout.toString().toLowerCase(Locale.ROOT), "[0:i4]"); + assertEquals("[0:i4]", layout.toString().toLowerCase(Locale.ROOT)); SequenceLayout nested = MemoryLayout.sequenceLayout(0, layout); - assertEquals(nested.toString().toLowerCase(Locale.ROOT), "[0:[0:i4]]"); + assertEquals("[0:[0:i4]]", nested.toString().toLowerCase(Locale.ROOT)); SequenceLayout layout2 = MemoryLayout.sequenceLayout(0, JAVA_INT); - assertEquals(layout, layout2); + assertEquals(layout2, layout); SequenceLayout nested2 = MemoryLayout.sequenceLayout(0, layout2); - assertEquals(nested, nested2); + assertEquals(nested2, nested); } @Test @@ -246,14 +268,14 @@ public void testStructOverflow() { @Test public void testPadding() { var padding = MemoryLayout.paddingLayout(1); - assertEquals(padding.byteAlignment(), 1); + assertEquals(1, padding.byteAlignment()); } @Test public void testPaddingInStruct() { var padding = MemoryLayout.paddingLayout(1); var struct = MemoryLayout.structLayout(padding); - assertEquals(struct.byteAlignment(), 1); + assertEquals(1, struct.byteAlignment()); } @Test @@ -273,31 +295,34 @@ public void testStructToString() { for (ByteOrder order : List.of(ByteOrder.LITTLE_ENDIAN, ByteOrder.BIG_ENDIAN)) { String intRepresentation = (order == ByteOrder.LITTLE_ENDIAN ? "i" : "I"); StructLayout padding = MemoryLayout.structLayout(JAVA_INT.withOrder(order)).withName("struct"); - assertEquals(padding.toString(), "[" + intRepresentation + "4](struct)"); + assertEquals("[" + intRepresentation + "4](struct)", padding.toString()); var toStringUnaligned = padding.withByteAlignment(8).toString(); - assertEquals(toStringUnaligned, "8%[" + intRepresentation + "4](struct)"); + assertEquals("8%[" + intRepresentation + "4](struct)", toStringUnaligned); } } - @Test(dataProvider = "layoutKinds") + @ParameterizedTest + @MethodSource("layoutsKinds") public void testPadding(LayoutKind kind) { - assertEquals(kind == LayoutKind.PADDING, kind.layout instanceof PaddingLayout); + assertEquals(kind.layout instanceof PaddingLayout, kind == LayoutKind.PADDING); } - @Test(dataProvider="layoutsAndAlignments") + @ParameterizedTest + @MethodSource("layoutsAndAlignments") public void testAlignmentString(MemoryLayout layout, long byteAlign) { long[] alignments = { 1, 2, 4, 8, 16 }; for (long a : alignments) { if (layout.byteAlignment() == byteAlign) { assertFalse(layout.toString().contains("%")); if (a >= layout.byteAlignment()) { - assertEquals(layout.withByteAlignment(a).toString().contains("%"), a != byteAlign); + assertEquals(a != byteAlign, layout.withByteAlignment(a).toString().contains("%")); } } } } - @Test(dataProvider="layoutsAndAlignments") + @ParameterizedTest + @MethodSource("layoutsAndAlignments") public void testBadByteAlignment(MemoryLayout layout, long byteAlign) { long[] alignments = { 1, 2, 4, 8, 16 }; for (long a : alignments) { @@ -307,15 +332,17 @@ public void testBadByteAlignment(MemoryLayout layout, long byteAlign) { } } - @Test(dataProvider="layoutsAndAlignments") + @ParameterizedTest + @MethodSource("layoutsAndAlignments") public void testBadSequenceElementAlignmentTooBig(MemoryLayout layout, long byteAlign) { MemoryLayout elementLayout = layout.withByteAlignment(nextPowerOfTwo(layout.byteSize() * 2)); // hyper-align - IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, + IllegalArgumentException iae = assertThrows(IllegalArgumentException.class, () -> MemoryLayout.sequenceLayout(1, elementLayout)); - assertEquals(iae.getMessage(), "Element layout size is not multiple of alignment"); + assertEquals("Element layout size is not multiple of alignment", iae.getMessage()); } - @Test(dataProvider="layoutsAndAlignments") + @ParameterizedTest + @MethodSource("layoutsAndAlignments") public void testBadSequenceElementSizeNotMultipleOfAlignment(MemoryLayout layout, long byteAlign) { boolean shouldFail = layout.byteSize() % layout.byteAlignment() != 0; try { @@ -326,7 +353,8 @@ public void testBadSequenceElementSizeNotMultipleOfAlignment(MemoryLayout layout } } - @Test(dataProvider="layoutsAndAlignments") + @ParameterizedTest + @MethodSource("layoutsAndAlignments") public void testBadSpliteratorElementSizeNotMultipleOfAlignment(MemoryLayout layout, long byteAlign) { boolean shouldFail = layout.byteSize() % layout.byteAlignment() != 0; try (Arena arena = Arena.ofConfined()) { @@ -338,7 +366,8 @@ public void testBadSpliteratorElementSizeNotMultipleOfAlignment(MemoryLayout lay } } - @Test(dataProvider="layoutsAndAlignments") + @ParameterizedTest + @MethodSource("layoutsAndAlignments") public void testBadElementsElementSizeNotMultipleOfAlignment(MemoryLayout layout, long byteAlign) { boolean shouldFail = layout.byteSize() % layout.byteAlignment() != 0; try (Arena arena = Arena.ofConfined()) { @@ -350,18 +379,21 @@ public void testBadElementsElementSizeNotMultipleOfAlignment(MemoryLayout layout } } - @Test(dataProvider="layoutsAndAlignments") + @ParameterizedTest + @MethodSource("layoutsAndAlignments") public void testBadStruct(MemoryLayout layout, long byteAlign) { MemoryLayout elementLayout = layout.withByteAlignment(nextPowerOfTwo(layout.byteSize() * 2)); // hyper-align - IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, + IllegalArgumentException iae = assertThrows(IllegalArgumentException.class, () -> MemoryLayout.structLayout(elementLayout, elementLayout)); assertTrue(iae.getMessage().contains("Invalid alignment constraint for member layout")); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testSequenceElement() { - // Step must be != 0 - PathElement.sequenceElement(3, 0); + assertThrows(IllegalArgumentException.class, () -> { + // Step must be != 0 + PathElement.sequenceElement(3, 0); + }); } @Test @@ -373,29 +405,34 @@ public void testVarHandleCaching() { assertNotSame(ADDRESS.withTargetLayout(JAVA_INT).varHandle(), ADDRESS.varHandle()); } - @Test(expectedExceptions=IllegalArgumentException.class, - expectedExceptionsMessageRegExp=".*offset is negative.*") + @Test public void testScaleNegativeOffset() { - JAVA_INT.scale(-1, 0); + assertThrows(IllegalArgumentException.class, () -> { + JAVA_INT.scale(-1, 0); + }); } - @Test(expectedExceptions=IllegalArgumentException.class, - expectedExceptionsMessageRegExp=".*index is negative.*") + @Test public void testScaleNegativeIndex() { - JAVA_INT.scale(0, -1); + assertThrows(IllegalArgumentException.class, () -> { + JAVA_INT.scale(0, -1); + }); } - @Test(expectedExceptions=ArithmeticException.class) + @Test public void testScaleAddOverflow() { - JAVA_INT.scale(Long.MAX_VALUE, 1); + assertThrows(ArithmeticException.class, () -> { + JAVA_INT.scale(Long.MAX_VALUE, 1); + }); } - @Test(expectedExceptions=ArithmeticException.class) + @Test public void testScaleMultiplyOverflow() { - JAVA_INT.scale(0, Long.MAX_VALUE); + assertThrows(ArithmeticException.class, () -> { + JAVA_INT.scale(0, Long.MAX_VALUE); + }); } - @DataProvider(name = "badAlignments") public Object[][] layoutsAndBadAlignments() { LayoutKind[] layoutKinds = LayoutKind.values(); Object[][] values = new Object[layoutKinds.length * 2][2]; @@ -406,7 +443,6 @@ public Object[][] layoutsAndBadAlignments() { return values; } - @DataProvider(name = "layoutKinds") public Object[][] layoutsKinds() { return Stream.of(LayoutKind.values()) .map(lk -> new Object[] { lk }) @@ -454,28 +490,24 @@ enum LayoutKind { } } - @DataProvider(name = "basicLayouts") public Object[][] basicLayouts() { return Stream.of(basicLayouts) .map(l -> new Object[] { l }) .toArray(Object[][]::new); } - @DataProvider(name = "basicLayoutsAndAddress") public Object[][] basicLayoutsAndAddress() { return Stream.concat(Stream.of(basicLayouts), Stream.of(ADDRESS)) .map(l -> new Object[] { l }) .toArray(Object[][]::new); } - @DataProvider(name = "basicLayoutsAndAddressAndGroups") public Object[][] basicLayoutsAndAddressAndGroups() { return Stream.concat(Stream.concat(Stream.of(basicLayouts), Stream.of(ADDRESS)), groupLayoutStream()) .map(l -> new Object[] { l }) .toArray(Object[][]::new); } - @DataProvider(name = "layoutsAndAlignments") public Object[][] layoutsAndAlignments() { List layoutsAndAlignments = new ArrayList<>(); int i = 0; @@ -505,14 +537,12 @@ public Object[][] layoutsAndAlignments() { return layoutsAndAlignments.toArray(Object[][]::new); } - @DataProvider(name = "groupLayouts") public Object[][] groupLayouts() { return groupLayoutStream() .map(l -> new Object[] { l }) .toArray(Object[][]::new); } - @DataProvider(name = "validCarriers") public Object[][] validCarriers() { return Stream.of( boolean.class, diff --git a/test/jdk/java/foreign/TestLinker.java b/test/jdk/java/foreign/TestLinker.java index 902b938ac62aa..11d22b3905cf5 100644 --- a/test/jdk/java/foreign/TestLinker.java +++ b/test/jdk/java/foreign/TestLinker.java @@ -24,14 +24,12 @@ /* * @test * @modules java.base/jdk.internal.foreign java.base/jdk.internal.foreign.abi.fallback - * @run testng TestLinker - * @run testng/othervm TestLinker + * @run junit TestLinker + * @run junit/othervm TestLinker */ import jdk.internal.foreign.CABI; import jdk.internal.foreign.abi.fallback.FallbackLinker; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.Linker; @@ -47,15 +45,22 @@ import static java.lang.foreign.MemoryLayout.*; import static java.lang.foreign.ValueLayout.*; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestLinker extends NativeTestHelper { static final boolean IS_FALLBACK_LINKER = CABI.current() == CABI.FALLBACK; record LinkRequest(FunctionDescriptor descriptor, Linker.Option... options) {} - @Test(dataProvider = "notSameCases") + @ParameterizedTest + @MethodSource("notSameCases") public void testLinkerOptionsCache(LinkRequest l1, LinkRequest l2) { Linker linker = Linker.nativeLinker(); MethodHandle mh1 = linker.downcallHandle(l1.descriptor(), l1.options()); @@ -64,7 +69,6 @@ public void testLinkerOptionsCache(LinkRequest l1, LinkRequest l2) { assertNotSame(mh1, mh2); } - @DataProvider public static Object[][] notSameCases() { FunctionDescriptor fd_II_V = FunctionDescriptor.ofVoid(C_INT, C_INT); return new Object[][]{ @@ -74,7 +78,8 @@ public static Object[][] notSameCases() { }; } - @Test(dataProvider = "namedDescriptors") + @ParameterizedTest + @MethodSource("namedDescriptors") public void testNamedLinkerCache(FunctionDescriptor f1, FunctionDescriptor f2) { Linker linker = Linker.nativeLinker(); MethodHandle mh1 = linker.downcallHandle(f1); @@ -83,7 +88,6 @@ public void testNamedLinkerCache(FunctionDescriptor f1, FunctionDescriptor f2) { assertSame(mh1, mh2); } - @DataProvider public static Object[][] namedDescriptors() { List cases = new ArrayList<>(Arrays.asList(new Object[][]{ { FunctionDescriptor.ofVoid(C_INT), @@ -120,7 +124,6 @@ public static Object[][] namedDescriptors() { return cases.toArray(Object[][]::new); } - @DataProvider public static Object[][] invalidIndexCases() { return new Object[][]{ { -1, }, @@ -128,22 +131,25 @@ public static Object[][] invalidIndexCases() { }; } - @Test(dataProvider = "invalidIndexCases", - expectedExceptions = IllegalArgumentException.class, - expectedExceptionsMessageRegExp = ".*not in bounds for descriptor.*") + @ParameterizedTest + @MethodSource("invalidIndexCases") public void testInvalidOption(int invalidIndex) { Linker.Option option = Linker.Option.firstVariadicArg(invalidIndex); FunctionDescriptor desc = FunctionDescriptor.ofVoid(); - Linker.nativeLinker().downcallHandle(desc, option); // throws + assertThrows(IllegalArgumentException.class, () -> { + Linker.nativeLinker().downcallHandle(desc, option); + }); } - @Test(expectedExceptions = IllegalArgumentException.class, - expectedExceptionsMessageRegExp = ".*Unknown name.*") + @Test public void testInvalidPreservedValueName() { - Linker.Option.captureCallState("foo"); // throws + assertThrows(IllegalArgumentException.class, () -> { + Linker.Option.captureCallState("foo"); + }); } - @Test(dataProvider = "canonicalTypeNames") + @ParameterizedTest + @MethodSource("canonicalTypeNames") public void testCanonicalLayouts(String typeName) { MemoryLayout layout = LINKER.canonicalLayouts().get(typeName); assertNotNull(layout); @@ -157,7 +163,7 @@ public void embeddedPaddingLayout() { StructLayout struct = MemoryLayout.structLayout(sequence); FunctionDescriptor fd = FunctionDescriptor.of(struct, struct); Linker linker = Linker.nativeLinker(); - var x = expectThrows(IllegalArgumentException.class, () -> linker.downcallHandle(fd)); + var x = assertThrows(IllegalArgumentException.class, () -> linker.downcallHandle(fd)); assertTrue(x.getMessage().contains("not supported because a sequence of a padding layout is not allowed")); } @@ -167,7 +173,7 @@ public void groupLayoutWithOnlyPadding() { StructLayout struct = MemoryLayout.structLayout(padding); FunctionDescriptor fd = FunctionDescriptor.of(struct, struct); Linker linker = Linker.nativeLinker(); - var x = expectThrows(IllegalArgumentException.class, () -> linker.downcallHandle(fd)); + var x = assertThrows(IllegalArgumentException.class, () -> linker.downcallHandle(fd)); assertTrue(x.getMessage().contains("is non-empty and only has padding layouts")); } @@ -180,9 +186,8 @@ public void interwovenPadding() { var struct = MemoryLayout.structLayout(JAVA_BYTE, padding1, padding2, JAVA_INT); var fd = FunctionDescriptor.of(struct, struct, struct); - var e = expectThrows(IllegalArgumentException.class, () -> linker.downcallHandle(fd)); - assertEquals(e.getMessage(), - "The padding layout x2 was preceded by another padding layout x1 in " + struct); + var e = assertThrows(IllegalArgumentException.class, () -> linker.downcallHandle(fd)); + assertEquals( "The padding layout x2 was preceded by another padding layout x1 in " + struct, e.getMessage()); } @Test @@ -198,9 +203,8 @@ public void stackedPadding() { var union = MemoryLayout.unionLayout(struct32, padding32); var struct = MemoryLayout.structLayout(JAVA_BYTE, padding1, padding2, padding4, padding8, padding16, union); var fd = FunctionDescriptor.of(struct, struct, struct); - var e = expectThrows(IllegalArgumentException.class, () -> linker.downcallHandle(fd)); - assertEquals(e.getMessage(), - "The padding layout x2 was preceded by another padding layout x1 in " + struct); + var e = assertThrows(IllegalArgumentException.class, () -> linker.downcallHandle(fd)); + assertEquals( "The padding layout x2 was preceded by another padding layout x1 in " + struct, e.getMessage()); } @Test @@ -208,8 +212,8 @@ public void paddingUnionByteSize3() { Linker linker = Linker.nativeLinker(); var union = MemoryLayout.unionLayout(MemoryLayout.paddingLayout(3), ValueLayout.JAVA_INT); var fd = FunctionDescriptor.of(union, union, union); - var e = expectThrows(IllegalArgumentException.class, () -> linker.downcallHandle(fd)); - assertEquals(e.getMessage(), "Superfluous padding x3 in " + union); + var e = assertThrows(IllegalArgumentException.class, () -> linker.downcallHandle(fd)); + assertEquals("Superfluous padding x3 in " + union, e.getMessage()); } @Test @@ -217,8 +221,8 @@ public void paddingUnionByteSize4() { Linker linker = Linker.nativeLinker(); var union = MemoryLayout.unionLayout(MemoryLayout.paddingLayout(4), ValueLayout.JAVA_INT); var fd = FunctionDescriptor.of(union, union, union); - var e = expectThrows(IllegalArgumentException.class, () -> linker.downcallHandle(fd)); - assertEquals(e.getMessage(), "Superfluous padding x4 in " + union); + var e = assertThrows(IllegalArgumentException.class, () -> linker.downcallHandle(fd)); + assertEquals("Superfluous padding x4 in " + union, e.getMessage()); } @Test @@ -226,8 +230,8 @@ public void paddingUnionByteSize5() { Linker linker = Linker.nativeLinker(); var union = MemoryLayout.unionLayout(MemoryLayout.paddingLayout(5), ValueLayout.JAVA_INT); var fd = FunctionDescriptor.of(union, union, union); - var e = expectThrows(IllegalArgumentException.class, () -> linker.downcallHandle(fd)); - assertEquals(e.getMessage(), "Layout '" + union + "' has unexpected size: 5 != 4"); + var e = assertThrows(IllegalArgumentException.class, () -> linker.downcallHandle(fd)); + assertEquals("Layout '" + union + "' has unexpected size: 5 != 4", e.getMessage()); } @Test @@ -239,8 +243,8 @@ public void paddingUnionSeveral() { MemoryLayout.paddingLayout(16), MemoryLayout.paddingLayout(16)); var fd = FunctionDescriptor.of(union, union, union); - var e = expectThrows(IllegalArgumentException.class, () -> linker.downcallHandle(fd)); - assertEquals(e.getMessage(), "More than one padding in " + union); + var e = assertThrows(IllegalArgumentException.class, () -> linker.downcallHandle(fd)); + assertEquals("More than one padding in " + union, e.getMessage()); } @Test @@ -253,14 +257,13 @@ public void sequenceOfZeroElements() { var fd = FunctionDescriptor.of(struct8a8, struct8a8, struct8a8); if (linker.getClass().equals(FallbackLinker.class)) { // The fallback linker does not support empty layouts (FFI_BAD_TYPEDEF) - var iae = expectThrows(IllegalArgumentException.class, () -> linker.downcallHandle(fd)); + var iae = assertThrows(IllegalArgumentException.class, () -> linker.downcallHandle(fd)); assertTrue(iae.getMessage().contains("is empty")); } else { linker.downcallHandle(fd); } } - @DataProvider public static Object[][] canonicalTypeNames() { return new Object[][]{ { "bool" }, @@ -277,8 +280,10 @@ public static Object[][] canonicalTypeNames() { }; } - @Test(expectedExceptions=UnsupportedOperationException.class) + @Test public void testCanonicalLayoutsUnmodifiable() { - LINKER.canonicalLayouts().put("asdf", C_INT); + assertThrows(UnsupportedOperationException.class, () -> { + LINKER.canonicalLayouts().put("asdf", C_INT); + }); } } diff --git a/test/jdk/java/foreign/TestMappedHandshake.java b/test/jdk/java/foreign/TestMappedHandshake.java index 46fb4fb45fb9d..a291c502a87a1 100644 --- a/test/jdk/java/foreign/TestMappedHandshake.java +++ b/test/jdk/java/foreign/TestMappedHandshake.java @@ -26,10 +26,10 @@ * @requires vm.flavor != "zero" * @modules java.base/jdk.internal.vm.annotation java.base/jdk.internal.misc * @key randomness - * @run testng/othervm TestMappedHandshake - * @run testng/othervm -Xint TestMappedHandshake - * @run testng/othervm -XX:TieredStopAtLevel=1 TestMappedHandshake - * @run testng/othervm -XX:-TieredCompilation TestMappedHandshake + * @run junit/othervm TestMappedHandshake + * @run junit/othervm -Xint TestMappedHandshake + * @run junit/othervm -XX:TieredStopAtLevel=1 TestMappedHandshake + * @run junit/othervm -XX:-TieredCompilation TestMappedHandshake */ import java.io.File; @@ -44,9 +44,8 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import org.testng.annotations.Test; - -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class TestMappedHandshake { diff --git a/test/jdk/java/foreign/TestMatrix.java b/test/jdk/java/foreign/TestMatrix.java index 4b2885da7ce06..1801a1557ccf7 100644 --- a/test/jdk/java/foreign/TestMatrix.java +++ b/test/jdk/java/foreign/TestMatrix.java @@ -35,7 +35,7 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestUpcallHighArity * - * @run testng/othervm/native/manual + * @run junit/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=false * -Djdk.internal.foreign.UpcallLinker.USE_SPEC=false @@ -46,7 +46,7 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestUpcallHighArity * - * @run testng/othervm/native/manual + * @run junit/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=true * -Djdk.internal.foreign.UpcallLinker.USE_SPEC=false @@ -57,7 +57,7 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestUpcallHighArity * - * @run testng/othervm/native/manual + * @run junit/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=false * -Djdk.internal.foreign.UpcallLinker.USE_SPEC=true @@ -68,7 +68,7 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestUpcallHighArity * - * @run testng/othervm/native/manual + * @run junit/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=true * -Djdk.internal.foreign.UpcallLinker.USE_SPEC=true @@ -79,7 +79,7 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestDowncallBase * - * @run testng/othervm/native/manual + * @run junit/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=false * TestDowncallScope @@ -89,7 +89,7 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestDowncallBase * - * @run testng/othervm/native/manual + * @run junit/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=true * TestDowncallScope @@ -99,7 +99,7 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestDowncallBase * - * @run testng/othervm/native/manual + * @run junit/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=false * TestDowncallStack @@ -109,7 +109,7 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestDowncallBase * - * @run testng/othervm/native/manual + * @run junit/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=true * TestDowncallStack @@ -119,7 +119,7 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestUpcallBase * - * @run testng/othervm/native/manual + * @run junit/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=false * -Djdk.internal.foreign.UpcallLinker.USE_SPEC=false @@ -130,7 +130,7 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestUpcallBase * - * @run testng/othervm/native/manual + * @run junit/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=true * -Djdk.internal.foreign.UpcallLinker.USE_SPEC=false @@ -141,7 +141,7 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestUpcallBase * - * @run testng/othervm/native/manual + * @run junit/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=false * -Djdk.internal.foreign.UpcallLinker.USE_SPEC=true @@ -152,7 +152,7 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestUpcallBase * - * @run testng/othervm/native/manual + * @run junit/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=true * -Djdk.internal.foreign.UpcallLinker.USE_SPEC=true @@ -163,7 +163,7 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestUpcallBase * - * @run testng/othervm/native/manual + * @run junit/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=false * -Djdk.internal.foreign.UpcallLinker.USE_SPEC=false @@ -174,7 +174,7 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestUpcallBase * - * @run testng/othervm/native/manual + * @run junit/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=true * -Djdk.internal.foreign.UpcallLinker.USE_SPEC=false @@ -185,7 +185,7 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestUpcallBase * - * @run testng/othervm/native/manual + * @run junit/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=false * -Djdk.internal.foreign.UpcallLinker.USE_SPEC=true @@ -196,7 +196,7 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestUpcallBase * - * @run testng/othervm/native/manual + * @run junit/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=true * -Djdk.internal.foreign.UpcallLinker.USE_SPEC=true @@ -207,7 +207,7 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestUpcallBase * - * @run testng/othervm/native/manual + * @run junit/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=false * -Djdk.internal.foreign.UpcallLinker.USE_SPEC=false @@ -218,7 +218,7 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestUpcallBase * - * @run testng/othervm/native/manual + * @run junit/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=true * -Djdk.internal.foreign.UpcallLinker.USE_SPEC=false @@ -229,7 +229,7 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestUpcallBase * - * @run testng/othervm/native/manual + * @run junit/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=false * -Djdk.internal.foreign.UpcallLinker.USE_SPEC=true @@ -240,7 +240,7 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestUpcallBase * - * @run testng/othervm/native/manual + * @run junit/othervm/native/manual * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=true * -Djdk.internal.foreign.UpcallLinker.USE_SPEC=true @@ -252,7 +252,7 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper * - * @run testng/othervm/native/manual + * @run junit/othervm/native/manual * --enable-native-access=ALL-UNNAMED * TestVarArgs */ diff --git a/test/jdk/java/foreign/TestMemoryAccess.java b/test/jdk/java/foreign/TestMemoryAccess.java index ded9be1c085d2..f693d4340a604 100644 --- a/test/jdk/java/foreign/TestMemoryAccess.java +++ b/test/jdk/java/foreign/TestMemoryAccess.java @@ -23,10 +23,10 @@ /* * @test - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false -Xverify:all TestMemoryAccess - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true -Xverify:all TestMemoryAccess - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false -Xverify:all TestMemoryAccess - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true -Xverify:all TestMemoryAccess + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false -Xverify:all TestMemoryAccess + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true -Xverify:all TestMemoryAccess + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false -Xverify:all TestMemoryAccess + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true -Xverify:all TestMemoryAccess */ import java.lang.foreign.*; @@ -36,42 +36,51 @@ import java.nio.ByteOrder; import java.util.function.Function; -import org.testng.annotations.*; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestMemoryAccess { - @Test(dataProvider = "elements") + @ParameterizedTest + @MethodSource("createData") public void testAccess(Function viewFactory, ValueLayout elemLayout, Checker checker) { ValueLayout layout = elemLayout.withName("elem"); testAccessInternal(viewFactory, layout, layout.varHandle(), checker); } - @Test(dataProvider = "elements") + @ParameterizedTest + @MethodSource("createData") public void testPaddedAccessByName(Function viewFactory, MemoryLayout elemLayout, Checker checker) { GroupLayout layout = MemoryLayout.structLayout(MemoryLayout.paddingLayout(elemLayout.byteSize()), elemLayout.withName("elem")); testAccessInternal(viewFactory, layout, layout.varHandle(PathElement.groupElement("elem")), checker); } - @Test(dataProvider = "elements") + @ParameterizedTest + @MethodSource("createData") public void testPaddedAccessByIndexSeq(Function viewFactory, MemoryLayout elemLayout, Checker checker) { SequenceLayout layout = MemoryLayout.sequenceLayout(2, elemLayout); testAccessInternal(viewFactory, layout, layout.varHandle(PathElement.sequenceElement(1)), checker); } - @Test(dataProvider = "arrayElements") + @ParameterizedTest + @MethodSource("createArrayData") public void testArrayAccess(Function viewFactory, MemoryLayout elemLayout, ArrayChecker checker) { SequenceLayout seq = MemoryLayout.sequenceLayout(10, elemLayout.withName("elem")); testArrayAccessInternal(viewFactory, seq, seq.varHandle(PathElement.sequenceElement()), checker); } - @Test(dataProvider = "arrayElements") + @ParameterizedTest + @MethodSource("createArrayData") public void testPaddedArrayAccessByName(Function viewFactory, MemoryLayout elemLayout, ArrayChecker checker) { SequenceLayout seq = MemoryLayout.sequenceLayout(10, MemoryLayout.structLayout(MemoryLayout.paddingLayout(elemLayout.byteSize()), elemLayout.withName("elem"))); testArrayAccessInternal(viewFactory, seq, seq.varHandle(MemoryLayout.PathElement.sequenceElement(), MemoryLayout.PathElement.groupElement("elem")), checker); } - @Test(dataProvider = "arrayElements") + @ParameterizedTest + @MethodSource("createArrayData") public void testPaddedArrayAccessByIndexSeq(Function viewFactory, MemoryLayout elemLayout, ArrayChecker checker) { SequenceLayout seq = MemoryLayout.sequenceLayout(10, MemoryLayout.sequenceLayout(2, elemLayout)); testArrayAccessInternal(viewFactory, seq, seq.varHandle(PathElement.sequenceElement(), MemoryLayout.PathElement.sequenceElement(1)), checker); @@ -143,7 +152,8 @@ private void testArrayAccessInternal(Function view } } - @Test(dataProvider = "matrixElements") + @ParameterizedTest + @MethodSource("createMatrixData") public void testMatrixAccess(Function viewFactory, MemoryLayout elemLayout, MatrixChecker checker) { SequenceLayout seq = MemoryLayout.sequenceLayout(20, MemoryLayout.sequenceLayout(10, elemLayout.withName("elem"))); @@ -151,7 +161,8 @@ public void testMatrixAccess(Function viewFactory, PathElement.sequenceElement(), PathElement.sequenceElement()), checker); } - @Test(dataProvider = "matrixElements") + @ParameterizedTest + @MethodSource("createMatrixData") public void testPaddedMatrixAccessByName(Function viewFactory, MemoryLayout elemLayout, MatrixChecker checker) { SequenceLayout seq = MemoryLayout.sequenceLayout(20, MemoryLayout.sequenceLayout(10, MemoryLayout.structLayout(MemoryLayout.paddingLayout(elemLayout.byteSize()), elemLayout.withName("elem")))); @@ -161,7 +172,8 @@ public void testPaddedMatrixAccessByName(Function checker); } - @Test(dataProvider = "matrixElements") + @ParameterizedTest + @MethodSource("createMatrixData") public void testPaddedMatrixAccessByIndexSeq(Function viewFactory, MemoryLayout elemLayout, MatrixChecker checker) { SequenceLayout seq = MemoryLayout.sequenceLayout(20, MemoryLayout.sequenceLayout(10, MemoryLayout.sequenceLayout(2, elemLayout))); @@ -211,7 +223,6 @@ private void testMatrixAccessInternal(Function vie static Function ID = Function.identity(); static Function IMMUTABLE = MemorySegment::asReadOnly; - @DataProvider(name = "elements") public Object[][] createData() { return new Object[][] { //BE, RW @@ -288,7 +299,6 @@ interface Checker { }; } - @DataProvider(name = "arrayElements") public Object[][] createArrayData() { return new Object[][] { //BE, RW @@ -331,41 +341,40 @@ interface ArrayChecker { ArrayChecker BYTE = (handle, segment, i) -> { handle.set(segment, 0L, i, (byte)i); - assertEquals(i, (byte)handle.get(segment, 0L, i)); + assertEquals((byte)handle.get(segment, 0L, i), i); }; ArrayChecker SHORT = (handle, segment, i) -> { handle.set(segment, 0L, i, (short)i); - assertEquals(i, (short)handle.get(segment, 0L, i)); + assertEquals((short)handle.get(segment, 0L, i), i); }; ArrayChecker CHAR = (handle, segment, i) -> { handle.set(segment, 0L, i, (char)i); - assertEquals(i, (char)handle.get(segment, 0L, i)); + assertEquals((char)handle.get(segment, 0L, i), i); }; ArrayChecker INT = (handle, segment, i) -> { handle.set(segment, 0L, i, (int)i); - assertEquals(i, (int)handle.get(segment, 0L, i)); + assertEquals((int)handle.get(segment, 0L, i), i); }; ArrayChecker LONG = (handle, segment, i) -> { handle.set(segment, 0L, i, (long)i); - assertEquals(i, (long)handle.get(segment, 0L, i)); + assertEquals((long)handle.get(segment, 0L, i), i); }; ArrayChecker FLOAT = (handle, segment, i) -> { handle.set(segment, 0L, i, (float)i); - assertEquals((float)i, (float)handle.get(segment, 0L, i)); + assertEquals((float)handle.get(segment, 0L, i), (float)i); }; ArrayChecker DOUBLE = (handle, segment, i) -> { handle.set(segment, 0L, i, (double)i); - assertEquals((double)i, (double)handle.get(segment, 0L, i)); + assertEquals((double)handle.get(segment, 0L, i), (double)i); }; } - @DataProvider(name = "matrixElements") public Object[][] createMatrixData() { return new Object[][] { //BE, RW @@ -416,47 +425,47 @@ interface MatrixChecker { MatrixChecker BYTE = (handle, segment, r, c) -> { handle.set(segment, 0L, r, c, (byte)(r + c)); - assertEquals(r + c, (byte)handle.get(segment, 0L, r, c)); + assertEquals((byte)handle.get(segment, 0L, r, c), r + c); }; MatrixChecker BOOLEAN = (handle, segment, r, c) -> { handle.set(segment, 0L, r, c, (r + c) != 0); - assertEquals((r + c) != 0, (boolean)handle.get(segment, 0L, r, c)); + assertEquals((boolean)handle.get(segment, 0L, r, c), (r + c) != 0); }; MatrixChecker SHORT = (handle, segment, r, c) -> { handle.set(segment, 0L, r, c, (short)(r + c)); - assertEquals(r + c, (short)handle.get(segment, 0L, r, c)); + assertEquals((short)handle.get(segment, 0L, r, c), r + c); }; MatrixChecker CHAR = (handle, segment, r, c) -> { handle.set(segment, 0L, r, c, (char)(r + c)); - assertEquals(r + c, (char)handle.get(segment, 0L, r, c)); + assertEquals((char)handle.get(segment, 0L, r, c), r + c); }; MatrixChecker INT = (handle, segment, r, c) -> { handle.set(segment, 0L, r, c, (int)(r + c)); - assertEquals(r + c, (int)handle.get(segment, 0L, r, c)); + assertEquals((int)handle.get(segment, 0L, r, c), r + c); }; MatrixChecker LONG = (handle, segment, r, c) -> { handle.set(segment, 0L, r, c, r + c); - assertEquals(r + c, (long)handle.get(segment, 0L, r, c)); + assertEquals((long)handle.get(segment, 0L, r, c), r + c); }; MatrixChecker ADDR = (handle, segment, r, c) -> { handle.set(segment, 0L, r, c, MemorySegment.ofAddress(r + c)); - assertEquals(MemorySegment.ofAddress(r + c), (MemorySegment) handle.get(segment, 0L, r, c)); + assertEquals((MemorySegment) handle.get(segment, 0L, r, c), MemorySegment.ofAddress(r + c)); }; MatrixChecker FLOAT = (handle, segment, r, c) -> { handle.set(segment, 0L, r, c, (float)(r + c)); - assertEquals((float)(r + c), (float)handle.get(segment, 0L, r, c)); + assertEquals((float)handle.get(segment, 0L, r, c), (float)(r + c)); }; MatrixChecker DOUBLE = (handle, segment, r, c) -> { handle.set(segment, 0L, r, c, (double)(r + c)); - assertEquals((double)(r + c), (double)handle.get(segment, 0L, r, c)); + assertEquals((double)handle.get(segment, 0L, r, c), (double)(r + c)); }; } } diff --git a/test/jdk/java/foreign/TestMemoryAccessInstance.java b/test/jdk/java/foreign/TestMemoryAccessInstance.java index de1a17f5f1135..bf80cc306c611 100644 --- a/test/jdk/java/foreign/TestMemoryAccessInstance.java +++ b/test/jdk/java/foreign/TestMemoryAccessInstance.java @@ -23,8 +23,8 @@ /* * @test - * @run testng/othervm --enable-native-access=ALL-UNNAMED TestMemoryAccessInstance - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_SEGMENT_FORCE_EXACT=true --enable-native-access=ALL-UNNAMED TestMemoryAccessInstance + * @run junit/othervm --enable-native-access=ALL-UNNAMED TestMemoryAccessInstance + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_SEGMENT_FORCE_EXACT=true --enable-native-access=ALL-UNNAMED TestMemoryAccessInstance */ import java.lang.foreign.MemorySegment; @@ -33,10 +33,14 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; -import org.testng.annotations.*; -import org.testng.SkipException; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestMemoryAccessInstance { static class Accessor { @@ -80,9 +84,9 @@ void test() { MemorySegment segment = arena.allocate(128, 1); ByteBuffer buffer = segment.asByteBuffer(); segmentSetter.set(segment, layout, 8, value); - assertEquals(bufferGetter.get(buffer, 8), value); + assertEquals(value, bufferGetter.get(buffer, 8)); bufferSetter.set(buffer, 8, value); - assertEquals(value, segmentGetter.get(segment, layout, 8)); + assertEquals(segmentGetter.get(segment, layout, 8), value); } } @@ -121,41 +125,43 @@ static Accessor of(L layout, X value, } } - @Test(dataProvider = "segmentAccessors") + @ParameterizedTest + @MethodSource("segmentAccessors") public void testSegmentAccess(String testName, Accessor accessor) { accessor.test(); } - @Test(dataProvider = "segmentAccessors") + @ParameterizedTest + @MethodSource("segmentAccessors") public void testSegmentAccessHyper(String testName, Accessor accessor) { - if (testName.contains("index")) { - accessor.testHyperAligned(); - } else { - throw new SkipException("Skipping"); - } + Assumptions.assumeTrue(testName.contains("index"), "Skipping"); + accessor.testHyperAligned(); } - @Test(expectedExceptions = IllegalArgumentException.class, - expectedExceptionsMessageRegExp = ".*Heap segment not allowed.*") + @Test public void badHeapSegmentSet() { long byteSize = ValueLayout.ADDRESS.byteSize(); Arena scope = Arena.ofAuto(); MemorySegment targetSegment = scope.allocate(byteSize, 1); MemorySegment segment = MemorySegment.ofArray(new byte[]{ 0, 1, 2 }); - targetSegment.set(ValueLayout.ADDRESS, 0, segment); // should throw + assertThrows(IllegalArgumentException.class, () -> { + targetSegment.set(ValueLayout.ADDRESS, 0, segment); + }); } - @Test(expectedExceptions = IllegalArgumentException.class, - expectedExceptionsMessageRegExp = ".*Heap segment not allowed.*") + @Test public void badHeapSegmentSetAtIndex() { long byteSize = ValueLayout.ADDRESS.byteSize(); Arena scope = Arena.ofAuto(); MemorySegment targetSegment = scope.allocate(byteSize, 1); MemorySegment segment = MemorySegment.ofArray(new byte[]{ 0, 1, 2 }); - targetSegment.setAtIndex(ValueLayout.ADDRESS, 0, segment); // should throw + assertThrows(IllegalArgumentException.class, () -> { + targetSegment.setAtIndex(ValueLayout.ADDRESS, 0, segment); + }); } - @Test(dataProvider = "segmentAccessors") + @ParameterizedTest + @MethodSource("segmentAccessors") public void badAccessOverflowInIndexedAccess(String testName, Accessor accessor) { MemorySegment segment = MemorySegment.ofArray(new byte[100]); if (testName.contains("/index") && accessor.layout.byteSize() > 1) { @@ -164,7 +170,8 @@ public void badAccessOverflowInIndexedAccess(String t } } - @Test(dataProvider = "segmentAccessors") + @ParameterizedTest + @MethodSource("segmentAccessors") public void negativeOffset(String testName, Accessor accessor) { MemorySegment segment = MemorySegment.ofArray(new byte[100]); assertThrows(IndexOutOfBoundsException.class, () -> accessor.get(segment, -ValueLayout.JAVA_LONG.byteSize())); @@ -173,7 +180,6 @@ public void negativeOffset(String testName, Accessor< static final ByteOrder NE = ByteOrder.nativeOrder(); - @DataProvider(name = "segmentAccessors") static Object[][] segmentAccessors() { return new Object[][]{ diff --git a/test/jdk/java/foreign/TestMemoryAlignment.java b/test/jdk/java/foreign/TestMemoryAlignment.java index 19f9f576ab2e2..4af819f4b1ff9 100644 --- a/test/jdk/java/foreign/TestMemoryAlignment.java +++ b/test/jdk/java/foreign/TestMemoryAlignment.java @@ -23,7 +23,7 @@ /* * @test - * @run testng TestMemoryAlignment + * @run junit TestMemoryAlignment */ import java.io.File; @@ -46,18 +46,23 @@ import java.util.stream.LongStream; import java.util.stream.Stream; -import org.testng.annotations.*; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestMemoryAlignment { - @Test(dataProvider = "alignments") + @ParameterizedTest + @MethodSource("createAlignments") public void testAlignedAccess(long align) { ValueLayout layout = ValueLayout.JAVA_INT .withOrder(ByteOrder.BIG_ENDIAN); - assertEquals(layout.byteAlignment(), 4); + assertEquals(4, layout.byteAlignment()); ValueLayout aligned = layout.withByteAlignment(align); - assertEquals(aligned.byteAlignment(), align); //unreasonable alignment here, to make sure access throws + assertEquals(align, aligned.byteAlignment()); //unreasonable alignment here, to make sure access throws VarHandle vh = aligned.varHandle(); try (Arena arena = Arena.ofConfined()) { MemorySegment segment = arena.allocate(aligned); @@ -69,24 +74,26 @@ public void testAlignedAccess(long align) { vh.set(nextSegment, 0L, 0xffffff); int val = (int)vh.get(segment, 0L); - assertEquals(val, -42); + assertEquals(-42, val); } } - @Test(dataProvider = "alignments") + @ParameterizedTest + @MethodSource("createAlignments") public void testUnalignedPath(long align) { MemoryLayout layout = ValueLayout.JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN); MemoryLayout aligned = layout.withByteAlignment(align).withName("value"); try { GroupLayout alignedGroup = MemoryLayout.structLayout(MemoryLayout.paddingLayout(1), aligned); alignedGroup.varHandle(PathElement.groupElement("value")); - assertEquals(align, 1); //this is the only case where path is aligned + assertEquals(1, align); //this is the only case where path is aligned } catch (IllegalArgumentException ex) { - assertNotEquals(align, 1); //if align != 8, path is always unaligned + assertNotEquals(1, align); //if align != 8, path is always unaligned } } - @Test(dataProvider = "alignments") + @ParameterizedTest + @MethodSource("createAlignments") public void testUnalignedSequence(long align) { try { SequenceLayout layout = MemoryLayout.sequenceLayout(5, ValueLayout.JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN).withByteAlignment(align)); @@ -111,22 +118,23 @@ public void testPackedAccess() { GroupLayout g = MemoryLayout.structLayout(vChar.withByteAlignment(1).withName("a"), vShort.withByteAlignment(1).withName("b"), vInt.withByteAlignment(1).withName("c")); - assertEquals(g.byteAlignment(), 1); + assertEquals(1, g.byteAlignment()); VarHandle vh_c = g.varHandle(PathElement.groupElement("a")); VarHandle vh_s = g.varHandle(PathElement.groupElement("b")); VarHandle vh_i = g.varHandle(PathElement.groupElement("c")); try (Arena arena = Arena.ofConfined()) { MemorySegment segment = arena.allocate(g);; vh_c.set(segment, 0L, Byte.MIN_VALUE); - assertEquals(vh_c.get(segment, 0L), Byte.MIN_VALUE); + assertEquals(Byte.MIN_VALUE, vh_c.get(segment, 0L)); vh_s.set(segment, 0L, Short.MIN_VALUE); - assertEquals(vh_s.get(segment, 0L), Short.MIN_VALUE); + assertEquals(Short.MIN_VALUE, vh_s.get(segment, 0L)); vh_i.set(segment, 0L, Integer.MIN_VALUE); - assertEquals(vh_i.get(segment, 0L), Integer.MIN_VALUE); + assertEquals(Integer.MIN_VALUE, vh_i.get(segment, 0L)); } } - @Test(dataProvider = "alignments") + @ParameterizedTest + @MethodSource("createAlignments") public void testActualByteAlignment(long align) { if (align > (1L << 10)) { return; @@ -135,8 +143,8 @@ public void testActualByteAlignment(long align) { var segment = arena.allocate(4, align); assertTrue(segment.maxByteAlignment() >= align); // Power of two? - assertEquals(Long.bitCount(segment.maxByteAlignment()), 1); - assertEquals(segment.asSlice(1).maxByteAlignment(), 1); + assertEquals(1, Long.bitCount(segment.maxByteAlignment())); + assertEquals(1, segment.asSlice(1).maxByteAlignment()); } } @@ -149,8 +157,8 @@ public void testActualByteAlignmentMappedSegment() throws IOException { // be positive. assertTrue(segment.maxByteAlignment() >= Byte.BYTES); // Power of two? - assertEquals(Long.bitCount(segment.maxByteAlignment()), 1); - assertEquals(segment.asSlice(1).maxByteAlignment(), 1); + assertEquals(1, Long.bitCount(segment.maxByteAlignment())); + assertEquals(1, segment.asSlice(1).maxByteAlignment()); } finally { tmp.delete(); } @@ -159,25 +167,24 @@ public void testActualByteAlignmentMappedSegment() throws IOException { @Test() public void testActualByteAlignmentNull() { long alignment = MemorySegment.NULL.maxByteAlignment(); - assertEquals(1L << 62, alignment); + assertEquals(alignment, 1L << 62); } - @Test(dataProvider = "heapSegments") + @ParameterizedTest + @MethodSource("heapSegments") public void testActualByteAlignmentHeap(MemorySegment segment, int bytes) { - assertEquals(segment.maxByteAlignment(), bytes); + assertEquals(bytes, segment.maxByteAlignment()); // A slice at offset 1 should always have an alignment of 1 var segmentSlice = segment.asSlice(1); - assertEquals(segmentSlice.maxByteAlignment(), 1); + assertEquals(1, segmentSlice.maxByteAlignment()); } - @DataProvider(name = "alignments") public Object[][] createAlignments() { return LongStream.range(1, 20) .mapToObj(v -> new Object[] { 1L << v }) .toArray(Object[][]::new); } - @DataProvider(name = "heapSegments") public Object[][] heapSegments() { return Stream.of( new Object[]{MemorySegment.ofArray(new byte[]{1}), Byte.BYTES}, diff --git a/test/jdk/java/foreign/TestMemoryDereference.java b/test/jdk/java/foreign/TestMemoryDereference.java index 4680b148b6551..c4a148a8d9281 100644 --- a/test/jdk/java/foreign/TestMemoryDereference.java +++ b/test/jdk/java/foreign/TestMemoryDereference.java @@ -23,7 +23,7 @@ /* * @test - * @run testng TestMemoryDereference + * @run junit TestMemoryDereference */ import java.lang.foreign.MemorySegment; @@ -32,11 +32,15 @@ import java.nio.ByteOrder; import java.lang.foreign.ValueLayout; -import org.testng.annotations.*; import static java.lang.foreign.ValueLayout.*; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestMemoryDereference { static class Accessor { @@ -77,9 +81,9 @@ void test() { MemorySegment segment = MemorySegment.ofArray(new byte[32]); ByteBuffer buffer = segment.asByteBuffer(); segmentSetter.set(segment, value); - assertEquals(bufferGetter.get(buffer), value); + assertEquals(value, bufferGetter.get(buffer)); bufferSetter.set(buffer, value); - assertEquals(value, segmentGetter.get(segment)); + assertEquals(segmentGetter.get(segment), value); } Accessor of(Z value, @@ -89,7 +93,8 @@ Accessor of(Z value, } } - @Test(dataProvider = "accessors") + @ParameterizedTest + @MethodSource("accessors") public void testMemoryAccess(String testName, Accessor accessor) { accessor.test(); } @@ -98,7 +103,6 @@ public void testMemoryAccess(String testName, Accessor accessor) { static final ByteOrder LE = ByteOrder.LITTLE_ENDIAN; static final ByteOrder NE = ByteOrder.nativeOrder(); - @DataProvider(name = "accessors") static Object[][] accessors() { return new Object[][]{ diff --git a/test/jdk/java/foreign/TestMemorySession.java b/test/jdk/java/foreign/TestMemorySession.java index b06e2707c399d..1548791b7cc81 100644 --- a/test/jdk/java/foreign/TestMemorySession.java +++ b/test/jdk/java/foreign/TestMemorySession.java @@ -24,7 +24,7 @@ /* * @test * @modules java.base/jdk.internal.foreign - * @run testng/othervm TestMemorySession + * @run junit/othervm TestMemorySession */ import java.lang.foreign.Arena; @@ -36,11 +36,14 @@ import java.util.function.Supplier; import java.util.stream.IntStream; import jdk.internal.foreign.MemorySessionImpl; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestMemorySession { final static int N_THREADS = 100; @@ -53,13 +56,14 @@ public void testConfined() { int delta = i; addCloseAction(arena, () -> acc.addAndGet(delta)); } - assertEquals(acc.get(), 0); + assertEquals(0, acc.get()); arena.close(); - assertEquals(acc.get(), IntStream.range(0, N_THREADS).sum()); + assertEquals(IntStream.range(0, N_THREADS).sum(), acc.get()); } - @Test(dataProvider = "sharedSessions") + @ParameterizedTest + @MethodSource("sharedSessions") public void testSharedSingleThread(ArenaSupplier arenaSupplier) { AtomicInteger acc = new AtomicInteger(); Arena session = arenaSupplier.get(); @@ -67,11 +71,11 @@ public void testSharedSingleThread(ArenaSupplier arenaSupplier) { int delta = i; addCloseAction(session, () -> acc.addAndGet(delta)); } - assertEquals(acc.get(), 0); + assertEquals(0, acc.get()); if (!TestMemorySession.ArenaSupplier.isImplicit(session)) { TestMemorySession.ArenaSupplier.close(session); - assertEquals(acc.get(), IntStream.range(0, N_THREADS).sum()); + assertEquals(IntStream.range(0, N_THREADS).sum(), acc.get()); } else { session = null; int expected = IntStream.range(0, N_THREADS).sum(); @@ -81,7 +85,8 @@ public void testSharedSingleThread(ArenaSupplier arenaSupplier) { } } - @Test(dataProvider = "sharedSessions") + @ParameterizedTest + @MethodSource("sharedSessions") public void testSharedMultiThread(ArenaSupplier arenaSupplier) { AtomicInteger acc = new AtomicInteger(); List threads = new ArrayList<>(); @@ -101,7 +106,7 @@ public void testSharedMultiThread(ArenaSupplier arenaSupplier) { }); threads.add(thread); } - assertEquals(acc.get(), 0); + assertEquals(0, acc.get()); threads.forEach(Thread::start); // if no cleaner, close - not all segments might have been added to the session! @@ -126,7 +131,7 @@ public void testSharedMultiThread(ArenaSupplier arenaSupplier) { }); if (!TestMemorySession.ArenaSupplier.isImplicit(session)) { - assertEquals(acc.get(), IntStream.range(0, N_THREADS).sum()); + assertEquals(IntStream.range(0, N_THREADS).sum(), acc.get()); } else { session = null; sessionRef.set(null); @@ -150,7 +155,7 @@ public void testLockSingleThread() { while (true) { try { arena.close(); - assertEquals(handles.size(), 0); + assertEquals(0, handles.size()); break; } catch (IllegalStateException ex) { assertTrue(handles.size() > 0); @@ -180,7 +185,7 @@ public void testLockSharedMultiThread() { while (true) { try { arena.close(); - assertEquals(lockCount.get(), 0); + assertEquals(0, lockCount.get()); break; } catch (IllegalStateException ex) { waitSomeTime(); @@ -215,13 +220,14 @@ public void testCloseConfinedLock() { try { t.join(); assertNotNull(failure.get()); - assertEquals(failure.get().getClass(), WrongThreadException.class); + assertEquals(WrongThreadException.class, failure.get().getClass()); } catch (Throwable ex) { throw new AssertionError(ex); } } - @Test(dataProvider = "allSessions") + @ParameterizedTest + @MethodSource("allSessions") public void testSessionAcquires(ArenaSupplier ArenaSupplier) { Arena session = ArenaSupplier.get(); acquireRecursive(session, 5); @@ -299,7 +305,8 @@ public void testConfinedSessionWithSharedDependency() { root.close(); } - @Test(dataProvider = "nonCloseableSessions") + @ParameterizedTest + @MethodSource("nonCloseableSessions") public void testNonCloseableSessions(ArenaSupplier arenaSupplier) { var arena = arenaSupplier.get(); var sessionImpl = ((MemorySessionImpl) arena.scope()); @@ -308,14 +315,15 @@ public void testNonCloseableSessions(ArenaSupplier arenaSupplier) { sessionImpl.close()); } - @Test(dataProvider = "allSessionsAndGlobal") + @ParameterizedTest + @MethodSource("allSessionsAndGlobal") public void testIsCloseableBy(ArenaSupplier arenaSupplier) { var arena = arenaSupplier.get(); var sessionImpl = ((MemorySessionImpl) arena.scope()); - assertEquals(sessionImpl.isCloseableBy(Thread.currentThread()), sessionImpl.isCloseable()); + assertEquals(sessionImpl.isCloseable(), sessionImpl.isCloseableBy(Thread.currentThread())); Thread otherThread = new Thread(); boolean isCloseableByOther = sessionImpl.isCloseable() && !"ConfinedSession".equals(sessionImpl.getClass().getSimpleName()); - assertEquals(sessionImpl.isCloseableBy(otherThread), isCloseableByOther); + assertEquals(isCloseableByOther, sessionImpl.isCloseableBy(otherThread)); } /** @@ -402,7 +410,6 @@ private void kickGC() { } } - @DataProvider static Object[][] drops() { return new Object[][] { { (Supplier) Arena::ofConfined}, @@ -444,7 +451,6 @@ static ArenaSupplier ofArena(Supplier arenaSupplier) { } } - @DataProvider(name = "sharedSessions") static Object[][] sharedSessions() { return new Object[][] { { ArenaSupplier.ofArena(Arena::ofShared) }, @@ -452,7 +458,6 @@ static Object[][] sharedSessions() { }; } - @DataProvider(name = "allSessions") static Object[][] allSessions() { return new Object[][] { { ArenaSupplier.ofArena(Arena::ofConfined) }, @@ -461,7 +466,6 @@ static Object[][] allSessions() { }; } - @DataProvider(name = "nonCloseableSessions") static Object[][] nonCloseableSessions() { return new Object[][] { { ArenaSupplier.ofGlobal() }, @@ -469,7 +473,6 @@ static Object[][] nonCloseableSessions() { }; } - @DataProvider(name = "allSessionsAndGlobal") static Object[][] allSessionsAndGlobal() { return new Object[][] { { ArenaSupplier.ofArena(Arena::ofConfined) }, diff --git a/test/jdk/java/foreign/TestMismatch.java b/test/jdk/java/foreign/TestMismatch.java index fa01f1553ebfd..217e857ec97be 100644 --- a/test/jdk/java/foreign/TestMismatch.java +++ b/test/jdk/java/foreign/TestMismatch.java @@ -24,7 +24,7 @@ /* * @test * @bug 8323552 - * @run testng/timeout=480 TestMismatch + * @run junit/timeout=480 TestMismatch */ import java.lang.foreign.Arena; @@ -39,12 +39,16 @@ import java.util.function.IntFunction; import java.util.stream.Stream; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import static java.lang.System.out; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestMismatch { // stores an increasing sequence of values into the memory of the given segment @@ -55,56 +59,76 @@ static MemorySegment initializeSegment(MemorySegment segment) { return segment; } - @Test(dataProvider = "slices", expectedExceptions = IndexOutOfBoundsException.class) + @ParameterizedTest + @MethodSource("slices") public void testNegativeSrcFromOffset(MemorySegment s1, MemorySegment s2) { - MemorySegment.mismatch(s1, -1, 0, s2, 0, 0); + assertThrows(IndexOutOfBoundsException.class, () -> { + MemorySegment.mismatch(s1, -1, 0, s2, 0, 0); + }); } - @Test(dataProvider = "slices", expectedExceptions = IndexOutOfBoundsException.class) + @ParameterizedTest + @MethodSource("slices") public void testNegativeDstFromOffset(MemorySegment s1, MemorySegment s2) { - MemorySegment.mismatch(s1, 0, 0, s2, -1, 0); + assertThrows(IndexOutOfBoundsException.class, () -> { + MemorySegment.mismatch(s1, 0, 0, s2, -1, 0); + }); } - @Test(dataProvider = "slices", expectedExceptions = IndexOutOfBoundsException.class) + @ParameterizedTest + @MethodSource("slices") public void testNegativeSrcToOffset(MemorySegment s1, MemorySegment s2) { - MemorySegment.mismatch(s1, 0, -1, s2, 0, 0); + assertThrows(IndexOutOfBoundsException.class, () -> { + MemorySegment.mismatch(s1, 0, -1, s2, 0, 0); + }); } - @Test(dataProvider = "slices", expectedExceptions = IndexOutOfBoundsException.class) + @ParameterizedTest + @MethodSource("slices") public void testNegativeDstToOffset(MemorySegment s1, MemorySegment s2) { - MemorySegment.mismatch(s1, 0, 0, s2, 0, -1); + assertThrows(IndexOutOfBoundsException.class, () -> { + MemorySegment.mismatch(s1, 0, 0, s2, 0, -1); + }); } - @Test(dataProvider = "slices", expectedExceptions = IndexOutOfBoundsException.class) + @ParameterizedTest + @MethodSource("slices") public void testNegativeSrcLength(MemorySegment s1, MemorySegment s2) { - MemorySegment.mismatch(s1, 3, 2, s2, 0, 0); + assertThrows(IndexOutOfBoundsException.class, () -> { + MemorySegment.mismatch(s1, 3, 2, s2, 0, 0); + }); } - @Test(dataProvider = "slices", expectedExceptions = IndexOutOfBoundsException.class) + @ParameterizedTest + @MethodSource("slices") public void testNegativeDstLength(MemorySegment s1, MemorySegment s2) { - MemorySegment.mismatch(s1, 0, 0, s2, 3, 2); + assertThrows(IndexOutOfBoundsException.class, () -> { + MemorySegment.mismatch(s1, 0, 0, s2, 3, 2); + }); } - @Test(dataProvider = "slices") + @ParameterizedTest + @MethodSource("slices") public void testSameValues(MemorySegment ss1, MemorySegment ss2) { out.format("testSameValues s1:%s, s2:%s\n", ss1, ss2); MemorySegment s1 = initializeSegment(ss1); MemorySegment s2 = initializeSegment(ss2); if (s1.byteSize() == s2.byteSize()) { - assertEquals(s1.mismatch(s2), -1); // identical - assertEquals(s2.mismatch(s1), -1); + assertEquals(-1, s1.mismatch(s2)); // identical + assertEquals(-1, s2.mismatch(s1)); } else if (s1.byteSize() > s2.byteSize()) { - assertEquals(s1.mismatch(s2), s2.byteSize()); // proper prefix - assertEquals(s2.mismatch(s1), s2.byteSize()); + assertEquals(s2.byteSize(), s1.mismatch(s2)); // proper prefix + assertEquals(s2.byteSize(), s2.mismatch(s1)); } else { assert s1.byteSize() < s2.byteSize(); - assertEquals(s1.mismatch(s2), s1.byteSize()); // proper prefix - assertEquals(s2.mismatch(s1), s1.byteSize()); + assertEquals(s1.byteSize(), s1.mismatch(s2)); // proper prefix + assertEquals(s1.byteSize(), s2.mismatch(s1)); } } - @Test(dataProvider = "slicesStatic") + @ParameterizedTest + @MethodSource("slicesStatic") public void testSameValuesStatic(SliceOffsetAndSize ss1, SliceOffsetAndSize ss2) { out.format("testSameValuesStatic s1:%s, s2:%s\n", ss1, ss2); MemorySegment s1 = initializeSegment(ss1.toSlice()); @@ -114,13 +138,13 @@ public void testSameValuesStatic(SliceOffsetAndSize ss1, SliceOffsetAndSize ss2) long bytes = i - ss2.offset; long expected = (bytes == ss1.size) ? -1 : Long.min(ss1.size, bytes); - assertEquals(MemorySegment.mismatch(ss1.segment, ss1.offset, ss1.endOffset(), ss2.segment, ss2.offset, i), expected); + assertEquals(expected, MemorySegment.mismatch(ss1.segment, ss1.offset, ss1.endOffset(), ss2.segment, ss2.offset, i)); } for (long i = ss1.offset ; i < ss1.size ; i++) { long bytes = i - ss1.offset; long expected = (bytes == ss2.size) ? -1 : Long.min(ss2.size, bytes); - assertEquals(MemorySegment.mismatch(ss2.segment, ss2.offset, ss2.endOffset(), ss1.segment, ss1.offset, i), expected); + assertEquals(expected, MemorySegment.mismatch(ss2.segment, ss2.offset, ss2.endOffset(), ss1.segment, ss1.offset, i)); } } @@ -160,21 +184,21 @@ public void random() { } // They are not equal and differs in position beginDiff - assertEquals(src.mismatch(dst), beginDiff); - assertEquals(dst.mismatch(src), beginDiff); + assertEquals(beginDiff, src.mismatch(dst)); + assertEquals(beginDiff, dst.mismatch(src)); } else { // In this branch, there is no injection if (src.byteSize() == dst.byteSize()) { // The content matches and they are of equal size - assertEquals(src.mismatch(dst), -1); - assertEquals(dst.mismatch(src), -1); + assertEquals(-1, src.mismatch(dst)); + assertEquals(-1, dst.mismatch(src)); } else { // The content matches but they are of different length // Remember, the size of src is always smaller or equal // to the size of dst. - assertEquals(src.mismatch(dst), src.byteSize()); - assertEquals(dst.mismatch(src), src.byteSize()); + assertEquals(src.byteSize(), src.mismatch(dst)); + assertEquals(src.byteSize(), dst.mismatch(src)); } } } @@ -186,7 +210,8 @@ static byte randomByte(Random rnd) { return (byte) rnd.nextInt(Byte.MIN_VALUE, Byte.MAX_VALUE + 1); } - @Test(dataProvider = "slices") + @ParameterizedTest + @MethodSource("slices") public void testDifferentValues(MemorySegment s1, MemorySegment s2) { out.format("testDifferentValues s1:%s, s2:%s\n", s1, s2); s1 = initializeSegment(s1); @@ -197,21 +222,22 @@ public void testDifferentValues(MemorySegment s1, MemorySegment s2) { s2.set(ValueLayout.JAVA_BYTE, i, (byte) 0xFF); if (s1.byteSize() == s2.byteSize()) { - assertEquals(s1.mismatch(s2), expectedMismatchOffset); - assertEquals(s2.mismatch(s1), expectedMismatchOffset); + assertEquals(expectedMismatchOffset, s1.mismatch(s2)); + assertEquals(expectedMismatchOffset, s2.mismatch(s1)); } else if (s1.byteSize() > s2.byteSize()) { - assertEquals(s1.mismatch(s2), expectedMismatchOffset); - assertEquals(s2.mismatch(s1), expectedMismatchOffset); + assertEquals(expectedMismatchOffset, s1.mismatch(s2)); + assertEquals(expectedMismatchOffset, s2.mismatch(s1)); } else { assert s1.byteSize() < s2.byteSize(); var off = Math.min(s1.byteSize(), expectedMismatchOffset); - assertEquals(s1.mismatch(s2), off); // proper prefix - assertEquals(s2.mismatch(s1), off); + assertEquals(off, s1.mismatch(s2)); // proper prefix + assertEquals(off, s2.mismatch(s1)); } } } - @Test(dataProvider = "slicesStatic") + @ParameterizedTest + @MethodSource("slicesStatic") public void testDifferentValuesStatic(SliceOffsetAndSize ss1, SliceOffsetAndSize ss2) { out.format("testDifferentValues s1:%s, s2:%s\n", ss1, ss2); @@ -223,10 +249,10 @@ public void testDifferentValuesStatic(SliceOffsetAndSize ss1, SliceOffsetAndSize ss2.toSlice().set(ValueLayout.JAVA_BYTE, i, (byte) 0xFF); for (long j = expectedMismatchOffset + 1 ; j < ss2.size ; j++) { - assertEquals(MemorySegment.mismatch(ss1.segment, ss1.offset, ss1.endOffset(), ss2.segment, ss2.offset, j + ss2.offset), expectedMismatchOffset); + assertEquals(expectedMismatchOffset, MemorySegment.mismatch(ss1.segment, ss1.offset, ss1.endOffset(), ss2.segment, ss2.offset, j + ss2.offset)); } for (long j = expectedMismatchOffset + 1 ; j < ss1.size ; j++) { - assertEquals(MemorySegment.mismatch(ss2.segment, ss2.offset, ss2.endOffset(), ss1.segment, ss1.offset, j + ss1.offset), expectedMismatchOffset); + assertEquals(expectedMismatchOffset, MemorySegment.mismatch(ss2.segment, ss2.offset, ss2.endOffset(), ss1.segment, ss1.offset, j + ss1.offset)); } } } @@ -234,12 +260,12 @@ public void testDifferentValuesStatic(SliceOffsetAndSize ss1, SliceOffsetAndSize @Test public void testEmpty() { var s1 = MemorySegment.ofArray(new byte[0]); - assertEquals(s1.mismatch(s1), -1); + assertEquals(-1, s1.mismatch(s1)); try (Arena arena = Arena.ofConfined()) { var nativeSegment = arena.allocate(4, 4);; var s2 = nativeSegment.asSlice(0, 0); - assertEquals(s1.mismatch(s2), -1); - assertEquals(s2.mismatch(s1), -1); + assertEquals(-1, s1.mismatch(s2)); + assertEquals(-1, s2.mismatch(s1)); } } @@ -250,9 +276,9 @@ public void testLarge() { try (Arena arena = Arena.ofConfined()) { var s1 = arena.allocate((long) Integer.MAX_VALUE + 10L, 8);; var s2 = arena.allocate((long) Integer.MAX_VALUE + 10L, 8);; - assertEquals(s1.mismatch(s1), -1); - assertEquals(s1.mismatch(s2), -1); - assertEquals(s2.mismatch(s1), -1); + assertEquals(-1, s1.mismatch(s1)); + assertEquals(-1, s1.mismatch(s2)); + assertEquals(-1, s2.mismatch(s1)); testLargeAcrossMaxBoundary(s1, s2); @@ -266,13 +292,13 @@ private void testLargeAcrossMaxBoundary(MemorySegment s1, MemorySegment s2) { var s3 = s1.asSlice(0, i); var s4 = s2.asSlice(0, i); // instance - assertEquals(s3.mismatch(s3), -1); - assertEquals(s3.mismatch(s4), -1); - assertEquals(s4.mismatch(s3), -1); + assertEquals(-1, s3.mismatch(s3)); + assertEquals(-1, s3.mismatch(s4)); + assertEquals(-1, s4.mismatch(s3)); // static - assertEquals(MemorySegment.mismatch(s1, 0, s1.byteSize(), s1, 0, i), -1); - assertEquals(MemorySegment.mismatch(s2, 0, s1.byteSize(), s1, 0, i), -1); - assertEquals(MemorySegment.mismatch(s1, 0, s1.byteSize(), s2, 0, i), -1); + assertEquals(-1, MemorySegment.mismatch(s1, 0, s1.byteSize(), s1, 0, i)); + assertEquals(-1, MemorySegment.mismatch(s2, 0, s1.byteSize(), s1, 0, i)); + assertEquals(-1, MemorySegment.mismatch(s1, 0, s1.byteSize(), s2, 0, i)); } } @@ -280,8 +306,8 @@ private void testLargeMismatchAcrossMaxBoundary(MemorySegment s1, MemorySegment for (long i = s2.byteSize() -1 ; i >= Integer.MAX_VALUE - 10L; i--) { s2.set(ValueLayout.JAVA_BYTE, i, (byte) 0xFF); long expectedMismatchOffset = i; - assertEquals(s1.mismatch(s2), expectedMismatchOffset); - assertEquals(s2.mismatch(s1), expectedMismatchOffset); + assertEquals(expectedMismatchOffset, s1.mismatch(s2)); + assertEquals(expectedMismatchOffset, s2.mismatch(s1)); } } @@ -351,22 +377,22 @@ public void testSameSegment() { long match = MemorySegment.mismatch( segment, 0L, 4L, segment, 4L, 8L); - assertEquals(match, -1); + assertEquals(-1, match); long noMatch = MemorySegment.mismatch( segment, 0L, 4L, segment, 1L, 5L); - assertEquals(noMatch, 0); + assertEquals(0, noMatch); long noMatchEnd = MemorySegment.mismatch( segment, 0L, 2L, segment, 8L, 10L); - assertEquals(noMatchEnd, 1); + assertEquals(1, noMatchEnd); long same = MemorySegment.mismatch( segment, 0L, 8L, segment, 0L, 8L); - assertEquals(same, -1); + assertEquals(-1, same); } enum SegmentKind { @@ -393,7 +419,6 @@ long endOffset() { } }; - @DataProvider(name = "slicesStatic") static Object[][] slicesStatic() { int[] sizes = { 16, 8, 1 }; List aSliceOffsetAndSizes = new ArrayList<>(); @@ -419,7 +444,6 @@ static Object[][] slicesStatic() { return sliceArray; } - @DataProvider(name = "slices") static Object[][] slices() { Object[][] slicesStatic = slicesStatic(); return Stream.of(slicesStatic) diff --git a/test/jdk/java/foreign/TestNULLAddress.java b/test/jdk/java/foreign/TestNULLAddress.java index 32d19fb48740b..d0a330ab4705d 100644 --- a/test/jdk/java/foreign/TestNULLAddress.java +++ b/test/jdk/java/foreign/TestNULLAddress.java @@ -23,12 +23,11 @@ /* * @test - * @run testng/othervm/native + * @run junit/othervm/native * --enable-native-access=ALL-UNNAMED * TestNULLAddress */ -import org.testng.annotations.Test; import java.lang.foreign.Linker; import java.lang.foreign.FunctionDescriptor; @@ -37,7 +36,8 @@ import java.lang.foreign.ValueLayout; import java.lang.invoke.MethodHandle; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class TestNULLAddress { @@ -47,18 +47,22 @@ public class TestNULLAddress { static final Linker LINKER = Linker.nativeLinker(); - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testNULLLinking() { - LINKER.downcallHandle( - MemorySegment.NULL, - FunctionDescriptor.ofVoid()); + assertThrows(IllegalArgumentException.class, () -> { + LINKER.downcallHandle( + MemorySegment.NULL, + FunctionDescriptor.ofVoid()); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testNULLVirtual() throws Throwable { MethodHandle mh = LINKER.downcallHandle( FunctionDescriptor.ofVoid()); - mh.invokeExact(MemorySegment.NULL); + assertThrows(IllegalArgumentException.class, () -> { + mh.invokeExact(MemorySegment.NULL); + }); } @Test diff --git a/test/jdk/java/foreign/TestNative.java b/test/jdk/java/foreign/TestNative.java index c39a1292b4005..d582edd3a0f9f 100644 --- a/test/jdk/java/foreign/TestNative.java +++ b/test/jdk/java/foreign/TestNative.java @@ -24,14 +24,12 @@ /* * @test - * @run testng/othervm/native --enable-native-access=ALL-UNNAMED TestNative + * @run junit/othervm/native --enable-native-access=ALL-UNNAMED TestNative */ import java.lang.foreign.*; import java.lang.foreign.MemoryLayout.PathElement; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import java.lang.invoke.VarHandle; import java.nio.Buffer; @@ -49,8 +47,14 @@ import java.util.function.Function; import static java.lang.foreign.ValueLayout.JAVA_INT; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestNative extends NativeTestHelper { static SequenceLayout bytes = MemoryLayout.sequenceLayout(100, @@ -108,13 +112,13 @@ static void checkBytes(MemorySegment base, SequenceLayout lay Object bufferValue = nativeBufferExtractor.apply(z, (int)i); Object rawValue = nativeRawExtractor.apply(base.address(), (int)i); if (handleValue instanceof Number) { - assertEquals(((Number)handleValue).longValue(), i); - assertEquals(((Number)bufferValue).longValue(), i); - assertEquals(((Number)rawValue).longValue(), i); + assertEquals(i, ((Number)handleValue).longValue()); + assertEquals(i, ((Number)bufferValue).longValue()); + assertEquals(i, ((Number)rawValue).longValue()); } else { - assertEquals((long)(char)handleValue, i); - assertEquals((long)(char)bufferValue, i); - assertEquals((long)(char)rawValue, i); + assertEquals(i, (long)(char)handleValue); + assertEquals(i, (long)(char)bufferValue); + assertEquals(i, (long)(char)rawValue); } } } @@ -137,7 +141,8 @@ static void checkBytes(MemorySegment base, SequenceLayout lay public static native long getCapacity(Buffer buffer); - @Test(dataProvider="nativeAccessOps") + @ParameterizedTest + @MethodSource("nativeAccessOps") public void testNativeAccess(Consumer checker, Consumer initializer, SequenceLayout seq) { try (Arena arena = Arena.ofConfined()) { MemorySegment segment = arena.allocate(seq);; @@ -146,7 +151,8 @@ public void testNativeAccess(Consumer checker, Consumer bufferFunction, int elemSize) { int capacity = (int)doubles.byteSize(); try (Arena arena = Arena.ofConfined()) { @@ -154,8 +160,8 @@ public void testNativeCapacity(Function bufferFunction, int ByteBuffer bb = segment.asByteBuffer(); Buffer buf = bufferFunction.apply(bb); int expected = capacity / elemSize; - assertEquals(buf.capacity(), expected); - assertEquals(getCapacity(buf), expected); + assertEquals(expected, buf.capacity()); + assertEquals(expected, getCapacity(buf)); } } @@ -176,7 +182,7 @@ public void testMallocSegment() { try (Arena arena = Arena.ofConfined()) { mallocSegment = addr.asSlice(0, 12) .reinterpret(arena, TestNative::freeMemory); - assertEquals(mallocSegment.byteSize(), 12); + assertEquals(12, mallocSegment.byteSize()); //free here } assertTrue(!mallocSegment.scope().isAlive()); @@ -186,7 +192,7 @@ public void testMallocSegment() { public void testAddressAccess() { MemorySegment addr = allocateMemory(4); addr.set(JAVA_INT, 0, 42); - assertEquals(addr.get(JAVA_INT, 0), 42); + assertEquals(42, addr.get(JAVA_INT, 0)); freeMemory(addr); } @@ -203,7 +209,6 @@ public void testBadResize() { System.loadLibrary("NativeAccess"); } - @DataProvider(name = "nativeAccessOps") public Object[][] nativeAccessOps() { Consumer byteInitializer = (base) -> initBytes(base, bytes, (addr, pos) -> byteHandle.set(addr, 0L, pos, (byte)(long)pos)); @@ -246,7 +251,6 @@ public Object[][] nativeAccessOps() { }; } - @DataProvider(name = "buffers") public Object[][] buffers() { return new Object[][] { { (Function)bb -> bb, 1 }, diff --git a/test/jdk/java/foreign/TestNulls.java b/test/jdk/java/foreign/TestNulls.java index 6822863c2ca10..578ee1ddcdf60 100644 --- a/test/jdk/java/foreign/TestNulls.java +++ b/test/jdk/java/foreign/TestNulls.java @@ -24,7 +24,7 @@ /* * @test * @modules java.base/jdk.internal.ref - * @run testng/othervm + * @run junit/othervm * --enable-native-access=ALL-UNNAMED * TestNulls */ @@ -32,9 +32,6 @@ import java.lang.foreign.*; import jdk.internal.ref.CleanerFactory; -import org.testng.annotations.DataProvider; -import org.testng.annotations.NoInjection; -import org.testng.annotations.Test; import java.lang.constant.Constable; import java.lang.foreign.Arena; @@ -62,8 +59,12 @@ import static java.lang.foreign.ValueLayout.JAVA_INT; import static java.lang.foreign.ValueLayout.JAVA_LONG; -import static org.testng.Assert.*; -import static org.testng.Assert.fail; + +import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.fail; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; /** * This test makes sure that public API classes (listed in {@link TestNulls#CLASSES}) throws NPEs whenever @@ -75,6 +76,7 @@ * by adding/removing default mappings for standard carrier types (see {@link #DEFAULT_VALUES} or by * adding/removing custom replacements (see {@link #REPLACEMENT_VALUES}). */ +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestNulls { static final Class[] CLASSES = new Class[] { @@ -189,20 +191,20 @@ static void addReplacements(Class carrier, Z... value) { addReplacements(Set.class, null, Stream.of(new Object[] { null }).collect(Collectors.toSet())); } - @Test(dataProvider = "cases") - public void testNulls(String testName, @NoInjection Method meth, Object receiver, Object[] args) { + @ParameterizedTest(autoCloseArguments = false) + @MethodSource("cases") + public void testNulls(String testName, Method meth, Object receiver, Object[] args) { try { meth.invoke(receiver, args); fail("Method invocation completed normally"); } catch (InvocationTargetException ex) { Class cause = ex.getCause().getClass(); - assertEquals(cause, NullPointerException.class, "got " + cause.getName() + " - expected NullPointerException"); + assertEquals(NullPointerException.class, cause, "got " + cause.getName() + " - expected NullPointerException"); } catch (Throwable ex) { fail("Unexpected exception: " + ex); } } - @DataProvider(name = "cases") static Iterator cases() { List cases = new ArrayList<>(); for (Class clazz : CLASSES) { diff --git a/test/jdk/java/foreign/TestOfBufferIssue.java b/test/jdk/java/foreign/TestOfBufferIssue.java index c30384efc6929..54766d988eafe 100644 --- a/test/jdk/java/foreign/TestOfBufferIssue.java +++ b/test/jdk/java/foreign/TestOfBufferIssue.java @@ -22,18 +22,18 @@ * */ -import org.testng.annotations.*; import java.lang.foreign.MemorySegment; import java.nio.CharBuffer; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; /* * @test * @bug 8294621 * @summary test that StringCharBuffer is not accepted by MemorySegment::ofBuffer - * @run testng TestOfBufferIssue + * @run junit TestOfBufferIssue */ public class TestOfBufferIssue { diff --git a/test/jdk/java/foreign/TestReshape.java b/test/jdk/java/foreign/TestReshape.java index 5b64a3d38b673..ea362153411fd 100644 --- a/test/jdk/java/foreign/TestReshape.java +++ b/test/jdk/java/foreign/TestReshape.java @@ -23,7 +23,7 @@ /* * @test - * @run testng TestReshape + * @run junit TestReshape */ import java.lang.foreign.MemoryLayout; @@ -34,12 +34,17 @@ import java.util.List; import java.util.stream.LongStream; -import org.testng.annotations.*; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestReshape { - @Test(dataProvider = "shapes") + @ParameterizedTest + @MethodSource("shapes") public void testReshape(MemoryLayout layout, long[] expectedShape) { long flattenedSize = LongStream.of(expectedShape).reduce(1L, Math::multiplyExact); SequenceLayout seq_flattened = MemoryLayout.sequenceLayout(flattenedSize, layout); @@ -47,32 +52,40 @@ public void testReshape(MemoryLayout layout, long[] expectedShape) { for (long[] shape : new Shape(expectedShape)) { SequenceLayout seq_shaped = seq_flattened.reshape(shape); assertDimensions(seq_shaped, expectedShape); - assertEquals(seq_shaped.flatten(), seq_flattened); + assertEquals(seq_flattened, seq_shaped.flatten()); } } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testInvalidReshape() { SequenceLayout seq = MemoryLayout.sequenceLayout(4, ValueLayout.JAVA_INT); - seq.reshape(3, 2); + assertThrows(IllegalArgumentException.class, () -> { + seq.reshape(3, 2); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadReshapeInference() { SequenceLayout seq = MemoryLayout.sequenceLayout(4, ValueLayout.JAVA_INT); - seq.reshape(-1, -1); + assertThrows(IllegalArgumentException.class, () -> { + seq.reshape(-1, -1); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadReshapeParameterZero() { SequenceLayout seq = MemoryLayout.sequenceLayout(4, ValueLayout.JAVA_INT); - seq.reshape(0, 4); + assertThrows(IllegalArgumentException.class, () -> { + seq.reshape(0, 4); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadReshapeParameterNegative() { SequenceLayout seq = MemoryLayout.sequenceLayout(4, ValueLayout.JAVA_INT); - seq.reshape(-2, 2); + assertThrows(IllegalArgumentException.class, () -> { + seq.reshape(-2, 2); + }); } static void assertDimensions(SequenceLayout layout, long... dims) { @@ -81,7 +94,7 @@ static void assertDimensions(SequenceLayout layout, long... dims) { if (prev != null) { layout = (SequenceLayout)prev.elementLayout(); } - assertEquals(layout.elementCount(), dims[i]); + assertEquals(dims[i], layout.elementCount()); prev = layout; } } @@ -110,7 +123,6 @@ public Iterator iterator() { ValueLayout.JAVA_INT ); - @DataProvider(name = "shapes") Object[][] shapes() { return new Object[][] { { ValueLayout.JAVA_BYTE, new long[] { 256 } }, diff --git a/test/jdk/java/foreign/TestRestricted.java b/test/jdk/java/foreign/TestRestricted.java index 771037ff8ba9d..bcdd83fb6417c 100644 --- a/test/jdk/java/foreign/TestRestricted.java +++ b/test/jdk/java/foreign/TestRestricted.java @@ -25,12 +25,11 @@ * @test * @modules java.base/jdk.internal.javac * @modules java.base/jdk.internal.reflect - * @run testng TestRestricted + * @run junit TestRestricted */ import jdk.internal.javac.Restricted; import jdk.internal.reflect.CallerSensitive; -import org.testng.annotations.Test; import java.io.IOException; import java.io.UncheckedIOException; @@ -57,8 +56,9 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; +import org.junit.jupiter.api.Test; /** * This test checks all methods in java.base to make sure that methods annotated with {@link Restricted} are diff --git a/test/jdk/java/foreign/TestScope.java b/test/jdk/java/foreign/TestScope.java index cfc1f3deaff33..3e5b74bef2fda 100644 --- a/test/jdk/java/foreign/TestScope.java +++ b/test/jdk/java/foreign/TestScope.java @@ -23,10 +23,9 @@ /* * @test - * @run testng/othervm/native --enable-native-access=ALL-UNNAMED TestScope + * @run junit/othervm/native --enable-native-access=ALL-UNNAMED TestScope */ -import org.testng.annotations.*; import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; @@ -37,7 +36,8 @@ import java.util.HexFormat; import java.util.stream.LongStream; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class TestScope { @@ -49,21 +49,21 @@ public class TestScope { public void testDifferentArrayScope() { MemorySegment.Scope scope1 = MemorySegment.ofArray(new byte[10]).scope(); MemorySegment.Scope scope2 = MemorySegment.ofArray(new byte[10]).scope(); - assertNotEquals(scope1, scope2); + assertNotEquals(scope2, scope1); } @Test public void testDifferentBufferScope() { MemorySegment.Scope scope1 = MemorySegment.ofBuffer(ByteBuffer.allocateDirect(10)).scope(); MemorySegment.Scope scope2 = MemorySegment.ofBuffer(ByteBuffer.allocateDirect(10)).scope(); - assertNotEquals(scope1, scope2); + assertNotEquals(scope2, scope1); } @Test public void testDifferentArenaScope() { MemorySegment.Scope scope1 = Arena.ofAuto().allocate(10).scope(); MemorySegment.Scope scope2 = Arena.ofAuto().allocate(10).scope(); - assertNotEquals(scope1, scope2); + assertNotEquals(scope2, scope1); } @Test @@ -71,7 +71,7 @@ public void testSameArrayScope() { byte[] arr = new byte[10]; assertEquals(MemorySegment.ofArray(arr).scope(), MemorySegment.ofArray(arr).scope()); ByteBuffer buf = ByteBuffer.wrap(arr); - assertEquals(MemorySegment.ofArray(arr).scope(), MemorySegment.ofBuffer(buf).scope()); + assertEquals(MemorySegment.ofBuffer(buf).scope(), MemorySegment.ofArray(arr).scope()); testDerivedBufferScope(MemorySegment.ofArray(arr)); } @@ -87,7 +87,7 @@ public void testSameArenaScope() { try (Arena arena = Arena.ofConfined()) { MemorySegment segment1 = arena.allocate(10); MemorySegment segment2 = arena.allocate(10); - assertEquals(segment1.scope(), segment2.scope()); + assertEquals(segment2.scope(), segment1.scope()); testDerivedBufferScope(segment1); } } @@ -96,9 +96,9 @@ public void testSameArenaScope() { public void testSameNativeScope() { MemorySegment segment1 = MemorySegment.ofAddress(42); MemorySegment segment2 = MemorySegment.ofAddress(43); - assertEquals(segment1.scope(), segment2.scope()); - assertEquals(segment1.scope(), segment2.reinterpret(10).scope()); - assertEquals(segment1.scope(), Arena.global().scope()); + assertEquals(segment2.scope(), segment1.scope()); + assertEquals(segment2.reinterpret(10).scope(), segment1.scope()); + assertEquals(Arena.global().scope(), segment1.scope()); testDerivedBufferScope(segment1.reinterpret(10)); } @@ -107,7 +107,7 @@ public void testSameLookupScope() { SymbolLookup loaderLookup = SymbolLookup.loaderLookup(); MemorySegment segment1 = loaderLookup.find("f").get(); MemorySegment segment2 = loaderLookup.find("c").get(); - assertEquals(segment1.scope(), segment2.scope()); + assertEquals(segment2.scope(), segment1.scope()); testDerivedBufferScope(segment1.reinterpret(10)); } @@ -138,7 +138,7 @@ public void testZeroedOfShared() { void testDerivedBufferScope(MemorySegment segment) { ByteBuffer buffer = segment.asByteBuffer(); MemorySegment.Scope expectedScope = segment.scope(); - assertEquals(MemorySegment.ofBuffer(buffer).scope(), expectedScope); + assertEquals(expectedScope, MemorySegment.ofBuffer(buffer).scope()); // buffer slices should have same scope ByteBuffer slice = buffer.slice(0, 2); assertEquals(expectedScope, MemorySegment.ofBuffer(slice).scope()); @@ -153,7 +153,7 @@ void testZeroed(Arena arena) { long byteSize = ZEROED_MEMORY.byteSize(); var segment = arena.allocate(byteSize, Long.BYTES); long mismatch = ZEROED_MEMORY.mismatch(segment); - assertEquals(mismatch, -1); + assertEquals(-1, mismatch); } } diff --git a/test/jdk/java/foreign/TestScopedOperations.java b/test/jdk/java/foreign/TestScopedOperations.java index 92b4ea5370fe8..b2913ab29ab9d 100644 --- a/test/jdk/java/foreign/TestScopedOperations.java +++ b/test/jdk/java/foreign/TestScopedOperations.java @@ -23,7 +23,7 @@ /* * @test - * @run testng/othervm --enable-native-access=ALL-UNNAMED TestScopedOperations + * @run junit/othervm --enable-native-access=ALL-UNNAMED TestScopedOperations */ import java.lang.foreign.Arena; @@ -31,8 +31,6 @@ import java.lang.foreign.MemorySegment; import java.lang.foreign.ValueLayout; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import java.io.File; import java.io.IOException; @@ -46,11 +44,16 @@ import java.util.function.Function; import static java.lang.foreign.ValueLayout.JAVA_BYTE; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestScopedOperations { static Path tempPath; @@ -65,7 +68,8 @@ public class TestScopedOperations { } } - @Test(dataProvider = "scopedOperations") + @ParameterizedTest + @MethodSource("scopedOperations") public void testOpAfterClose(String name, ScopedOperation scopedOperation) { Arena arena = Arena.ofConfined(); Z obj = scopedOperation.apply(arena); @@ -78,7 +82,8 @@ public void testOpAfterClose(String name, ScopedOperation scopedOperation } } - @Test(dataProvider = "scopedOperations") + @ParameterizedTest + @MethodSource("scopedOperations") public void testOpOutsideConfinement(String name, ScopedOperation scopedOperation) { try (Arena arena = Arena.ofConfined()) { Z obj = scopedOperation.apply(arena); @@ -93,7 +98,7 @@ public void testOpOutsideConfinement(String name, ScopedOperation scopedO t.start(); t.join(); assertNotNull(failed.get()); - assertEquals(failed.get().getClass(), WrongThreadException.class); + assertEquals(WrongThreadException.class, failed.get().getClass()); assertTrue(failed.get().getMessage().contains("outside")); } catch (InterruptedException ex) { throw new AssertionError(ex); @@ -140,7 +145,6 @@ public void testOpOutsideConfinement(String name, ScopedOperation scopedO ScopedOperation.ofScope(a -> a.allocateFrom(ValueLayout.JAVA_INT, source, JAVA_BYTE, 0, 1), "Arena::allocateFrom/5arg"); }; - @DataProvider(name = "scopedOperations") static Object[][] scopedOperations() { return scopedOperations.stream().map(op -> new Object[] { op.name, op }).toArray(Object[][]::new); } diff --git a/test/jdk/java/foreign/TestSegmentAllocators.java b/test/jdk/java/foreign/TestSegmentAllocators.java index c178f64450dd3..70f5b2559c3dd 100644 --- a/test/jdk/java/foreign/TestSegmentAllocators.java +++ b/test/jdk/java/foreign/TestSegmentAllocators.java @@ -25,12 +25,11 @@ /* * @test * @modules java.base/jdk.internal.foreign - * @run testng/othervm TestSegmentAllocators + * @run junit/othervm TestSegmentAllocators */ import java.lang.foreign.*; -import org.testng.annotations.*; import java.lang.foreign.Arena; import java.lang.invoke.VarHandle; @@ -50,14 +49,20 @@ import java.util.function.BiFunction; import java.util.function.Function; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestSegmentAllocators { final static int ELEMS = 128; - @Test(dataProvider = "scalarAllocations") @SuppressWarnings("unchecked") + @ParameterizedTest + @MethodSource("scalarAllocations") public void testAllocation(Z value, AllocationFactory allocationFactory, L layout, AllocationFunction allocationFunction, Function handleFactory) { layout = (L)layout.withByteAlignment(layout.byteSize()); L[] layouts = (L[])new ValueLayout[] { @@ -78,10 +83,10 @@ public void testAllocation(Z value, AllocationFactory SegmentAllocator allocator = allocationFactory.allocator(alignedLayout.byteSize() * ELEMS, arena); for (int i = 0; i < elems; i++) { MemorySegment address = allocationFunction.allocate(allocator, alignedLayout, value); - assertEquals(address.byteSize(), alignedLayout.byteSize()); + assertEquals(alignedLayout.byteSize(), address.byteSize()); addressList.add(address); VarHandle handle = handleFactory.apply(alignedLayout); - assertEquals(value, handle.get(address, 0L)); + assertEquals(handle.get(address, 0L), value); } boolean isBound = allocationFactory.isBound(); try { @@ -102,14 +107,18 @@ public void testAllocation(Z value, AllocationFactory static final int SIZE_256M = 1024 * 1024 * 256; - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testReadOnlySlicingAllocator() { - SegmentAllocator.slicingAllocator(MemorySegment.ofArray(new int[0]).asReadOnly()); + assertThrows(IllegalArgumentException.class, () -> { + SegmentAllocator.slicingAllocator(MemorySegment.ofArray(new int[0]).asReadOnly()); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testReadOnlyPrefixAllocator() { - SegmentAllocator.prefixAllocator(MemorySegment.ofArray(new int[0]).asReadOnly()); + assertThrows(IllegalArgumentException.class, () -> { + SegmentAllocator.prefixAllocator(MemorySegment.ofArray(new int[0]).asReadOnly()); + }); } @Test @@ -119,9 +128,9 @@ public void testBigAllocationInUnboundedSession() { SegmentAllocator allocator = SegmentAllocator.slicingAllocator(arena.allocate(i * 2 + 1)); MemorySegment address = allocator.allocate(i, i); //check size - assertEquals(address.byteSize(), i); + assertEquals(i, address.byteSize()); //check alignment - assertEquals(address.address() % i, 0); + assertEquals(0, address.address() % i); } } } @@ -135,59 +144,81 @@ public void testTooBigForBoundedArena() { } } - @Test(dataProvider = "allocators", expectedExceptions = IllegalArgumentException.class) + @ParameterizedTest + @MethodSource("allocators") public void testBadAllocationSize(SegmentAllocator allocator) { - allocator.allocate(-1); + assertThrows(IllegalArgumentException.class, () -> { + allocator.allocate(-1); + }); } - @Test(dataProvider = "allocators", expectedExceptions = IllegalArgumentException.class) + @ParameterizedTest + @MethodSource("allocators") public void testBadAllocationAlignZero(SegmentAllocator allocator) { - allocator.allocate(1, 0); + assertThrows(IllegalArgumentException.class, () -> { + allocator.allocate(1, 0); + }); } - @Test(dataProvider = "allocators", expectedExceptions = IllegalArgumentException.class) + @ParameterizedTest + @MethodSource("allocators") public void testBadAllocationAlignNeg(SegmentAllocator allocator) { - allocator.allocate(1, -1); + assertThrows(IllegalArgumentException.class, () -> { + allocator.allocate(1, -1); + }); } - @Test(dataProvider = "allocators", expectedExceptions = IllegalArgumentException.class) + @ParameterizedTest + @MethodSource("allocators") public void testBadAllocationAlignNotPowerTwo(SegmentAllocator allocator) { - allocator.allocate(1, 3); + assertThrows(IllegalArgumentException.class, () -> { + allocator.allocate(1, 3); + }); } - @Test(dataProvider = "allocators", expectedExceptions = IllegalArgumentException.class) + @ParameterizedTest + @MethodSource("allocators") public void testBadAllocationArrayNegSize(SegmentAllocator allocator) { - allocator.allocate(ValueLayout.JAVA_BYTE, -1); + assertThrows(IllegalArgumentException.class, () -> { + allocator.allocate(ValueLayout.JAVA_BYTE, -1); + }); } - @Test(dataProvider = "allocators", expectedExceptions = IllegalArgumentException.class) + @ParameterizedTest + @MethodSource("allocators") public void testBadAllocationArrayOverflow(SegmentAllocator allocator) { - allocator.allocate(ValueLayout.JAVA_LONG, Long.MAX_VALUE); + assertThrows(IllegalArgumentException.class, () -> { + allocator.allocate(ValueLayout.JAVA_LONG, Long.MAX_VALUE); + }); } - @Test(expectedExceptions = OutOfMemoryError.class) + @Test public void testBadArenaNullReturn() { try (Arena arena = Arena.ofConfined()) { - arena.allocate(Long.MAX_VALUE, 2); + assertThrows(OutOfMemoryError.class, () -> { + arena.allocate(Long.MAX_VALUE, 2); + }); } } - @Test(expectedExceptions = IllegalArgumentException.class, - expectedExceptionsMessageRegExp = ".*Heap segment not allowed.*") + @Test public void testArenaAllocateFromHeapSegment() { try (Arena arena = Arena.ofConfined()) { var heapSegment = MemorySegment.ofArray(new int[]{1}); - arena.allocateFrom(ValueLayout.ADDRESS, heapSegment); + assertThrows(IllegalArgumentException.class, () -> { + arena.allocateFrom(ValueLayout.ADDRESS, heapSegment); + }); } } - @Test(expectedExceptions = IllegalArgumentException.class, - expectedExceptionsMessageRegExp = ".*Heap segment not allowed.*") + @Test public void testAllocatorAllocateFromHeapSegment() { try (Arena arena = Arena.ofConfined()) { SegmentAllocator allocator = SegmentAllocator.prefixAllocator(arena.allocate(16)); var heapSegment = MemorySegment.ofArray(new int[]{1}); - allocator.allocateFrom(ValueLayout.ADDRESS, heapSegment); + assertThrows(IllegalArgumentException.class, () -> { + allocator.allocateFrom(ValueLayout.ADDRESS, heapSegment); + }); } } @@ -288,7 +319,7 @@ public MemorySegment allocateFrom(ValueLayout elementLayout, MemorySegment sourc allocator.allocateFrom(ValueLayout.JAVA_FLOAT); allocator.allocateFrom(ValueLayout.JAVA_LONG); allocator.allocateFrom(ValueLayout.JAVA_DOUBLE); - assertEquals(calls.get(), 7); + assertEquals(7, calls.get()); } @Test @@ -307,11 +338,12 @@ public MemorySegment allocate(long size) { }; }; allocator.allocateFrom("Hello"); - assertEquals(calls.get(), 1); + assertEquals(1, calls.get()); } - @Test(dataProvider = "arrayAllocations") + @ParameterizedTest + @MethodSource("arrayAllocations") public void testArray(AllocationFactory allocationFactory, ValueLayout layout, AllocationFunction allocationFunction, ToArrayHelper arrayHelper) { Z arr = arrayHelper.array(); Arena[] arenas = { @@ -323,12 +355,35 @@ public void testArray(AllocationFactory allocationFactory, ValueLayout layou SegmentAllocator allocator = allocationFactory.allocator(100, arena); MemorySegment address = allocationFunction.allocate(allocator, layout, arr); Z found = arrayHelper.toArray(address, layout); - assertEquals(found, arr); + assertArraysEqual(arr, found); } } } - @Test(dataProvider = "arrayAllocations") + private static void assertArraysEqual(Object arr, Object found) { + //in JUnit, assertEquals will really only call .equals, and that does not work well for arrays + //there's a set of explicit assertArrayEquals method, but we need "sharp" types for that to work(??): + if (arr instanceof byte[]) { + assertArrayEquals((byte[]) arr, (byte[]) found); + } else if (arr instanceof char[]) { + assertArrayEquals((char[]) arr, (char[]) found); + } else if (arr instanceof short[]) { + assertArrayEquals((short[]) arr, (short[]) found); + } else if (arr instanceof int[]) { + assertArrayEquals((int[]) arr, (int[]) found); + } else if (arr instanceof long[]) { + assertArrayEquals((long[]) arr, (long[]) found); + } else if (arr instanceof float[]) { + assertArrayEquals((float[]) arr, (float[]) found); + } else if (arr instanceof double[]) { + assertArrayEquals((double[]) arr, (double[]) found); + } else { + assertArrayEquals((Object[]) arr, (Object[]) found); + } + } + + @ParameterizedTest + @MethodSource("arrayAllocations") public void testPredicatesAndCommands(AllocationFactory allocationFactory, ValueLayout layout, AllocationFunction allocationFunction, ToArrayHelper arrayHelper) { Z arr = arrayHelper.array(); Arena[] arenas = { @@ -349,7 +404,6 @@ public void testPredicatesAndCommands(AllocationFactory allocationFactory, V } } - @DataProvider(name = "scalarAllocations") static Object[][] scalarAllocations() { List scalarAllocations = new ArrayList<>(); for (AllocationFactory factory : AllocationFactory.values()) { @@ -405,7 +459,6 @@ static Object[][] scalarAllocations() { return scalarAllocations.toArray(Object[][]::new); } - @DataProvider(name = "arrayAllocations") static Object[][] arrayAllocations() { List arrayAllocations = new ArrayList<>(); for (AllocationFactory factory : AllocationFactory.values()) { @@ -609,7 +662,6 @@ public double[] toArray(MemorySegment segment, ValueLayout layout) { }; } - @DataProvider(name = "allocators") static Object[][] allocators() { return new Object[][] { { SegmentAllocator.prefixAllocator(Arena.global().allocate(10, 1)) }, diff --git a/test/jdk/java/foreign/TestSegmentCopy.java b/test/jdk/java/foreign/TestSegmentCopy.java index 9a4500b2f5a1a..d11a48861c84e 100644 --- a/test/jdk/java/foreign/TestSegmentCopy.java +++ b/test/jdk/java/foreign/TestSegmentCopy.java @@ -24,7 +24,7 @@ /* * @test - * @run testng TestSegmentCopy + * @run junit TestSegmentCopy */ import java.lang.foreign.Arena; @@ -37,18 +37,23 @@ import java.util.List; import java.util.function.IntFunction; -import org.testng.SkipException; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import static java.lang.foreign.ValueLayout.JAVA_BYTE; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestSegmentCopy { static final int TEST_BYTE_SIZE = 16; - @Test(dataProvider = "segmentKinds") + @ParameterizedTest + @MethodSource("segmentKinds") public void testByteCopy(SegmentKind kind1, SegmentKind kind2) { MemorySegment s1 = kind1.makeSegment(TEST_BYTE_SIZE); MemorySegment s2 = kind2.makeSegment(TEST_BYTE_SIZE); @@ -75,7 +80,8 @@ public void testByteCopy(SegmentKind kind1, SegmentKind kind2) { } } - @Test(dataProvider = "conjunctSegments") + @ParameterizedTest + @MethodSource("conjunctSegments") public void testCopy5ArgInvariants(MemorySegment src, MemorySegment dst) { assertThrows(IndexOutOfBoundsException.class, () -> MemorySegment.copy(src, 0, dst, 0, -1)); assertThrows(IndexOutOfBoundsException.class, () -> MemorySegment.copy(src, -1, dst, 0, src.byteSize())); @@ -84,22 +90,26 @@ public void testCopy5ArgInvariants(MemorySegment src, MemorySegment dst) { assertThrows(IndexOutOfBoundsException.class, () -> MemorySegment.copy(src, 0, dst, 1, src.byteSize())); } - @Test(dataProvider = "conjunctSegments") + @ParameterizedTest + @MethodSource("conjunctSegments") public void testConjunctCopy7ArgRight(MemorySegment src, MemorySegment dst) { testConjunctCopy(src, 0, dst, 1, CopyOp.of7Arg()); } - @Test(dataProvider = "conjunctSegments") + @ParameterizedTest + @MethodSource("conjunctSegments") public void testConjunctCopy5ArgRight(MemorySegment src, MemorySegment dst) { testConjunctCopy(src, 0, dst, 1, CopyOp.of5Arg()); } - @Test(dataProvider = "conjunctSegments") + @ParameterizedTest + @MethodSource("conjunctSegments") public void testConjunctCopy7ArgLeft(MemorySegment src, MemorySegment dst) { testConjunctCopy(src, 1, dst, 0, CopyOp.of7Arg()); } - @Test(dataProvider = "conjunctSegments") + @ParameterizedTest + @MethodSource("conjunctSegments") public void testConjunctCopy5ArgLeft(MemorySegment src, MemorySegment dst) { testConjunctCopy(src, 1, dst, 0, CopyOp.of5Arg()); } @@ -121,7 +131,7 @@ void testConjunctCopy(MemorySegment src, long srcOffset, MemorySegment dst, long op.copy(src, srcOffset, dst, dstOffset, 3); byte[] actual = dst.toArray(JAVA_BYTE); - assertEquals(actual, expected); + assertArrayEquals(expected, actual); } } @@ -140,7 +150,8 @@ static CopyOp of7Arg() { } - @Test(dataProvider = "segmentKinds") + @ParameterizedTest + @MethodSource("segmentKinds") public void testByteCopySizes(SegmentKind kind1, SegmentKind kind2) { record Offsets(int src, int dst){} @@ -157,40 +168,45 @@ record Offsets(int src, int dst){} MemorySegment.copy(src, offsets.src(), dst, offsets.dst(), size); //check that copy actually worked for (int i = 0; i < size; i++) { - assertEquals(dst.get(JAVA_BYTE, i + offsets.dst()), (byte) i); + assertEquals((byte) i, dst.get(JAVA_BYTE, i + offsets.dst())); } } } } - @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "segmentKinds") + @ParameterizedTest + @MethodSource("segmentKinds") public void testReadOnlyCopy(SegmentKind kind1, SegmentKind kind2) { MemorySegment s1 = kind1.makeSegment(TEST_BYTE_SIZE); MemorySegment s2 = kind2.makeSegment(TEST_BYTE_SIZE); // check failure with read-only dest - MemorySegment.copy(s1, Type.BYTE.layout, 0, s2.asReadOnly(), Type.BYTE.layout, 0, 0); + assertThrows(IllegalArgumentException.class, () -> { + MemorySegment.copy(s1, Type.BYTE.layout, 0, s2.asReadOnly(), Type.BYTE.layout, 0, 0); + }); } - @Test(expectedExceptions = IllegalArgumentException.class, - expectedExceptionsMessageRegExp = ".*Attempt to write a read-only segment.*") + @Test public void badCopy6Arg() { try (Arena scope = Arena.ofConfined()) { MemorySegment dest = scope.allocate(ValueLayout.JAVA_INT).asReadOnly(); - MemorySegment.copy(new int[1],0, dest, ValueLayout.JAVA_INT, 0 ,1); // should throw + assertThrows(IllegalArgumentException.class, () -> { + MemorySegment.copy(new int[1],0, dest, ValueLayout.JAVA_INT, 0 ,1); + }); } } - @Test(expectedExceptions = IndexOutOfBoundsException.class, dataProvider = "types") + @ParameterizedTest + @MethodSource("types") public void testBadOverflow(Type type) { - if (type.layout.byteSize() > 1) { - MemorySegment segment = MemorySegment.ofArray(new byte[100]); + Assumptions.assumeTrue(type.layout.byteSize() > 1, "Byte layouts do not overflow"); + MemorySegment segment = MemorySegment.ofArray(new byte[100]); + assertThrows(IndexOutOfBoundsException.class, () -> { MemorySegment.copy(segment, type.layout, 0, segment, type.layout, 0, Long.MAX_VALUE); - } else { - throw new SkipException("Byte layouts do not overflow"); - } + }); } - @Test(dataProvider = "segmentKindsAndTypes") + @ParameterizedTest + @MethodSource("segmentKindsAndTypes") public void testElementCopy(SegmentKind kind1, SegmentKind kind2, Type type1, Type type2) { MemorySegment s1 = kind1.makeSegment(TEST_BYTE_SIZE); MemorySegment s2 = kind2.makeSegment(TEST_BYTE_SIZE); @@ -220,16 +236,20 @@ public void testElementCopy(SegmentKind kind1, SegmentKind kind2, Type type1, Ty } } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testHyperAlignedSrc() { MemorySegment segment = MemorySegment.ofArray(new byte[] {1, 2, 3, 4}); - MemorySegment.copy(segment, 0, segment, JAVA_BYTE.withByteAlignment(2), 0, 4); + assertThrows(IllegalArgumentException.class, () -> { + MemorySegment.copy(segment, 0, segment, JAVA_BYTE.withByteAlignment(2), 0, 4); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testHyperAlignedDst() { MemorySegment segment = MemorySegment.ofArray(new byte[] {1, 2, 3, 4}); - MemorySegment.copy(segment, JAVA_BYTE.withByteAlignment(2), 0, segment, 0, 4); + assertThrows(IllegalArgumentException.class, () -> { + MemorySegment.copy(segment, JAVA_BYTE.withByteAlignment(2), 0, segment, 0, 4); + }); } @Test @@ -334,7 +354,7 @@ void set(MemorySegment segment, long offset, int index, int val) { } void check(MemorySegment segment, long offset, int index, int val) { - assertEquals(handle().get(segment, offset + (index * size())), valueConverter.apply(val)); + assertEquals(valueConverter.apply(val), handle().get(segment, offset + (index * size()))); } } @@ -353,7 +373,6 @@ MemorySegment makeSegment(int size) { } } - @DataProvider static Object[][] segmentKinds() { List cases = new ArrayList<>(); for (SegmentKind kind1 : SegmentKind.values()) { @@ -364,7 +383,6 @@ static Object[][] segmentKinds() { return cases.toArray(Object[][]::new); } - @DataProvider static Object[][] conjunctSegments() { List cases = new ArrayList<>(); for (SegmentKind kind : SegmentKind.values()) { @@ -386,14 +404,12 @@ static Object[][] conjunctSegments() { return cases.toArray(Object[][]::new); } - @DataProvider static Object[][] types() { return Arrays.stream(Type.values()) .map(t -> new Object[] { t }) .toArray(Object[][]::new); } - @DataProvider static Object[][] segmentKindsAndTypes() { List cases = new ArrayList<>(); for (Object[] segmentKinds : segmentKinds()) { diff --git a/test/jdk/java/foreign/TestSegmentOverlap.java b/test/jdk/java/foreign/TestSegmentOverlap.java index 817d79b08ccf2..8c09a98ad6ff8 100644 --- a/test/jdk/java/foreign/TestSegmentOverlap.java +++ b/test/jdk/java/foreign/TestSegmentOverlap.java @@ -23,7 +23,7 @@ /* * @test - * @run testng/othervm TestSegmentOverlap + * @run junit/othervm TestSegmentOverlap */ import java.io.File; @@ -37,11 +37,14 @@ import java.util.function.Supplier; import java.lang.foreign.MemorySegment; -import org.testng.annotations.Test; -import org.testng.annotations.DataProvider; import static java.lang.System.out; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestSegmentOverlap { static Path tempPath; @@ -58,7 +61,6 @@ public class TestSegmentOverlap { } } - @DataProvider(name = "segmentFactories") public Object[][] segmentFactories() { List> l = List.of( () -> Arena.ofAuto().allocate(16, 1), @@ -80,7 +82,8 @@ public Object[][] segmentFactories() { return l.stream().map(s -> new Object[] { s }).toArray(Object[][]::new); } - @Test(dataProvider="segmentFactories") + @ParameterizedTest + @MethodSource("segmentFactories") public void testBasic(Supplier segmentSupplier) { var s1 = segmentSupplier.get(); var s2 = segmentSupplier.get(); @@ -92,39 +95,41 @@ public void testBasic(Supplier segmentSupplier) { assertTrue(s1.asOverlappingSlice(sOther).isEmpty()); } - @Test(dataProvider="segmentFactories") + @ParameterizedTest + @MethodSource("segmentFactories") public void testIdentical(Supplier segmentSupplier) { var s1 = segmentSupplier.get(); var s2 = s1.asReadOnly(); out.format("testIdentical s1:%s, s2:%s\n", s1, s2); - assertEquals(s1.asOverlappingSlice(s2).get().byteSize(), s1.byteSize()); - assertEquals(s1.asOverlappingSlice(s2).get().scope(), s1.scope()); + assertEquals(s1.byteSize(), s1.asOverlappingSlice(s2).get().byteSize()); + assertEquals(s1.scope(), s1.asOverlappingSlice(s2).get().scope()); - assertEquals(s2.asOverlappingSlice(s1).get().byteSize(), s2.byteSize()); - assertEquals(s2.asOverlappingSlice(s1).get().scope(), s2.scope()); + assertEquals(s2.byteSize(), s2.asOverlappingSlice(s1).get().byteSize()); + assertEquals(s2.scope(), s2.asOverlappingSlice(s1).get().scope()); if (s1.isNative()) { - assertEquals(s1.asOverlappingSlice(s2).get().address(), s1.address()); - assertEquals(s2.asOverlappingSlice(s1).get().address(), s2.address()); + assertEquals(s1.address(), s1.asOverlappingSlice(s2).get().address()); + assertEquals(s2.address(), s2.asOverlappingSlice(s1).get().address()); } } - @Test(dataProvider="segmentFactories") + @ParameterizedTest + @MethodSource("segmentFactories") public void testSlices(Supplier segmentSupplier) { MemorySegment s1 = segmentSupplier.get(); MemorySegment s2 = segmentSupplier.get(); for (int offset = 0 ; offset < 4 ; offset++) { MemorySegment slice = s1.asSlice(offset); out.format("testSlices s1:%s, s2:%s, slice:%s, offset:%d\n", s1, s2, slice, offset); - assertEquals(s1.asOverlappingSlice(slice).get().byteSize(), s1.byteSize() - offset); - assertEquals(s1.asOverlappingSlice(slice).get().scope(), s1.scope()); + assertEquals(s1.byteSize() - offset, s1.asOverlappingSlice(slice).get().byteSize()); + assertEquals(s1.scope(), s1.asOverlappingSlice(slice).get().scope()); - assertEquals(slice.asOverlappingSlice(s1).get().byteSize(), slice.byteSize()); - assertEquals(slice.asOverlappingSlice(s1).get().scope(), slice.scope()); + assertEquals(slice.byteSize(), slice.asOverlappingSlice(s1).get().byteSize()); + assertEquals(slice.scope(), slice.asOverlappingSlice(s1).get().scope()); if (s1.isNative()) { - assertEquals(s1.asOverlappingSlice(slice).get().address(), s1.address() + offset); - assertEquals(slice.asOverlappingSlice(s1).get().address(), slice.address()); + assertEquals(s1.address() + offset, s1.asOverlappingSlice(slice).get().address()); + assertEquals(slice.address(), slice.asOverlappingSlice(s1).get().address()); } assertTrue(s2.asOverlappingSlice(slice).isEmpty()); } diff --git a/test/jdk/java/foreign/TestSegments.java b/test/jdk/java/foreign/TestSegments.java index e9f3e8a87cc21..69cac5993d3d5 100644 --- a/test/jdk/java/foreign/TestSegments.java +++ b/test/jdk/java/foreign/TestSegments.java @@ -25,13 +25,11 @@ * @test * @requires vm.bits == 64 * @modules java.base/sun.nio.ch - * @run testng/othervm -Xmx4G -XX:MaxDirectMemorySize=1M --enable-native-access=ALL-UNNAMED TestSegments + * @run junit/othervm -Xmx4G -XX:MaxDirectMemorySize=1M --enable-native-access=ALL-UNNAMED TestSegments */ import java.lang.foreign.*; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import java.lang.invoke.VarHandle; import java.nio.ByteBuffer; @@ -45,20 +43,29 @@ import static java.lang.foreign.ValueLayout.JAVA_BYTE; import static java.lang.foreign.ValueLayout.JAVA_INT; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestSegments { - @Test(dataProvider = "badSizeAndAlignments", expectedExceptions = IllegalArgumentException.class) + @ParameterizedTest + @MethodSource("sizesAndAlignments") public void testBadAllocateAlign(long size, long align) { - Arena.ofAuto().allocate(size, align); + assertThrows(IllegalArgumentException.class, () -> { + Arena.ofAuto().allocate(size, align); + }); } @Test public void testZeroLengthNativeSegment() { try (Arena arena = Arena.ofConfined()) { var segment = arena.allocate(0, 1); - assertEquals(segment.byteSize(), 0); + assertEquals(0, segment.byteSize()); if (segment.address() == 0) { fail("Segment address is zero"); } @@ -67,14 +74,14 @@ public void testZeroLengthNativeSegment() { } MemoryLayout seq = MemoryLayout.sequenceLayout(0, JAVA_INT); segment = arena.allocate(seq); - assertEquals(segment.byteSize(), 0); - assertEquals(segment.address() % seq.byteAlignment(), 0); + assertEquals(0, segment.byteSize()); + assertEquals(0, segment.address() % seq.byteAlignment()); segment = arena.allocate(0, 4); - assertEquals(segment.byteSize(), 0); - assertEquals(segment.address() % 4, 0); + assertEquals(0, segment.byteSize()); + assertEquals(0, segment.address() % 4); MemorySegment rawAddress = MemorySegment.ofAddress(segment.address()); - assertEquals(rawAddress.byteSize(), 0); - assertEquals(rawAddress.address() % 4, 0); + assertEquals(0, rawAddress.byteSize()); + assertEquals(0, rawAddress.address() % 4); } } @@ -83,7 +90,7 @@ public void testZeroLengthNativeSegmentHyperAligned() { long byteAlignment = 1024; try (Arena arena = Arena.ofConfined()) { var segment = arena.allocate(0, byteAlignment); - assertEquals(segment.byteSize(), 0); + assertEquals(0, segment.byteSize()); if (segment.address() == 0) { fail("Segment address is zero"); } @@ -91,17 +98,18 @@ public void testZeroLengthNativeSegmentHyperAligned() { } } - - @Test(expectedExceptions = { OutOfMemoryError.class, - IllegalArgumentException.class }) + @Test public void testAllocateTooBig() { - Arena.ofAuto().allocate(Long.MAX_VALUE, 1); + assertThrows(OutOfMemoryError.class, + () -> Arena.ofAuto().allocate(Long.MAX_VALUE, 1)); } - @Test(expectedExceptions = OutOfMemoryError.class) + @Test public void testNativeAllocationTooBig() { - Arena scope = Arena.ofAuto(); - MemorySegment segment = scope.allocate(1024L * 1024 * 8 * 2, 1); // 2M + assertThrows(OutOfMemoryError.class, () -> { + Arena scope = Arena.ofAuto(); + MemorySegment segment = scope.allocate(1024L * 1024 * 8 * 2, 1); // 2M + }); } @Test @@ -127,88 +135,91 @@ public void testSlices() { for (int offset = 0 ; offset < 10 ; offset++) { MemorySegment slice = segment.asSlice(offset); for (long i = offset ; i < 10 ; i++) { - assertEquals( - byteHandle.get(segment, i), - byteHandle.get(slice, i - offset) + assertEquals( byteHandle.get(slice, i - offset), byteHandle.get(segment, i) ); } } } } - @Test(dataProvider = "segmentFactories") + @ParameterizedTest + @MethodSource("segmentFactories") public void testDerivedScopes(Supplier segmentSupplier) { MemorySegment segment = segmentSupplier.get(); assertEquals(segment.scope(), segment.scope()); // one level - assertEquals(segment.asSlice(0).scope(), segment.scope()); - assertEquals(segment.asReadOnly().scope(), segment.scope()); + assertEquals(segment.scope(), segment.asSlice(0).scope()); + assertEquals(segment.scope(), segment.asReadOnly().scope()); // two levels - assertEquals(segment.asSlice(0).asReadOnly().scope(), segment.scope()); - assertEquals(segment.asReadOnly().asSlice(0).scope(), segment.scope()); + assertEquals(segment.scope(), segment.asSlice(0).asReadOnly().scope()); + assertEquals(segment.scope(), segment.asReadOnly().asSlice(0).scope()); // check fresh every time MemorySegment another = segmentSupplier.get(); - assertNotEquals(segment.scope(), another.scope()); + assertNotEquals(another.scope(), segment.scope()); } @Test public void testEqualsOffHeap() { try (Arena arena = Arena.ofConfined()) { MemorySegment segment = arena.allocate(100, 1); - assertEquals(segment, segment.asReadOnly()); - assertEquals(segment, segment.asSlice(0, 100)); - assertNotEquals(segment, segment.asSlice(10, 90)); - assertEquals(segment, segment.asSlice(0, 90)); - assertEquals(segment, MemorySegment.ofAddress(segment.address())); + assertEquals(segment.asReadOnly(), segment); + assertEquals(segment.asSlice(0, 100), segment); + assertNotEquals(segment.asSlice(10, 90), segment); + assertEquals(segment.asSlice(0, 90), segment); + assertEquals(MemorySegment.ofAddress(segment.address()), segment); MemorySegment segment2 = arena.allocate(100, 1); - assertNotEquals(segment, segment2); + assertNotEquals(segment2, segment); } } @Test public void testEqualsOnHeap() { MemorySegment segment = MemorySegment.ofArray(new byte[100]); - assertEquals(segment, segment.asReadOnly()); - assertEquals(segment, segment.asSlice(0, 100)); - assertNotEquals(segment, segment.asSlice(10, 90)); - assertEquals(segment, segment.asSlice(0, 90)); + assertEquals(segment.asReadOnly(), segment); + assertEquals(segment.asSlice(0, 100), segment); + assertNotEquals(segment.asSlice(10, 90), segment); + assertEquals(segment.asSlice(0, 90), segment); MemorySegment segment2 = MemorySegment.ofArray(new byte[100]); - assertNotEquals(segment, segment2); + assertNotEquals(segment2, segment); } @Test public void testHashCodeOffHeap() { try (Arena arena = Arena.ofConfined()) { MemorySegment segment = arena.allocate(100, 1); - assertEquals(segment.hashCode(), segment.asReadOnly().hashCode()); - assertEquals(segment.hashCode(), segment.asSlice(0, 100).hashCode()); - assertEquals(segment.hashCode(), segment.asSlice(0, 90).hashCode()); - assertEquals(segment.hashCode(), MemorySegment.ofAddress(segment.address()).hashCode()); + assertEquals(segment.asReadOnly().hashCode(), segment.hashCode()); + assertEquals(segment.asSlice(0, 100).hashCode(), segment.hashCode()); + assertEquals(segment.asSlice(0, 90).hashCode(), segment.hashCode()); + assertEquals(MemorySegment.ofAddress(segment.address()).hashCode(), segment.hashCode()); } } @Test public void testHashCodeOnHeap() { MemorySegment segment = MemorySegment.ofArray(new byte[100]); - assertEquals(segment.hashCode(), segment.asReadOnly().hashCode()); - assertEquals(segment.hashCode(), segment.asSlice(0, 100).hashCode()); - assertEquals(segment.hashCode(), segment.asSlice(0, 90).hashCode()); + assertEquals(segment.asReadOnly().hashCode(), segment.hashCode()); + assertEquals(segment.asSlice(0, 100).hashCode(), segment.hashCode()); + assertEquals(segment.asSlice(0, 90).hashCode(), segment.hashCode()); } - @Test(expectedExceptions = IndexOutOfBoundsException.class) + @Test public void testSmallSegmentMax() { long offset = (long)Integer.MAX_VALUE + (long)Integer.MAX_VALUE + 2L + 6L; // overflows to 6 when cast to int Arena scope = Arena.ofAuto(); MemorySegment memorySegment = scope.allocate(10, 1); - memorySegment.get(JAVA_INT, offset); + assertThrows(IndexOutOfBoundsException.class, () -> { + memorySegment.get(JAVA_INT, offset); + }); } - @Test(expectedExceptions = IndexOutOfBoundsException.class) + @Test public void testSmallSegmentMin() { long offset = ((long)Integer.MIN_VALUE * 2L) + 6L; // underflows to 6 when cast to int Arena scope = Arena.ofAuto(); MemorySegment memorySegment = scope.allocate(10L, 1); - memorySegment.get(JAVA_INT, offset); + assertThrows(IndexOutOfBoundsException.class, () -> { + memorySegment.get(JAVA_INT, offset); + }); } @Test @@ -241,13 +252,13 @@ public void testSegmentSliceOOBMessage() { } } - @Test(dataProvider = "segmentFactories") + @ParameterizedTest + @MethodSource("segmentFactories") public void testAccessModesOfFactories(Supplier segmentSupplier) { MemorySegment segment = segmentSupplier.get(); assertFalse(segment.isReadOnly()); } - @DataProvider(name = "scopes") public Object[][] scopes() { return new Object[][] { { Arena.ofAuto(), false }, @@ -257,14 +268,16 @@ public Object[][] scopes() { }; } - @Test(dataProvider = "scopes") + @ParameterizedTest(autoCloseArguments = false) + @MethodSource("scopes") public void testIsAccessibleBy(Arena arena, boolean isConfined) { MemorySegment segment = MemorySegment.NULL.reinterpret(arena, null); assertTrue(segment.isAccessibleBy(Thread.currentThread())); assertTrue(segment.isAccessibleBy(new Thread()) != isConfined); } - @Test(dataProvider = "segmentFactories") + @ParameterizedTest + @MethodSource("segmentFactories") public void testToString(Supplier segmentSupplier) { var segment = segmentSupplier.get(); String s = segment.toString(); @@ -281,7 +294,6 @@ public void testToString(Supplier segmentSupplier) { assertFalse(s.contains("Optional")); } - @DataProvider(name = "segmentFactories") public Object[][] segmentFactories() { List> l = List.of( () -> MemorySegment.ofArray(new byte[] { 0x00, 0x01, 0x02, 0x03 }), @@ -302,7 +314,8 @@ public Object[][] segmentFactories() { return l.stream().map(s -> new Object[] { s }).toArray(Object[][]::new); } - @Test(dataProvider = "segmentFactories") + @ParameterizedTest + @MethodSource("segmentFactories") public void testFill(Supplier segmentSupplier) { VarHandle byteHandle = ValueLayout.JAVA_BYTE.varHandle(); @@ -310,27 +323,28 @@ public void testFill(Supplier segmentSupplier) { MemorySegment segment = segmentSupplier.get(); segment.fill(value); for (long l = 0; l < segment.byteSize(); l++) { - assertEquals((byte) byteHandle.get(segment, l), value); + assertEquals(value, (byte) byteHandle.get(segment, l)); } // fill a slice var sliceSegment = segment.asSlice(1, segment.byteSize() - 2).fill((byte) ~value); for (long l = 0; l < sliceSegment.byteSize(); l++) { - assertEquals((byte) byteHandle.get(sliceSegment, l), ~value); + assertEquals(~value, (byte) byteHandle.get(sliceSegment, l)); } // assert enclosing slice - assertEquals((byte) byteHandle.get(segment, 0L), value); + assertEquals(value, (byte) byteHandle.get(segment, 0L)); for (long l = 1; l < segment.byteSize() - 2; l++) { - assertEquals((byte) byteHandle.get(segment, l), (byte) ~value); + assertEquals((byte) ~value, (byte) byteHandle.get(segment, l)); } - assertEquals((byte) byteHandle.get(segment, segment.byteSize() - 1L), value); + assertEquals(value, (byte) byteHandle.get(segment, segment.byteSize() - 1L)); } } - @Test(dataProvider = "segmentFactories") + @ParameterizedTest + @MethodSource("segmentFactories") public void testHeapBase(Supplier segmentSupplier) { MemorySegment segment = segmentSupplier.get(); - assertEquals(segment.isNative(), !segment.heapBase().isPresent()); + assertEquals(!segment.heapBase().isPresent(), segment.isNative()); segment = segment.asReadOnly(); assertTrue(segment.heapBase().isEmpty()); } @@ -339,7 +353,7 @@ public void testHeapBase(Supplier segmentSupplier) { public void testScopeConfinedArena() { try (Arena arena = Arena.ofConfined()) { MemorySegment segment = arena.allocate(100); - assertEquals(segment.scope(), arena.scope()); + assertEquals(arena.scope(), segment.scope()); } } @@ -347,7 +361,7 @@ public void testScopeConfinedArena() { public void testScopeSharedArena() { try (Arena arena = Arena.ofShared()) { MemorySegment segment = arena.allocate(100); - assertEquals(segment.scope(), arena.scope()); + assertEquals(arena.scope(), segment.scope()); } } @@ -355,29 +369,36 @@ public void testScopeSharedArena() { public void testScopeAutoArena() { Arena arena = Arena.ofAuto(); MemorySegment segment = arena.allocate(100); - assertEquals(segment.scope(), arena.scope()); + assertEquals(arena.scope(), segment.scope()); } @Test public void testScopeGlobalArena() { Arena arena = Arena.global(); MemorySegment segment = arena.allocate(100); - assertEquals(segment.scope(), arena.scope()); + assertEquals(arena.scope(), segment.scope()); } - @Test(dataProvider = "segmentFactories", expectedExceptions = IllegalArgumentException.class) + @ParameterizedTest + @MethodSource("segmentFactories") public void testFillIllegalAccessMode(Supplier segmentSupplier) { MemorySegment segment = segmentSupplier.get(); - segment.asReadOnly().fill((byte) 0xFF); + assertThrows(IllegalArgumentException.class, () -> { + segment.asReadOnly().fill((byte) 0xFF); + }); } - @Test(dataProvider = "segmentFactories", expectedExceptions = IllegalArgumentException.class) + @ParameterizedTest + @MethodSource("segmentFactories") public void testFromStringIllegalAccessMode(Supplier segmentSupplier) { MemorySegment segment = segmentSupplier.get(); - segment.asReadOnly().setString(0, "a"); + assertThrows(IllegalArgumentException.class, () -> { + segment.asReadOnly().setString(0, "a"); + }); } - @Test(dataProvider = "segmentFactories") + @ParameterizedTest + @MethodSource("segmentFactories") public void testFillThread(Supplier segmentSupplier) throws Exception { MemorySegment segment = segmentSupplier.get(); AtomicReference exception = new AtomicReference<>(); @@ -407,12 +428,13 @@ public void testFillEmpty() { MemorySegment.ofBuffer(ByteBuffer.allocateDirect(0)).fill((byte) 0xFF); } - @Test(dataProvider = "heapFactories") + @ParameterizedTest + @MethodSource("heapFactories") public void testVirtualizedBaseAddress(IntFunction heapSegmentFactory, int factor) { MemorySegment segment = heapSegmentFactory.apply(10); - assertEquals(segment.address(), 0); // base address should be zero (no leaking of impl details) + assertEquals(0, segment.address()); // base address should be zero (no leaking of impl details) MemorySegment end = segment.asSlice(segment.byteSize(), 0); - assertEquals(end.address(), segment.byteSize()); // end address should be equal to segment byte size + assertEquals(segment.byteSize(), end.address()); // end address should be equal to segment byte size } @Test @@ -420,18 +442,18 @@ void testReinterpret() { AtomicInteger counter = new AtomicInteger(); try (Arena arena = Arena.ofConfined()){ // check size - assertEquals(MemorySegment.ofAddress(42).reinterpret(100).byteSize(), 100); - assertEquals(MemorySegment.ofAddress(42).reinterpret(100, Arena.ofAuto(), null).byteSize(), 100); + assertEquals(100, MemorySegment.ofAddress(42).reinterpret(100).byteSize()); + assertEquals(100, MemorySegment.ofAddress(42).reinterpret(100, Arena.ofAuto(), null).byteSize()); // check scope and cleanup - assertEquals(MemorySegment.ofAddress(42).reinterpret(100, arena, s -> counter.incrementAndGet()).scope(), arena.scope()); - assertEquals(MemorySegment.ofAddress(42).reinterpret(arena, _ -> counter.incrementAndGet()).scope(), arena.scope()); + assertEquals(arena.scope(), MemorySegment.ofAddress(42).reinterpret(100, arena, s -> counter.incrementAndGet()).scope()); + assertEquals(arena.scope(), MemorySegment.ofAddress(42).reinterpret(arena, _ -> counter.incrementAndGet()).scope()); // check read-only state assertFalse(MemorySegment.ofAddress(42).reinterpret(100).isReadOnly()); assertTrue(MemorySegment.ofAddress(42).asReadOnly().reinterpret(100).isReadOnly()); assertTrue(MemorySegment.ofAddress(42).asReadOnly().reinterpret(100, Arena.ofAuto(), null).isReadOnly()); assertTrue(MemorySegment.ofAddress(42).asReadOnly().reinterpret(arena, _ -> counter.incrementAndGet()).isReadOnly()); } - assertEquals(counter.get(), 3); + assertEquals(3, counter.get()); } @Test @@ -477,8 +499,8 @@ void testThrowInCleanup() { thrown = ex; } assertNotNull(thrown); - assertEquals(counter.get(), 1); - assertEquals(thrown.getSuppressed().length, 19); + assertEquals(1, counter.get()); + assertEquals(19, thrown.getSuppressed().length); Throwable[] errors = new IllegalArgumentException[20]; assertTrue(thrown instanceof IllegalArgumentException); errors[0] = thrown; @@ -512,12 +534,11 @@ void testThrowInCleanupSame() { } catch (RuntimeException ex) { thrown = ex; } - assertEquals(thrown, iae); - assertEquals(counter.get(), 1); - assertEquals(thrown.getSuppressed().length, 0); + assertEquals(iae, thrown); + assertEquals(1, counter.get()); + assertEquals(0, thrown.getSuppressed().length); } - @DataProvider(name = "badSizeAndAlignments") public Object[][] sizesAndAlignments() { return new Object[][] { { -1, 8 }, @@ -526,7 +547,6 @@ public Object[][] sizesAndAlignments() { }; } - @DataProvider(name = "heapFactories") public Object[][] heapFactories() { return new Object[][] { { (IntFunction) size -> MemorySegment.ofArray(new byte[size]), 1 }, diff --git a/test/jdk/java/foreign/TestSharedAccess.java b/test/jdk/java/foreign/TestSharedAccess.java index 9823f6f0bbfb0..5ea9fdbdb284e 100644 --- a/test/jdk/java/foreign/TestSharedAccess.java +++ b/test/jdk/java/foreign/TestSharedAccess.java @@ -24,7 +24,7 @@ /* * @test - * @run testng/othervm --enable-native-access=ALL-UNNAMED TestSharedAccess + * @run junit/othervm --enable-native-access=ALL-UNNAMED TestSharedAccess */ import java.lang.foreign.*; @@ -37,9 +37,8 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicInteger; -import org.testng.annotations.*; - -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class TestSharedAccess { @@ -74,7 +73,7 @@ public void testShared() throws Throwable { for (Spliterator spliterator : spliterators) { threads.add(new Thread(() -> { spliterator.tryAdvance(local -> { - assertEquals(getInt(local), 42); + assertEquals(42, getInt(local)); accessCount.incrementAndGet(); }); })); @@ -87,7 +86,7 @@ public void testShared() throws Throwable { throw new IllegalStateException(e); } }); - assertEquals(accessCount.get(), 1024); + assertEquals(1024, accessCount.get()); } } @@ -96,11 +95,11 @@ public void testSharedUnsafe() throws Throwable { try (Arena arena = Arena.ofShared()) { MemorySegment s = arena.allocate(4, 1);; setInt(s, 42); - assertEquals(getInt(s), 42); + assertEquals(42, getInt(s)); List threads = new ArrayList<>(); for (int i = 0 ; i < 1000 ; i++) { threads.add(new Thread(() -> { - assertEquals(getInt(s), 42); + assertEquals(42, getInt(s)); })); } threads.forEach(Thread::start); diff --git a/test/jdk/java/foreign/TestSlices.java b/test/jdk/java/foreign/TestSlices.java index 88fe98cc847ec..fad121b7e2b8a 100644 --- a/test/jdk/java/foreign/TestSlices.java +++ b/test/jdk/java/foreign/TestSlices.java @@ -30,13 +30,17 @@ import java.util.ArrayList; import java.util.List; -import org.testng.annotations.*; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; /* * @test - * @run testng/othervm -Xverify:all TestSlices + * @run junit/othervm -Xverify:all TestSlices */ +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestSlices { static MemoryLayout LAYOUT = MemoryLayout.sequenceLayout(2, @@ -45,7 +49,8 @@ public class TestSlices { static VarHandle VH_ALL = LAYOUT.varHandle( MemoryLayout.PathElement.sequenceElement(), MemoryLayout.PathElement.sequenceElement()); - @Test(dataProvider = "slices") + @ParameterizedTest + @MethodSource("slices") public void testSlices(VarHandle handle, int lo, int hi, int[] values) { try (Arena arena = Arena.ofConfined()) { MemorySegment segment = arena.allocate(LAYOUT);; @@ -60,12 +65,13 @@ public void testSlices(VarHandle handle, int lo, int hi, int[] values) { } } - @Test(dataProvider = "slices") + @ParameterizedTest + @MethodSource("slices") public void testSliceBadIndex(VarHandle handle, int lo, int hi, int[] values) { try (Arena arena = Arena.ofConfined()) { MemorySegment segment = arena.allocate(LAYOUT);; - assertThrows(() -> handle.get(segment, 0L, lo, 0)); - assertThrows(() -> handle.get(segment, 0L, 0, hi)); + assertThrows(Throwable.class, () -> handle.get(segment, 0L, lo, 0)); + assertThrows(Throwable.class, () -> handle.get(segment, 0L, 0, hi)); } } @@ -74,54 +80,71 @@ static void checkSlice(MemorySegment segment, VarHandle handle, long i_max, long for (long i = 0 ; i < i_max ; i++) { for (long j = 0 ; j < j_max ; j++) { int x = (int) handle.get(segment, 0L, i, j); - assertEquals(x, values[index++]); + assertEquals(values[index++], x); } } - assertEquals(index, values.length); + assertEquals(values.length, index); } - @Test(expectedExceptions = IndexOutOfBoundsException.class) + @Test public void testSliceNegativeOffset() { - MemorySegment.ofArray(new byte[100]).asSlice(-1); + assertThrows(IndexOutOfBoundsException.class, () -> { + MemorySegment.ofArray(new byte[100]).asSlice(-1); + }); } - @Test(expectedExceptions = IndexOutOfBoundsException.class) + @Test public void testSliceNegativeOffsetGoodSize() { - MemorySegment.ofArray(new byte[100]).asSlice(-1, 10); + assertThrows(IndexOutOfBoundsException.class, () -> { + MemorySegment.ofArray(new byte[100]).asSlice(-1, 10); + }); } - @Test(expectedExceptions = IndexOutOfBoundsException.class) + @Test public void testSliceGoodOffsetNegativeSize() { - MemorySegment.ofArray(new byte[100]).asSlice(10, -1); + assertThrows(IndexOutOfBoundsException.class, () -> { + MemorySegment.ofArray(new byte[100]).asSlice(10, -1); + }); } - @Test(expectedExceptions = IndexOutOfBoundsException.class) + @Test public void testSliceNegativeOffsetGoodLayout() { - MemorySegment.ofArray(new byte[100]).asSlice(-1, ValueLayout.JAVA_INT); + assertThrows(IndexOutOfBoundsException.class, () -> { + MemorySegment.ofArray(new byte[100]).asSlice(-1, ValueLayout.JAVA_INT); + }); } - @Test(expectedExceptions = IndexOutOfBoundsException.class) + @Test public void testSliceOffsetTooBig() { - MemorySegment.ofArray(new byte[100]).asSlice(120); + assertThrows(IndexOutOfBoundsException.class, () -> { + MemorySegment.ofArray(new byte[100]).asSlice(120); + }); } - @Test(expectedExceptions = IndexOutOfBoundsException.class) + @Test public void testSliceOffsetTooBigSizeGood() { - MemorySegment.ofArray(new byte[100]).asSlice(120, 0); + assertThrows(IndexOutOfBoundsException.class, () -> { + MemorySegment.ofArray(new byte[100]).asSlice(120, 0); + }); } - @Test(expectedExceptions = IndexOutOfBoundsException.class) + @Test public void testSliceOffsetOkSizeTooBig() { - MemorySegment.ofArray(new byte[100]).asSlice(0, 120); + assertThrows(IndexOutOfBoundsException.class, () -> { + MemorySegment.ofArray(new byte[100]).asSlice(0, 120); + }); } - @Test(expectedExceptions = IndexOutOfBoundsException.class) + @Test public void testSliceLayoutTooBig() { - MemorySegment.ofArray(new byte[100]) - .asSlice(0, MemoryLayout.sequenceLayout(120, ValueLayout.JAVA_BYTE)); + assertThrows(IndexOutOfBoundsException.class, () -> { + MemorySegment.ofArray(new byte[100]) + .asSlice(0, MemoryLayout.sequenceLayout(120, ValueLayout.JAVA_BYTE)); + }); } - @Test(dataProvider = "segmentsAndLayouts") + @ParameterizedTest + @MethodSource("segmentsAndLayouts") public void testSliceAlignment(MemorySegment segment, long alignment, ValueLayout layout) { boolean badAlign = layout.byteAlignment() > alignment; try { @@ -149,7 +172,6 @@ public void testSliceAlignmentPowerOfTwo() { } } - @DataProvider(name = "slices") static Object[][] slices() { return new Object[][] { // x @@ -169,7 +191,6 @@ static Object[][] slices() { }; } - @DataProvider(name = "segmentsAndLayouts") static Object[][] segmentsAndLayouts() { List segmentsAndLayouts = new ArrayList<>(); for (SegmentKind sk : SegmentKind.values()) { diff --git a/test/jdk/java/foreign/TestSpliterator.java b/test/jdk/java/foreign/TestSpliterator.java index 285e8ab27ea0e..937c38c3670ef 100644 --- a/test/jdk/java/foreign/TestSpliterator.java +++ b/test/jdk/java/foreign/TestSpliterator.java @@ -23,7 +23,7 @@ /* * @test - * @run testng TestSpliterator + * @run junit TestSpliterator */ import java.lang.foreign.*; @@ -35,15 +35,19 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.stream.LongStream; -import org.testng.annotations.*; - -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestSpliterator { final static int CARRIER_SIZE = 4; - @Test(dataProvider = "splits") + @ParameterizedTest + @MethodSource("splits") public void testSum(int size, int threshold) { SequenceLayout layout = MemoryLayout.sequenceLayout(size, ValueLayout.JAVA_INT); @@ -56,17 +60,17 @@ public void testSum(int size, int threshold) { long expected = LongStream.range(0, layout.elementCount()).sum(); //serial long serial = sum(0, segment); - assertEquals(serial, expected); + assertEquals(expected, serial); //parallel counted completer long parallelCounted = new SumSegmentCounted(null, segment.spliterator(layout.elementLayout()), threshold).invoke(); - assertEquals(parallelCounted, expected); + assertEquals(expected, parallelCounted); //parallel recursive action long parallelRecursive = new SumSegmentRecursive(segment.spliterator(layout.elementLayout()), threshold).invoke(); - assertEquals(parallelRecursive, expected); + assertEquals(expected, parallelRecursive); //parallel stream long streamParallel = segment.elements(layout.elementLayout()).parallel() .reduce(0L, TestSpliterator::sumSingle, Long::sum); - assertEquals(streamParallel, expected); + assertEquals(expected, streamParallel); } } @@ -86,35 +90,39 @@ public void testSumSameThread() { AtomicLong spliteratorSum = new AtomicLong(); segment.spliterator(layout.elementLayout()) .forEachRemaining(s -> spliteratorSum.addAndGet(sumSingle(0L, s))); - assertEquals(spliteratorSum.get(), expected); + assertEquals(expected, spliteratorSum.get()); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadSpliteratorElementSizeTooBig() { - Arena scope = Arena.ofAuto(); - scope.allocate(2, 1) - .spliterator(ValueLayout.JAVA_INT); + MemorySegment segment = Arena.ofAuto().allocate(2, 1); + assertThrows(IllegalArgumentException.class, () -> { + segment.spliterator(ValueLayout.JAVA_INT); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadStreamElementSizeTooBig() { - Arena scope = Arena.ofAuto(); - scope.allocate(2, 1) - .elements(ValueLayout.JAVA_INT); + MemorySegment segment = Arena.ofAuto().allocate(2, 1); + assertThrows(IllegalArgumentException.class, () -> { + segment.elements(ValueLayout.JAVA_INT); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadSpliteratorElementSizeNotMultiple() { - Arena scope = Arena.ofAuto(); - scope.allocate(7, 1) - .spliterator(ValueLayout.JAVA_INT); + MemorySegment segment = Arena.ofAuto().allocate(7, 1); + assertThrows(IllegalArgumentException.class, () -> { + segment.spliterator(ValueLayout.JAVA_INT); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadStreamElementSizeNotMultiple() { - Arena scope = Arena.ofAuto(); - scope.allocate(7, 1) - .elements(ValueLayout.JAVA_INT); + MemorySegment segment = Arena.ofAuto().allocate(7, 1); + assertThrows(IllegalArgumentException.class, () -> { + segment.elements(ValueLayout.JAVA_INT); + }); } @Test @@ -131,18 +139,20 @@ public void testStreamElementSizeMultipleButNotPowerOfTwo() { .elements(ValueLayout.JAVA_INT); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadSpliteratorElementSizeZero() { - Arena scope = Arena.ofAuto(); - scope.allocate(7, 1) - .spliterator(MemoryLayout.sequenceLayout(0, ValueLayout.JAVA_INT)); + MemorySegment segment = Arena.ofAuto().allocate(7, 1); + assertThrows(IllegalArgumentException.class, () -> { + segment.spliterator(MemoryLayout.sequenceLayout(0, ValueLayout.JAVA_INT)); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testBadStreamElementSizeZero() { - Arena scope = Arena.ofAuto(); - scope.allocate(7, 1) - .elements(MemoryLayout.sequenceLayout(0, ValueLayout.JAVA_INT)); + MemorySegment segment = Arena.ofAuto().allocate(7, 1); + assertThrows(IllegalArgumentException.class, () -> { + segment.elements(MemoryLayout.sequenceLayout(0, ValueLayout.JAVA_INT)); + }); } @Test @@ -155,9 +165,9 @@ public void testHyperAligned() { Collections.nCopies(Math.toIntExact(bigByteAlign), ValueLayout.JAVA_BYTE).toArray(MemoryLayout[]::new)) .withByteAlignment(bigByteAlign); SequenceLayout layout = MemoryLayout.sequenceLayout(2, elementLayout); - IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, + IllegalArgumentException iae = assertThrows(IllegalArgumentException.class, () -> segment.elements(layout)); - assertEquals(iae.getMessage(), "Incompatible alignment constraints"); + assertEquals("Incompatible alignment constraints", iae.getMessage()); } static long sumSingle(long acc, MemorySegment segment) { @@ -239,7 +249,6 @@ protected Long compute() { } } - @DataProvider(name = "splits") public Object[][] splits() { return new Object[][] { { 10, 1 }, diff --git a/test/jdk/java/foreign/TestStringEncoding.java b/test/jdk/java/foreign/TestStringEncoding.java index e9e47420a6844..38418e2bd7004 100644 --- a/test/jdk/java/foreign/TestStringEncoding.java +++ b/test/jdk/java/foreign/TestStringEncoding.java @@ -42,17 +42,22 @@ import jdk.internal.foreign.AbstractMemorySegmentImpl; import jdk.internal.foreign.StringSupport; -import org.testng.annotations.*; import static java.lang.foreign.ValueLayout.*; -import static org.testng.Assert.*; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; /* * @test * @modules java.base/jdk.internal.foreign - * @run testng TestStringEncoding + * @run junit TestStringEncoding */ +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestStringEncoding { @Test @@ -61,7 +66,7 @@ public void emptySegment() { for (Arena arena : arenas()) { try (arena) { var segment = arena.allocate(0); - var e = expectThrows(IndexOutOfBoundsException.class, () -> + var e = assertThrows(IndexOutOfBoundsException.class, () -> segment.getString(0, charset)); assertTrue(e.getMessage().contains("No null terminator found")); } @@ -69,7 +74,8 @@ public void emptySegment() { } } - @Test(dataProvider = "strings") + @ParameterizedTest + @MethodSource("strings") public void testStrings(String testString) { for (Charset charset : Charset.availableCharsets().values()) { if (isStandard(charset)) { @@ -89,11 +95,11 @@ public void testStrings(String testString) { testString.getBytes(charset).length + terminatorSize; - assertEquals(text.byteSize(), expectedByteLength); + assertEquals(expectedByteLength, text.byteSize()); String roundTrip = text.getString(0, charset); if (charset.newEncoder().canEncode(testString)) { - assertEquals(roundTrip, testString); + assertEquals(testString, roundTrip); } } } @@ -103,7 +109,8 @@ public void testStrings(String testString) { } } - @Test(dataProvider = "strings") + @ParameterizedTest + @MethodSource("strings") public void testStringsLength(String testString) { if (!testString.isEmpty()) { for (Charset charset : Charset.availableCharsets().values()) { @@ -112,10 +119,10 @@ public void testStringsLength(String testString) { try (arena) { MemorySegment text = arena.allocateFrom(testString, charset, 0, testString.length()); long length = text.byteSize(); - assertEquals(length, testString.getBytes(charset).length); + assertEquals(testString.getBytes(charset).length, length); String roundTrip = text.getString(0, charset, length); if (charset.newEncoder().canEncode(testString)) { - assertEquals(roundTrip, testString); + assertEquals(testString, roundTrip); } } } @@ -124,7 +131,8 @@ public void testStringsLength(String testString) { } } - @Test(dataProvider = "strings") + @ParameterizedTest + @MethodSource("strings") public void testStringsCopy(String testString) { if (!testString.isEmpty()) { for (Charset charset : Charset.availableCharsets().values()) { @@ -136,7 +144,7 @@ public void testStringsCopy(String testString) { MemorySegment.copy(testString, charset, 0, text, 0, testString.length()); String roundTrip = text.getString(0, charset, bytes.length); if (charset.newEncoder().canEncode(testString)) { - assertEquals(roundTrip, testString); + assertEquals(testString, roundTrip); } } } @@ -237,7 +245,8 @@ public void testGetStringThrows() { } } - @Test(dataProvider = "strings") + @ParameterizedTest + @MethodSource("strings") public void testStringsHeap(String testString) { for (Charset charset : singleByteCharsets()) { for (var arena : arenas()) { @@ -248,11 +257,11 @@ public void testStringsHeap(String testString) { int expectedByteLength = testString.getBytes(charset).length + 1; - assertEquals(text.byteSize(), expectedByteLength); + assertEquals(expectedByteLength, text.byteSize()); String roundTrip = text.getString(0, charset); if (charset.newEncoder().canEncode(testString)) { - assertEquals(roundTrip, testString); + assertEquals(testString, roundTrip); } } } @@ -264,7 +273,8 @@ MemorySegment toHeapSegment(MemorySegment segment) { return MemorySegment.ofArray(heapArray); } - @Test(dataProvider = "strings") + @ParameterizedTest + @MethodSource("strings") public void unboundedSegment(String testString) { testModifyingSegment(testString, standardCharsets(), @@ -272,7 +282,8 @@ public void unboundedSegment(String testString) { UnaryOperator.identity()); } - @Test(dataProvider = "strings") + @ParameterizedTest + @MethodSource("strings") public void unalignedSegmentSingleByte(String testString) { testModifyingSegment(testString, singleByteCharsets(), @@ -280,7 +291,8 @@ public void unalignedSegmentSingleByte(String testString) { s -> s.length() > 0 ? s.substring(1) : s); } - @Test(dataProvider = "strings") + @ParameterizedTest + @MethodSource("strings") public void expandedSegment(String testString) { try (var arena = Arena.ofConfined()) { for (int i = 0; i < Long.BYTES; i++) { @@ -309,7 +321,7 @@ public void testModifyingSegment(String testString, String roundTrip = text.getString(0, charset); String expected = stringMapper.apply(testString); if (charset.newEncoder().canEncode(testString)) { - assertEquals(roundTrip, expected); + assertEquals(expected, roundTrip); } } } @@ -330,14 +342,15 @@ public void testPeculiarContentSingleByte() { for (Charset charset : singleByteCharsets()) { var s = segment.getString(0, charset); var ref = referenceImpl(segment, 0, charset); - assertEquals(s, ref); + assertEquals(ref, s); } } } } } - @Test(dataProvider = "strings") + @ParameterizedTest + @MethodSource("strings") public void testOffset(String testString) { if (testString.length() < 3 || !containsOnlyRegularCharacters(testString)) { return; @@ -349,14 +362,15 @@ public void testOffset(String testString) { for (int i = 0; i < 3; i++) { String expected = testString.substring(i); String actual = inSegment.getString(i, charset); - assertEquals(actual, expected); + assertEquals(expected, actual); } } } } } - @Test(dataProvider = "strings") + @ParameterizedTest + @MethodSource("strings") public void testSubstringGetString(String testString) { if (testString.length() < 3 || !containsOnlyRegularCharacters(testString)) { return; @@ -370,7 +384,7 @@ public void testSubstringGetString(String testString) { // this test assumes single-byte charsets String roundTrip = text.getString(srcIndex, charset, numChars); String substring = testString.substring(srcIndex, srcIndex + numChars); - assertEquals(roundTrip, substring); + assertEquals(substring, roundTrip); } } } @@ -378,7 +392,8 @@ public void testSubstringGetString(String testString) { } } - @Test(dataProvider = "strings") + @ParameterizedTest + @MethodSource("strings") public void testSubstringAllocate(String testString) { if (testString.length() < 3 || !containsOnlyRegularCharacters(testString)) { return; @@ -390,9 +405,9 @@ public void testSubstringAllocate(String testString) { for (int numChars = 0; numChars <= testString.length() - srcIndex; numChars++) { MemorySegment text = arena.allocateFrom(testString, charset, srcIndex, numChars); String substring = testString.substring(srcIndex, srcIndex + numChars); - assertEquals(text.byteSize(), substring.getBytes(charset).length); + assertEquals(substring.getBytes(charset).length, text.byteSize()); String roundTrip = text.getString(0, charset, text.byteSize()); - assertEquals(roundTrip, substring); + assertEquals(substring, roundTrip); } } } @@ -400,7 +415,8 @@ public void testSubstringAllocate(String testString) { } } - @Test(dataProvider = "strings") + @ParameterizedTest + @MethodSource("strings") public void testSubstringCopy(String testString) { if (testString.length() < 3 || !containsOnlyRegularCharacters(testString)) { return; @@ -415,8 +431,8 @@ public void testSubstringCopy(String testString) { MemorySegment text = arena.allocate(JAVA_BYTE, length); long copied = MemorySegment.copy(testString, charset, srcIndex, text, 0, numChars); String roundTrip = text.getString(0, charset, length); - assertEquals(roundTrip, substring); - assertEquals(copied, length); + assertEquals(substring, roundTrip); + assertEquals(length, copied); } } } @@ -431,7 +447,8 @@ public void testSubstringCopy(String testString) { LINKER.defaultLookup().find("strcat").orElseThrow(), FunctionDescriptor.of(CHAR_POINTER, CHAR_POINTER, CHAR_POINTER)); - @Test(dataProvider = "strings") + @ParameterizedTest + @MethodSource("strings") public void nativeSegFromNativeCall(String testString) { String addition = "123"; try (var arena = Arena.ofConfined()) { @@ -443,7 +460,7 @@ public void nativeSegFromNativeCall(String testString) { MemorySegment concatenation = (MemorySegment) STRCAT.invokeExact(destination, arena.allocateFrom(addition)); var actual = concatenation.getString(0); - assertEquals(actual, testString + addition); + assertEquals(testString + addition, actual); } catch (Throwable t) { throw new AssertionError(t); } @@ -469,7 +486,8 @@ public void segmentationFault() { // This test ensures that we do not address outside the segment even though there // are odd bytes at the end. - @Test(dataProvider = "strings") + @ParameterizedTest + @MethodSource("strings") public void offBoundaryTrailingBytes(String testString) { if (testString.length() < 3 || !containsOnlyRegularCharacters(testString)) { return; @@ -485,7 +503,7 @@ public void offBoundaryTrailingBytes(String testString) { inSegment.fill((byte) 1); for (int i = 0; i < 4; i++) { final int offset = i; - var e = expectThrows(IndexOutOfBoundsException.class, () -> inSegment.getString(offset, charset)); + var e = assertThrows(IndexOutOfBoundsException.class, () -> inSegment.getString(offset, charset)); assertTrue(e.getMessage().contains("No null terminator found")); } } @@ -516,12 +534,12 @@ public void chunked_strlen_byte() { segment.setAtIndex(JAVA_BYTE, len, (byte) 0); for (int j = 0; j < len; j++) { int actual = StringSupport.strlenByte((AbstractMemorySegmentImpl) segment, j, segment.byteSize()); - assertEquals(actual, len - j); + assertEquals(len - j, actual); } // Test end offset for (int j = 0; j < len - 1; j++) { final long toOffset = j; - expectThrows(IndexOutOfBoundsException.class, () -> + assertThrows(IndexOutOfBoundsException.class, () -> StringSupport.strlenByte((AbstractMemorySegmentImpl) segment, 0, toOffset)); } } @@ -546,7 +564,7 @@ public void chunked_strlen_short() { segment.setAtIndex(JAVA_SHORT, len, (short) 0); for (int j = 0; j < len; j++) { int actual = StringSupport.strlenShort((AbstractMemorySegmentImpl) segment, j * Short.BYTES, segment.byteSize()); - assertEquals(actual, (len - j) * Short.BYTES); + assertEquals((len - j) * Short.BYTES, actual); } } } @@ -570,35 +588,37 @@ public void strlen_int() { segment.setAtIndex(JAVA_INT, len, 0); for (int j = 0; j < len; j++) { int actual = StringSupport.strlenInt((AbstractMemorySegmentImpl) segment, j * Integer.BYTES, segment.byteSize()); - assertEquals(actual, (len - j) * Integer.BYTES); + assertEquals((len - j) * Integer.BYTES, actual); } } } } } - @Test(dataProvider = "charsetsAndSegments") + @ParameterizedTest + @MethodSource("charsetsAndSegments") public void testStringGetWithCharset(Charset charset, MemorySegment segment) { for (int offset = 0 ; offset < Long.BYTES ; offset++) { segment.getString(offset, charset); } } - @Test(dataProvider = "charsetsAndSegments") + @ParameterizedTest + @MethodSource("charsetsAndSegments") public void testStringSetWithCharset(Charset charset, MemorySegment segment) { for (int offset = 0 ; offset < Long.BYTES ; offset++) { segment.setString(offset, "H", charset); } } - @Test(dataProvider = "charsetsAndSegments") + @ParameterizedTest + @MethodSource("charsetsAndSegments") public void testStringAllocateFromWithCharset(Charset charset, MemorySegment segment) { for (int offset = 0 ; offset < Long.BYTES ; offset++) { SegmentAllocator.prefixAllocator(segment.asSlice(offset)).allocateFrom("H", charset); } } - @DataProvider public static Object[][] strings() { return new Object[][]{ {"testing"}, @@ -733,7 +753,6 @@ static MemorySegment[] heapSegments() { }; } - @DataProvider public static Object[][] charsetsAndSegments() { List values = new ArrayList<>(); for (Charset charset : standardCharsets()) { diff --git a/test/jdk/java/foreign/TestStringEncodingJumbo.java b/test/jdk/java/foreign/TestStringEncodingJumbo.java index bdae83bbd8b30..49d1396ba89dc 100644 --- a/test/jdk/java/foreign/TestStringEncodingJumbo.java +++ b/test/jdk/java/foreign/TestStringEncodingJumbo.java @@ -21,7 +21,6 @@ * questions. */ -import org.testng.annotations.*; import java.io.IOException; import java.io.RandomAccessFile; @@ -34,7 +33,9 @@ import java.util.function.Consumer; import static java.lang.foreign.ValueLayout.*; -import static org.testng.Assert.*; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; /* * @test @@ -42,7 +43,7 @@ * @requires sun.arch.data.model == "64" * @requires vm.flavor != "zero" * - * @run testng/othervm/timeout=480 -Xmx6G TestStringEncodingJumbo + * @run junit/othervm/timeout=480 -Xmx6G TestStringEncodingJumbo */ public class TestStringEncodingJumbo { @@ -53,7 +54,7 @@ public void testJumboSegment() { segment.fill((byte) 1); segment.set(JAVA_BYTE, Integer.MAX_VALUE + 10L, (byte) 0); String big = segment.getString(100); - assertEquals(big.length(), Integer.MAX_VALUE - (100 - 10)); + assertEquals(Integer.MAX_VALUE - (100 - 10), big.length()); }); } diff --git a/test/jdk/java/foreign/TestStubAllocFailure.java b/test/jdk/java/foreign/TestStubAllocFailure.java index 8cd4a61626e71..c378600e95659 100644 --- a/test/jdk/java/foreign/TestStubAllocFailure.java +++ b/test/jdk/java/foreign/TestStubAllocFailure.java @@ -26,7 +26,7 @@ * @library ../ /test/lib * @requires jdk.foreign.linker != "FALLBACK" * @requires vm.compMode != "Xcomp" - * @run testng/othervm/native/timeout=480 + * @run junit/othervm/native/timeout=480 * --enable-native-access=ALL-UNNAMED * TestStubAllocFailure */ @@ -39,9 +39,8 @@ import java.util.function.Consumer; import java.util.stream.Stream; -import org.testng.annotations.Test; - -import static org.testng.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; +import org.junit.jupiter.api.Test; public class TestStubAllocFailure extends UpcallTestHelper { diff --git a/test/jdk/java/foreign/TestTypeAccess.java b/test/jdk/java/foreign/TestTypeAccess.java index 13d3eaf0c0f02..a3c32c78c87c8 100644 --- a/test/jdk/java/foreign/TestTypeAccess.java +++ b/test/jdk/java/foreign/TestTypeAccess.java @@ -24,61 +24,75 @@ /* * @test - * @run testng TestTypeAccess + * @run junit TestTypeAccess */ import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; import java.lang.foreign.ValueLayout; -import org.testng.annotations.*; import java.lang.invoke.VarHandle; import java.lang.invoke.WrongMethodTypeException; +import static org.junit.jupiter.api.Assertions.assertThrows; +import org.junit.jupiter.api.Test; + public class TestTypeAccess { static final VarHandle INT_HANDLE = ValueLayout.JAVA_INT.varHandle(); static final VarHandle ADDR_HANDLE = ValueLayout.ADDRESS.varHandle(); - @Test(expectedExceptions=ClassCastException.class) + @Test public void testMemoryAddressCoordinateAsString() { - int v = (int)INT_HANDLE.get("string", 0L); + assertThrows(ClassCastException.class, () -> { + int v = (int)INT_HANDLE.get("string", 0L); + }); } - @Test(expectedExceptions=WrongMethodTypeException.class) + @Test public void testMemoryCoordinatePrimitive() { - int v = (int)INT_HANDLE.get(1); + assertThrows(WrongMethodTypeException.class, () -> { + int v = (int)INT_HANDLE.get(1); + }); } - @Test(expectedExceptions=ClassCastException.class) + @Test public void testMemoryAddressValueGetAsString() { try (Arena arena = Arena.ofConfined()) { MemorySegment s = arena.allocate(8, 8); - String address = (String)ADDR_HANDLE.get(s, 0L); + assertThrows(ClassCastException.class, () -> { + String address = (String)ADDR_HANDLE.get(s, 0L); + }); } } - @Test(expectedExceptions=ClassCastException.class) + @Test public void testMemoryAddressValueSetAsString() { try (Arena arena = Arena.ofConfined()) { - MemorySegment s = arena.allocate(8, 8);; - ADDR_HANDLE.set(s, 0L, "string"); + MemorySegment s = arena.allocate(8, 8); + assertThrows(ClassCastException.class, () -> { + ADDR_HANDLE.set(s, 0L, "string"); + }); } } - @Test(expectedExceptions=WrongMethodTypeException.class) + @Test public void testMemoryAddressValueGetAsPrimitive() { try (Arena arena = Arena.ofConfined()) { MemorySegment s = arena.allocate(8, 8); - int address = (int)ADDR_HANDLE.get(s, 0L); + assertThrows(WrongMethodTypeException.class, () -> { + int address = (int)ADDR_HANDLE.get(s, 0L); + }); } } - @Test(expectedExceptions=WrongMethodTypeException.class) + @Test public void testMemoryAddressValueSetAsPrimitive() { try (Arena arena = Arena.ofConfined()) { - MemorySegment s = arena.allocate(8, 8);; - ADDR_HANDLE.set(s, 1); + MemorySegment s = arena.allocate(8, 8); + assertThrows(WrongMethodTypeException.class, () -> { + ADDR_HANDLE.set(s, 1); + }); } } diff --git a/test/jdk/java/foreign/TestUpcallAsync.java b/test/jdk/java/foreign/TestUpcallAsync.java index b912b1cd79e59..e409d0433e235 100644 --- a/test/jdk/java/foreign/TestUpcallAsync.java +++ b/test/jdk/java/foreign/TestUpcallAsync.java @@ -27,14 +27,13 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestUpcallBase * - * @run testng/othervm/native -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies + * @run junit/othervm/native -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies * --enable-native-access=ALL-UNNAMED -Dgenerator.sample.factor=17 * TestUpcallAsync */ import java.lang.foreign.*; -import org.testng.annotations.Test; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; @@ -45,6 +44,11 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestUpcallAsync extends TestUpcallBase { static { @@ -52,7 +56,8 @@ public class TestUpcallAsync extends TestUpcallBase { System.loadLibrary("AsyncInvokers"); } - @Test(dataProvider="functions", dataProviderClass=CallGeneratorHelper.class) + @ParameterizedTest + @MethodSource("functions") public void testUpcallsAsync(int count, String fName, Ret ret, List paramTypes, List fields) throws Throwable { List> returnChecks = new ArrayList<>(); List> argChecks = new ArrayList<>(); diff --git a/test/jdk/java/foreign/TestUpcallBase.java b/test/jdk/java/foreign/TestUpcallBase.java index e768ade8577ce..ed3d1efcc2569 100644 --- a/test/jdk/java/foreign/TestUpcallBase.java +++ b/test/jdk/java/foreign/TestUpcallBase.java @@ -32,6 +32,9 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import org.junit.jupiter.api.TestInstance; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public abstract class TestUpcallBase extends CallGeneratorHelper { static FunctionDescriptor function(Ret ret, List params, List fields) { diff --git a/test/jdk/java/foreign/TestUpcallException.java b/test/jdk/java/foreign/TestUpcallException.java index beaa33f5e61f3..763561592a8b4 100644 --- a/test/jdk/java/foreign/TestUpcallException.java +++ b/test/jdk/java/foreign/TestUpcallException.java @@ -26,13 +26,11 @@ * @library /test/lib * @build TestUpcallException * - * @run testng/othervm/native + * @run junit/othervm/native * --enable-native-access=ALL-UNNAMED * TestUpcallException */ -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import java.io.IOException; import java.lang.foreign.Arena; @@ -43,16 +41,21 @@ import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestUpcallException extends UpcallTestHelper { - @Test(dataProvider = "exceptionCases") + @ParameterizedTest + @MethodSource("exceptionCases") public void testException(Class target, boolean useSpec) throws InterruptedException, IOException { runInNewProcess(target, useSpec) .shouldNotHaveExitValue(0) .stderrShouldContain("Testing upcall exceptions"); } - @DataProvider public static Object[][] exceptionCases() { return new Object[][]{ { VoidUpcallRunner.class, false }, diff --git a/test/jdk/java/foreign/TestUpcallHighArity.java b/test/jdk/java/foreign/TestUpcallHighArity.java index 7bb369c884d6a..be8ef0c6c7115 100644 --- a/test/jdk/java/foreign/TestUpcallHighArity.java +++ b/test/jdk/java/foreign/TestUpcallHighArity.java @@ -27,15 +27,13 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestUpcallHighArity * - * @run testng/othervm/native + * @run junit/othervm/native * --enable-native-access=ALL-UNNAMED * TestUpcallHighArity */ import java.lang.foreign.*; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodType; @@ -44,6 +42,11 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestUpcallHighArity extends CallGeneratorHelper { static final MethodHandle MH_do_upcall; @@ -59,7 +62,8 @@ public class TestUpcallHighArity extends CallGeneratorHelper { ); } - @Test(dataProvider = "args") + @ParameterizedTest + @MethodSource("args") public void testUpcall(MethodHandle downcall, MethodType upcallType, FunctionDescriptor upcallDescriptor) throws Throwable { AtomicReference capturedArgs = new AtomicReference<>(); @@ -83,7 +87,6 @@ public void testUpcall(MethodHandle downcall, MethodType upcallType, } } - @DataProvider public static Object[][] args() { return new Object[][]{ { MH_do_upcall, diff --git a/test/jdk/java/foreign/TestUpcallScope.java b/test/jdk/java/foreign/TestUpcallScope.java index 6b8930e1a55d1..2746f8eec29f9 100644 --- a/test/jdk/java/foreign/TestUpcallScope.java +++ b/test/jdk/java/foreign/TestUpcallScope.java @@ -26,7 +26,7 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestUpcallBase * - * @run testng/othervm/native -Xcheck:jni -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies + * @run junit/othervm/native -Xcheck:jni -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies * --enable-native-access=ALL-UNNAMED -Dgenerator.sample.factor=17 * TestUpcallScope */ @@ -35,7 +35,6 @@ import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; -import org.testng.annotations.Test; import java.lang.invoke.MethodHandle; import java.util.ArrayList; @@ -43,13 +42,19 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestUpcallScope extends TestUpcallBase { static { System.loadLibrary("TestUpcall"); } - @Test(dataProvider="functions", dataProviderClass=CallGeneratorHelper.class) + @ParameterizedTest + @MethodSource("functions") public void testUpcalls(int count, String fName, Ret ret, List paramTypes, List fields) throws Throwable { List> returnChecks = new ArrayList<>(); List> argChecks = new ArrayList<>(); diff --git a/test/jdk/java/foreign/TestUpcallStack.java b/test/jdk/java/foreign/TestUpcallStack.java index 4552cbef73498..a1f729dfcfc94 100644 --- a/test/jdk/java/foreign/TestUpcallStack.java +++ b/test/jdk/java/foreign/TestUpcallStack.java @@ -27,7 +27,7 @@ * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestUpcallBase * - * @run testng/othervm/native/timeout=480 -Xcheck:jni -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies + * @run junit/othervm/native/timeout=480 -Xcheck:jni -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies * --enable-native-access=ALL-UNNAMED -Dgenerator.sample.factor=17 * TestUpcallStack */ @@ -36,7 +36,6 @@ import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; -import org.testng.annotations.Test; import java.lang.invoke.MethodHandle; import java.util.ArrayList; @@ -44,13 +43,19 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestUpcallStack extends TestUpcallBase { static { System.loadLibrary("TestUpcallStack"); } - @Test(dataProvider="functions", dataProviderClass=CallGeneratorHelper.class) + @ParameterizedTest + @MethodSource("functions") public void testUpcallsStack(int count, String fName, Ret ret, List paramTypes, List fields) throws Throwable { List> returnChecks = new ArrayList<>(); diff --git a/test/jdk/java/foreign/TestUpcallStress.java b/test/jdk/java/foreign/TestUpcallStress.java index db5320eff372c..460dc115bffcf 100644 --- a/test/jdk/java/foreign/TestUpcallStress.java +++ b/test/jdk/java/foreign/TestUpcallStress.java @@ -30,7 +30,7 @@ * @build NativeTestHelper CallGeneratorHelper TestUpcallBase * @bug 8337753 * - * @run testng/native/othervm + * @run junit/native/othervm * -Xcheck:jni * -XX:+IgnoreUnrecognizedVMOptions * -XX:-VerifyDependencies @@ -43,9 +43,6 @@ import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; import jdk.test.lib.Utils; import java.lang.invoke.MethodHandle; @@ -55,6 +52,13 @@ import java.util.concurrent.*; import java.util.function.Consumer; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestUpcallStress extends TestUpcallBase { static { @@ -65,12 +69,12 @@ public class TestUpcallStress extends TestUpcallBase { ExecutorService executor; - @BeforeClass + @BeforeAll public void setup() { executor = Executors.newFixedThreadPool(THREAD_COUNT); } - @AfterClass + @AfterAll public void tearDown() throws InterruptedException { executor.shutdown(); // Let it run for a while, and then just terminate @@ -78,7 +82,8 @@ public void tearDown() throws InterruptedException { } - @Test(dataProvider="functions", dataProviderClass=CallGeneratorHelper.class) + @ParameterizedTest + @MethodSource("functions") public void testUpcallsStress(int count, String fName, Ret ret, List paramTypes, List fields) { for (int threadIdx = 0; threadIdx < THREAD_COUNT; threadIdx++) { diff --git a/test/jdk/java/foreign/TestUpcallStructScope.java b/test/jdk/java/foreign/TestUpcallStructScope.java index b71156d9e52f4..b91644507a951 100644 --- a/test/jdk/java/foreign/TestUpcallStructScope.java +++ b/test/jdk/java/foreign/TestUpcallStructScope.java @@ -25,11 +25,11 @@ /* * @test * - * @run testng/othervm/native + * @run junit/othervm/native * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=false * TestUpcallStructScope - * @run testng/othervm/native + * @run junit/othervm/native * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=true * TestUpcallStructScope @@ -37,7 +37,6 @@ import java.lang.foreign.*; -import org.testng.annotations.Test; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; @@ -46,9 +45,10 @@ import java.util.function.BiConsumer; import java.util.function.Consumer; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; public class TestUpcallStructScope extends NativeTestHelper { static final MethodHandle MH_do_upcall; @@ -117,7 +117,7 @@ public void testOtherPointer() throws Throwable { // We've captured the address '42' from the upcall. This should have // the global scope, so it should still be alive here. MemorySegment captured = capturedSegment.get(); - assertEquals(argAddr, captured); + assertEquals(captured, argAddr); assertTrue(captured.scope().isAlive()); } } diff --git a/test/jdk/java/foreign/TestValueLayouts.java b/test/jdk/java/foreign/TestValueLayouts.java index 4c30a3c7d0300..7615a6cb6770f 100644 --- a/test/jdk/java/foreign/TestValueLayouts.java +++ b/test/jdk/java/foreign/TestValueLayouts.java @@ -24,17 +24,18 @@ /* * @test * @modules java.base/jdk.internal.misc - * @run testng TestValueLayouts + * @run junit TestValueLayouts */ -import org.testng.annotations.*; import java.lang.foreign.*; import java.nio.ByteOrder; import jdk.internal.misc.Unsafe; import static java.lang.foreign.ValueLayout.*; -import static org.testng.Assert.*; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class TestValueLayouts { @@ -141,10 +142,10 @@ void test(ValueLayout layout, Class carrier, long byteSize, long byteAlignment) { - assertEquals(layout.carrier(), carrier); - assertEquals(layout.byteSize(), byteSize); - assertEquals(layout.order(), ByteOrder.nativeOrder()); - assertEquals(layout.byteAlignment(), byteAlignment); + assertEquals(carrier, layout.carrier()); + assertEquals(byteSize, layout.byteSize()); + assertEquals(ByteOrder.nativeOrder(), layout.order()); + assertEquals(byteAlignment, layout.byteAlignment()); assertTrue(layout.name().isEmpty()); } diff --git a/test/jdk/java/foreign/TestVarArgs.java b/test/jdk/java/foreign/TestVarArgs.java index 006105da1a7c4..f411afd80f672 100644 --- a/test/jdk/java/foreign/TestVarArgs.java +++ b/test/jdk/java/foreign/TestVarArgs.java @@ -25,7 +25,7 @@ /* * @test * @modules java.base/jdk.internal.foreign - * @run testng/othervm/native --enable-native-access=ALL-UNNAMED -Dgenerator.sample.factor=17 TestVarArgs + * @run junit/othervm/native --enable-native-access=ALL-UNNAMED -Dgenerator.sample.factor=17 TestVarArgs */ import java.lang.foreign.Arena; @@ -35,8 +35,6 @@ import java.lang.foreign.ValueLayout; import java.lang.foreign.MemorySegment; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import java.lang.foreign.ValueLayout; import java.lang.invoke.MethodHandle; @@ -48,6 +46,11 @@ import static java.lang.foreign.MemoryLayout.PathElement.*; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestVarArgs extends CallGeneratorHelper { static final MethodHandle MH_CHECK; @@ -65,7 +68,8 @@ public class TestVarArgs extends CallGeneratorHelper { static final MemorySegment VARARGS_ADDR = findNativeOrThrow("varargs"); - @Test(dataProvider = "variadicFunctions") + @ParameterizedTest + @MethodSource("variadicFunctions") public void testVarArgs(int count, String fName, Ret ret, // ignore this stuff List paramTypes, List fields) throws Throwable { try (Arena arena = Arena.ofConfined()) { @@ -121,7 +125,6 @@ private static List createFieldsForStruct(int fieldCount, Struc return fields; } - @DataProvider(name = "variadicFunctions") public static Object[][] variadicFunctions() { List downcalls = new ArrayList<>(); diff --git a/test/jdk/java/foreign/TestVarHandleCombinators.java b/test/jdk/java/foreign/TestVarHandleCombinators.java index ccf12b9fdee78..3c5480e4707c0 100644 --- a/test/jdk/java/foreign/TestVarHandleCombinators.java +++ b/test/jdk/java/foreign/TestVarHandleCombinators.java @@ -24,20 +24,21 @@ /* * @test - * @run testng TestVarHandleCombinators + * @run junit TestVarHandleCombinators */ import java.lang.foreign.Arena; import java.lang.foreign.ValueLayout; -import org.testng.annotations.Test; import java.lang.foreign.MemorySegment; import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.nio.ByteOrder; -import static org.testng.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import org.junit.jupiter.api.Test; public class TestVarHandleCombinators { @@ -47,17 +48,20 @@ public void testElementAccess() { byte[] arr = { 0, 0, -1, 0 }; MemorySegment segment = MemorySegment.ofArray(arr); - assertEquals((byte) vh.get(segment, 2), (byte) -1); + assertEquals((byte) -1, (byte) vh.get(segment, 2)); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testUnalignedElement() { VarHandle vh = ValueLayout.JAVA_BYTE.withByteAlignment(4).varHandle(); MemorySegment segment = MemorySegment.ofArray(new byte[4]); - vh.get(segment, 2L); //should throw + assertThrows(IllegalArgumentException.class, () -> { + vh.get(segment, 2L); + }); //FIXME: the VH only checks the alignment of the segment, which is fine if the VH is derived from layouts, //FIXME: but not if the VH is just created from scratch - we need a VH variable to govern this property, //FIXME: at least until the VM is fixed + } @Test @@ -67,7 +71,7 @@ public void testAlign() { Arena scope = Arena.ofAuto(); MemorySegment segment = scope.allocate(1L, 2); vh.set(segment, 0L, (byte) 10); // fine, memory region is aligned - assertEquals((byte) vh.get(segment, 0L), (byte) 10); + assertEquals((byte) 10, (byte) vh.get(segment, 0L)); } @Test @@ -76,8 +80,8 @@ public void testByteOrderLE() { byte[] arr = new byte[2]; MemorySegment segment = MemorySegment.ofArray(arr); vh.set(segment, 0L, (short) 0xFF); - assertEquals(arr[0], (byte) 0xFF); - assertEquals(arr[1], (byte) 0); + assertEquals((byte) 0xFF, arr[0]); + assertEquals((byte) 0, arr[1]); } @Test @@ -86,8 +90,8 @@ public void testByteOrderBE() { byte[] arr = new byte[2]; MemorySegment segment = MemorySegment.ofArray(arr); vh.set(segment, 0L, (short) 0xFF); - assertEquals(arr[0], (byte) 0); - assertEquals(arr[1], (byte) 0xFF); + assertEquals((byte) 0, arr[0]); + assertEquals((byte) 0xFF, arr[1]); } @Test @@ -104,9 +108,7 @@ public void testNestedSequenceAccess() { for (long i = 0; i < outer_size; i++) { for (long j = 0; j < inner_size; j++) { vh.set(segment, i * 40 + j * 8, count); - assertEquals( - (int)vh.get(segment.asSlice(i * inner_size * 8), j * 8), - count); + assertEquals( count, (int)vh.get(segment.asSlice(i * inner_size * 8), j * 8)); count++; } } diff --git a/test/jdk/java/foreign/UpcallTestHelper.java b/test/jdk/java/foreign/UpcallTestHelper.java index 8adf5580f514c..9b7da7d0c150f 100644 --- a/test/jdk/java/foreign/UpcallTestHelper.java +++ b/test/jdk/java/foreign/UpcallTestHelper.java @@ -31,7 +31,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import static org.testng.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; public class UpcallTestHelper extends NativeTestHelper { diff --git a/test/jdk/java/foreign/arraystructs/TestArrayStructs.java b/test/jdk/java/foreign/arraystructs/TestArrayStructs.java index 6dba22becdd12..ca6eb6f4bdee5 100644 --- a/test/jdk/java/foreign/arraystructs/TestArrayStructs.java +++ b/test/jdk/java/foreign/arraystructs/TestArrayStructs.java @@ -26,7 +26,7 @@ * @library ../ * @requires (!(os.name == "Mac OS X" & os.arch == "aarch64") | jdk.foreign.linker != "FALLBACK") * @modules java.base/jdk.internal.foreign - * @run testng/othervm/native + * @run junit/othervm/native * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=true * -Djdk.internal.foreign.UpcallLinker.USE_SPEC=true @@ -38,15 +38,13 @@ * @library ../ * @requires (!(os.name == "Mac OS X" & os.arch == "aarch64") | jdk.foreign.linker != "FALLBACK") * @modules java.base/jdk.internal.foreign - * @run testng/othervm/native + * @run junit/othervm/native * --enable-native-access=ALL-UNNAMED * -Djdk.internal.foreign.DowncallLinker.USE_SPEC=false * -Djdk.internal.foreign.UpcallLinker.USE_SPEC=false * TestArrayStructs */ -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import java.lang.foreign.Arena; import java.lang.foreign.FunctionDescriptor; @@ -64,13 +62,19 @@ import static java.lang.foreign.MemoryLayout.sequenceLayout; import static java.lang.foreign.MemoryLayout.structLayout; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestArrayStructs extends NativeTestHelper { static { System.loadLibrary("ArrayStructs"); } // Test if structs of various different sizes, including non-powers of two, work correctly - @Test(dataProvider = "arrayStructs") + @ParameterizedTest + @MethodSource("arrayStructs") public void testArrayStruct(String functionName, FunctionDescriptor baseDesc, int numPrefixArgs, int numElements) throws Throwable { FunctionDescriptor downcallDesc = baseDesc.insertArgumentLayouts(0, C_POINTER); // CB MemoryLayout[] elementLayouts = Collections.nCopies(numElements, C_CHAR).toArray(MemoryLayout[]::new); @@ -109,7 +113,6 @@ public void testArrayStruct(String functionName, FunctionDescriptor baseDesc, in } } - @DataProvider public static Object[][] arrayStructs() { List cases = new ArrayList<>(); for (int i = 0; i < layouts.size(); i++) { diff --git a/test/jdk/java/foreign/callarranger/CallArrangerTestBase.java b/test/jdk/java/foreign/callarranger/CallArrangerTestBase.java index 037db225c65fe..da76068707b75 100644 --- a/test/jdk/java/foreign/callarranger/CallArrangerTestBase.java +++ b/test/jdk/java/foreign/callarranger/CallArrangerTestBase.java @@ -27,22 +27,22 @@ import java.util.Arrays; import java.util.List; -import static org.testng.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class CallArrangerTestBase { public static void checkArgumentBindings(CallingSequence callingSequence, Binding[][] argumentBindings) { - assertEquals(callingSequence.argumentBindingsCount(), argumentBindings.length, + assertEquals(argumentBindings.length, callingSequence.argumentBindingsCount(), callingSequence.asString() + " != " + Arrays.deepToString(argumentBindings)); for (int i = 0; i < callingSequence.argumentBindingsCount(); i++) { List actual = callingSequence.argumentBindings(i); Binding[] expected = argumentBindings[i]; - assertEquals(actual, Arrays.asList(expected), "bindings at: " + i + ": " + actual + " != " + Arrays.toString(expected)); + assertEquals(Arrays.asList(expected), actual, "bindings at: " + i + ": " + actual + " != " + Arrays.toString(expected)); } } public static void checkReturnBindings(CallingSequence callingSequence, Binding[] returnBindings) { - assertEquals(callingSequence.returnBindings(), Arrays.asList(returnBindings), callingSequence.returnBindings() + " != " + Arrays.toString(returnBindings)); + assertEquals(Arrays.asList(returnBindings), callingSequence.returnBindings(), callingSequence.returnBindings() + " != " + Arrays.toString(returnBindings)); } } diff --git a/test/jdk/java/foreign/callarranger/TestLayoutEquality.java b/test/jdk/java/foreign/callarranger/TestLayoutEquality.java index 0f43148949635..2341280685622 100644 --- a/test/jdk/java/foreign/callarranger/TestLayoutEquality.java +++ b/test/jdk/java/foreign/callarranger/TestLayoutEquality.java @@ -27,7 +27,7 @@ * @compile platform/PlatformLayouts.java * @modules java.base/jdk.internal.foreign.abi * @modules java.base/jdk.internal.foreign.layout - * @run testng TestLayoutEquality + * @run junit TestLayoutEquality */ import java.lang.foreign.AddressLayout; @@ -35,18 +35,21 @@ import jdk.internal.foreign.layout.ValueLayouts; import platform.PlatformLayouts; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestLayoutEquality { - @Test(dataProvider = "layoutConstants") + @ParameterizedTest + @MethodSource("layoutConstants") public void testReconstructedEquality(ValueLayout layout) { ValueLayout newLayout = ValueLayouts.valueLayout(layout.carrier(), layout.order()); newLayout = newLayout.withByteAlignment(layout.byteAlignment()); @@ -55,15 +58,14 @@ public void testReconstructedEquality(ValueLayout layout) { } // properties should be equal - assertEquals(newLayout.byteSize(), layout.byteSize()); - assertEquals(newLayout.byteAlignment(), layout.byteAlignment()); - assertEquals(newLayout.name(), layout.name()); + assertEquals(layout.byteSize(), newLayout.byteSize()); + assertEquals(layout.byteAlignment(), newLayout.byteAlignment()); + assertEquals(layout.name(), newLayout.name()); // layouts should be equals - assertEquals(newLayout, layout); + assertEquals(layout, newLayout); } - @DataProvider public static Object[][] layoutConstants() throws ReflectiveOperationException { List testValues = new ArrayList<>(); diff --git a/test/jdk/java/foreign/callarranger/TestLinuxAArch64CallArranger.java b/test/jdk/java/foreign/callarranger/TestLinuxAArch64CallArranger.java index ae08f1c9be435..790aa39495ea4 100644 --- a/test/jdk/java/foreign/callarranger/TestLinuxAArch64CallArranger.java +++ b/test/jdk/java/foreign/callarranger/TestLinuxAArch64CallArranger.java @@ -30,7 +30,7 @@ * java.base/jdk.internal.foreign.abi * java.base/jdk.internal.foreign.abi.aarch64 * @build CallArrangerTestBase - * @run testng TestLinuxAArch64CallArranger + * @run junit TestLinuxAArch64CallArranger */ import java.lang.foreign.FunctionDescriptor; @@ -43,8 +43,6 @@ import jdk.internal.foreign.abi.StubLocations; import jdk.internal.foreign.abi.VMStorage; import jdk.internal.foreign.abi.aarch64.CallArranger; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import java.lang.invoke.MethodType; @@ -55,10 +53,15 @@ import static jdk.internal.foreign.abi.aarch64.AArch64Architecture.Regs.*; import static platform.PlatformLayouts.AArch64.*; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestLinuxAArch64CallArranger extends CallArrangerTestBase { private static final VMStorage TARGET_ADDRESS_STORAGE = StubLocations.TARGET_ADDRESS.storage(StorageType.PLACEHOLDER); @@ -72,8 +75,8 @@ public void testEmpty() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) } @@ -96,8 +99,8 @@ public void testInteger() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -126,8 +129,8 @@ public void testTwoIntTwoFloat() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -140,7 +143,8 @@ public void testTwoIntTwoFloat() { checkReturnBindings(callingSequence, new Binding[]{}); } - @Test(dataProvider = "structs") + @ParameterizedTest + @MethodSource("structs") public void testStruct(MemoryLayout struct, Binding[] expectedBindings) { MethodType mt = MethodType.methodType(void.class, MemorySegment.class); FunctionDescriptor fd = FunctionDescriptor.ofVoid(struct); @@ -148,8 +152,8 @@ public void testStruct(MemoryLayout struct, Binding[] expectedBindings) { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -159,7 +163,6 @@ public void testStruct(MemoryLayout struct, Binding[] expectedBindings) { checkReturnBindings(callingSequence, new Binding[]{}); } - @DataProvider public static Object[][] structs() { MemoryLayout struct2 = MemoryLayout.structLayout(C_INT, C_INT, C_DOUBLE, C_INT); return new Object[][]{ @@ -208,8 +211,8 @@ public void testMultipleStructs() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -239,8 +242,8 @@ public void testReturnStruct1() { assertTrue(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), MethodType.methodType(void.class, MemorySegment.class, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), FunctionDescriptor.ofVoid(ADDRESS, C_POINTER)); + assertEquals(MethodType.methodType(void.class, MemorySegment.class, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(FunctionDescriptor.ofVoid(ADDRESS, C_POINTER), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -263,8 +266,8 @@ public void testReturnStruct2() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(RETURN_BUFFER_STORAGE, long.class) }, @@ -292,8 +295,8 @@ public void testStructHFA1() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(RETURN_BUFFER_STORAGE, long.class) }, @@ -330,8 +333,8 @@ public void testStructHFA3() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -384,8 +387,8 @@ public void testStructStackSpill() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -413,8 +416,8 @@ public void testVarArgsInRegs() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fdExpected); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fdExpected, callingSequence.functionDesc()); // This is identical to the non-variadic calling sequence checkArgumentBindings(callingSequence, new Binding[][]{ @@ -440,8 +443,8 @@ public void testFloatArrayStruct() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fdExpected); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fdExpected, callingSequence.functionDesc()); // This is identical to the non-variadic calling sequence checkArgumentBindings(callingSequence, new Binding[][]{ diff --git a/test/jdk/java/foreign/callarranger/TestMacOsAArch64CallArranger.java b/test/jdk/java/foreign/callarranger/TestMacOsAArch64CallArranger.java index 30119db72e8c3..9a608fb09673d 100644 --- a/test/jdk/java/foreign/callarranger/TestMacOsAArch64CallArranger.java +++ b/test/jdk/java/foreign/callarranger/TestMacOsAArch64CallArranger.java @@ -30,7 +30,7 @@ * java.base/jdk.internal.foreign.abi * java.base/jdk.internal.foreign.abi.aarch64 * @build CallArrangerTestBase - * @run testng TestMacOsAArch64CallArranger + * @run junit TestMacOsAArch64CallArranger */ import java.lang.foreign.FunctionDescriptor; @@ -43,8 +43,6 @@ import jdk.internal.foreign.abi.StubLocations; import jdk.internal.foreign.abi.VMStorage; import jdk.internal.foreign.abi.aarch64.CallArranger; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import java.lang.invoke.MethodType; @@ -54,9 +52,11 @@ import static jdk.internal.foreign.abi.aarch64.AArch64Architecture.*; import static jdk.internal.foreign.abi.aarch64.AArch64Architecture.Regs.*; import static platform.PlatformLayouts.AArch64.*; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; public class TestMacOsAArch64CallArranger extends CallArrangerTestBase { @@ -71,8 +71,8 @@ public void testVarArgsOnStack() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fdExpected); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fdExpected, callingSequence.functionDesc()); // The two variadic arguments should be allocated on the stack checkArgumentBindings(callingSequence, new Binding[][]{ @@ -99,8 +99,8 @@ public void testMacArgsOnStack() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -143,8 +143,8 @@ public void testMacArgsOnStack2() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -199,8 +199,8 @@ public void testMacArgsOnStack3() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -252,8 +252,8 @@ public void testMacArgsOnStack4() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -304,8 +304,8 @@ public void testMacArgsOnStack5() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -358,8 +358,8 @@ public void testMacArgsOnStack6() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, diff --git a/test/jdk/java/foreign/callarranger/TestRISCV64CallArranger.java b/test/jdk/java/foreign/callarranger/TestRISCV64CallArranger.java index f248623964590..13d274944ebc2 100644 --- a/test/jdk/java/foreign/callarranger/TestRISCV64CallArranger.java +++ b/test/jdk/java/foreign/callarranger/TestRISCV64CallArranger.java @@ -33,7 +33,7 @@ * java.base/jdk.internal.foreign.abi.riscv64 * java.base/jdk.internal.foreign.abi.riscv64.linux * @build CallArrangerTestBase - * @run testng TestRISCV64CallArranger + * @run junit TestRISCV64CallArranger */ import java.lang.foreign.FunctionDescriptor; @@ -45,8 +45,6 @@ import jdk.internal.foreign.abi.riscv64.linux.LinuxRISCV64CallArranger; import jdk.internal.foreign.abi.StubLocations; import jdk.internal.foreign.abi.VMStorage; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import java.lang.foreign.ValueLayout; import java.lang.invoke.MethodType; @@ -58,10 +56,15 @@ import static jdk.internal.foreign.abi.riscv64.RISCV64Architecture.Regs.*; import static platform.PlatformLayouts.RISCV64.*; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestRISCV64CallArranger extends CallArrangerTestBase { private static final short STACK_SLOT_SIZE = 8; @@ -76,8 +79,8 @@ public void testEmpty() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) } @@ -100,8 +103,8 @@ public void testInteger() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -128,8 +131,8 @@ public void testTwoIntTwoFloat() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -142,7 +145,8 @@ public void testTwoIntTwoFloat() { checkReturnBindings(callingSequence, new Binding[]{}); } - @Test(dataProvider = "structs") + @ParameterizedTest + @MethodSource("structs") public void testStruct(MemoryLayout struct, Binding[] expectedBindings) { MethodType mt = MethodType.methodType(void.class, MemorySegment.class); FunctionDescriptor fd = FunctionDescriptor.ofVoid(struct); @@ -150,8 +154,8 @@ public void testStruct(MemoryLayout struct, Binding[] expectedBindings) { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -161,7 +165,6 @@ public void testStruct(MemoryLayout struct, Binding[] expectedBindings) { checkReturnBindings(callingSequence, new Binding[]{}); } - @DataProvider public static Object[][] structs() { MemoryLayout struct1 = MemoryLayout.structLayout(C_INT, C_INT, C_DOUBLE, C_INT); return new Object[][]{ @@ -226,8 +229,8 @@ public void testStructFA1() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(RETURN_BUFFER_STORAGE, long.class) }, @@ -264,8 +267,8 @@ public void testStructFA2() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(RETURN_BUFFER_STORAGE, long.class) }, @@ -305,8 +308,8 @@ void spillFloatingPointStruct() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -336,8 +339,8 @@ public void testStructBoth() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -384,8 +387,8 @@ public void testStructStackSpill() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -413,8 +416,8 @@ public void testVarArgsInRegs() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fdExpected); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fdExpected, callingSequence.functionDesc()); // This is identical to the non-variadic calling sequence checkArgumentBindings(callingSequence, new Binding[][]{ @@ -442,8 +445,8 @@ public void testVarArgsLong() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fdExpected); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fdExpected, callingSequence.functionDesc()); // This is identical to the non-variadic calling sequence checkArgumentBindings(callingSequence, new Binding[][]{ @@ -474,11 +477,9 @@ public void testReturnStruct1() { assertTrue(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), - MethodType.methodType(void.class, MemorySegment.class, MemorySegment.class, - int.class, int.class, float.class)); - assertEquals(callingSequence.functionDesc(), - FunctionDescriptor.ofVoid(ADDRESS, C_POINTER, C_INT, C_INT, C_FLOAT)); + assertEquals( MethodType.methodType(void.class, MemorySegment.class, MemorySegment.class, + int.class, int.class, float.class), callingSequence.callerMethodType()); + assertEquals( FunctionDescriptor.ofVoid(ADDRESS, C_POINTER, C_INT, C_INT, C_FLOAT), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -501,8 +502,8 @@ public void testReturnStruct2() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(RETURN_BUFFER_STORAGE, long.class) }, diff --git a/test/jdk/java/foreign/callarranger/TestSysVCallArranger.java b/test/jdk/java/foreign/callarranger/TestSysVCallArranger.java index 53317b22dc080..417c417878097 100644 --- a/test/jdk/java/foreign/callarranger/TestSysVCallArranger.java +++ b/test/jdk/java/foreign/callarranger/TestSysVCallArranger.java @@ -30,7 +30,7 @@ * java.base/jdk.internal.foreign.abi.x64 * java.base/jdk.internal.foreign.abi.x64.sysv * @build CallArrangerTestBase - * @run testng TestSysVCallArranger + * @run junit TestSysVCallArranger */ import java.lang.foreign.FunctionDescriptor; @@ -41,8 +41,6 @@ import jdk.internal.foreign.abi.StubLocations; import jdk.internal.foreign.abi.VMStorage; import jdk.internal.foreign.abi.x64.sysv.CallArranger; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import java.lang.invoke.MethodType; @@ -52,10 +50,15 @@ import static jdk.internal.foreign.abi.x64.X86_64Architecture.Regs.*; import static platform.PlatformLayouts.SysV.*; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestSysVCallArranger extends CallArrangerTestBase { private static final short STACK_SLOT_SIZE = 8; @@ -70,8 +73,8 @@ public void testEmpty() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -79,7 +82,7 @@ public void testEmpty() { checkReturnBindings(callingSequence, new Binding[]{}); - assertEquals(bindings.nVectorArgs(), 0); + assertEquals(0, bindings.nVectorArgs()); } @Test @@ -97,8 +100,8 @@ public void testNestedStructs() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -108,7 +111,7 @@ public void testNestedStructs() { checkReturnBindings(callingSequence, new Binding[]{}); - assertEquals(bindings.nVectorArgs(), 0); + assertEquals(0, bindings.nVectorArgs()); } @Test @@ -127,8 +130,8 @@ public void testNestedUnion() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -138,7 +141,7 @@ public void testNestedUnion() { checkReturnBindings(callingSequence, new Binding[]{}); - assertEquals(bindings.nVectorArgs(), 0); + assertEquals(0, bindings.nVectorArgs()); } @Test @@ -151,8 +154,8 @@ public void testIntegerRegs() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -166,7 +169,7 @@ public void testIntegerRegs() { checkReturnBindings(callingSequence, new Binding[]{}); - assertEquals(bindings.nVectorArgs(), 0); + assertEquals(0, bindings.nVectorArgs()); } @Test @@ -181,8 +184,8 @@ public void testDoubleRegs() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -198,7 +201,7 @@ public void testDoubleRegs() { checkReturnBindings(callingSequence, new Binding[]{}); - assertEquals(bindings.nVectorArgs(), 8); + assertEquals(8, bindings.nVectorArgs()); } @Test @@ -215,8 +218,8 @@ public void testMixed() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -242,7 +245,7 @@ public void testMixed() { checkReturnBindings(callingSequence, new Binding[]{}); - assertEquals(bindings.nVectorArgs(), 8); + assertEquals(8, bindings.nVectorArgs()); } /** @@ -271,8 +274,8 @@ public void testAbiExample() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -294,7 +297,7 @@ public void testAbiExample() { checkReturnBindings(callingSequence, new Binding[]{}); - assertEquals(bindings.nVectorArgs(), 3); + assertEquals(3, bindings.nVectorArgs()); } /** @@ -313,8 +316,8 @@ public void testMemoryAddress() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -323,10 +326,11 @@ public void testMemoryAddress() { checkReturnBindings(callingSequence, new Binding[]{}); - assertEquals(bindings.nVectorArgs(), 0); + assertEquals(0, bindings.nVectorArgs()); } - @Test(dataProvider = "structs") + @ParameterizedTest + @MethodSource("structs") public void testStruct(MemoryLayout struct, Binding[] expectedBindings) { MethodType mt = MethodType.methodType(void.class, MemorySegment.class); FunctionDescriptor fd = FunctionDescriptor.ofVoid(struct); @@ -334,8 +338,8 @@ public void testStruct(MemoryLayout struct, Binding[] expectedBindings) { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -344,11 +348,10 @@ public void testStruct(MemoryLayout struct, Binding[] expectedBindings) { checkReturnBindings(callingSequence, new Binding[]{}); - assertEquals(bindings.nVectorArgs(), 0); + assertEquals(0, bindings.nVectorArgs()); } - @DataProvider public static Object[][] structs() { return new Object[][]{ { MemoryLayout.structLayout(C_LONG), new Binding[]{ @@ -392,8 +395,8 @@ public void testReturnRegisterStruct() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(RETURN_BUFFER_STORAGE, long.class) }, @@ -410,7 +413,7 @@ public void testReturnRegisterStruct() { bufferStore(8, long.class) }); - assertEquals(bindings.nVectorArgs(), 0); + assertEquals(0, bindings.nVectorArgs()); } @Test @@ -423,8 +426,8 @@ public void testIMR() { assertTrue(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), MethodType.methodType(void.class, MemorySegment.class, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), FunctionDescriptor.ofVoid(ADDRESS, C_POINTER)); + assertEquals(MethodType.methodType(void.class, MemorySegment.class, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(FunctionDescriptor.ofVoid(ADDRESS, C_POINTER), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -433,7 +436,7 @@ public void testIMR() { checkReturnBindings(callingSequence, new Binding[] {}); - assertEquals(bindings.nVectorArgs(), 0); + assertEquals(0, bindings.nVectorArgs()); } @Test @@ -446,8 +449,8 @@ public void testFloatStructsUpcall() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.calleeMethodType(), mt); - assertEquals(callingSequence.functionDesc(), fd); + assertEquals(mt, callingSequence.calleeMethodType()); + assertEquals(fd, callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { allocate(struct), dup(), vmLoad(xmm0, float.class), bufferStore(0, float.class) }, @@ -457,7 +460,7 @@ public void testFloatStructsUpcall() { bufferLoad(0, float.class), vmStore(xmm0, float.class) }); - assertEquals(bindings.nVectorArgs(), 1); + assertEquals(1, bindings.nVectorArgs()); } } diff --git a/test/jdk/java/foreign/callarranger/TestWindowsAArch64CallArranger.java b/test/jdk/java/foreign/callarranger/TestWindowsAArch64CallArranger.java index 4c612ef868c69..0287bf3403400 100644 --- a/test/jdk/java/foreign/callarranger/TestWindowsAArch64CallArranger.java +++ b/test/jdk/java/foreign/callarranger/TestWindowsAArch64CallArranger.java @@ -29,7 +29,7 @@ * java.base/jdk.internal.foreign.abi * java.base/jdk.internal.foreign.abi.aarch64 * @build CallArrangerTestBase - * @run testng TestWindowsAArch64CallArranger + * @run junit TestWindowsAArch64CallArranger */ import java.lang.foreign.FunctionDescriptor; @@ -41,8 +41,6 @@ import jdk.internal.foreign.abi.StubLocations; import jdk.internal.foreign.abi.VMStorage; import jdk.internal.foreign.abi.aarch64.CallArranger; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import java.lang.invoke.MethodType; @@ -52,9 +50,11 @@ import static jdk.internal.foreign.abi.aarch64.AArch64Architecture.*; import static jdk.internal.foreign.abi.aarch64.AArch64Architecture.Regs.*; import static platform.PlatformLayouts.AArch64.*; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; public class TestWindowsAArch64CallArranger extends CallArrangerTestBase { @@ -69,8 +69,8 @@ public void testWindowsArgsInRegs() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -92,8 +92,8 @@ public void testWindowsVarArgsInRegs() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fdExpected); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fdExpected, callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -118,8 +118,8 @@ public void testWindowsArgsInRegsAndOnStack() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -152,8 +152,8 @@ public void testWindowsVarArgsInRegsAndOnStack() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fdExpected); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fdExpected, callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -182,8 +182,8 @@ public void testWindowsHfa4FloatsInFloatRegs() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -216,8 +216,8 @@ public void testWindowsVariadicHfa4FloatsInIntRegs() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -245,8 +245,8 @@ public void testWindowsHfa2DoublesInFloatRegs() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -274,8 +274,8 @@ public void testWindowsVariadicHfa2DoublesInIntRegs() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -303,8 +303,8 @@ public void testWindowsHfa3DoublesInFloatRegs() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -335,8 +335,8 @@ public void testWindowsVariadicHfa3DoublesAsReferenceStruct() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, diff --git a/test/jdk/java/foreign/callarranger/TestWindowsCallArranger.java b/test/jdk/java/foreign/callarranger/TestWindowsCallArranger.java index 3f47952dd83ea..a0375e59902e0 100644 --- a/test/jdk/java/foreign/callarranger/TestWindowsCallArranger.java +++ b/test/jdk/java/foreign/callarranger/TestWindowsCallArranger.java @@ -31,7 +31,7 @@ * java.base/jdk.internal.foreign.abi.x64 * java.base/jdk.internal.foreign.abi.x64.windows * @build CallArrangerTestBase - * @run testng TestWindowsCallArranger + * @run junit TestWindowsCallArranger */ import java.lang.foreign.FunctionDescriptor; @@ -43,7 +43,6 @@ import jdk.internal.foreign.abi.StubLocations; import jdk.internal.foreign.abi.VMStorage; import jdk.internal.foreign.abi.x64.windows.CallArranger; -import org.testng.annotations.Test; import java.lang.invoke.MethodType; @@ -55,7 +54,8 @@ import static jdk.internal.foreign.abi.x64.X86_64Architecture.Regs.*; import static platform.PlatformLayouts.Win64.*; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class TestWindowsCallArranger extends CallArrangerTestBase { @@ -70,8 +70,8 @@ public void testEmpty() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) } @@ -87,8 +87,8 @@ public void testIntegerRegs() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -109,8 +109,8 @@ public void testDoubleRegs() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -133,8 +133,8 @@ public void testMixed() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -164,8 +164,8 @@ public void testAbiExample() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -201,8 +201,8 @@ public void testAbiExampleVarargs() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fdExpected); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fdExpected, callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -235,8 +235,8 @@ public void testStructRegister() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -265,8 +265,8 @@ public void testStructReference() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -296,8 +296,8 @@ public void testMemoryAddress() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -317,8 +317,8 @@ public void testReturnRegisterStruct() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -341,8 +341,8 @@ public void testIMR() { assertTrue(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), MethodType.methodType(void.class, MemorySegment.class, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), FunctionDescriptor.ofVoid(ADDRESS, C_POINTER)); + assertEquals(MethodType.methodType(void.class, MemorySegment.class, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(FunctionDescriptor.ofVoid(ADDRESS, C_POINTER), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, @@ -370,8 +370,8 @@ public void testStackStruct() { assertFalse(bindings.isInMemoryReturn()); CallingSequence callingSequence = bindings.callingSequence(); - assertEquals(callingSequence.callerMethodType(), mt.insertParameterTypes(0, MemorySegment.class)); - assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS)); + assertEquals(mt.insertParameterTypes(0, MemorySegment.class), callingSequence.callerMethodType()); + assertEquals(fd.insertArgumentLayouts(0, ADDRESS), callingSequence.functionDesc()); checkArgumentBindings(callingSequence, new Binding[][]{ { unboxAddress(), vmStore(TARGET_ADDRESS_STORAGE, long.class) }, diff --git a/test/jdk/java/foreign/capturecallstate/TestCaptureCallState.java b/test/jdk/java/foreign/capturecallstate/TestCaptureCallState.java index 8ef5483bd82a2..f88dd051841c3 100644 --- a/test/jdk/java/foreign/capturecallstate/TestCaptureCallState.java +++ b/test/jdk/java/foreign/capturecallstate/TestCaptureCallState.java @@ -25,11 +25,9 @@ * @test * @bug 8356126 * @library ../ /test/lib - * @run testng/othervm/native --enable-native-access=ALL-UNNAMED TestCaptureCallState + * @run junit/othervm/native --enable-native-access=ALL-UNNAMED TestCaptureCallState */ -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import java.lang.foreign.Arena; import java.lang.foreign.FunctionDescriptor; @@ -48,8 +46,14 @@ import static java.lang.foreign.ValueLayout.JAVA_DOUBLE; import static java.lang.foreign.ValueLayout.JAVA_INT; import static java.lang.foreign.ValueLayout.JAVA_LONG; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestCaptureCallState extends NativeTestHelper { static { @@ -67,7 +71,7 @@ public void testApiContracts() { assertThrows(IllegalArgumentException.class, () -> Linker.Option.captureCallState("Does not exist")); var duplicateOpt = Linker.Option.captureCallState("errno", "errno"); // duplicates var noDuplicateOpt = Linker.Option.captureCallState("errno"); - assertEquals(duplicateOpt, noDuplicateOpt, "auto deduplication"); + assertEquals(noDuplicateOpt, duplicateOpt, "auto deduplication"); var display = duplicateOpt.toString(); assertTrue(display.contains("errno"), "toString should contain state name 'errno': " + display); } @@ -75,7 +79,8 @@ public void testApiContracts() { private record SaveValuesCase(String nativeTarget, FunctionDescriptor nativeDesc, String threadLocalName, Consumer resultCheck, boolean expectTestValue, boolean critical) {} - @Test(dataProvider = "cases") + @ParameterizedTest + @MethodSource("cases") public void testSavedThreadLocal(SaveValuesCase testCase) throws Throwable { List options = new ArrayList<>(); options.add(Linker.Option.captureCallState(testCase.threadLocalName())); @@ -101,14 +106,15 @@ public void testSavedThreadLocal(SaveValuesCase testCase) throws Throwable { testCase.resultCheck().accept(result); int savedErrno = (int) errnoHandle.get(saveSeg, 0L); if (testCase.expectTestValue()) { - assertEquals(savedErrno, testValue); + assertEquals(testValue, savedErrno); } else { - assertEquals(savedErrno, prevValue); + assertEquals(prevValue, savedErrno); } } } - @Test(dataProvider = "invalidCaptureSegmentCases") + @ParameterizedTest + @MethodSource("invalidCaptureSegmentCases") public void testInvalidCaptureSegment(MemorySegment captureSegment, Class expectedExceptionType, String expectedExceptionMessage, Linker.Option[] extraOptions) { @@ -128,7 +134,6 @@ public void testInvalidCaptureSegment(MemorySegment captureSegment, } } - @DataProvider public static Object[][] cases() { List cases = new ArrayList<>(); @@ -138,9 +143,9 @@ public static Object[][] cases() { cases.add(new SaveValuesCase("noset_errno_V", FunctionDescriptor.ofVoid(JAVA_INT), "errno", o -> {}, false, critical)); cases.add(new SaveValuesCase("set_errno_I", FunctionDescriptor.of(JAVA_INT, JAVA_INT), - "errno", o -> assertEquals((int) o, 42), true, critical)); + "errno", o -> assertEquals(42, (int) o), true, critical)); cases.add(new SaveValuesCase("set_errno_D", FunctionDescriptor.of(JAVA_DOUBLE, JAVA_INT), - "errno", o -> assertEquals((double) o, 42.0), true, critical)); + "errno", o -> assertEquals(42.0, (double) o), true, critical)); cases.add(structCase("SL", Map.of(JAVA_LONG.withName("x"), 42L), true, critical)); cases.add(structCase("SLL", Map.of(JAVA_LONG.withName("x"), 42L, @@ -180,14 +185,13 @@ static SaveValuesCase structCase(String name, MemoryLayout fieldLayout = field.getKey(); VarHandle fieldHandle = layout.varHandle(MemoryLayout.PathElement.groupElement(fieldLayout.name().get())); Object value = field.getValue(); - check = check.andThen(o -> assertEquals(fieldHandle.get(o, 0L), value)); + check = check.andThen(o -> assertEquals(value, fieldHandle.get(o, 0L))); } String prefix = expectTestValue ? "set_errno_" : "noset_errno_"; return new SaveValuesCase(prefix + name, FunctionDescriptor.of(layout, JAVA_INT), "errno", check, expectTestValue, critical); } - @DataProvider public static Object[][] invalidCaptureSegmentCases() { return new Object[][]{ {Arena.ofAuto().allocate(1), IndexOutOfBoundsException.class, ".*Out of bound access on segment.*", new Linker.Option[0]}, diff --git a/test/jdk/java/foreign/channels/AbstractChannelsTest.java b/test/jdk/java/foreign/channels/AbstractChannelsTest.java index 6c9e64a40a27b..3a09e0de4adf6 100644 --- a/test/jdk/java/foreign/channels/AbstractChannelsTest.java +++ b/test/jdk/java/foreign/channels/AbstractChannelsTest.java @@ -32,14 +32,16 @@ import java.util.stream.Stream; import jdk.test.lib.RandomFactory; -import org.testng.annotations.*; import static java.lang.foreign.ValueLayout.JAVA_BYTE; -import static org.testng.Assert.*; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.TestInstance; /** * Not a test, but infra for channel tests. */ +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class AbstractChannelsTest { static final Class IOE = IOException.class; @@ -120,28 +122,24 @@ static void assertCauses(Throwable ex, Class... exceptions) } } - @DataProvider(name = "confinedArenas") public static Object[][] confinedArenas() { return new Object[][] { { ArenaSupplier.NEW_CONFINED }, }; } - @DataProvider(name = "sharedArenas") public static Object[][] sharedArenas() { return new Object[][] { { ArenaSupplier.NEW_SHARED }, }; } - @DataProvider(name = "closeableArenas") public static Object[][] closeableArenas() { return Stream.of(sharedArenas(), confinedArenas()) .flatMap(Arrays::stream) .toArray(Object[][]::new); } - @DataProvider(name = "sharedArenasAndTimeouts") public static Object[][] sharedArenasAndTimeouts() { return new Object[][] { { ArenaSupplier.NEW_SHARED , 0 }, diff --git a/test/jdk/java/foreign/channels/TestAsyncSocketChannels.java b/test/jdk/java/foreign/channels/TestAsyncSocketChannels.java index 37fef8bb4b665..ee72ee5cf786c 100644 --- a/test/jdk/java/foreign/channels/TestAsyncSocketChannels.java +++ b/test/jdk/java/foreign/channels/TestAsyncSocketChannels.java @@ -26,9 +26,9 @@ * @library /test/lib * @modules java.base/sun.nio.ch * @key randomness - * @run testng/othervm TestAsyncSocketChannels - * @run testng/othervm -Dsun.nio.ch.disableSynchronousRead=true TestAsyncSocketChannels - * @run testng/othervm -Dsun.nio.ch.disableSynchronousRead=false TestAsyncSocketChannels + * @run junit/othervm TestAsyncSocketChannels + * @run junit/othervm -Dsun.nio.ch.disableSynchronousRead=true TestAsyncSocketChannels + * @run junit/othervm -Dsun.nio.ch.disableSynchronousRead=false TestAsyncSocketChannels */ import java.io.IOException; @@ -50,15 +50,19 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.function.Supplier; -import org.testng.annotations.*; import static java.lang.System.out; import static java.util.concurrent.TimeUnit.SECONDS; import static java.lang.foreign.ValueLayout.JAVA_BYTE; -import static org.testng.Assert.*; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; /** * Tests consisting of buffer views with asynchronous NIO network channels. */ +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestAsyncSocketChannels extends AbstractChannelsTest { static final Class IOE = IOException.class; @@ -67,7 +71,8 @@ public class TestAsyncSocketChannels extends AbstractChannelsTest { static final Class ISE = IllegalStateException.class; /** Tests that confined sessions are not supported. */ - @Test(dataProvider = "confinedArenas") + @ParameterizedTest + @MethodSource("confinedArenas") public void testWithConfined(Supplier arenaSupplier) throws Throwable { @@ -92,13 +97,14 @@ public void testWithConfined(Supplier arenaSupplier) for (var ioOp : ioOps) { out.println("testAsyncWithConfined - op"); var handler = new TestHandler(); - expectThrows(IAE, () -> ioOp.accept(handler)); + assertThrows(IAE, () -> ioOp.accept(handler)); } } } /** Tests that I/O with a closed session throws a suitable exception. */ - @Test(dataProvider = "sharedArenasAndTimeouts") + @ParameterizedTest + @MethodSource("sharedArenasAndTimeouts") public void testIOWithClosedSharedSession(Supplier arenaSupplier, int timeout) throws Exception { @@ -110,7 +116,7 @@ public void testIOWithClosedSharedSession(Supplier arenaSupplier, int tim ByteBuffer[] buffers = segmentBuffersOfSize(8, drop, 32); drop.close(); { - assertCauses(expectThrows(EE, () -> connectedChannel.read(bb).get()), IOE, ISE); + assertCauses(assertThrows(EE, () -> connectedChannel.read(bb).get()), IOE, ISE); } { var handler = new TestHandler(); @@ -128,7 +134,7 @@ public void testIOWithClosedSharedSession(Supplier arenaSupplier, int tim handler.await().assertFailedWith(ISE).assertExceptionMessage("Already closed"); } { - assertCauses(expectThrows(EE, () -> connectedChannel.write(bb).get()), IOE, ISE); + assertCauses(assertThrows(EE, () -> connectedChannel.write(bb).get()), IOE, ISE); } { var handler = new TestHandler(); @@ -149,7 +155,8 @@ public void testIOWithClosedSharedSession(Supplier arenaSupplier, int tim } /** Tests basic I/O operations work with views over implicit and shared sessions. */ - @Test(dataProvider = "sharedArenas") + @ParameterizedTest + @MethodSource("sharedArenas") public void testBasicIOWithSupportedSession(Supplier arenaSupplier) throws Exception { @@ -168,9 +175,9 @@ public void testBasicIOWithSupportedSession(Supplier arenaSupplier) { // Future variants ByteBuffer bb1 = segment1.asByteBuffer(); ByteBuffer bb2 = segment2.asByteBuffer(); - assertEquals((int)asc1.write(bb1).get(), 10); - assertEquals((int)asc2.read(bb2).get(), 10); - assertEquals(bb2.flip(), ByteBuffer.wrap(new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9})); + assertEquals(10, (int)asc1.write(bb1).get()); + assertEquals(10, (int)asc2.read(bb2).get()); + assertEquals(ByteBuffer.wrap(new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}), bb2.flip()); } { // CompletionHandler variants ByteBuffer bb1 = segment1.asByteBuffer(); @@ -181,7 +188,7 @@ public void testBasicIOWithSupportedSession(Supplier arenaSupplier) var readHandler = new TestHandler(); asc2.read(new ByteBuffer[]{bb2}, 0, 1, 30L, SECONDS, null, readHandler); readHandler.await().assertCompleteWith(10L); - assertEquals(bb2.flip(), ByteBuffer.wrap(new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9})); + assertEquals(ByteBuffer.wrap(new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}), bb2.flip()); } { // Gathering/Scattering variants var writeBuffers = mixedBuffersOfSize(16, drop, 32); @@ -193,13 +200,14 @@ public void testBasicIOWithSupportedSession(Supplier arenaSupplier) var readHandler = new TestHandler(); asc2.read(readBuffers, 0, 16, 30L, SECONDS, null, readHandler); readHandler.await().assertCompleteWith(expectedCount); - assertEquals(flip(readBuffers), clear(writeBuffers)); + assertArrayEquals(clear(writeBuffers), flip(readBuffers)); } } } /** Tests that a session is not closeable when there is an outstanding read operation. */ - @Test(dataProvider = "sharedArenasAndTimeouts") + @ParameterizedTest + @MethodSource("sharedArenasAndTimeouts") public void testCloseWithOutstandingRead(Supplier arenaSupplier, int timeout) throws Throwable { @@ -235,7 +243,8 @@ public void testCloseWithOutstandingRead(Supplier arenaSupplier, int time /** Tests that a session is not closeable when there is an outstanding write operation. */ // Note: limited scenarios are checked, given the 5 sec sleep! - @Test(dataProvider = "sharedArenasAndTimeouts") + @ParameterizedTest + @MethodSource("sharedArenasAndTimeouts") public void testCloseWithOutstandingWrite(Supplier arenaSupplier, int timeout) throws Throwable { @@ -357,20 +366,20 @@ TestHandler await() throws InterruptedException{ } TestHandler assertCompleteWith(V value) { - assertEquals(result.longValue(), value.longValue()); - assertEquals(throwable, null); + assertEquals(value.longValue(), result.longValue()); + assertEquals(null, throwable); return this; } TestHandler assertFailedWith(Class expectedException) { assertTrue(expectedException.isInstance(throwable), "Expected type:%s, got:%s".formatted(expectedException, throwable) ); - assertEquals(result, null, "Unexpected result: " + result); + assertEquals(null, result, "Unexpected result: " + result); return this; } TestHandler assertExceptionMessage(String expectedMessage) { - assertEquals(throwable.getMessage(), expectedMessage); + assertEquals(expectedMessage, throwable.getMessage()); return this; } diff --git a/test/jdk/java/foreign/channels/TestSocketChannels.java b/test/jdk/java/foreign/channels/TestSocketChannels.java index e2cb012a50883..c38b0245b266b 100644 --- a/test/jdk/java/foreign/channels/TestSocketChannels.java +++ b/test/jdk/java/foreign/channels/TestSocketChannels.java @@ -26,7 +26,7 @@ * @library /test/lib * @modules java.base/sun.nio.ch * @key randomness - * @run testng/othervm TestSocketChannels + * @run junit/othervm TestSocketChannels */ import java.lang.foreign.Arena; @@ -43,20 +43,27 @@ import java.lang.foreign.MemorySegment; -import org.testng.annotations.*; import static java.lang.foreign.ValueLayout.JAVA_BYTE; -import static org.testng.Assert.*; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.function.Executable; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; /** * Tests consisting of buffer views with synchronous NIO network channels. */ +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestSocketChannels extends AbstractChannelsTest { static final Class ISE = IllegalStateException.class; static final Class WTE = WrongThreadException.class; - @Test(dataProvider = "closeableArenas") + @ParameterizedTest + @MethodSource("closeableArenas") public void testBasicIOWithClosedSegment(Supplier arenaSupplier) throws Exception { @@ -66,16 +73,17 @@ public void testBasicIOWithClosedSegment(Supplier arenaSupplier) Arena drop = arenaSupplier.get(); ByteBuffer bb = segmentBufferOfSize(drop, 16); drop.close(); - assertMessage(expectThrows(ISE, () -> channel.read(bb)), "Already closed"); - assertMessage(expectThrows(ISE, () -> channel.read(new ByteBuffer[] {bb})), "Already closed"); - assertMessage(expectThrows(ISE, () -> channel.read(new ByteBuffer[] {bb}, 0, 1)), "Already closed"); - assertMessage(expectThrows(ISE, () -> channel.write(bb)), "Already closed"); - assertMessage(expectThrows(ISE, () -> channel.write(new ByteBuffer[] {bb})), "Already closed"); - assertMessage(expectThrows(ISE, () -> channel.write(new ByteBuffer[] {bb}, 0 ,1)), "Already closed"); + assertMessage(assertThrows(ISE, () -> channel.read(bb)), "Already closed"); + assertMessage(assertThrows(ISE, () -> channel.read(new ByteBuffer[] {bb})), "Already closed"); + assertMessage(assertThrows(ISE, () -> channel.read(new ByteBuffer[] {bb}, 0, 1)), "Already closed"); + assertMessage(assertThrows(ISE, () -> channel.write(bb)), "Already closed"); + assertMessage(assertThrows(ISE, () -> channel.write(new ByteBuffer[] {bb})), "Already closed"); + assertMessage(assertThrows(ISE, () -> channel.write(new ByteBuffer[] {bb}, 0 ,1)), "Already closed"); } } - @Test(dataProvider = "closeableArenas") + @ParameterizedTest + @MethodSource("closeableArenas") public void testScatterGatherWithClosedSegment(Supplier arenaSupplier) throws Exception { @@ -85,14 +93,15 @@ public void testScatterGatherWithClosedSegment(Supplier arenaSupplier) Arena drop = arenaSupplier.get(); ByteBuffer[] buffers = segmentBuffersOfSize(8, drop, 16); drop.close(); - assertMessage(expectThrows(ISE, () -> channel.write(buffers)), "Already closed"); - assertMessage(expectThrows(ISE, () -> channel.read(buffers)), "Already closed"); - assertMessage(expectThrows(ISE, () -> channel.write(buffers, 0 ,8)), "Already closed"); - assertMessage(expectThrows(ISE, () -> channel.read(buffers, 0, 8)), "Already closed"); + assertMessage(assertThrows(ISE, () -> channel.write(buffers)), "Already closed"); + assertMessage(assertThrows(ISE, () -> channel.read(buffers)), "Already closed"); + assertMessage(assertThrows(ISE, () -> channel.write(buffers, 0 ,8)), "Already closed"); + assertMessage(assertThrows(ISE, () -> channel.read(buffers, 0, 8)), "Already closed"); } } - @Test(dataProvider = "closeableArenas") + @ParameterizedTest + @MethodSource("closeableArenas") public void testBasicIO(Supplier arenaSupplier) throws Exception { @@ -110,9 +119,9 @@ public void testBasicIO(Supplier arenaSupplier) } ByteBuffer bb1 = segment1.asByteBuffer(); ByteBuffer bb2 = segment2.asByteBuffer(); - assertEquals(sc1.write(bb1), 10); - assertEquals(sc2.read(bb2), 10); - assertEquals(bb2.flip(), ByteBuffer.wrap(new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9})); + assertEquals(10, sc1.write(bb1)); + assertEquals(10, sc2.read(bb2)); + assertEquals(ByteBuffer.wrap(new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}), bb2.flip()); } } @@ -128,13 +137,14 @@ public void testBasicHeapIOWithGlobalSession() throws Exception { } ByteBuffer bb1 = segment1.asByteBuffer(); ByteBuffer bb2 = segment2.asByteBuffer(); - assertEquals(sc1.write(bb1), 10); - assertEquals(sc2.read(bb2), 10); - assertEquals(bb2.flip(), ByteBuffer.wrap(new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9})); + assertEquals(10, sc1.write(bb1)); + assertEquals(10, sc2.read(bb2)); + assertEquals(ByteBuffer.wrap(new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}), bb2.flip()); } } - @Test(dataProvider = "confinedArenas") + @ParameterizedTest + @MethodSource("confinedArenas") public void testIOOnConfinedFromAnotherThread(Supplier arenaSupplier) throws Exception { @@ -145,7 +155,7 @@ public void testIOOnConfinedFromAnotherThread(Supplier arenaSupplier) Arena scope = drop; var segment = scope.allocate(10, 1); ByteBuffer bb = segment.asByteBuffer(); - List ioOps = List.of( + List ioOps = List.of( () -> channel.write(bb), () -> channel.read(bb), () -> channel.write(new ByteBuffer[] {bb}), @@ -155,7 +165,7 @@ public void testIOOnConfinedFromAnotherThread(Supplier arenaSupplier) ); for (var ioOp : ioOps) { AtomicReference exception = new AtomicReference<>(); - Runnable task = () -> exception.set(expectThrows(WTE, ioOp)); + Runnable task = () -> exception.set(assertThrows(WTE, ioOp)); var t = new Thread(task); t.start(); t.join(); @@ -164,7 +174,8 @@ public void testIOOnConfinedFromAnotherThread(Supplier arenaSupplier) } } - @Test(dataProvider = "closeableArenas") + @ParameterizedTest + @MethodSource("closeableArenas") public void testScatterGatherIO(Supplier arenaSupplier) throws Exception { @@ -176,13 +187,14 @@ public void testScatterGatherIO(Supplier arenaSupplier) var writeBuffers = mixedBuffersOfSize(32, drop, 64); var readBuffers = mixedBuffersOfSize(32, drop, 64); long expectedCount = remaining(writeBuffers); - assertEquals(writeNBytes(sc1, writeBuffers, 0, 32, expectedCount), expectedCount); - assertEquals(readNBytes(sc2, readBuffers, 0, 32, expectedCount), expectedCount); - assertEquals(flip(readBuffers), clear(writeBuffers)); + assertEquals(expectedCount, writeNBytes(sc1, writeBuffers, 0, 32, expectedCount)); + assertEquals(expectedCount, readNBytes(sc2, readBuffers, 0, 32, expectedCount)); + assertArrayEquals(clear(writeBuffers), flip(readBuffers)); } } - @Test(dataProvider = "closeableArenas") + @ParameterizedTest + @MethodSource("closeableArenas") public void testBasicIOWithDifferentSessions(Supplier arenaSupplier) throws Exception { @@ -199,9 +211,9 @@ public void testBasicIOWithDifferentSessions(Supplier arenaSupplier) .toArray(ByteBuffer[]::new); long expectedCount = remaining(writeBuffers); - assertEquals(writeNBytes(sc1, writeBuffers, 0, 32, expectedCount), expectedCount); - assertEquals(readNBytes(sc2, readBuffers, 0, 32, expectedCount), expectedCount); - assertEquals(flip(readBuffers), clear(writeBuffers)); + assertEquals(expectedCount, writeNBytes(sc1, writeBuffers, 0, 32, expectedCount)); + assertEquals(expectedCount, readNBytes(sc2, readBuffers, 0, 32, expectedCount)); + assertArrayEquals(clear(writeBuffers), flip(readBuffers)); } } diff --git a/test/jdk/java/foreign/critical/TestCritical.java b/test/jdk/java/foreign/critical/TestCritical.java index 499278685cf68..e7ab8b279589c 100644 --- a/test/jdk/java/foreign/critical/TestCritical.java +++ b/test/jdk/java/foreign/critical/TestCritical.java @@ -25,11 +25,9 @@ * @test * @library ../ /test/lib * - * @run testng/othervm/native --enable-native-access=ALL-UNNAMED TestCritical + * @run junit/othervm/native --enable-native-access=ALL-UNNAMED TestCritical */ -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import java.lang.foreign.Arena; import java.lang.foreign.FunctionDescriptor; @@ -48,8 +46,13 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import static org.testng.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestCritical extends NativeTestHelper { static final MemoryLayout CAPTURE_STATE_LAYOUT = Linker.Option.captureStateLayout(); @@ -69,7 +72,7 @@ public void testEmpty() throws Throwable { public void testIdentity() throws Throwable { MethodHandle handle = downcallHandle("identity", FunctionDescriptor.of(C_INT, C_INT), Linker.Option.critical(false)); int result = (int) handle.invokeExact(42); - assertEquals(result, 42); + assertEquals(42, result); } @Test @@ -84,16 +87,17 @@ public void testWithReturnBuffer() throws Throwable { try (Arena arena = Arena.ofConfined()) { MemorySegment result = (MemorySegment) handle.invokeExact((SegmentAllocator) arena); long x = (long) vhX.get(result, 0L); - assertEquals(x, 10); + assertEquals(10, x); long y = (long) vhY.get(result, 0L); - assertEquals(y, 11); + assertEquals(11, y); } } public record AllowHeapCase(IntFunction newArraySegment, ValueLayout elementLayout, String fName, FunctionDescriptor fDesc, boolean readOnly, boolean captureErrno) {} - @Test(dataProvider = "allowHeapCases") + @ParameterizedTest + @MethodSource("allowHeapCases") public void testAllowHeap(AllowHeapCase testCase) throws Throwable { List options = new ArrayList<>(); options.add(Linker.Option.critical(true)); @@ -138,12 +142,11 @@ public void testAllowHeap(AllowHeapCase testCase) throws Throwable { if (testCase.captureErrno()) { int errno = (int) ERRNO_HANDLE.get(captureSegment, 0L); - assertEquals(errno, 42); + assertEquals(42, errno); } } } - @DataProvider public Object[][] allowHeapCases() { FunctionDescriptor voidDesc = FunctionDescriptor.ofVoid(C_POINTER, C_POINTER, C_INT); FunctionDescriptor intDesc = voidDesc.changeReturnLayout(C_INT).insertArgumentLayouts(0, C_INT); diff --git a/test/jdk/java/foreign/critical/TestCriticalUpcall.java b/test/jdk/java/foreign/critical/TestCriticalUpcall.java index d6fd640539e75..b032e53436efa 100644 --- a/test/jdk/java/foreign/critical/TestCriticalUpcall.java +++ b/test/jdk/java/foreign/critical/TestCriticalUpcall.java @@ -25,10 +25,9 @@ * @test * @library ../ /test/lib * @requires jdk.foreign.linker != "FALLBACK" - * @run testng/othervm/native --enable-native-access=ALL-UNNAMED TestCriticalUpcall + * @run junit/othervm/native --enable-native-access=ALL-UNNAMED TestCriticalUpcall */ -import org.testng.annotations.Test; import java.io.IOException; import java.lang.foreign.FunctionDescriptor; @@ -37,7 +36,8 @@ import java.lang.invoke.MethodHandle; import java.util.List; -import static org.testng.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; +import org.junit.jupiter.api.Test; public class TestCriticalUpcall extends UpcallTestHelper { diff --git a/test/jdk/java/foreign/dontrelease/TestDontRelease.java b/test/jdk/java/foreign/dontrelease/TestDontRelease.java index b107c758ba2c5..674cc6de7fdf9 100644 --- a/test/jdk/java/foreign/dontrelease/TestDontRelease.java +++ b/test/jdk/java/foreign/dontrelease/TestDontRelease.java @@ -25,11 +25,10 @@ * @test * @library ../ /test/lib * @modules java.base/jdk.internal.ref java.base/jdk.internal.foreign - * @run testng/othervm/native --enable-native-access=ALL-UNNAMED TestDontRelease + * @run junit/othervm/native --enable-native-access=ALL-UNNAMED TestDontRelease */ import jdk.internal.foreign.MemorySessionImpl; -import org.testng.annotations.Test; import java.lang.foreign.Arena; import java.lang.foreign.FunctionDescriptor; @@ -38,7 +37,9 @@ import static java.lang.foreign.ValueLayout.ADDRESS; import static java.lang.foreign.ValueLayout.JAVA_INT; -import static org.testng.Assert.assertTrue; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; public class TestDontRelease extends NativeTestHelper { diff --git a/test/jdk/java/foreign/enablenativeaccess/TestEnableNativeAccess.java b/test/jdk/java/foreign/enablenativeaccess/TestEnableNativeAccess.java index 6fc3f79260bf8..43d6e747935b1 100644 --- a/test/jdk/java/foreign/enablenativeaccess/TestEnableNativeAccess.java +++ b/test/jdk/java/foreign/enablenativeaccess/TestEnableNativeAccess.java @@ -33,7 +33,7 @@ * panama_jni_use_module/* * * org.openjdk.foreigntest.unnamed.PanamaMainUnnamedModule - * @run testng/othervm/native/timeout=180 TestEnableNativeAccess + * @run junit/othervm/native/timeout=180 TestEnableNativeAccess * @summary Basic test for java --enable-native-access */ @@ -43,9 +43,11 @@ import jdk.test.lib.process.ProcessTools; import jdk.test.lib.process.OutputAnalyzer; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; /** * Basic test of --enable-native-access with expected behaviour: @@ -57,10 +59,9 @@ * (on first access per module only) */ -@Test +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestEnableNativeAccess extends TestEnableNativeAccessBase { - @DataProvider(name = "succeedCases") public Object[][] succeedCases() { return new Object[][] { { "panama_enable_native_access", PANAMA_MAIN, successNoWarning(), new String[]{"--enable-native-access=panama_module"} }, @@ -110,7 +111,8 @@ OutputAnalyzer run(String action, String cls, Result expectedResult, String... v return outputAnalyzer; } - @Test(dataProvider = "succeedCases") + @ParameterizedTest + @MethodSource("succeedCases") public void testSucceed(String action, String cls, Result expectedResult, String... vmopts) throws Exception { run(action, cls, expectedResult, vmopts); } @@ -119,6 +121,7 @@ public void testSucceed(String action, String cls, Result expectedResult, String * Tests that without --enable-native-access, a multi-line warning is printed * on first access of a module. */ + @Test public void testWarnFirstAccess() throws Exception { List output1 = run("panama_enable_native_access_first", PANAMA_MAIN, successWithWarning("panama")).asLines(); @@ -129,6 +132,7 @@ public void testWarnFirstAccess() throws Exception { * Specifies --enable-native-access more than once, each list of module names * is appended. */ + @Test public void testRepeatedOption() throws Exception { run("panama_enable_native_access_last_one_wins", PANAMA_MAIN, success(), "--enable-native-access=java.base", "--enable-native-access=panama_module"); @@ -139,6 +143,7 @@ public void testRepeatedOption() throws Exception { /** * Specifies bad value to --enable-native-access. */ + @Test public void testBadValue() throws Exception { run("panama_deny_bad_unknown_module", PANAMA_MAIN, failWithWarning("WARNING: Unknown module: BAD specified to --enable-native-access"), @@ -160,6 +165,7 @@ public void testBadValue() throws Exception { "--illegal-native-access=deny"); } + @Test public void testDetailedWarningMessage() throws Exception { run("panama_enable_native_access_warn_jni", PANAMA_JNI, success() diff --git a/test/jdk/java/foreign/enablenativeaccess/TestEnableNativeAccessBase.java b/test/jdk/java/foreign/enablenativeaccess/TestEnableNativeAccessBase.java index a14fd5c12d266..52ccacaf8ade1 100644 --- a/test/jdk/java/foreign/enablenativeaccess/TestEnableNativeAccessBase.java +++ b/test/jdk/java/foreign/enablenativeaccess/TestEnableNativeAccessBase.java @@ -27,7 +27,7 @@ import jdk.test.lib.process.OutputAnalyzer; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class TestEnableNativeAccessBase { static final String MODULE_PATH = System.getProperty("jdk.module.path"); diff --git a/test/jdk/java/foreign/enablenativeaccess/TestEnableNativeAccessDynamic.java b/test/jdk/java/foreign/enablenativeaccess/TestEnableNativeAccessDynamic.java index 2fccb2fa121eb..607e32e4e3522 100644 --- a/test/jdk/java/foreign/enablenativeaccess/TestEnableNativeAccessDynamic.java +++ b/test/jdk/java/foreign/enablenativeaccess/TestEnableNativeAccessDynamic.java @@ -29,7 +29,7 @@ * @build TestEnableNativeAccessDynamic * panama_module/* NativeAccessDynamicMain - * @run testng/othervm/timeout=180 TestEnableNativeAccessDynamic + * @run junit/othervm/timeout=180 TestEnableNativeAccessDynamic * @summary Test for dynamically setting --enable-native-access flag for a module */ @@ -39,13 +39,13 @@ import jdk.test.lib.process.ProcessTools; import jdk.test.lib.process.OutputAnalyzer; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; -@Test +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestEnableNativeAccessDynamic extends TestEnableNativeAccessBase { - @DataProvider(name = "succeedCases") public Object[][] succeedCases() { return new Object[][] { { "panama_enable_native_access", PANAMA_MAIN, successNoWarning() }, @@ -54,7 +54,6 @@ public Object[][] succeedCases() { }; } - @DataProvider(name = "failureCases") public Object[][] failureCases() { String errMsg = "Illegal native access from module panama_module"; return new Object[][] { @@ -92,13 +91,15 @@ OutputAnalyzer run(String action, String moduleAndCls, boolean enableNativeAcces return outputAnalyzer; } - @Test(dataProvider = "succeedCases") + @ParameterizedTest + @MethodSource("succeedCases") public void testSucceed(String action, String moduleAndCls, Result expectedResult) throws Exception { run(action, moduleAndCls, true, expectedResult, false); } - @Test(dataProvider = "failureCases") + @ParameterizedTest + @MethodSource("failureCases") public void testFailures(String action, String moduleAndCls, Result expectedResult) throws Exception { run(action, moduleAndCls, false, expectedResult, false); @@ -106,7 +107,8 @@ public void testFailures(String action, String moduleAndCls, // make sure that having a same named module in boot layer with native access // does not influence same named dynamic module. - @Test(dataProvider = "failureCases") + @ParameterizedTest + @MethodSource("failureCases") public void testFailuresWithPanamaModuleInBootLayer(String action, String moduleAndCls, Result expectedResult) throws Exception { run(action, moduleAndCls, false, expectedResult, true); diff --git a/test/jdk/java/foreign/enablenativeaccess/TestEnableNativeAccessJarManifest.java b/test/jdk/java/foreign/enablenativeaccess/TestEnableNativeAccessJarManifest.java index 3522921bdd340..3bcd960ccd015 100644 --- a/test/jdk/java/foreign/enablenativeaccess/TestEnableNativeAccessJarManifest.java +++ b/test/jdk/java/foreign/enablenativeaccess/TestEnableNativeAccessJarManifest.java @@ -32,7 +32,7 @@ * @build TestEnableNativeAccessJarManifest * panama_module/* * org.openjdk.foreigntest.unnamed.PanamaMainUnnamedModule - * @run testng/native TestEnableNativeAccessJarManifest + * @run junit/native TestEnableNativeAccessJarManifest */ import java.nio.file.Files; @@ -47,16 +47,19 @@ import jdk.test.lib.process.ProcessTools; import jdk.test.lib.util.JarUtils; -import org.testng.annotations.Test; -import org.testng.annotations.DataProvider; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestEnableNativeAccessJarManifest extends TestEnableNativeAccessBase { private static final String REINVOKER = "TestEnableNativeAccessJarManifest$Reinvoker"; static record Attribute(String name, String value) {} - @Test(dataProvider = "cases") + @ParameterizedTest + @MethodSource("cases") public void testEnableNativeAccessInJarManifest(String action, String cls, Result expectedResult, List attributes, List vmArgs, List programArgs) throws Exception { Manifest man = new Manifest(); @@ -89,7 +92,6 @@ public void testEnableNativeAccessInJarManifest(String action, String cls, Resul checkResult(expectedResult, outputAnalyzer); } - @DataProvider public Object[][] cases() { return new Object[][] { // simple cases where a jar contains a single main class with no dependencies diff --git a/test/jdk/java/foreign/handles/Driver.java b/test/jdk/java/foreign/handles/Driver.java index 63528e19dcbb7..1b5fbf6f857ec 100644 --- a/test/jdk/java/foreign/handles/Driver.java +++ b/test/jdk/java/foreign/handles/Driver.java @@ -24,6 +24,6 @@ /* * @test * @build invoker_module/* lookup_module/* - * @run testng/othervm --illegal-native-access=deny --enable-native-access=invoker_module + * @run junit/othervm --illegal-native-access=deny --enable-native-access=invoker_module * lookup_module/handle.lookup.MethodHandleLookup */ diff --git a/test/jdk/java/foreign/handles/lookup_module/handle/lookup/MethodHandleLookup.java b/test/jdk/java/foreign/handles/lookup_module/handle/lookup/MethodHandleLookup.java index f41cf59b07f1c..254a95a3b2085 100644 --- a/test/jdk/java/foreign/handles/lookup_module/handle/lookup/MethodHandleLookup.java +++ b/test/jdk/java/foreign/handles/lookup_module/handle/lookup/MethodHandleLookup.java @@ -37,16 +37,19 @@ import java.nio.file.Path; import java.util.function.Consumer; -import org.testng.annotations.*; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class MethodHandleLookup { - @Test(dataProvider = "restrictedMethods") + @ParameterizedTest + @MethodSource("restrictedMethods") public void testRestrictedHandles(MethodHandle handle, String testName) throws Throwable { new handle.invoker.MethodHandleInvoker().call(handle); } - @DataProvider(name = "restrictedMethods") static Object[][] restrictedMethods() { try { return new Object[][]{ diff --git a/test/jdk/java/foreign/handles/lookup_module/module-info.java b/test/jdk/java/foreign/handles/lookup_module/module-info.java index 54efcb071ef74..d6578a9fde9ab 100644 --- a/test/jdk/java/foreign/handles/lookup_module/module-info.java +++ b/test/jdk/java/foreign/handles/lookup_module/module-info.java @@ -22,7 +22,7 @@ */ open module lookup_module { - requires org.testng; + requires org.junit.platform.console.standalone; requires invoker_module; exports handle.lookup; } diff --git a/test/jdk/java/foreign/loaderLookup/TestLoaderLookupJNI.java b/test/jdk/java/foreign/loaderLookup/TestLoaderLookupJNI.java index cb6c0c0bb9e5b..ef9621787ae51 100644 --- a/test/jdk/java/foreign/loaderLookup/TestLoaderLookupJNI.java +++ b/test/jdk/java/foreign/loaderLookup/TestLoaderLookupJNI.java @@ -21,15 +21,15 @@ * questions. */ -import org.testng.annotations.Test; import java.lang.foreign.SymbolLookup; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; /* * @test - * @run testng/othervm/native TestLoaderLookupJNI + * @run junit/othervm/native TestLoaderLookupJNI */ public class TestLoaderLookupJNI { diff --git a/test/jdk/java/foreign/loaderLookup/TestSymbolLookupFindOrThrow.java b/test/jdk/java/foreign/loaderLookup/TestSymbolLookupFindOrThrow.java index 146fdbbcf5a0a..0f6495505f7c5 100644 --- a/test/jdk/java/foreign/loaderLookup/TestSymbolLookupFindOrThrow.java +++ b/test/jdk/java/foreign/loaderLookup/TestSymbolLookupFindOrThrow.java @@ -30,10 +30,9 @@ import java.lang.foreign.SymbolLookup; import java.util.NoSuchElementException; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; final class TestSymbolLookupFindOrThrow { @@ -44,7 +43,7 @@ final class TestSymbolLookupFindOrThrow { @Test void findOrThrow() { MemorySegment symbol = SymbolLookup.loaderLookup().findOrThrow("foo"); - Assertions.assertNotEquals(0, symbol.address()); + assertNotEquals(0, symbol.address()); } @Test diff --git a/test/jdk/java/foreign/nested/TestNested.java b/test/jdk/java/foreign/nested/TestNested.java index 70237bafc1334..e416d54aaee27 100644 --- a/test/jdk/java/foreign/nested/TestNested.java +++ b/test/jdk/java/foreign/nested/TestNested.java @@ -26,11 +26,9 @@ * @library ../ /test/lib * @requires jdk.foreign.linker != "FALLBACK" * @build NativeTestHelper - * @run testng/othervm/native --enable-native-access=ALL-UNNAMED TestNested + * @run junit/othervm/native --enable-native-access=ALL-UNNAMED TestNested */ -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import java.lang.foreign.Arena; import java.lang.foreign.FunctionDescriptor; @@ -45,13 +43,19 @@ import java.util.Random; import java.util.concurrent.atomic.AtomicReference; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestNested extends NativeTestHelper { static { System.loadLibrary("Nested"); } - @Test(dataProvider = "nestedLayouts") + @ParameterizedTest + @MethodSource("nestedLayouts") public void testNested(GroupLayout layout) throws Throwable { try (Arena arena = Arena.ofConfined()) { Random random = new Random(0); @@ -73,7 +77,6 @@ public void testNested(GroupLayout layout) throws Throwable { } } - @DataProvider public static Object[][] nestedLayouts() { List layouts = List.of( S1, U1, U17, S2, S3, S4, S5, S6, U2, S7, U3, U4, U5, U6, U7, S8, S9, U8, U9, U10, S10, diff --git a/test/jdk/java/foreign/normalize/TestNormalize.java b/test/jdk/java/foreign/normalize/TestNormalize.java index b68e43c0705a6..ee238f2e1fe2f 100644 --- a/test/jdk/java/foreign/normalize/TestNormalize.java +++ b/test/jdk/java/foreign/normalize/TestNormalize.java @@ -24,15 +24,13 @@ /* * @test * @library ../ - * @run testng/othervm/native + * @run junit/othervm/native * --enable-native-access=ALL-UNNAMED * -Xbatch * -XX:CompileCommand=dontinline,TestNormalize::doCall* * TestNormalize */ -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import java.lang.foreign.*; import java.lang.invoke.MethodHandle; @@ -45,9 +43,14 @@ import static java.lang.foreign.ValueLayout.JAVA_CHAR; import static java.lang.foreign.ValueLayout.JAVA_INT; import static java.lang.foreign.ValueLayout.JAVA_SHORT; -import static org.testng.Assert.assertEquals; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; // test normalization of smaller than int primitive types +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestNormalize extends NativeTestHelper { private static final Linker LINKER = Linker.nativeLinker(); @@ -98,7 +101,8 @@ public class TestNormalize extends NativeTestHelper { // When we do either of those, argument normalization should take place, so that the resulting value is sane (1). // After that we convert the value back to int again, the JVM can/will skip value normalization here. // We then check the high order bits of the resulting int. If argument normalization took place at (1), they should all be 0. - @Test(dataProvider = "cases") + @ParameterizedTest + @MethodSource("cases") public void testNormalize(ValueLayout layout, int testValue, int hobMask, MethodHandle toInt, MethodHandle saver) throws Throwable { // use actual type as parameter type to test upcall arg normalization FunctionDescriptor upcallDesc = FunctionDescriptor.ofVoid(layout); @@ -125,8 +129,8 @@ public void testNormalize(ValueLayout layout, int testValue, int hobMask, Method private static void doCall(MethodHandle downcallHandle, MemorySegment upcallStub, int[] box, int dirtyValue, int hobMask) throws Throwable { int result = (int) downcallHandle.invokeExact(upcallStub, dirtyValue); - assertEquals(box[0] & hobMask, 0); // check normalized upcall arg - assertEquals(result & hobMask, 0); // check normalized downcall return value + assertEquals(0, box[0] & hobMask); // check normalized upcall arg + assertEquals(0, result & hobMask); // check normalized downcall return value } public static void saveBooleanAsInt(boolean b, int[] box) { @@ -159,7 +163,6 @@ public static int shortToInt(short s) { return s; } - @DataProvider public static Object[][] cases() { return new Object[][] { { JAVA_BOOLEAN, booleanToInt(true), BOOLEAN_HOB_MASK, BOOLEAN_TO_INT, SAVE_BOOLEAN_AS_INT }, @@ -171,7 +174,8 @@ public static Object[][] cases() { // test which int values are considered true and false // we currently convert any int with a non-zero first byte to true, otherwise false. - @Test(dataProvider = "bools") + @ParameterizedTest + @MethodSource("bools") public void testBool(int testValue, boolean expected) throws Throwable { MemorySegment addr = findNativeOrThrow("test"); MethodHandle target = LINKER.downcallHandle(addr, FunctionDescriptor.of(JAVA_BOOLEAN, ADDRESS, JAVA_INT)); @@ -182,8 +186,8 @@ public void testBool(int testValue, boolean expected) throws Throwable { try (Arena arena = Arena.ofConfined()) { MemorySegment callback = LINKER.upcallStub(upcallTarget, FunctionDescriptor.ofVoid(JAVA_BOOLEAN), arena); boolean result = (boolean) target.invokeExact(callback, testValue); - assertEquals(box[0], expected); - assertEquals(result, expected); + assertEquals(expected, box[0]); + assertEquals(expected, result); } } @@ -191,7 +195,6 @@ private static void saveBoolean(boolean b, boolean[] box) { box[0] = b; } - @DataProvider public static Object[][] bools() { return new Object[][]{ { 0b10, true }, // zero least significant bit, but non-zero first byte diff --git a/test/jdk/java/foreign/normalize/TestNormalizeBooleanVarHandle.java b/test/jdk/java/foreign/normalize/TestNormalizeBooleanVarHandle.java index acca0d095c301..567fec7ccb885 100644 --- a/test/jdk/java/foreign/normalize/TestNormalizeBooleanVarHandle.java +++ b/test/jdk/java/foreign/normalize/TestNormalizeBooleanVarHandle.java @@ -23,11 +23,9 @@ /* * @test - * @run testng TestNormalizeBooleanVarHandle + * @run junit TestNormalizeBooleanVarHandle */ -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; @@ -38,14 +36,20 @@ import java.util.function.Predicate; import static java.lang.foreign.ValueLayout.*; -import static org.testng.Assert.*; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; // test normalization of smaller than int primitive types +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestNormalizeBooleanVarHandle { static final VarHandle VH = JAVA_BOOLEAN.varHandle(); - @Test(dataProvider = "bools") + @ParameterizedTest + @MethodSource("bools") public void testBool(Function segmentFactory, Predicate accessor, byte testValue, boolean expected) { try (Arena arena = Arena.ofConfined()) { @@ -53,11 +57,10 @@ public void testBool(Function segmentFactory, Predicate cases = new ArrayList<>(); for (Function segmentFactory : factories()) { diff --git a/test/jdk/java/foreign/passheapsegment/TestPassHeapSegment.java b/test/jdk/java/foreign/passheapsegment/TestPassHeapSegment.java index 1f63d7bfe2313..53af722c950df 100644 --- a/test/jdk/java/foreign/passheapsegment/TestPassHeapSegment.java +++ b/test/jdk/java/foreign/passheapsegment/TestPassHeapSegment.java @@ -24,11 +24,9 @@ /* * @test * @library ../ /test/lib - * @run testng/othervm/native --enable-native-access=ALL-UNNAMED TestPassHeapSegment + * @run junit/othervm/native --enable-native-access=ALL-UNNAMED TestPassHeapSegment */ -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import java.io.IOException; import java.lang.foreign.*; @@ -36,22 +34,29 @@ import static java.lang.foreign.ValueLayout.ADDRESS; +import static org.junit.jupiter.api.Assertions.assertThrows; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class TestPassHeapSegment extends UpcallTestHelper { static { System.loadLibrary("PassHeapSegment"); } - @Test(expectedExceptions = IllegalArgumentException.class, - expectedExceptionsMessageRegExp = ".*Heap segment not allowed.*") + @Test public void testNoHeapArgs() throws Throwable { MethodHandle handle = downcallHandle("test_args", FunctionDescriptor.ofVoid(ADDRESS)); MemorySegment segment = MemorySegment.ofArray(new byte[]{ 0, 1, 2 }); - handle.invoke(segment); // should throw + assertThrows(IllegalArgumentException.class, () -> { + handle.invoke(segment); + }); } - @Test(expectedExceptions = IllegalArgumentException.class, - expectedExceptionsMessageRegExp = ".*Heap segment not allowed.*") + @Test public void testNoHeapCaptureCallState() throws Throwable { MethodHandle handle = downcallHandle("test_args", FunctionDescriptor.ofVoid(ADDRESS), Linker.Option.captureCallState("errno")); @@ -59,11 +64,14 @@ public void testNoHeapCaptureCallState() throws Throwable { assert Linker.Option.captureStateLayout().byteAlignment() % 4 == 0; MemorySegment captureHeap = MemorySegment.ofArray(new int[(int) Linker.Option.captureStateLayout().byteSize() / 4]); MemorySegment segment = arena.allocateFrom(C_CHAR, new byte[]{ 0, 1, 2 }); - handle.invoke(captureHeap, segment); // should throw for captureHeap + assertThrows(IllegalArgumentException.class, () -> { + handle.invoke(captureHeap, segment); + }); } } - @Test(dataProvider = "specs") + @ParameterizedTest + @MethodSource("specs") public void testNoHeapReturns(boolean spec) throws IOException, InterruptedException { runInNewProcess(Runner.class, spec) .shouldNotHaveExitValue(0) @@ -87,7 +95,6 @@ public static MemorySegment target() { } } - @DataProvider public static Object[][] specs() { return new Object[][]{ { true }, diff --git a/test/jdk/java/foreign/virtual/TestVirtualCalls.java b/test/jdk/java/foreign/virtual/TestVirtualCalls.java index ddb4eb6669496..54b76de298ca5 100644 --- a/test/jdk/java/foreign/virtual/TestVirtualCalls.java +++ b/test/jdk/java/foreign/virtual/TestVirtualCalls.java @@ -24,7 +24,7 @@ /* * @test * @library ../ - * @run testng/othervm/native + * @run junit/othervm/native * --enable-native-access=ALL-UNNAMED * TestVirtualCalls */ @@ -35,9 +35,9 @@ import java.lang.foreign.MemorySegment; import java.lang.invoke.MethodHandle; -import org.testng.annotations.*; - -import static org.testng.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import org.junit.jupiter.api.Test; public class TestVirtualCalls extends NativeTestHelper { @@ -60,14 +60,16 @@ public class TestVirtualCalls extends NativeTestHelper { @Test public void testVirtualCalls() throws Throwable { - assertEquals((int) func.invokeExact(funcA), 1); - assertEquals((int) func.invokeExact(funcB), 2); - assertEquals((int) func.invokeExact(funcC), 3); + assertEquals(1, (int) func.invokeExact(funcA)); + assertEquals(2, (int) func.invokeExact(funcB)); + assertEquals(3, (int) func.invokeExact(funcC)); } - @Test(expectedExceptions = NullPointerException.class) + @Test public void testNullTarget() throws Throwable { - int x = (int) func.invokeExact((MemorySegment)null); + assertThrows(NullPointerException.class, () -> { + int x = (int) func.invokeExact((MemorySegment)null); + }); } }