@@ -63,12 +63,16 @@ public class TestCaptureCallState extends NativeTestHelper {
63
63
}
64
64
}
65
65
66
- private record SaveValuesCase (String nativeTarget , FunctionDescriptor nativeDesc , String threadLocalName , Consumer <Object > resultCheck ) {}
66
+ private record SaveValuesCase (String nativeTarget , FunctionDescriptor nativeDesc , boolean trivial , String threadLocalName , Consumer <Object > resultCheck ) {}
67
67
68
68
@ Test (dataProvider = "cases" )
69
69
public void testSavedThreadLocal (SaveValuesCase testCase ) throws Throwable {
70
- Linker .Option stl = Linker .Option .captureCallState (testCase .threadLocalName ());
71
- MethodHandle handle = downcallHandle (testCase .nativeTarget (), testCase .nativeDesc (), stl );
70
+ List <Linker .Option > options = new ArrayList <>();
71
+ options .add (Linker .Option .captureCallState (testCase .threadLocalName ()));
72
+ if (testCase .trivial ()) {
73
+ options .add (Linker .Option .isTrivial ());
74
+ }
75
+ MethodHandle handle = downcallHandle (testCase .nativeTarget (), testCase .nativeDesc (), options .toArray (Linker .Option []::new ));
72
76
73
77
StructLayout capturedStateLayout = Linker .Option .captureStateLayout ();
74
78
VarHandle errnoHandle = capturedStateLayout .varHandle (groupElement (testCase .threadLocalName ()));
@@ -101,36 +105,44 @@ public void testInvalidCaptureSegment(MemorySegment captureSegment,
101
105
}
102
106
}
103
107
108
+ interface CaseAdder {
109
+ void addCase (String nativeTarget , FunctionDescriptor nativeDesc , String threadLocalName , Consumer <Object > resultCheck );
110
+ }
111
+
104
112
@ DataProvider
105
113
public static Object [][] cases () {
106
114
List <SaveValuesCase > cases = new ArrayList <>();
115
+ CaseAdder adder = (nativeTarget , nativeDesc , threadLocalName , resultCheck ) -> {
116
+ cases .add (new SaveValuesCase (nativeTarget , nativeDesc , false , threadLocalName , resultCheck ));
117
+ cases .add (new SaveValuesCase (nativeTarget , nativeDesc , true , threadLocalName , resultCheck ));
118
+ };
107
119
108
- cases . add ( new SaveValuesCase ( "set_errno_V" , FunctionDescriptor .ofVoid (JAVA_INT ), "errno" , o -> {}) );
109
- cases . add ( new SaveValuesCase ( "set_errno_I" , FunctionDescriptor .of (JAVA_INT , JAVA_INT ), "errno" , o -> assertEquals ((int ) o , 42 ) ));
110
- cases . add ( new SaveValuesCase ( "set_errno_D" , FunctionDescriptor .of (JAVA_DOUBLE , JAVA_INT ), "errno" , o -> assertEquals ((double ) o , 42.0 ) ));
111
-
112
- cases . add ( structCase ("SL" , Map .of (JAVA_LONG .withName ("x" ), 42L ) ));
113
- cases . add ( structCase ("SLL" , Map .of (JAVA_LONG .withName ("x" ), 42L ,
114
- JAVA_LONG .withName ("y" ), 42L ) ));
115
- cases . add ( structCase ("SLLL" , Map .of (JAVA_LONG .withName ("x" ), 42L ,
116
- JAVA_LONG .withName ("y" ), 42L ,
117
- JAVA_LONG .withName ("z" ), 42L ) ));
118
- cases . add ( structCase ("SD" , Map .of (JAVA_DOUBLE .withName ("x" ), 42D ) ));
119
- cases . add ( structCase ("SDD" , Map .of (JAVA_DOUBLE .withName ("x" ), 42D ,
120
- JAVA_DOUBLE .withName ("y" ), 42D ) ));
121
- cases . add ( structCase ("SDDD" , Map .of (JAVA_DOUBLE .withName ("x" ), 42D ,
122
- JAVA_DOUBLE .withName ("y" ), 42D ,
123
- JAVA_DOUBLE .withName ("z" ), 42D ) ));
120
+ adder . addCase ( "set_errno_V" , FunctionDescriptor .ofVoid (JAVA_INT ), "errno" , o -> {});
121
+ adder . addCase ( "set_errno_I" , FunctionDescriptor .of (JAVA_INT , JAVA_INT ), "errno" , o -> assertEquals ((int ) o , 42 ));
122
+ adder . addCase ( "set_errno_D" , FunctionDescriptor .of (JAVA_DOUBLE , JAVA_INT ), "errno" , o -> assertEquals ((double ) o , 42.0 ));
123
+
124
+ structCase (adder , "SL" , Map .of (JAVA_LONG .withName ("x" ), 42L ));
125
+ structCase (adder , "SLL" , Map .of (JAVA_LONG .withName ("x" ), 42L ,
126
+ JAVA_LONG .withName ("y" ), 42L ));
127
+ structCase (adder , "SLLL" , Map .of (JAVA_LONG .withName ("x" ), 42L ,
128
+ JAVA_LONG .withName ("y" ), 42L ,
129
+ JAVA_LONG .withName ("z" ), 42L ));
130
+ structCase (adder , "SD" , Map .of (JAVA_DOUBLE .withName ("x" ), 42D ));
131
+ structCase (adder , "SDD" , Map .of (JAVA_DOUBLE .withName ("x" ), 42D ,
132
+ JAVA_DOUBLE .withName ("y" ), 42D ));
133
+ structCase (adder , "SDDD" , Map .of (JAVA_DOUBLE .withName ("x" ), 42D ,
134
+ JAVA_DOUBLE .withName ("y" ), 42D ,
135
+ JAVA_DOUBLE .withName ("z" ), 42D ));
124
136
125
137
if (IS_WINDOWS ) {
126
- cases . add ( new SaveValuesCase ( "SetLastError" , FunctionDescriptor .ofVoid (JAVA_INT ), "GetLastError" , o -> {}) );
127
- cases . add ( new SaveValuesCase ( "WSASetLastError" , FunctionDescriptor .ofVoid (JAVA_INT ), "WSAGetLastError" , o -> {}) );
138
+ adder . addCase ( "SetLastError" , FunctionDescriptor .ofVoid (JAVA_INT ), "GetLastError" , o -> {});
139
+ adder . addCase ( "WSASetLastError" , FunctionDescriptor .ofVoid (JAVA_INT ), "WSAGetLastError" , o -> {});
128
140
}
129
141
130
142
return cases .stream ().map (tc -> new Object [] {tc }).toArray (Object [][]::new );
131
143
}
132
144
133
- static SaveValuesCase structCase (String name , Map <MemoryLayout , Object > fields ) {
145
+ static void structCase (CaseAdder adder , String name , Map <MemoryLayout , Object > fields ) {
134
146
StructLayout layout = MemoryLayout .structLayout (fields .keySet ().toArray (MemoryLayout []::new ));
135
147
136
148
Consumer <Object > check = o -> {};
@@ -141,7 +153,7 @@ static SaveValuesCase structCase(String name, Map<MemoryLayout, Object> fields)
141
153
check = check .andThen (o -> assertEquals (fieldHandle .get (o , 0L ), value ));
142
154
}
143
155
144
- return new SaveValuesCase ("set_errno_" + name , FunctionDescriptor .of (layout , JAVA_INT ), "errno" , check );
156
+ adder . addCase ("set_errno_" + name , FunctionDescriptor .of (layout , JAVA_INT ), "errno" , check );
145
157
}
146
158
147
159
@ DataProvider
0 commit comments