Files
MentOS/programs/tests/CMakeLists.txt
T
2024-01-15 15:26:56 +01:00

84 lines
2.9 KiB
CMake

# =============================================================================
# BUILD
# =============================================================================
# Set the directory where the compiled binaries will be placed.
set(MENTOS_TESTS_DIR ${CMAKE_SOURCE_DIR}/files/bin/tests)
# Create the directory.
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${MENTOS_TESTS_DIR})
# Add the executables (manually).
set(TESTS
t_mem.c
t_fork.c
# Real-time programs
t_periodic1.c
t_periodic2.c
t_periodic3.c
# Exec
t_exec.c
t_exec_callee.c
# Test environmental variables.
t_setenv.c
t_getenv.c
# Test: signals.
t_stopcont.c
t_sigusr.c
t_abort.c
t_sigfpe.c
t_siginfo.c
t_sleep.c
t_sigaction.c
t_sigmask.c
t_groups.c
t_alarm.c
t_kill.c
t_itimer.c
t_gid.c
)
foreach(FILE_NAME ${TESTS})
# Prepare the program name.
string(REPLACE ".c" "" EXECUTABLE_NAME ${FILE_NAME})
# Set the name of the target.
set(TARGET_NAME test_${EXECUTABLE_NAME})
# =========================================================================
# TEXT ADDRESS
# =========================================================================
# Randomize .text section address so when debugging symbols don't clash.
# The allowed range is from 256MB to 2.75GB
# Minimum allowed address: 0x10000000
# Max allowed address: 0xB0000000
string(MD5 RAND_HASH ${FILE_NAME})
string(SUBSTRING ${RAND_HASH} 1 3 TEXADDR_INFIX)
string(RANDOM LENGTH 1 ALPHABET 0123456789AB RANDOM_SEED ${RAND_HASH} TEXADDR_FIRST)
set(TEXT_ADDR 0x${TEXADDR_FIRST}${TEXADDR_INFIX}0000)
# =========================================================================
# EXECUTABLE
# =========================================================================
# Create the target.
add_executable(${TARGET_NAME} ${CMAKE_SOURCE_DIR}/programs/tests/${FILE_NAME})
# Add the dependency to libc.
add_dependencies(${TARGET_NAME} libc)
# Add the includes.
target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/libc/inc)
# Link the libc library.
target_link_libraries(${TARGET_NAME} libc)
# We need to specify the name of the entry function.
target_compile_options(${TARGET_NAME} PRIVATE -u_start)
# Add the linking properties.
set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS "-Wl,-Ttext=${TEXT_ADDR},-e_start,-melf_i386")
# Set the output directory.
set_target_properties(${TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${MENTOS_TESTS_DIR}")
# Set the output name.
set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME "${EXECUTABLE_NAME}")
# Append the program name to the list of all the executables.
list(APPEND ALL_TESTS ${TARGET_NAME})
endforeach()
# Add the overall target that builds all the programs.
add_custom_target(all_tests ALL DEPENDS ${ALL_TESTS})