From cb215b5f215fd9db7f22f0cc9d5a516463c1da78 Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Thu, 19 Oct 2023 12:49:00 +0200 Subject: [PATCH] FEXLinuxTests/thunks: Add assume_compatible_data_layout tests --- ThunkLibs/libfex_thunk_test/api.h | 9 +++++++++ ThunkLibs/libfex_thunk_test/lib.cpp | 8 ++++++++ .../libfex_thunk_test_interface.cpp | 4 ++++ .../tests/thunks/thunk_testlib.64.cpp | 16 +++++++++++++--- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/ThunkLibs/libfex_thunk_test/api.h b/ThunkLibs/libfex_thunk_test/api.h index ecdbd83bf3..daacaacecd 100644 --- a/ThunkLibs/libfex_thunk_test/api.h +++ b/ThunkLibs/libfex_thunk_test/api.h @@ -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*); + } diff --git a/ThunkLibs/libfex_thunk_test/lib.cpp b/ThunkLibs/libfex_thunk_test/lib.cpp index 1f43381eb8..7502de1a00 100644 --- a/ThunkLibs/libfex_thunk_test/lib.cpp +++ b/ThunkLibs/libfex_thunk_test/lib.cpp @@ -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" diff --git a/ThunkLibs/libfex_thunk_test/libfex_thunk_test_interface.cpp b/ThunkLibs/libfex_thunk_test/libfex_thunk_test_interface.cpp index 7704fd0836..8e85d7d4b9 100644 --- a/ThunkLibs/libfex_thunk_test/libfex_thunk_test_interface.cpp +++ b/ThunkLibs/libfex_thunk_test/libfex_thunk_test_interface.cpp @@ -17,3 +17,7 @@ template<> struct fex_gen_type : fexgen::opaque_type {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; + +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_config {}; +template<> struct fex_gen_config {}; diff --git a/unittests/FEXLinuxTests/tests/thunks/thunk_testlib.64.cpp b/unittests/FEXLinuxTests/tests/thunks/thunk_testlib.64.cpp index 7b49139715..7c17ad7556 100644 --- a/unittests/FEXLinuxTests/tests/thunks/thunk_testlib.64.cpp +++ b/unittests/FEXLinuxTests/tests/thunks/thunk_testlib.64.cpp @@ -21,6 +21,9 @@ struct Fixture { GET_SYMBOL(MakeOpaqueType); GET_SYMBOL(ReadOpaqueTypeData); GET_SYMBOL(DestroyOpaqueType); + + GET_SYMBOL(MakeUnionType); + GET_SYMBOL(GetUnionTypeA); }; TEST_CASE_METHOD(Fixture, "Trivial") { @@ -28,7 +31,14 @@ TEST_CASE_METHOD(Fixture, "Trivial") { } 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); + } }