Skip to content

Commit

Permalink
FEXLinuxTests/Thunks: Add tests for assisted struct repacking
Browse files Browse the repository at this point in the history
  • Loading branch information
neobrain committed Jan 15, 2024
1 parent 6eaeb48 commit 190d802
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ThunkLibs/libfex_thunk_test/Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,12 @@ static uint32_t fexfn_impl_libfex_thunk_test_QueryOffsetOf(guest_layout<Reorderi
}
}

void fex_custom_repack_entry(host_layout<CustomRepackedType>& to, guest_layout<CustomRepackedType> const& from) {
to.data.custom_repack_invoked = 1;
}

bool fex_custom_repack_exit(guest_layout<CustomRepackedType>& to, host_layout<CustomRepackedType> const& from) {
return false;
}

EXPORTS(libfex_thunk_test)
13 changes: 13 additions & 0 deletions ThunkLibs/libfex_thunk_test/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,17 @@ uint32_t GetReorderingTypeMember(ReorderingType*, int index);
void ModifyReorderingTypeMembers(ReorderingType* data);
uint32_t QueryOffsetOf(ReorderingType*, int index);


/// Interfaces used to test assisted struct repacking

// We enable custom repacking on the "data" member, with repacking code that
// sets the first bit of "custom_repack_invoked" to 1 on entry.
struct CustomRepackedType {
ReorderingType* data;
int custom_repack_invoked;
};

// Should return true if the custom repacker set "custom_repack_invoked" to true
int RanCustomRepack(CustomRepackedType*);

}
4 changes: 4 additions & 0 deletions ThunkLibs/libfex_thunk_test/lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ void ModifyReorderingTypeMembers(ReorderingType* data) {
data->b += 2;
}

int RanCustomRepack(CustomRepackedType* data) {
return data->custom_repack_invoked;
}

} // extern "C"
3 changes: 3 additions & 0 deletions ThunkLibs/libfex_thunk_test/libfex_thunk_test_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ template<> struct fex_gen_config<ModifyReorderingTypeMembers> {};

template<> struct fex_gen_config<QueryOffsetOf> : fexgen::custom_host_impl {};
template<> struct fex_gen_param<QueryOffsetOf, 0, ReorderingType*> : fexgen::ptr_passthrough {};

template<> struct fex_gen_config<&CustomRepackedType::data> : fexgen::custom_repack {};
template<> struct fex_gen_config<RanCustomRepack> {};
7 changes: 7 additions & 0 deletions unittests/FEXLinuxTests/tests/thunks/thunk_testlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ struct Fixture {
GET_SYMBOL(GetReorderingTypeMember);
GET_SYMBOL(ModifyReorderingTypeMembers);
GET_SYMBOL(QueryOffsetOf);

GET_SYMBOL(RanCustomRepack);
};

TEST_CASE_METHOD(Fixture, "Trivial") {
Expand Down Expand Up @@ -69,3 +71,8 @@ TEST_CASE_METHOD(Fixture, "Automatic struct repacking") {
CHECK(GetReorderingTypeMember(&test_struct, 1) == 0x567a);
};
}

TEST_CASE_METHOD(Fixture, "Assisted struct repacking") {
CustomRepackedType data {};
CHECK(RanCustomRepack(&data) == 1);
}

0 comments on commit 190d802

Please sign in to comment.