19 const auto& struct_type =
22 const char* test_result = struct_type.ToCString(zone,
true);
24 const int kFilePathLength = 100;
25 char expectation_file_path[kFilePathLength];
27 "runtime/vm/compiler/ffi/unit_tests/%s/%s_%s.expect",
name,
28 kTargetArchitectureName,
kOs);
35 char* expectation_file_contents =
nullptr;
36 ReadFromFile(expectation_file_path, &expectation_file_contents);
37 EXPECT_NOTNULL(expectation_file_contents);
38 if (expectation_file_contents !=
nullptr) {
39 EXPECT_STREQ(expectation_file_contents, test_result);
40 free(expectation_file_contents);
49 EXPECT_EQ(1, native_type.SizeInBytes());
50 EXPECT(native_type.IsInt());
51 EXPECT(native_type.IsPrimitive());
53 EXPECT_STREQ(
"int8", native_type.ToCString(
Z));
60 members.Add(&int8type);
61 members.Add(&int8type);
62 members.Add(&int8type);
63 members.Add(&int8type);
64 members.Add(&int8type);
65 members.Add(&int8type);
66 members.Add(&int8type);
67 members.Add(&int8type);
68 members.Add(&int8type);
69 members.Add(&int8type);
71 const auto& struct_type =
RunStructTest(
Z,
"struct_int8x10", members);
73 EXPECT(!struct_type.ContainsHomogeneousFloats());
75 EXPECT_EQ(0, struct_type.NumberOfWordSizeChunksOnlyFloat());
79 struct_type.NumberOfWordSizeChunksNotOnlyFloat());
86 members.Add(&float_type);
87 members.Add(&float_type);
88 members.Add(&float_type);
89 members.Add(&float_type);
91 const auto& struct_type =
RunStructTest(
Z,
"struct_floatx4", members);
97 EXPECT(struct_type.ContainsHomogeneousFloats());
104 struct_type.NumberOfWordSizeChunksOnlyFloat());
105 EXPECT_EQ(0, struct_type.NumberOfWordSizeChunksNotOnlyFloat());
146 members.Add(&intptr_type);
149 members.Add(&intptr_type);
150 members.Add(&intptr_type);
151 members.Add(&intptr_type);
164 const auto& struct_type =
RunStructTest(
Z,
"struct_int8array", members);
166 EXPECT_EQ(8, struct_type.SizeInBytes());
167 EXPECT(!struct_type.ContainsHomogeneousFloats());
169 EXPECT_EQ(0, struct_type.NumberOfWordSizeChunksOnlyFloat());
173 struct_type.NumberOfWordSizeChunksNotOnlyFloat());
182 inner_struct_members.Add(&inner_array_type);
183 const auto& inner_struct =
191 const auto& struct_type =
RunStructTest(
Z,
"struct_floatarray", members);
193 EXPECT_EQ(16, struct_type.SizeInBytes());
194 EXPECT(struct_type.ContainsHomogeneousFloats());
197 struct_type.NumberOfWordSizeChunksOnlyFloat());
205 members.Add(&uint8_type);
206 members.Add(&uint16_type);
207 const intptr_t packing = 1;
209 const auto& struct_type =
213 EXPECT_EQ(3, struct_type.SizeInBytes());
214 EXPECT(struct_type.ContainsUnalignedMembers());
222 inner_members.Add(&uint16_type);
223 inner_members.Add(&uint8_type);
224 const intptr_t packing = 1;
225 const auto& inner_struct_type =
228 EXPECT_EQ(3, inner_struct_type.SizeInBytes());
231 EXPECT(!inner_struct_type.ContainsUnalignedMembers());
239 EXPECT_EQ(6, struct_type.SizeInBytes());
242 EXPECT(struct_type.ContainsUnalignedMembers());
250 inner_members.Add(&uint32_type);
251 inner_members.Add(&uint8_type);
252 const intptr_t packing = 1;
253 const auto& inner_struct_type =
256 EXPECT_EQ(5, inner_struct_type.SizeInBytes());
259 EXPECT(!inner_struct_type.ContainsUnalignedMembers());
262 members.Add(&uint8_type);
263 members.Add(&inner_struct_type);
266 EXPECT_EQ(6, struct_type.SizeInBytes());
269 EXPECT(struct_type.ContainsUnalignedMembers());
280 members.Add(&array8_bytes);
281 members.Add(&array9_bytes);
286 EXPECT_EQ(12, union_type.SizeInBytes());
288 EXPECT(!union_type.ContainsUnalignedMembers());
297 struct_member_types.Add(&float_type);
298 struct_member_types.Add(&float_type);
299 struct_member_types.Add(&float_type);
300 struct_member_types.Add(&float_type);
301 const auto& struct_type =
305 member_types.Add(&float_array_type);
306 member_types.Add(&struct_type);
309 EXPECT_EQ(16, union_type.SizeInBytes());
311 EXPECT_EQ(4, union_type.NumPrimitiveMembersRecursive());
312 EXPECT(union_type.FirstPrimitiveMember().Equals(float_type));
313 EXPECT(union_type.ContainsHomogeneousFloats());
315 EXPECT(!union_type.ContainsUnalignedMembers());
323 inner_members.Add(&uint8_type);
324 inner_members.Add(&uint32_type);
325 const intptr_t packing = 1;
326 const auto& struct_type =
333 member_types.Add(&struct_type);
336 EXPECT_EQ(5, union_type.SizeInBytes());
337 EXPECT_EQ(1, union_type.AlignmentInBytesField());
339 EXPECT(union_type.ContainsUnalignedMembers());
static void Print(const char *format,...) PRINTF_ATTRIBUTE(1
static int SNPrint(char *str, size_t size, const char *format,...) PRINTF_ATTRIBUTE(3
static constexpr T RoundUp(T x, uintptr_t alignment, uintptr_t offset=0)
static NativeStructType & FromNativeTypes(Zone *zone, const NativeTypes &members, intptr_t member_packing=kMaxInt32)
static NativeUnionType & FromNativeTypes(Zone *zone, const NativeTypes &members)
static Range StartAndEnd(intptr_t start_inclusive, intptr_t end_exclusive)
static bool update_expectations
UNIT_TEST_CASE_WITH_ZONE(NativeCallingConvention_int8x10)
void WriteToFile(char *path, const char *contents)
const NativeCompoundType & RunStructTest(dart::Zone *zone, const char *name, const NativeTypes &member_types, intptr_t packing=kMaxInt32)
ZoneGrowableArray< const NativeType * > NativeTypes
void ReadFromFile(char *path, char **buffer_pointer)
static constexpr intptr_t kWordSize
constexpr int32_t kMaxInt32
def array_type(data_type)
VeryLargeStruct * children