mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +00:00
Tests/LibELF: Run LibELF tests on Lagom using Linux runtime linker
So that we can be sure Serenity's runtime linker performs the same.
This commit is contained in:
parent
6894faac1f
commit
9c707c4205
Notes:
sideshowbarker
2024-07-16 20:12:13 +09:00
Author: https://github.com/DanShaders Commit: https://github.com/SerenityOS/serenity/commit/9c707c4205 Pull-request: https://github.com/SerenityOS/serenity/pull/24170 Reviewed-by: https://github.com/ADKaster ✅
4 changed files with 66 additions and 30 deletions
|
@ -655,6 +655,9 @@ if (BUILD_LAGOM)
|
||||||
list(APPEND TEST_DIRECTORIES LibWeb)
|
list(APPEND TEST_DIRECTORIES LibWeb)
|
||||||
list(APPEND TEST_DIRECTORIES LibWebView)
|
list(APPEND TEST_DIRECTORIES LibWebView)
|
||||||
endif()
|
endif()
|
||||||
|
if (LINUX)
|
||||||
|
list(APPEND TEST_DIRECTORIES LibELF)
|
||||||
|
endif()
|
||||||
|
|
||||||
foreach (dir IN LISTS TEST_DIRECTORIES)
|
foreach (dir IN LISTS TEST_DIRECTORIES)
|
||||||
add_serenity_subdirectory("Tests/${dir}")
|
add_serenity_subdirectory("Tests/${dir}")
|
||||||
|
|
|
@ -1,14 +1,29 @@
|
||||||
set(CMAKE_SKIP_RPATH FALSE)
|
set(CMAKE_SKIP_RPATH FALSE)
|
||||||
|
if (NOT BUILD_LAGOM)
|
||||||
|
set(CMAKE_INSTALL_RPATH "$ORIGIN:$ORIGIN/../lib")
|
||||||
|
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
|
||||||
|
else()
|
||||||
|
set(CMAKE_BUILD_RPATH "$ORIGIN:$ORIGIN/../lib")
|
||||||
|
set(CMAKE_INSTALL_RPATH "$ORIGIN:$ORIGIN/../lib")
|
||||||
|
endif()
|
||||||
|
|
||||||
macro(add_test_lib NAME FILE)
|
macro(add_test_lib NAME FILE)
|
||||||
add_library(${NAME} SHARED ${FILE})
|
add_library(${NAME} SHARED ${FILE})
|
||||||
serenity_set_implicit_links(${NAME})
|
if (NOT BUILD_LAGOM)
|
||||||
|
serenity_set_implicit_links(${NAME})
|
||||||
|
else()
|
||||||
|
target_link_libraries(${NAME} PRIVATE AK LibCore)
|
||||||
|
endif()
|
||||||
install(TARGETS ${NAME} DESTINATION usr/Tests/LibELF)
|
install(TARGETS ${NAME} DESTINATION usr/Tests/LibELF)
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
macro(add_test_exe NAME FILE)
|
macro(add_test_exe NAME FILE)
|
||||||
add_executable(${NAME} ${FILE})
|
add_executable(${NAME} ${FILE})
|
||||||
serenity_set_implicit_links(${NAME})
|
if (NOT BUILD_LAGOM)
|
||||||
|
serenity_set_implicit_links(${NAME})
|
||||||
|
else()
|
||||||
|
target_link_libraries(${NAME} PRIVATE AK LibCore)
|
||||||
|
endif()
|
||||||
install(TARGETS ${NAME} DESTINATION usr/Tests/LibELF)
|
install(TARGETS ${NAME} DESTINATION usr/Tests/LibELF)
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
|
@ -19,17 +34,12 @@ macro(add_dlopen_lib NAME FUNCTION)
|
||||||
target_link_libraries(${NAME} PRIVATE LibLine)
|
target_link_libraries(${NAME} PRIVATE LibLine)
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
add_dlopen_lib(DynlibA dynliba_function)
|
macro(target_link_manual TARGET LIB)
|
||||||
add_dlopen_lib(DynlibB dynlibb_function)
|
target_link_libraries(${TARGET} PRIVATE -Wl,--push-state,--no-as-needed $<TARGET_FILE:${LIB}> -Wl,--pop-state)
|
||||||
|
add_dependencies(${TARGET} ${LIB})
|
||||||
add_dlopen_lib(DynlibC dynlibc_function)
|
endmacro()
|
||||||
set(CMAKE_INSTALL_RPATH $ORIGIN)
|
|
||||||
add_dlopen_lib(DynlibD dynlibd_function)
|
|
||||||
target_link_libraries(DynlibD PRIVATE DynlibC)
|
|
||||||
unset(CMAKE_INSTALL_RPATH)
|
|
||||||
|
|
||||||
set(TEST_SOURCES
|
set(TEST_SOURCES
|
||||||
test-elf.cpp
|
|
||||||
TestDlOpen.cpp
|
TestDlOpen.cpp
|
||||||
TestOrder.cpp
|
TestOrder.cpp
|
||||||
TestTLS.cpp
|
TestTLS.cpp
|
||||||
|
@ -37,35 +47,58 @@ set(TEST_SOURCES
|
||||||
)
|
)
|
||||||
|
|
||||||
foreach(source IN LISTS TEST_SOURCES)
|
foreach(source IN LISTS TEST_SOURCES)
|
||||||
serenity_test("${source}" LibELF)
|
if (NOT BUILD_LAGOM)
|
||||||
|
serenity_test("${source}" LibELF)
|
||||||
|
else()
|
||||||
|
get_filename_component(test_name ${source} NAME_WE)
|
||||||
|
lagom_test("${source}" WORKING_DIRECTORY "$<TARGET_FILE_DIR:${test_name}>")
|
||||||
|
# FIXME: Figure out why on Ubuntu 22.04 dlopen ignores RUNPATH in executable.
|
||||||
|
set_tests_properties(${test_name} PROPERTIES ENVIRONMENT LD_LIBRARY_PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
|
||||||
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
# test-elf.cpp
|
||||||
|
if (NOT BUILD_LAGOM)
|
||||||
|
serenity_test(test-elf.cpp LibELF)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# TestDlOpen.cpp
|
||||||
|
add_dlopen_lib(DynlibA dynliba_function)
|
||||||
|
add_dlopen_lib(DynlibB dynlibb_function)
|
||||||
|
|
||||||
|
add_dlopen_lib(DynlibC dynlibc_function)
|
||||||
|
add_dlopen_lib(DynlibD dynlibd_function)
|
||||||
|
target_link_manual(DynlibD DynlibC)
|
||||||
|
|
||||||
|
# TestTLS.cpp
|
||||||
add_test_lib(TLSDef TLSDef.cpp)
|
add_test_lib(TLSDef TLSDef.cpp)
|
||||||
add_test_lib(TLSUse TLSUse.cpp)
|
add_test_lib(TLSUse TLSUse.cpp)
|
||||||
target_compile_options(TLSUse PRIVATE -ftls-model=global-dynamic)
|
target_compile_options(TLSUse PRIVATE -ftls-model=global-dynamic)
|
||||||
target_link_libraries(TLSUse PRIVATE LibCore LibTest LibThreading TLSDef)
|
target_link_libraries(TLSUse PRIVATE LibCore LibTest LibThreading TLSDef)
|
||||||
set_target_properties(TLSUse PROPERTIES INSTALL_RPATH "$ORIGIN")
|
|
||||||
target_link_libraries(TestTLS PRIVATE TLSUse)
|
target_link_libraries(TestTLS PRIVATE TLSUse)
|
||||||
set_target_properties(TestTLS PROPERTIES INSTALL_RPATH "$ORIGIN")
|
|
||||||
|
|
||||||
|
# TestWeakSymbolResolution.cpp
|
||||||
add_test_lib(TestWeakSymbolResolution1 TestWeakSymbolResolution1.cpp)
|
add_test_lib(TestWeakSymbolResolution1 TestWeakSymbolResolution1.cpp)
|
||||||
add_test_lib(TestWeakSymbolResolution2 TestWeakSymbolResolution2.cpp)
|
add_test_lib(TestWeakSymbolResolution2 TestWeakSymbolResolution2.cpp)
|
||||||
target_link_libraries(TestWeakSymbolResolution PRIVATE TestWeakSymbolResolution1 TestWeakSymbolResolution2)
|
target_link_manual(TestWeakSymbolResolution TestWeakSymbolResolution1)
|
||||||
set_target_properties(TestWeakSymbolResolution PROPERTIES INSTALL_RPATH "$ORIGIN")
|
target_link_manual(TestWeakSymbolResolution TestWeakSymbolResolution2)
|
||||||
|
|
||||||
|
# TestOrder.cpp
|
||||||
add_test_lib(TestOrderLib1 TestOrderLib1.cpp)
|
add_test_lib(TestOrderLib1 TestOrderLib1.cpp)
|
||||||
add_test_lib(TestOrderLib2 TestOrderLib2.cpp)
|
add_test_lib(TestOrderLib2 TestOrderLib2.cpp)
|
||||||
target_link_libraries(TestOrderLib2 PRIVATE TestOrderLib1)
|
target_link_manual(TestOrderLib2 TestOrderLib1)
|
||||||
set_target_properties(TestOrderLib2 PROPERTIES INSTALL_RPATH "$ORIGIN")
|
|
||||||
|
|
||||||
# NOTE: This is so ugly because CMake sorts targets supplied to target_link_libraries.
|
|
||||||
# .elf extension here avoids direct invocations by SerenityOS's test runner.
|
|
||||||
add_test_exe(TestOrderExe1.elf TestOrderExe.cpp)
|
add_test_exe(TestOrderExe1.elf TestOrderExe.cpp)
|
||||||
target_link_libraries(TestOrderExe1.elf PRIVATE $<TARGET_FILE:TestOrderLib1> $<TARGET_FILE:TestOrderLib2>)
|
target_link_manual(TestOrderExe1.elf TestOrderLib1)
|
||||||
add_dependencies(TestOrderExe1.elf TestOrderLib1 TestOrderLib2)
|
target_link_manual(TestOrderExe1.elf TestOrderLib2)
|
||||||
set_target_properties(TestOrderExe1.elf PROPERTIES INSTALL_RPATH "$ORIGIN")
|
|
||||||
|
|
||||||
add_test_exe(TestOrderExe2.elf TestOrderExe.cpp)
|
add_test_exe(TestOrderExe2.elf TestOrderExe.cpp)
|
||||||
target_link_libraries(TestOrderExe2.elf PRIVATE $<TARGET_FILE:TestOrderLib2> $<TARGET_FILE:TestOrderLib1>)
|
target_link_manual(TestOrderExe2.elf TestOrderLib2)
|
||||||
add_dependencies(TestOrderExe2.elf TestOrderLib1 TestOrderLib2)
|
target_link_manual(TestOrderExe2.elf TestOrderLib1)
|
||||||
set_target_properties(TestOrderExe2.elf PROPERTIES INSTALL_RPATH "$ORIGIN")
|
|
||||||
|
add_dependencies(TestOrder
|
||||||
|
TestOrderLib1
|
||||||
|
TestOrderLib2
|
||||||
|
TestOrderExe1.elf
|
||||||
|
TestOrderExe2.elf
|
||||||
|
)
|
||||||
|
|
|
@ -9,9 +9,9 @@
|
||||||
|
|
||||||
TEST_CASE(test_dlopen)
|
TEST_CASE(test_dlopen)
|
||||||
{
|
{
|
||||||
auto liba = dlopen("/usr/Tests/LibELF/libDynlibA.so", 0);
|
auto liba = dlopen("libDynlibA.so", RTLD_LAZY | RTLD_GLOBAL);
|
||||||
EXPECT_NE(liba, nullptr);
|
EXPECT_NE(liba, nullptr);
|
||||||
auto libb = dlopen("/usr/Tests/LibELF/libDynlibB.so", 0);
|
auto libb = dlopen("libDynlibB.so", RTLD_LAZY | RTLD_GLOBAL);
|
||||||
EXPECT_NE(libb, nullptr);
|
EXPECT_NE(libb, nullptr);
|
||||||
|
|
||||||
typedef int (*dynlib_func_t)();
|
typedef int (*dynlib_func_t)();
|
||||||
|
@ -26,7 +26,7 @@ TEST_CASE(test_dlopen)
|
||||||
|
|
||||||
TEST_CASE(test_dlsym_rtld_default)
|
TEST_CASE(test_dlsym_rtld_default)
|
||||||
{
|
{
|
||||||
auto libd = dlopen("/usr/Tests/LibELF/libDynlibD.so", 0);
|
auto libd = dlopen("libDynlibD.so", RTLD_LAZY | RTLD_GLOBAL);
|
||||||
EXPECT_NE(libd, nullptr);
|
EXPECT_NE(libd, nullptr);
|
||||||
if (libd == nullptr) {
|
if (libd == nullptr) {
|
||||||
warnln("can't open libDynlibD.so, {}", dlerror());
|
warnln("can't open libDynlibD.so, {}", dlerror());
|
||||||
|
|
|
@ -17,7 +17,7 @@ TEST_CASE(basic)
|
||||||
|
|
||||||
TEST_CASE(local_exec)
|
TEST_CASE(local_exec)
|
||||||
{
|
{
|
||||||
[[gnu::tls_model("local-exec")]] static volatile __thread char test1[PAGE_SIZE * 4 + 10];
|
[[gnu::tls_model("local-exec")]] static volatile __thread char test1[4096 * 4 + 10];
|
||||||
|
|
||||||
for (size_t i = 0; i < sizeof(test1); i++) {
|
for (size_t i = 0; i < sizeof(test1); i++) {
|
||||||
test1[i] = static_cast<char>(i);
|
test1[i] = static_cast<char>(i);
|
||||||
|
|
Loading…
Reference in a new issue