-
Notifications
You must be signed in to change notification settings - Fork 0
test: add initial host based unittests #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jedi7
wants to merge
3
commits into
master
Choose a base branch
from
feature/add_unity_unittests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
name: Host Tests | ||
|
||
on: | ||
push: | ||
|
||
jobs: | ||
host-tests: | ||
runs-on: ubuntu-24.04 | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Install dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y \ | ||
build-essential \ | ||
cmake \ | ||
ninja-build \ | ||
ruby | ||
|
||
- name: Cache CMake build | ||
uses: actions/cache@v4 | ||
with: | ||
path: unittests/host/build | ||
key: ${{ runner.os }}-cmake-${{ hashFiles('unittests/host/CMakeLists.txt', 'unittests/host/cmock_config.yml') }} | ||
restore-keys: | | ||
${{ runner.os }}-cmake- | ||
|
||
- name: Run host tests | ||
run: |- | ||
cd unittests/host | ||
chmod +x run-tests.sh | ||
./run-tests.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
build*/ | ||
toolchains/ | ||
venv/ | ||
__pycache__ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
[submodule "esp-stub-lib"] | ||
path = esp-stub-lib | ||
url = https://github.com/espressif/esp-stub-lib | ||
shallow = true | ||
[submodule "unittests/CMock"] | ||
path = unittests/CMock | ||
url = https://github.com/ThrowTheSwitch/CMock.git | ||
shallow = true | ||
[submodule "unittests/Unity"] | ||
path = unittests/Unity | ||
url = https://github.com/ThrowTheSwitch/Unity.git | ||
shallow = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,51 @@ | ||
cmake_minimum_required(VERSION 3.28) | ||
|
||
# Validate TARGET_CHIP parameter | ||
option(TARGET_CHIP "Target ESP chip" "OFF") | ||
|
||
if("${TARGET_CHIP}" STREQUAL "OFF") | ||
message(FATAL_ERROR "Please set target chip via -DTARGET_CHIP.") | ||
endif() | ||
|
||
# Detect toolchain prefix and flags early | ||
set(EXTRA_RISCV_FLAGS -march=rv32imc -mabi=ilp32 -msmall-data-limit=0) | ||
set(EXTRA_XTENSA_FLAGS -mtext-section-literals -mlongcalls) | ||
|
||
set(ESP8266_FLAGS "-DESP8266" ${EXTRA_XTENSA_FLAGS}) | ||
set(XTENSA_FLAGS "-DXTENSA" ${EXTRA_XTENSA_FLAGS}) | ||
set(RISCV_FLAGS "-DRISCV" ${EXTRA_RISCV_FLAGS}) | ||
# Set up ESP_TARGET for toolchain and build system | ||
set(ESP_TARGET ${TARGET_CHIP} CACHE STRING "Target ESP chip" FORCE) | ||
|
||
set(ESP32_XTENSA_CHIPS esp32 esp32s2 esp32s3) | ||
|
||
if(TARGET_CHIP IN_LIST ESP32_XTENSA_CHIPS) | ||
set(TOOLCHAIN_EXECUTABLE_PREFIX "xtensa-${TARGET_CHIP}-elf-") | ||
set(CHIP_FLAGS "${XTENSA_FLAGS}") | ||
elseif(TARGET_CHIP STREQUAL "esp8266") | ||
set(TOOLCHAIN_EXECUTABLE_PREFIX "xtensa-lx106-elf-") | ||
set(CHIP_FLAGS "${ESP8266_FLAGS}") | ||
# The lx106 toolchain is of version 8.4 which doesn't support the --dependency-file linker option. | ||
set(CMAKE_LINK_DEPENDS_USE_LINKER FALSE) # requires CMake 3.27 or higher | ||
else() | ||
set(TOOLCHAIN_EXECUTABLE_PREFIX "riscv32-esp-elf-") | ||
set(CHIP_FLAGS "${RISCV_FLAGS}") | ||
endif() | ||
|
||
# Set compilers BEFORE project() to avoid host detection (e.g., -arch arm64 or -isysroot) | ||
set(CMAKE_SYSTEM_NAME Generic) | ||
set(CMAKE_C_COMPILER ${TOOLCHAIN_EXECUTABLE_PREFIX}gcc) | ||
set(CMAKE_LINKER ${TOOLCHAIN_EXECUTABLE_PREFIX}gcc) | ||
set(CMAKE_EXECUTABLE_SUFFIX_C ".elf") | ||
# Configure ESP toolchain | ||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) | ||
include(esp-targets) | ||
configure_esp_toolchain(${TARGET_CHIP}) | ||
|
||
project(flasher-stub C) | ||
|
||
# Configure ESP firmware build | ||
get_esp_target_flags(${TARGET_CHIP} TARGET_FLAGS) | ||
|
||
# C standard set based on the GCC version of the toolchain for ESP8266 (oldest one) | ||
set(COMMON_FLAGS -std=gnu17 -Wall -Wextra -Werror -Wshadow -Wundef -Wconversion -Os -fno-common -nostdlib -fno-builtin -ffunction-sections) | ||
# Firmware build flags | ||
set(ESP_FIRMWARE_C_FLAGS | ||
-std=gnu17 | ||
-Wall -Wextra -Werror -Wshadow -Wundef -Wconversion | ||
-fno-common -ffunction-sections | ||
-Os # Optimize for size | ||
-nostdlib -fno-builtin # No standard library | ||
) | ||
|
||
add_compile_options(${COMMON_FLAGS}) | ||
add_compile_options(${CHIP_FLAGS}) | ||
set(ESP_FIRMWARE_LINKER_FLAGS | ||
-Wl,-static -Wl,--gc-sections | ||
-nostdlib # No standard library linking | ||
) | ||
|
||
set(LINKER_FLAGS -Wl,-static -Wl,--gc-sections) | ||
# Create executable | ||
set(TARGET_NAME stub-${TARGET_CHIP} CACHE STRING "Target name") | ||
message(STATUS "Building for ${TARGET_CHIP}") | ||
add_executable(${TARGET_NAME}) | ||
|
||
# Set up linker script | ||
set(LINKER_SCRIPTS_DIR "${CMAKE_SOURCE_DIR}/src/ld") | ||
set(CHIP_LINKER_SCRIPT "${LINKER_SCRIPTS_DIR}/${TARGET_CHIP}.ld") | ||
|
||
target_link_options(${TARGET_NAME} PRIVATE | ||
${LINKER_FLAGS} | ||
${CHIP_FLAGS} | ||
"-T${CHIP_LINKER_SCRIPT}" | ||
-Wl,-Map=${CMAKE_BINARY_DIR}/${TARGET_NAME}.map | ||
) | ||
|
||
add_subdirectory(${CMAKE_SOURCE_DIR}/src) | ||
# Add esp-stub-lib | ||
add_compile_options(${ESP_FIRMWARE_C_FLAGS}) | ||
add_compile_options(${TARGET_FLAGS}) | ||
|
||
set(ESP_TARGET ${TARGET_CHIP} CACHE INTERNAL "Pass TARGET_CHIP as ESP_TARGET") | ||
add_subdirectory(${CMAKE_SOURCE_DIR}/esp-stub-lib) | ||
target_link_libraries(${TARGET_NAME} PRIVATE esp-stub-lib) | ||
|
||
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD | ||
COMMAND ${CMAKE_SOURCE_DIR}/tools/elf2json.py ${CMAKE_BINARY_DIR}/${TARGET_NAME}${CMAKE_EXECUTABLE_SUFFIX_C} ${CMAKE_BINARY_DIR}/${TARGET_CHIP}.json | ||
COMMENT "Running elf2json.py to produce a JSON file output" | ||
) | ||
# Add stub target | ||
add_subdirectory(${CMAKE_SOURCE_DIR}/src) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# ESP Target Definitions and Utilities | ||
# Shared across the entire esp-flasher-stub project | ||
|
||
# Define supported ESP targets | ||
set(ESP8266_TARGET esp8266) | ||
set(XTENSA_TARGETS esp32 esp32s2 esp32s3) | ||
set(RISCV_TARGETS esp32c2 esp32c3 esp32c5 esp32c6 esp32c61 esp32h2 esp32h21 esp32h4 esp32p4) | ||
set(ALL_ESP_TARGETS ${ESP8266_TARGET} ${XTENSA_TARGETS} ${RISCV_TARGETS}) | ||
|
||
# Function to validate ESP target | ||
function(validate_esp_target TARGET_CHIP) | ||
if(NOT TARGET_CHIP IN_LIST ALL_ESP_TARGETS) | ||
message(FATAL_ERROR "Invalid TARGET_CHIP '${TARGET_CHIP}'. Must be one of: ${ALL_ESP_TARGETS}") | ||
endif() | ||
endfunction() | ||
|
||
# Function to get toolchain prefix for target | ||
function(get_esp_toolchain_prefix TARGET_CHIP OUTPUT_VAR) | ||
validate_esp_target(${TARGET_CHIP}) | ||
|
||
if(TARGET_CHIP IN_LIST XTENSA_TARGETS) | ||
set(${OUTPUT_VAR} "xtensa-${TARGET_CHIP}-elf-" PARENT_SCOPE) | ||
elseif(TARGET_CHIP STREQUAL "esp8266") | ||
set(${OUTPUT_VAR} "xtensa-lx106-elf-" PARENT_SCOPE) | ||
else() | ||
set(${OUTPUT_VAR} "riscv32-esp-elf-" PARENT_SCOPE) | ||
endif() | ||
endfunction() | ||
|
||
# Function to get target-specific compile flags | ||
function(get_esp_target_flags TARGET_CHIP OUTPUT_VAR) | ||
validate_esp_target(${TARGET_CHIP}) | ||
|
||
# Architecture-specific flags | ||
set(EXTRA_RISCV_FLAGS -march=rv32imc -mabi=ilp32 -msmall-data-limit=0) | ||
dobairoland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
set(EXTRA_XTENSA_FLAGS -mtext-section-literals -mlongcalls) | ||
|
||
if(TARGET_CHIP IN_LIST XTENSA_TARGETS) | ||
set(${OUTPUT_VAR} "-DXTENSA" ${EXTRA_XTENSA_FLAGS} PARENT_SCOPE) | ||
elseif(TARGET_CHIP STREQUAL "esp8266") | ||
set(${OUTPUT_VAR} "-DESP8266" ${EXTRA_XTENSA_FLAGS} PARENT_SCOPE) | ||
else() | ||
set(${OUTPUT_VAR} "-DRISCV" ${EXTRA_RISCV_FLAGS} PARENT_SCOPE) | ||
endif() | ||
endfunction() | ||
|
||
# Function to configure ESP toolchain (must be called before project()) | ||
function(configure_esp_toolchain TARGET_CHIP) | ||
validate_esp_target(${TARGET_CHIP}) | ||
get_esp_toolchain_prefix(${TARGET_CHIP} TOOLCHAIN_PREFIX) | ||
|
||
# Set system and compiler before project() to avoid host detection | ||
set(CMAKE_SYSTEM_NAME Generic PARENT_SCOPE) | ||
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc PARENT_SCOPE) | ||
set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}gcc PARENT_SCOPE) | ||
set(CMAKE_EXECUTABLE_SUFFIX_C ".elf" PARENT_SCOPE) | ||
|
||
# ESP8266 specific handling | ||
if(TARGET_CHIP STREQUAL "esp8266") | ||
set(CMAKE_LINK_DEPENDS_USE_LINKER FALSE PARENT_SCOPE) | ||
endif() | ||
|
||
message(STATUS "ESP toolchain configured for ${TARGET_CHIP}") | ||
endfunction() | ||
|
||
message(STATUS "ESP targets loaded: ${ALL_ESP_TARGETS}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.