From 903d613a4efe1062fe9d37c6d9de1cf24ca6b27e Mon Sep 17 00:00:00 2001 From: Guillaume Souchere Date: Mon, 7 Jul 2025 14:24:14 +0200 Subject: [PATCH] feat(esp_gdbstub): Update test to CMake and use Catch2 component --- .gitlab/ci/host-test.yml | 6 -- .../rv_decode/.build-test-rules.yml | 3 + .../rv_decode/CMakeLists.txt | 9 +++ .../test_gdbstub_host/rv_decode/Makefile | 66 ------------------- .../test_gdbstub_host/rv_decode/README.md | 2 + .../rv_decode/include/sdkconfig.h | 8 --- .../test_gdbstub_host/rv_decode/main.cpp | 7 -- .../rv_decode/main/CMakeLists.txt | 17 +++++ .../rv_decode/main/idf_component.yml | 2 + .../rv_decode/{ => main}/test_rv_decode.cpp | 2 +- .../rv_decode/sdkconfig.defaults | 0 11 files changed, 34 insertions(+), 88 deletions(-) create mode 100644 components/esp_gdbstub/test_gdbstub_host/rv_decode/.build-test-rules.yml create mode 100644 components/esp_gdbstub/test_gdbstub_host/rv_decode/CMakeLists.txt delete mode 100644 components/esp_gdbstub/test_gdbstub_host/rv_decode/Makefile create mode 100644 components/esp_gdbstub/test_gdbstub_host/rv_decode/README.md delete mode 100644 components/esp_gdbstub/test_gdbstub_host/rv_decode/include/sdkconfig.h delete mode 100644 components/esp_gdbstub/test_gdbstub_host/rv_decode/main.cpp create mode 100644 components/esp_gdbstub/test_gdbstub_host/rv_decode/main/CMakeLists.txt create mode 100644 components/esp_gdbstub/test_gdbstub_host/rv_decode/main/idf_component.yml rename components/esp_gdbstub/test_gdbstub_host/rv_decode/{ => main}/test_rv_decode.cpp (99%) create mode 100644 components/esp_gdbstub/test_gdbstub_host/rv_decode/sdkconfig.defaults diff --git a/.gitlab/ci/host-test.yml b/.gitlab/ci/host-test.yml index 8a00601693..fbc172163d 100644 --- a/.gitlab/ci/host-test.yml +++ b/.gitlab/ci/host-test.yml @@ -89,12 +89,6 @@ test_certificate_bundle_on_host: - cd components/mbedtls/esp_crt_bundle/test_gen_crt_bundle/ - ./test_gen_crt_bundle.py -test_gdbstub_on_host: - extends: .host_test_template - script: - - cd components/esp_gdbstub/test_gdbstub_host - - make test - # Test for create virtualenv. It must be invoked from Python, not from virtualenv. # Use docker image system python without any extra dependencies test_cli_installer: diff --git a/components/esp_gdbstub/test_gdbstub_host/rv_decode/.build-test-rules.yml b/components/esp_gdbstub/test_gdbstub_host/rv_decode/.build-test-rules.yml new file mode 100644 index 0000000000..53c5c9787f --- /dev/null +++ b/components/esp_gdbstub/test_gdbstub_host/rv_decode/.build-test-rules.yml @@ -0,0 +1,3 @@ +components/esp_gdbstub/test_gdbstub_host/rv_decode: + enable: + - if: IDF_TARGET == "linux" diff --git a/components/esp_gdbstub/test_gdbstub_host/rv_decode/CMakeLists.txt b/components/esp_gdbstub/test_gdbstub_host/rv_decode/CMakeLists.txt new file mode 100644 index 0000000000..d56ccb0ed6 --- /dev/null +++ b/components/esp_gdbstub/test_gdbstub_host/rv_decode/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.16) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +set(COMPONENTS main) + +# This test app doesn't require FreeRTOS, using mock instead +list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/freertos/") + +project(rv_decode_test) diff --git a/components/esp_gdbstub/test_gdbstub_host/rv_decode/Makefile b/components/esp_gdbstub/test_gdbstub_host/rv_decode/Makefile deleted file mode 100644 index b33d53b98f..0000000000 --- a/components/esp_gdbstub/test_gdbstub_host/rv_decode/Makefile +++ /dev/null @@ -1,66 +0,0 @@ -TEST_PROGRAM=test_gdbstub_rv -GDBSTUB_SRC_DIR=../.. -all: $(TEST_PROGRAM) - -SOURCE_FILES = \ - $(addprefix $(GDBSTUB_SRC_DIR)/src/, \ - port/riscv/rv_decode.c \ - ) \ - test_rv_decode.cpp \ - main.cpp - -INCLUDE_FLAGS = -I./include \ - -I$(GDBSTUB_SRC_DIR)/private_include \ - -I$(GDBSTUB_SRC_DIR)/include \ - -I$(GDBSTUB_SRC_DIR)/src/port/riscv/include \ - -I$(GDBSTUB_SRC_DIR)/../../tools/catch \ - -I$(GDBSTUB_SRC_DIR)/../esp_hw_support/include \ - -I$(GDBSTUB_SRC_DIR)/../soc/esp32c3/include \ - -I$(GDBSTUB_SRC_DIR)/../esp_common/include \ - -I$(GDBSTUB_SRC_DIR)/../riscv/include -CPPFLAGS += $(INCLUDE_FLAGS) -D__riscv_c -Wall -Werror -g --coverage -CFLAGS += $(INCLUDE_FLAGS) -D__riscv_c -Wall -Werror -g --coverage -LDFLAGS += -lstdc++ --coverage - -ifeq ($(CC),clang) -CFLAGS += -fsanitize=address -CXXFLAGS += -fsanitize=address -LDFLAGS += -fsanitize=address -endif - -OBJ_FILES = $(filter %.o, $(SOURCE_FILES:.cpp=.o) $(SOURCE_FILES:.c=.o)) - -COVERAGE_FILES = $(OBJ_FILES:.o=.gc*) - -$(TEST_PROGRAM): $(OBJ_FILES) - $(CC) -o $@ $^ $(LDFLAGS) - -$(OUTPUT_DIR): - mkdir -p $(OUTPUT_DIR) - -test: $(TEST_PROGRAM) - ./$(TEST_PROGRAM) -d yes exclude:[long] - -long-test: $(TEST_PROGRAM) - ./$(TEST_PROGRAM) -d yes - -$(COVERAGE_FILES): $(TEST_PROGRAM) long-test - -coverage.info: $(COVERAGE_FILES) - find $(GDBSTUB_SRC_DIR)/src/ -name "*.gcno" -exec gcov -r -pb {} + - lcov --capture --directory $(GDBSTUB_SRC_DIR)/src --output-file coverage.info - -coverage_report: coverage.info - genhtml coverage.info --output-directory coverage_report - @echo "Coverage report is in coverage_report/index.html" - -clean-coverage: - rm -f $(COVERAGE_FILES) *.gcov - rm -rf coverage_report/ - rm -f coverage.info - -clean: clean-coverage - rm -f $(OBJ_FILES) $(TEST_PROGRAM) - - -.PHONY: clean clean-coverage all test long-test diff --git a/components/esp_gdbstub/test_gdbstub_host/rv_decode/README.md b/components/esp_gdbstub/test_gdbstub_host/rv_decode/README.md new file mode 100644 index 0000000000..37c142df16 --- /dev/null +++ b/components/esp_gdbstub/test_gdbstub_host/rv_decode/README.md @@ -0,0 +1,2 @@ +| Supported Targets | Linux | +| ----------------- | ----- | diff --git a/components/esp_gdbstub/test_gdbstub_host/rv_decode/include/sdkconfig.h b/components/esp_gdbstub/test_gdbstub_host/rv_decode/include/sdkconfig.h deleted file mode 100644 index 705a2cabae..0000000000 --- a/components/esp_gdbstub/test_gdbstub_host/rv_decode/include/sdkconfig.h +++ /dev/null @@ -1,8 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ -#pragma once - -#define CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME 1 diff --git a/components/esp_gdbstub/test_gdbstub_host/rv_decode/main.cpp b/components/esp_gdbstub/test_gdbstub_host/rv_decode/main.cpp deleted file mode 100644 index cd66dc3083..0000000000 --- a/components/esp_gdbstub/test_gdbstub_host/rv_decode/main.cpp +++ /dev/null @@ -1,7 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ -#define CATCH_CONFIG_MAIN -#include "catch.hpp" diff --git a/components/esp_gdbstub/test_gdbstub_host/rv_decode/main/CMakeLists.txt b/components/esp_gdbstub/test_gdbstub_host/rv_decode/main/CMakeLists.txt new file mode 100644 index 0000000000..845e22f872 --- /dev/null +++ b/components/esp_gdbstub/test_gdbstub_host/rv_decode/main/CMakeLists.txt @@ -0,0 +1,17 @@ +idf_component_register(SRCS + "test_rv_decode.cpp" + "../../../src/port/riscv/rv_decode.c" + INCLUDE_DIRS + "../../../private_include" + "../../../include" + "../../../src/port/riscv/include" + "../../../../../tools/catch" + "../../../../esp_hw_support/include" + "../../../../soc/esp32c3/include" + "../../../../esp_common/include" + "../../../../riscv/include" + WHOLE_ARCHIVE) + +# Currently 'main' for IDF_TARGET=linux is defined in freertos component. +# Since we are using a freertos mock here, need to let Catch2 provide 'main'. +target_link_libraries(${COMPONENT_LIB} PRIVATE Catch2WithMain) diff --git a/components/esp_gdbstub/test_gdbstub_host/rv_decode/main/idf_component.yml b/components/esp_gdbstub/test_gdbstub_host/rv_decode/main/idf_component.yml new file mode 100644 index 0000000000..f7982136b9 --- /dev/null +++ b/components/esp_gdbstub/test_gdbstub_host/rv_decode/main/idf_component.yml @@ -0,0 +1,2 @@ +dependencies: + espressif/catch2: "^3.4.0" diff --git a/components/esp_gdbstub/test_gdbstub_host/rv_decode/test_rv_decode.cpp b/components/esp_gdbstub/test_gdbstub_host/rv_decode/main/test_rv_decode.cpp similarity index 99% rename from components/esp_gdbstub/test_gdbstub_host/rv_decode/test_rv_decode.cpp rename to components/esp_gdbstub/test_gdbstub_host/rv_decode/main/test_rv_decode.cpp index 50c9ccc386..6a72922a29 100644 --- a/components/esp_gdbstub/test_gdbstub_host/rv_decode/test_rv_decode.cpp +++ b/components/esp_gdbstub/test_gdbstub_host/rv_decode/main/test_rv_decode.cpp @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#include "catch.hpp" +#include extern "C" { #include "esp_gdbstub_common.h" diff --git a/components/esp_gdbstub/test_gdbstub_host/rv_decode/sdkconfig.defaults b/components/esp_gdbstub/test_gdbstub_host/rv_decode/sdkconfig.defaults new file mode 100644 index 0000000000..e69de29bb2