Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions .github/workflows/smp_startup_qemu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: smp_startup_qemu

on:
push:
branches: [ master, dev ]
paths:
- ".github/workflows/smp_startup_qemu.yml"
- "CMakeLists.txt"
- "cmake/aarch64-none-elf.cmake"
- "cmake/cortex_a53.cmake"
- "common_smp/**"
- "ports_smp/cortex_a53_smp/gnu/**"
- "scripts/tx_ci_common.sh"
- "test/smp/cmake/startup_qemu/**"
pull_request:
branches: [ master, dev ]
paths:
- ".github/workflows/smp_startup_qemu.yml"
- "CMakeLists.txt"
- "cmake/aarch64-none-elf.cmake"
- "cmake/cortex_a53.cmake"
- "common_smp/**"
- "ports_smp/cortex_a53_smp/gnu/**"
- "scripts/tx_ci_common.sh"
- "test/smp/cmake/startup_qemu/**"

permissions:
contents: read

jobs:
smp_startup_qemu:
runs-on: ubuntu-24.04
timeout-minutes: 15

env:
GCC_VERSION: 14.3.rel1

steps:
- name: Check out the repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

# Share the AArch64 toolchain cache with gcc_check.yml.
- name: Cache the AArch64 Arm GNU toolchain
id: cache-arm64
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: toolchain64
key: arm-gnu-toolchain-${{ env.GCC_VERSION }}-x86_64-aarch64-none-elf

- name: Install the AArch64 Arm GNU toolchain
if: steps.cache-arm64.outputs.cache-hit != 'true'
run: |
set -eu
base="https://developer.arm.com/-/media/Files/downloads/gnu/$GCC_VERSION/binrel"
archive="arm-gnu-toolchain-$GCC_VERSION-x86_64-aarch64-none-elf.tar.xz"
mkdir -p toolchain64
cd toolchain64
curl -fsSLO "$base/$archive"
curl -fsSLO "$base/$archive.sha256asc"
sha256sum -c "$archive.sha256asc"
tar xf "$archive"
rm -f "$archive"

- name: Install QEMU
run: |
set -eu
. scripts/tx_ci_common.sh
packages="qemu-system-arm"
command -v ninja >/dev/null 2>&1 || packages="$packages ninja-build"
retry sudo "${TIMEOUT[@]}" apt-get "${APT_OPTIONS[@]}" update || true
# shellcheck disable=SC2086
retry sudo "${TIMEOUT[@]}" apt-get "${APT_OPTIONS[@]}" install -y --no-install-recommends $packages

- name: Build and run the SMP startup test
run: |
set -eu
export PATH="$GITHUB_WORKSPACE/toolchain64/arm-gnu-toolchain-$GCC_VERSION-x86_64-aarch64-none-elf/bin:$PATH"
cmake -S test/smp/cmake/startup_qemu -B build/smp_startup_qemu -G Ninja \
-DCMAKE_TOOLCHAIN_FILE="$PWD/cmake/cortex_a53.cmake"
cmake --build build/smp_startup_qemu
ctest --test-dir build/smp_startup_qemu --verbose --no-tests=error
4 changes: 0 additions & 4 deletions ports_smp/linux/gnu/inc/tx_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,6 @@ extern UINT priority_change_extension_selection;
/* Define extension macros for automated coverage tests. */


#define TX_PORT_SPECIFIC_MEMORY_SYNCHRONIZATION other_core_status = other_core_status + _tx_thread_system_state[0]; \
_tx_thread_system_state[0] = 0;


