summaryrefslogtreecommitdiff
path: root/test/tx/cmake/thread_stack_alignment/CMakeLists.txt
blob: 4040a0935188c1a542af841c2c074277f1b9061e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
##############################################################################
# Copyright (c) 2026 Eclipse ThreadX contributors
#
# This program and the accompanying materials are made available under the
# terms of the MIT License which is available at
# https://opensource.org/licenses/MIT.
#
# AI Disclosure: This file was largely AI-generated by Codex (gpt-6.1-sol).
# The AI-generated portions may be considered public domain (CC0-1.0)
# and not subject to the project's licence. The human contributor has
# reviewed and verified that the code is correct.
#
# SPDX-License-Identifier: MIT AND CC0-1.0
##############################################################################

cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
project(thread_stack_alignment_test LANGUAGES C)

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)

if(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux" OR
   NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|amd64|AMD64)$" OR
   NOT CMAKE_C_COMPILER_ID MATCHES "^(GNU|Clang)$")
  message(FATAL_ERROR "Stack alignment regression requires native x86_64 Linux/GNU port widths")
endif()

# The host suite normally builds with -m32 and configuration-specific TX_ macros.
# Keep that coverage intact, but compile this directory independently at native64
# width: the defect requires ALIGN_TYPE to be wider than ULONG. Clear only this
# directory's inherited options/definitions, then select the tested features.
set_property(DIRECTORY PROPERTY COMPILE_OPTIONS "")
set_property(DIRECTORY PROPERTY LINK_OPTIONS "")
set_property(DIRECTORY PROPERTY COMPILE_DEFINITIONS "")
add_compile_options(-m64 -Wall -Wextra -ffunction-sections -fdata-sections)
add_link_options(-m64 -Wl,--gc-sections)

enable_testing()
get_filename_component(REPO_ROOT "${CMAKE_CURRENT_LIST_DIR}/../../../.." ABSOLUTE)
set(TEST_SOURCE_DIR ${REPO_ROOT}/test/tx/thread_stack_alignment)

# Enforce warning-free compilation for the new tests and changed service.
# Unchanged MISRA/kernel sources keep their existing native64 diagnostics.
set_source_files_properties(
    ${TEST_SOURCE_DIR}/threadx_thread_stack_alignment_test.c
    ${TEST_SOURCE_DIR}/threadx_thread_stack_alignment_schedule_test.c
    ${REPO_ROOT}/common/src/tx_thread_create.c
    PROPERTIES COMPILE_OPTIONS -Werror)

foreach(mode misra control)
  set(test_target tx_stack_alignment_${mode})
  add_executable(${test_target}
      ${TEST_SOURCE_DIR}/threadx_thread_stack_alignment_test.c
      ${REPO_ROOT}/common/src/tx_thread_create.c
      ${REPO_ROOT}/common/src/tx_misra.c)
  target_include_directories(${test_target} PRIVATE
      ${REPO_ROOT}/common/inc ${REPO_ROOT}/ports/linux/gnu/inc)
  target_compile_definitions(${test_target} PRIVATE TX_ENABLE_STACK_CHECKING)
  if(mode STREQUAL "misra")
    target_compile_definitions(${test_target} PRIVATE TX_MISRA_ENABLE)
  endif()
  add_test(NAME thread_stack_alignment_native64_${mode} COMMAND ${test_target})
  set_tests_properties(thread_stack_alignment_native64_${mode}
      PROPERTIES TIMEOUT 20 LABELS "native64;stack_alignment")
endforeach()

# Use the existing source lists to build a separate real Linux kernel. This
# target also works when the parent already owns the normal native32 threadx.
set(PROJECT_NAME tx_stack_alignment_linux)
add_library(${PROJECT_NAME} STATIC)
add_subdirectory(${REPO_ROOT}/common common_native64)
add_subdirectory(${REPO_ROOT}/ports/linux/gnu linux_native64)
target_compile_definitions(${PROJECT_NAME} PUBLIC
    TX_MISRA_ENABLE TX_ENABLE_STACK_CHECKING TX_TIMER_PROCESS_IN_ISR)
target_link_libraries(${PROJECT_NAME} PUBLIC pthread)

add_executable(tx_stack_alignment_schedule
    ${TEST_SOURCE_DIR}/threadx_thread_stack_alignment_schedule_test.c)
target_link_libraries(tx_stack_alignment_schedule PRIVATE tx_stack_alignment_linux)
target_link_options(tx_stack_alignment_schedule PRIVATE -Wl,--wrap=_tx_thread_stack_build)

# Each process owns one kernel instance, with a fresh worker and observer.
foreach(offset RANGE 0 3)
  add_test(NAME thread_stack_alignment_native64_schedule_${offset}
      COMMAND tx_stack_alignment_schedule ${offset})
  set_tests_properties(thread_stack_alignment_native64_schedule_${offset}
      PROPERTIES TIMEOUT 20 RUN_SERIAL TRUE LABELS "native64;stack_alignment")
endforeach()