< prev index next >

test/jdk/java/foreign/TestIllegalLink.java

Print this page
@@ -21,12 +21,10 @@
   * questions.
   */
  
  /*
   * @test
-  * @enablePreview
-  * @requires jdk.foreign.linker != "UNSUPPORTED"
   * @modules java.base/jdk.internal.foreign
   * @run testng/othervm --enable-native-access=ALL-UNNAMED TestIllegalLink
   */
  
  import java.lang.foreign.Arena;

@@ -45,10 +43,12 @@
  
  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;
  
  public class TestIllegalLink extends NativeTestHelper {
  

@@ -100,11 +100,11 @@
      @DataProvider
      public static Object[][] downcallOnlyOptions() {
          return new Object[][]{
              { Linker.Option.firstVariadicArg(0) },
              { Linker.Option.captureCallState("errno") },
-             { Linker.Option.isTrivial() },
+             { Linker.Option.critical() },
          };
      }
  
      @DataProvider
      public static Object[][] types() {

@@ -126,11 +126,11 @@
                      IS_LE ? "Unsupported layout: 2%i4" : "Unsupported layout: 2%I4"
              },
              {
                      FunctionDescriptor.ofVoid(C_POINTER.withByteAlignment(2)),
                      NO_OPTIONS,
-                     IS_LE ? "Unsupported layout: 2%a8" : "Unsupported layout: 2%A8"
+                     (IS_LE ? "Unsupported layout: 2%a" : "Unsupported layout: 2%A") + ADDRESS.byteSize()
              },
              {
                      FunctionDescriptor.ofVoid(ValueLayout.JAVA_CHAR.withByteAlignment(4)),
                      NO_OPTIONS,
                      IS_LE ? "Unsupported layout: 4%c2" : "Unsupported layout: 4%C2"

@@ -154,11 +154,11 @@
                      NO_OPTIONS,
                      IS_LE ? "Unsupported layout: 1%s2" : "Unsupported layout: 1%S2"
              },
              {
                      FunctionDescriptor.ofVoid(MemoryLayout.structLayout(
-                             MemoryLayout.sequenceLayout(
+                             MemoryLayout.sequenceLayout(1,
                                  C_INT.withByteAlignment(1)
                              ))),
                      NO_OPTIONS,
                      IS_LE ? "Unsupported layout: 1%i4" : "Unsupported layout: 1%I4"
              },

@@ -179,28 +179,26 @@
                      FunctionDescriptor.of(MemoryLayout.structLayout(C_INT.withOrder(nonNativeOrder()))),
                      NO_OPTIONS,
                      IS_LE ? "Unsupported layout: I4" : "Unsupported layout: i4"
              },
              {
-                     FunctionDescriptor.of(MemoryLayout.structLayout(MemoryLayout.sequenceLayout(C_INT.withOrder(nonNativeOrder())))),
+                     FunctionDescriptor.of(MemoryLayout.structLayout(MemoryLayout.sequenceLayout(1, C_INT.withOrder(nonNativeOrder())))),
                      NO_OPTIONS,
                      IS_LE ? "Unsupported layout: I4" : "Unsupported layout: i4"
              },
-             {
-                     FunctionDescriptor.ofVoid(MemoryLayout.structLayout(
-                             ValueLayout.JAVA_LONG,
-                             ValueLayout.JAVA_INT)), // missing trailing padding
-                     NO_OPTIONS,
-                     "has unexpected size"
-             },
              {
                      FunctionDescriptor.ofVoid(MemoryLayout.structLayout(
                              ValueLayout.JAVA_INT,
                              MemoryLayout.paddingLayout(4))), // too much trailing padding
                      NO_OPTIONS,
                      "has unexpected size"
              },
+             {
+                     FunctionDescriptor.ofVoid(),
+                     new Linker.Option[]{Linker.Option.critical(), Linker.Option.captureCallState("errno")},
+                     "Incompatible linker options: captureCallState, critical"
+             },
          }));
  
          for (ValueLayout illegalLayout : List.of(C_CHAR, ValueLayout.JAVA_CHAR, C_BOOL, C_SHORT, C_FLOAT)) {
              cases.add(new Object[]{
                  FunctionDescriptor.ofVoid(C_INT, illegalLayout),

@@ -210,17 +208,26 @@
          }
  
          if (IS_SYSV) {
              cases.add(new Object[] {
                      FunctionDescriptor.ofVoid(MemoryLayout.structLayout(
-                             MemoryLayout.sequenceLayout(
+                             MemoryLayout.sequenceLayout(Long.MAX_VALUE / C_INT.byteSize(),
                                  C_INT
                              ))),
                      NO_OPTIONS,
                      "GroupLayout is too large"
              });
          }
+         if (ValueLayout.JAVA_LONG.byteAlignment() == 8) {
+             cases.add(new Object[]{
+                     FunctionDescriptor.ofVoid(MemoryLayout.structLayout(
+                             ValueLayout.JAVA_LONG,
+                             ValueLayout.JAVA_INT)), // missing trailing padding
+                     NO_OPTIONS,
+                     "has unexpected size"
+             });
+         }
          return cases.toArray(Object[][]::new);
      }
  
      private static ByteOrder nonNativeOrder() {
          return ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN
< prev index next >