From 84fd20fa8226d737d417bf85696e6586aa21b139 Mon Sep 17 00:00:00 2001 From: divyanshisingh987456321 Date: Thu, 1 Oct 2026 01:34:31 +0530 Subject: [PATCH] Fixed CORE-V CLI host tests (#64) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix CORE-V CLI host test mocks * Added the licence header to the four new mock files The mocks arrived without one. Every other file in this directory carries the MIT header, and a source file entering an Eclipse project without a copyright line is the kind of omission that is cheap now and awkward later. The header is the plain MIT one rather than the AI disclosure variant the neighbouring mocks carry, because nothing here establishes how these were written and the disclosure is a statement about that. Build clean and the CLI host tests pass. Assisted-by: Claude Code (Opus 5) --------- Co-authored-by: Frédéric Desbiens --- .../CORE-V-MCU/cli-test/tests/CMakeLists.txt | 2 + .../cli-test/tests/mock/cli_core_mock.c | 22 ++++++++ OpenHW/CORE-V-MCU/cli-test/tests/mock/gpio.h | 24 +++++++++ .../cli-test/tests/mock/hardware_mock.c | 50 +++++++++++++++++++ .../cli-test/tests/mock/uart_driver.h | 14 ++++++ .../cli-test/tests/test_cli_commands.c | 22 ++++++-- 6 files changed, 130 insertions(+), 4 deletions(-) create mode 100644 OpenHW/CORE-V-MCU/cli-test/tests/mock/cli_core_mock.c create mode 100644 OpenHW/CORE-V-MCU/cli-test/tests/mock/gpio.h create mode 100644 OpenHW/CORE-V-MCU/cli-test/tests/mock/hardware_mock.c create mode 100644 OpenHW/CORE-V-MCU/cli-test/tests/mock/uart_driver.h diff --git a/OpenHW/CORE-V-MCU/cli-test/tests/CMakeLists.txt b/OpenHW/CORE-V-MCU/cli-test/tests/CMakeLists.txt index eacd7218..9dc5be4b 100644 --- a/OpenHW/CORE-V-MCU/cli-test/tests/CMakeLists.txt +++ b/OpenHW/CORE-V-MCU/cli-test/tests/CMakeLists.txt @@ -20,6 +20,8 @@ set(CMAKE_C_STANDARD_REQUIRED ON) add_executable(cli_tests test_cli_commands.c mock/cli_mock.c + mock/cli_core_mock.c + mock/hardware_mock.c ../app/app_commands.c ) diff --git a/OpenHW/CORE-V-MCU/cli-test/tests/mock/cli_core_mock.c b/OpenHW/CORE-V-MCU/cli-test/tests/mock/cli_core_mock.c new file mode 100644 index 00000000..5759a92e --- /dev/null +++ b/OpenHW/CORE-V-MCU/cli-test/tests/mock/cli_core_mock.c @@ -0,0 +1,22 @@ +/***************************************************************************/ +/* 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. + * + * SPDX-License-Identifier: MIT + ***************************************************************************/ + +#include "cli.h" + +void CLI_uint32_required(const char *name, uint32_t *puthere) +{ + (void)name; + *puthere = 0U; +} + +void CLI_submenu_handler(const struct cli_cmd_entry *pEntry) +{ + (void)pEntry; +} diff --git a/OpenHW/CORE-V-MCU/cli-test/tests/mock/gpio.h b/OpenHW/CORE-V-MCU/cli-test/tests/mock/gpio.h new file mode 100644 index 00000000..f888c265 --- /dev/null +++ b/OpenHW/CORE-V-MCU/cli-test/tests/mock/gpio.h @@ -0,0 +1,24 @@ +/***************************************************************************/ +/* 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. + * + * SPDX-License-Identifier: MIT + ***************************************************************************/ + +#ifndef GPIO_H +#define GPIO_H + +#include + +void gpio_setpinmux(uint8_t io_pad, uint8_t mux); +uint8_t gpio_getpinmux(uint8_t io_pad); +void gpio_set(unsigned long mask); +void gpio_clear(unsigned long mask); +void gpio_toggle(unsigned long mask); +void gpio_pin_set_dir(uint8_t pin, uint8_t mode); +uint32_t gpio_pin_read_status(uint8_t pin); + +#endif diff --git a/OpenHW/CORE-V-MCU/cli-test/tests/mock/hardware_mock.c b/OpenHW/CORE-V-MCU/cli-test/tests/mock/hardware_mock.c new file mode 100644 index 00000000..6255ac00 --- /dev/null +++ b/OpenHW/CORE-V-MCU/cli-test/tests/mock/hardware_mock.c @@ -0,0 +1,50 @@ +/***************************************************************************/ +/* 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. + * + * SPDX-License-Identifier: MIT + ***************************************************************************/ + +#include "gpio.h" + +void gpio_setpinmux(uint8_t io_pad, uint8_t mux) +{ + (void)io_pad; + (void)mux; +} + +uint8_t gpio_getpinmux(uint8_t io_pad) +{ + (void)io_pad; + return 0U; +} + +void gpio_set(unsigned long mask) +{ + (void)mask; +} + +void gpio_clear(unsigned long mask) +{ + (void)mask; +} + +void gpio_toggle(unsigned long mask) +{ + (void)mask; +} + +void gpio_pin_set_dir(uint8_t pin, uint8_t mode) +{ + (void)pin; + (void)mode; +} + +uint32_t gpio_pin_read_status(uint8_t pin) +{ + (void)pin; + return 0U; +} diff --git a/OpenHW/CORE-V-MCU/cli-test/tests/mock/uart_driver.h b/OpenHW/CORE-V-MCU/cli-test/tests/mock/uart_driver.h new file mode 100644 index 00000000..e7d532e8 --- /dev/null +++ b/OpenHW/CORE-V-MCU/cli-test/tests/mock/uart_driver.h @@ -0,0 +1,14 @@ +/***************************************************************************/ +/* 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. + * + * SPDX-License-Identifier: MIT + ***************************************************************************/ + +#ifndef UART_DRIVER_H +#define UART_DRIVER_H + +#endif diff --git a/OpenHW/CORE-V-MCU/cli-test/tests/test_cli_commands.c b/OpenHW/CORE-V-MCU/cli-test/tests/test_cli_commands.c index 93eecc53..dd5fc337 100644 --- a/OpenHW/CORE-V-MCU/cli-test/tests/test_cli_commands.c +++ b/OpenHW/CORE-V-MCU/cli-test/tests/test_cli_commands.c @@ -21,16 +21,23 @@ static int test_version_output(void) { const struct cli_cmd_entry *menu; + const struct cli_cmd_entry *misc_menu; const char *output; cli_mock_reset(); menu = app_get_menu(); - if ((menu == NULL) || (menu[0].pHandler == NULL)) + if ((menu == NULL) || (menu[0].pHandler == NULL) || (menu[0].cookie == 0)) { return 1; } - menu[0].pHandler(&menu[0]); + misc_menu = (const struct cli_cmd_entry *)(uintptr_t)menu[0].cookie; + if ((misc_menu == NULL) || (misc_menu[0].pHandler == NULL)) + { + return 1; + } + + misc_menu[0].pHandler(&misc_menu[0]); output = cli_mock_get_output(); if (strstr(output, "CORE-V MCU ThreadX") == NULL) { @@ -44,15 +51,22 @@ static int test_version_output(void) static int test_version_no_crash(void) { const struct cli_cmd_entry *menu; + const struct cli_cmd_entry *misc_menu; cli_mock_reset(); menu = app_get_menu(); - if ((menu == NULL) || (menu[0].pHandler == NULL)) + if ((menu == NULL) || (menu[0].pHandler == NULL) || (menu[0].cookie == 0)) + { + return 1; + } + + misc_menu = (const struct cli_cmd_entry *)(uintptr_t)menu[0].cookie; + if ((misc_menu == NULL) || (misc_menu[0].pHandler == NULL)) { return 1; } - menu[0].pHandler(&menu[0]); + misc_menu[0].pHandler(&misc_menu[0]); return 0; }