Improve the generation of programs and tests.
This commit is contained in:
+1
-1
@@ -58,10 +58,10 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-stack-protector")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-pic")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i686")
|
||||
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcommon")
|
||||
endif()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i686")
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3")
|
||||
|
||||
@@ -76,10 +76,10 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-stack-protector")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-pic")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i686")
|
||||
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcommon")
|
||||
endif()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i686")
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3")
|
||||
|
||||
+65
-16
@@ -39,10 +39,10 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-stack-protector")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-pic")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i686")
|
||||
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcommon")
|
||||
endif()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i686")
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3")
|
||||
@@ -55,30 +55,79 @@ endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
# =============================================================================
|
||||
# BUILD
|
||||
# =============================================================================
|
||||
# Add the executables (manually).
|
||||
set(PROGRAMS
|
||||
nice.c
|
||||
ls.c
|
||||
mkdir.c
|
||||
ipcrm.c
|
||||
login.c
|
||||
man.c
|
||||
logo.c
|
||||
shell.c
|
||||
cpuid.c
|
||||
clear.c
|
||||
rmdir.c
|
||||
poweroff.c
|
||||
rm.c
|
||||
cat.c
|
||||
init.c
|
||||
ps.c
|
||||
kill.c
|
||||
edit.c
|
||||
sleep.c
|
||||
date.c
|
||||
echo.c
|
||||
showpid.c
|
||||
uname.c
|
||||
ipcs.c
|
||||
touch.c
|
||||
uptime.c
|
||||
pwd.c
|
||||
env.c
|
||||
)
|
||||
# Set the directory where the compiled binaries will be placed.
|
||||
set(MENTOS_BIN_DIR ${CMAKE_SOURCE_DIR}/files/bin)
|
||||
|
||||
foreach(PROGRAM ${PROGRAMS})
|
||||
foreach(FILE_NAME ${PROGRAMS})
|
||||
# Prepare the program name.
|
||||
string(REPLACE ".c" "" PROGRAM_NAME ${PROGRAM})
|
||||
string(REPLACE ".c" "" EXECUTABLE_NAME ${FILE_NAME})
|
||||
|
||||
# Set the name of the target.
|
||||
set(TARGET_NAME prog_${PROGRAM_NAME})
|
||||
set(TARGET_NAME prog_${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} ${PROGRAM})
|
||||
add_executable(${TARGET_NAME} ${CMAKE_SOURCE_DIR}/programs/${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} ${CMAKE_BINARY_DIR}/libc/libc.a)
|
||||
# Add the dependency to libc.
|
||||
add_dependencies(${TARGET_NAME} libc)
|
||||
# Copy the progam to the bin folder.
|
||||
add_custom_command(
|
||||
TARGET ${TARGET_NAME}
|
||||
BYPRODUCTS ${MENTOS_BIN_DIR}/${PROGRAM_NAME}
|
||||
COMMAND mkdir -p ${MENTOS_BIN_DIR}
|
||||
COMMAND cp ${PROJECT_BINARY_DIR}/${TARGET_NAME} ${MENTOS_BIN_DIR}/${PROGRAM_NAME}
|
||||
DEPENDS ${TARGET_NAME}
|
||||
)
|
||||
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_BIN_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_EXECUTABLES ${TARGET_NAME})
|
||||
endforeach()
|
||||
|
||||
@@ -8,51 +8,6 @@ cmake_minimum_required(VERSION 3.1...3.22)
|
||||
# Initialize the project.
|
||||
project(tests C)
|
||||
|
||||
# =============================================================================
|
||||
# List of programs.
|
||||
# =============================================================================
|
||||
# Add your file in this list.
|
||||
set(TESTS
|
||||
t_mem.c
|
||||
t_fork.c
|
||||
# Test real-time programs.
|
||||
t_periodic1.c
|
||||
t_periodic2.c
|
||||
t_periodic3.c
|
||||
# Testing task execution.
|
||||
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
|
||||
# Test semaphores.
|
||||
t_semget.c
|
||||
t_semflg.c
|
||||
t_semop.c
|
||||
# Test message queues.
|
||||
t_msgget.c
|
||||
# Test shared memory.
|
||||
t_shmget.c
|
||||
t_shm_read.c
|
||||
t_shm_write.c
|
||||
# Test scheduling feedback tests.
|
||||
t_schedfb.c
|
||||
)
|
||||
|
||||
# =============================================================================
|
||||
# C WARNINGs
|
||||
# =============================================================================
|
||||
@@ -84,10 +39,10 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-stack-protector")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-pic")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i686")
|
||||
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcommon")
|
||||
endif()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i686")
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3")
|
||||
@@ -100,30 +55,81 @@ endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
# =============================================================================
|
||||
# BUILD
|
||||
# =============================================================================
|
||||
# Add your file in this list.
|
||||
set(TESTS
|
||||
t_gid.c
|
||||
t_alarm.c
|
||||
t_periodic3.c
|
||||
t_setenv.c
|
||||
t_itimer.c
|
||||
t_fork.c
|
||||
t_semget.c
|
||||
t_exec.c
|
||||
t_sleep.c
|
||||
t_periodic2.c
|
||||
t_sigfpe.c
|
||||
t_sigmask.c
|
||||
t_getenv.c
|
||||
t_sigusr.c
|
||||
t_exec_callee.c
|
||||
t_shmget.c
|
||||
t_stopcont.c
|
||||
t_semop.c
|
||||
t_sigaction.c
|
||||
t_schedfb.c
|
||||
t_siginfo.c
|
||||
t_groups.c
|
||||
t_semflg.c
|
||||
t_abort.c
|
||||
t_msgget.c
|
||||
t_periodic1.c
|
||||
t_kill.c
|
||||
t_shm_write.c
|
||||
t_mem.c
|
||||
t_shm_read.c
|
||||
)
|
||||
# Set the directory where the compiled binaries will be placed.
|
||||
set(MENTOS_TESTS_DIR ${CMAKE_SOURCE_DIR}/files/bin/tests)
|
||||
|
||||
foreach(TEST ${TESTS})
|
||||
foreach(FILE_NAME ${TESTS})
|
||||
# Prepare the program name.
|
||||
string(REPLACE ".c" "" TEST_NAME ${TEST})
|
||||
string(REPLACE ".c" "" EXECUTABLE_NAME ${FILE_NAME})
|
||||
|
||||
# Set the name of the target.
|
||||
set(TARGET_NAME test_${TEST_NAME})
|
||||
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} ${TEST})
|
||||
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} ${CMAKE_BINARY_DIR}/libc/libc.a)
|
||||
# Add the dependency to libc.
|
||||
add_dependencies(${TARGET_NAME} libc)
|
||||
# Copy the progam to the bin folder.
|
||||
add_custom_command(
|
||||
TARGET ${TARGET_NAME}
|
||||
BYPRODUCTS ${MENTOS_TESTS_DIR}/${TEST_NAME}
|
||||
COMMAND mkdir -p ${MENTOS_TESTS_DIR}
|
||||
COMMAND cp ${PROJECT_BINARY_DIR}/${TARGET_NAME} ${MENTOS_TESTS_DIR}/${TEST_NAME}
|
||||
DEPENDS ${TARGET_NAME}
|
||||
)
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user