Skip to content

Commit

Permalink
FEXLinuxTests/thunks: Add assume_compatible_data_layout tests
Browse files Browse the repository at this point in the history
  • Loading branch information
neobrain committed Oct 19, 2023
1 parent 0cf2695 commit cb215b5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
9 changes: 9 additions & 0 deletions ThunkLibs/libfex_thunk_test/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,13 @@ OpaqueType* MakeOpaqueType(uint32_t data);
uint32_t ReadOpaqueTypeData(OpaqueType*);
void DestroyOpaqueType(OpaqueType*);

union UnionType {
uint32_t a;
int32_t b;
uint8_t c[4];
};

UnionType MakeUnionType(uint8_t a, uint8_t b, uint8_t c, uint8_t d);
uint32_t GetUnionTypeA(UnionType*);

}
8 changes: 8 additions & 0 deletions ThunkLibs/libfex_thunk_test/lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ void DestroyOpaqueType(OpaqueType* value) {
delete value;
}

UnionType MakeUnionType(uint8_t a, uint8_t b, uint8_t c, uint8_t d) {
return UnionType { .c = { a, b, c, d } };
}

uint32_t GetUnionTypeA(UnionType* value) {
return value->a;
}

} // extern "C"
4 changes: 4 additions & 0 deletions ThunkLibs/libfex_thunk_test/libfex_thunk_test_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ template<> struct fex_gen_type<OpaqueType> : fexgen::opaque_type {};
template<> struct fex_gen_config<MakeOpaqueType> {};
template<> struct fex_gen_config<ReadOpaqueTypeData> {};
template<> struct fex_gen_config<DestroyOpaqueType> {};

template<> struct fex_gen_type<UnionType> : fexgen::assume_compatible_data_layout {};
template<> struct fex_gen_config<MakeUnionType> {};
template<> struct fex_gen_config<GetUnionTypeA> {};
16 changes: 13 additions & 3 deletions unittests/FEXLinuxTests/tests/thunks/thunk_testlib.64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,24 @@ struct Fixture {
GET_SYMBOL(MakeOpaqueType);
GET_SYMBOL(ReadOpaqueTypeData);
GET_SYMBOL(DestroyOpaqueType);

GET_SYMBOL(MakeUnionType);
GET_SYMBOL(GetUnionTypeA);
};

TEST_CASE_METHOD(Fixture, "Trivial") {
CHECK(GetDoubledValue(10) == 20);
}

TEST_CASE_METHOD(Fixture, "Opaque data types") {
auto data = MakeOpaqueType(0x1234);
CHECK(ReadOpaqueTypeData(data) == 0x1234);
DestroyOpaqueType(data);
{
auto data = MakeOpaqueType(0x1234);
CHECK(ReadOpaqueTypeData(data) == 0x1234);
DestroyOpaqueType(data);
}

{
auto data = MakeUnionType(0x1, 0x2, 0x3, 0x4);
CHECK(GetUnionTypeA(&data) == 0x04030201);
}
}

0 comments on commit cb215b5

Please sign in to comment.