Skip to content

Commit bef64c5

Browse files
committed
unittests: Add test thunk library
1 parent 615ab8d commit bef64c5

File tree

12 files changed

+131
-3
lines changed

12 files changed

+131
-3
lines changed

CI/FEXLinuxTestsThunks.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"ThunksDB": {
3+
"fex_thunk_test": 1
4+
}
5+
}

Data/ThunksDB.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@
144144
"@PREFIX_LIB@/libasound.so.2.0.0"
145145
]
146146
},
147+
"fex_thunk_test": {
148+
"Library": "libfex_thunk_test-guest.so",
149+
"Overlay": [
150+
"@PREFIX_LIB@/libfex_thunk_test.so"
151+
]
152+
},
147153
"Xrender": {
148154
"Library": "libXrender-guest.so",
149155
"Overlay": [

ThunkLibs/GuestLibs/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,6 @@ if (BITNESS EQUAL 32)
291291
# 338: 0f 0b ud2
292292
target_compile_options(VDSO-guest PRIVATE "-fno-pic")
293293
endif()
294+
295+
generate(libfex_thunk_test ${CMAKE_CURRENT_SOURCE_DIR}/../libfex_thunk_test/libfex_thunk_test_interface.cpp)
296+
add_guest_lib(fex_thunk_test "libfex_thunk_test.so")

ThunkLibs/HostLibs/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,10 @@ foreach(GUEST_BITNESS IN LISTS BITNESS_LIST)
186186
target_include_directories(libdrm-${GUEST_BITNESS}-deps INTERFACE /usr/include/drm/)
187187
target_include_directories(libdrm-${GUEST_BITNESS}-deps INTERFACE /usr/include/libdrm/)
188188
add_host_lib(drm ${GUEST_BITNESS})
189+
190+
generate(libfex_thunk_test ${CMAKE_CURRENT_SOURCE_DIR}/../libfex_thunk_test/libfex_thunk_test_interface.cpp ${GUEST_BITNESS})
191+
add_host_lib(fex_thunk_test ${GUEST_BITNESS})
189192
endforeach()
193+
194+
add_library(fex_thunk_test SHARED ../libfex_thunk_test/lib.cpp)
195+
install(TARGETS fex_thunk_test LIBRARY DESTINATION lib COMPONENT TestLibraries)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
$info$
3+
tags: thunklibs|fex_thunk_test
4+
$end_info$
5+
*/
6+
7+
#include "common/Guest.h"
8+
#include "api.h"
9+
10+
#include "thunkgen_guest_libfex_thunk_test.inl"
11+
12+
LOAD_LIB(libfex_thunk_test)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
$info$
3+
tags: thunklibs|fex_thunk_test
4+
$end_info$
5+
*/
6+
7+
#include <cstddef>
8+
#include <dlfcn.h>
9+
10+
#include "common/Host.h"
11+
12+
#include "api.h"
13+
14+
#include "thunkgen_host_libfex_thunk_test.inl"
15+
16+
EXPORTS(libfex_thunk_test)

ThunkLibs/libfex_thunk_test/api.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* This file defines interfaces of a dummy library used to test various
3+
* features of the thunk generator.
4+
*/
5+
#pragma once
6+
7+
#include <cstdint>
8+
9+
extern "C" {
10+
11+
uint32_t GetDoubledValue(uint32_t);
12+
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "api.h"
2+
3+
extern "C" {
4+
5+
uint32_t GetDoubledValue(uint32_t input) {
6+
return 2 * input;
7+
}
8+
9+
} // extern "C"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <common/GeneratorInterface.h>
2+
3+
#include "api.h"
4+
5+
template<auto>
6+
struct fex_gen_config {};
7+
8+
template<typename>
9+
struct fex_gen_type {};
10+
11+
template<auto, int, typename>
12+
struct fex_gen_param {};
13+
14+
template<> struct fex_gen_config<GetDoubledValue> {};

unittests/FEXLinuxTests/CMakeLists.txt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ function(AddTests Tests BinDirectory Bitness)
4444
set(BIN_PATH "${CMAKE_CURRENT_BINARY_DIR}/${BinDirectory}/${TEST_NAME}.${Bitness}")
4545
set(TEST_CASE "${TEST_NAME}.${Bitness}")
4646

47+
set(THUNK_ARGS "")
48+
if(TEST_NAME STREQUAL "thunk_testlib")
49+
# Test thunking only if thunks are enabled and supported
50+
if(NOT BUILD_THUNKS OR ENABLE_GLIBC_ALLOCATOR_HOOK_FAULT)
51+
continue()
52+
endif()
53+
54+
set(THUNK_ARGS "-k" "${CMAKE_SOURCE_DIR}/CI/FEXLinuxTestsThunks.json")
55+
endif()
56+
4757
# Add jit test case
4858
add_test(NAME "${TEST_CASE}.jit.flt"
4959
COMMAND "python3" "${CMAKE_SOURCE_DIR}/Scripts/guest_test_runner.py"
@@ -54,9 +64,11 @@ function(AddTests Tests BinDirectory Bitness)
5464
"${TEST_CASE}"
5565
"guest"
5666
"$<TARGET_FILE:FEXLoader>"
67+
${THUNK_ARGS}
5768
"--no-silent" "-c" "irjit" "-n" "500" "--"
5869
"${BIN_PATH}")
59-
if (_M_X86_64)
70+
71+
if (_M_X86_64 AND NOT TEST_NAME STREQUAL "thunk_testlib")
6072
# Add host test case
6173
add_test(NAME "${TEST_CASE}.host.flt"
6274
COMMAND "python3" "${CMAKE_SOURCE_DIR}/Scripts/guest_test_runner.py"
@@ -79,6 +91,12 @@ AddTests("${TESTS_64_ONLY}" "FEXLinuxTests_64" 64)
7991
# Execute tests that are only 32-bit.
8092
AddTests("${TESTS_32_ONLY}" "FEXLinuxTests_32" 32)
8193

94+
if(TEST thunk_testlib.64.jit.flt)
95+
# Ensure libfex_thunk_test is found even when using an uncommon install prefix
96+
set_property(TEST "thunk_testlib.32.jit.flt" PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/lib")
97+
set_property(TEST "thunk_testlib.64.jit.flt" PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/lib")
98+
endif()
99+
82100
execute_process(COMMAND "nproc" OUTPUT_VARIABLE CORES)
83101
string(STRIP ${CORES} CORES)
84102

0 commit comments

Comments
 (0)