#define TX_BYTE_ALLOCATE_EXTENSION if (threadx_byte_allocate_loop_test == ((TEST_FLAG) 1)) \
{ \
pool_ptr -> tx_byte_pool_owner = TX_NULL; \
Expand Down
32 changes: 32 additions & 0 deletions test/smp/cmake/startup_qemu/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (c) 2026 Eclipse ThreadX contributors
# SPDX-License-Identifier: MIT

cmake_minimum_required(VERSION 3.18)
project(threadx_smp_startup_qemu LANGUAGES C ASM)

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

find_program(QEMU NAMES qemu-system-aarch64 REQUIRED)
find_program(GCOV NAMES aarch64-none-elf-gcov REQUIRED)

get_filename_component(THREADX_SOURCE "${CMAKE_CURRENT_LIST_DIR}/../../../.." ABSOLUTE)
set(THREADX_SMP ON)
add_subdirectory("${THREADX_SOURCE}" threadx)
target_compile_definitions(threadx PUBLIC TX_THREAD_SMP_MAX_CORES=2 TX_THREAD_SMP_CORE_MASK=3 EL1)
set_property(SOURCE "${THREADX_SOURCE}/common_smp/src/tx_initialize_kernel_enter.c"
TARGET_DIRECTORY threadx APPEND PROPERTY COMPILE_OPTIONS
-O0 -fprofile-arcs -ftest-coverage -fprofile-info-section)

add_executable(smp_startup startup.S startup.c)
target_link_options(smp_startup PRIVATE -nostartfiles "-T${CMAKE_CURRENT_LIST_DIR}/memory.ld")
set_property(TARGET smp_startup APPEND PROPERTY LINK_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/memory.ld")
target_link_libraries(smp_startup PRIVATE threadx gcov)

enable_testing()
add_test(NAME smp_startup_qemu COMMAND "${CMAKE_COMMAND}"
"-DQEMU=${QEMU}" "-DGCOV=${GCOV}" "-DIMAGE=$<TARGET_FILE:smp_startup>"
"-DGCOV_UNIT=${CMAKE_CURRENT_BINARY_DIR}/threadx/CMakeFiles/threadx.dir/common_smp/src/tx_initialize_kernel_enter.c"
-P "${CMAKE_CURRENT_LIST_DIR}/run.cmake")
set_tests_properties(smp_startup_qemu PROPERTIES TIMEOUT 30)
21 changes: 21 additions & 0 deletions test/smp/cmake/startup_qemu/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Cortex-A53 SMP startup test

The test boots two Cortex-A53 cores on QEMU `virt`. Core 1 waits five virtual
milliseconds after release, then enters the port's secondary startup routine
and clears its own system state. The test requires both cores to run a thread
and gcov to report both outcomes of `_tx_initialize_kernel_enter`'s core-ready
wait condition.

With `aarch64-none-elf-gcc`, `aarch64-none-elf-gcov`, and `qemu-system-aarch64`
on `PATH`, run from the repository root.

```sh
cmake -S test/smp/cmake/startup_qemu -B build/smp_startup_qemu -G Ninja \
-DCMAKE_TOOLCHAIN_FILE="$PWD/cmake/cortex_a53.cmake"
cmake --build build/smp_startup_qemu
ctest --test-dir build/smp_startup_qemu --verbose --no-tests=error
```

`startup.c` deviates from MISRA C:2023 Rule 11.5 in the gcov callbacks. The GCC
callback interface passes the file handle through `void *`. The callbacks
recover the pointer to the original `long` object.
36 changes: 36 additions & 0 deletions test/smp/cmake/startup_qemu/memory.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Copyright (c) 2026 Eclipse ThreadX contributors */
/* SPDX-License-Identifier: MIT */

ENTRY(_start)
PHDRS
{
code PT_LOAD FLAGS(5);
data PT_LOAD FLAGS(6);
}
SECTIONS
{
. = 0x40200000;
.text : { KEEP(*(.text.start)) *(.text .text.*) } :code
.rodata : { *(.rodata .rodata.*) } :code
.gcov_info :
{
__gcov_info_start = .;
KEEP(*(.gcov_info))
} :data
.data : { *(.data .data.*) } :data
.bss (NOLOAD) :
{
. = ALIGN(16);
__bss_start = .;
*(.bss .bss.*) *(COMMON)
. = ALIGN(16);
__bss_end = .;
. += 0x4000;
__primary_stack = .;
. += 0x4000;
__secondary_stack = .;
__top_of_ram = .;
PROVIDE(end = .);
} :data
}
ASSERT(SIZEOF(.gcov_info) == 8, "Expected one instrumented translation unit")
29 changes: 29 additions & 0 deletions test/smp/cmake/startup_qemu/run.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2026 Eclipse ThreadX contributors
# SPDX-License-Identifier: MIT

file(REMOVE "${GCOV_UNIT}.gcda")
execute_process(
COMMAND "${QEMU}" -M virt,gic-version=3 -cpu cortex-a53 -smp 2
-accel tcg,thread=single -icount shift=0,sleep=off -m 128M -nographic -nic none
-semihosting-config enable=on,target=native -kernel "${IMAGE}"
RESULT_VARIABLE qemu_status OUTPUT_VARIABLE qemu_output ERROR_VARIABLE qemu_output
TIMEOUT 20)
if(NOT qemu_status STREQUAL "0" OR NOT EXISTS "${GCOV_UNIT}.gcda")
message(FATAL_ERROR "SMP startup failed (${qemu_status})\n${qemu_output}")
endif()
message(STATUS "${qemu_output}")

execute_process(
COMMAND "${GCOV}" -b -c -t "${GCOV_UNIT}.gcno"
RESULT_VARIABLE gcov_status OUTPUT_VARIABLE coverage ERROR_VARIABLE gcov_error)
if(NOT gcov_status STREQUAL "0")
message(FATAL_ERROR "Could not read SMP startup coverage\n${gcov_error}")
endif()

string(REGEX MATCH
"while \\(other_core_status[^\n]*\nbranch +0 taken ([0-9]+)[^\n]*\nbranch +1 taken ([0-9]+)"
wait_branches "${coverage}")
if(NOT wait_branches OR CMAKE_MATCH_1 LESS 1 OR CMAKE_MATCH_2 LESS 1)
message(FATAL_ERROR "Expected both SMP startup wait outcomes\n${wait_branches}")
endif()
message(STATUS "SMP startup wait branch counts ${CMAKE_MATCH_1} and ${CMAKE_MATCH_2}")
131 changes: 131 additions & 0 deletions test/smp/cmake/startup_qemu/startup.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/***************************************************************************
* 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.2-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
**************************************************************************/

.section .text.start,"ax"

// Zero the shared state before starting the primary core.
.global _start
_start:
msr daifset, #15
msr spsel, #0
ldr x0, =__primary_stack
mov sp, x0
ldr x0, =__bss_start
ldr x1, =__bss_end
1:
cmp x0, x1
b.hs 2f
stp xzr, xzr, [x0], #16
b 1b
2:
bl set_up_core
b primary_start

// Give core 0 five virtual milliseconds to exercise the wait loop.
secondary_start:
msr daifset, #15
msr spsel, #0
ldr x0, =__secondary_stack
mov sp, x0
bl set_up_core
ldr x0, =_tx_thread_smp_release_cores_flag
1:
ldr w1, [x0]
cbz w1, 1b
mrs x0, cntfrq_el0
mov x1, #200
udiv x0, x0, x1
mrs x1, cntpct_el0
2:
mrs x2, cntpct_el0
sub x2, x2, x1
cmp x2, x0
b.lo 2b
b _tx_thread_smp_initialize_wait

// Set up exception handling and a shared identity mapping for virt RAM.
set_up_core:
mov x1, sp
sub x1, x1, #0x2000
msr spsel, #1
mov sp, x1
msr spsel, #0
ldr x0, =vectors
msr vbar_el1, x0
mrs x0, cpacr_el1
orr x0, x0, #(3 << 20)
msr cpacr_el1, x0
mov x0, #0xff00
msr mair_el1, x0
ldr x0, =0x280993519
msr tcr_el1, x0
ldr x0, =level_one_table
msr ttbr0_el1, x0
isb
mrs x0, sctlr_el1
bic x0, x0, #2
orr x0, x0, #1
msr sctlr_el1, x0
isb
ret

// Start core 1 through QEMU virt's PSCI HVC conduit.
.global start_secondary_core
start_secondary_core:
ldr x0, =0xc4000003
mov x1, #1
ldr x2, =secondary_start
mov x3, #0
hvc #0
ret

// Return when each core has entered a ThreadX thread.
.global wait_for_both_cores
wait_for_both_cores:
ldr x1, =started_cores
add x2, x1, w0, uxtw #2
mov w3, #1
stlr w3, [x2]
eor w0, w0, #1
add x2, x1, w0, uxtw #2
1:
ldar w3, [x2]
cbz w3, 1b
ret

// Call the Arm semihosting service with arguments in x0 and x1.
.global semihost_call
semihost_call:
hlt #0xf000
ret

.balign 2048
vectors:
.rept 16
b startup_fault
.balign 128
.endr

.section .rodata.boot,"a"
.balign 4096
level_one_table:
.quad 0x00000401
.quad 0x40000705
.zero 4080

.bss
.balign 4
started_cores:
.zero 8
Loading