feat(esp_gdbstub): Update test to CMake and use Catch2 component

This commit is contained in:
Guillaume Souchere
2025-07-07 14:24:14 +02:00
parent 4680b976f4
commit 903d613a4e
11 changed files with 34 additions and 88 deletions

View File

@@ -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:

View File

@@ -0,0 +1,3 @@
components/esp_gdbstub/test_gdbstub_host/rv_decode:
enable:
- if: IDF_TARGET == "linux"

View File

@@ -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)

View File

@@ -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

View File

@@ -0,0 +1,2 @@
| Supported Targets | Linux |
| ----------------- | ----- |

View File

@@ -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

View File

@@ -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"

View File

@@ -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)

View File

@@ -0,0 +1,2 @@
dependencies:
espressif/catch2: "^3.4.0"

View File

@@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "catch.hpp"
#include <catch2/catch_test_macros.hpp>
extern "C" {
#include "esp_gdbstub_common.h"