From d616e460b0ac37508f94fdb5f2243655c8d4b1df Mon Sep 17 00:00:00 2001 From: JohnK1987 Date: Fri, 5 Sep 2025 21:40:25 +0200 Subject: [PATCH 1/6] Update pyproject.toml with Greentea dependencies Add Greentea requirements for USB Device host tests --- tools/pyproject.toml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/pyproject.toml b/tools/pyproject.toml index 0087c13fcb0..8635a110000 100644 --- a/tools/pyproject.toml +++ b/tools/pyproject.toml @@ -71,6 +71,13 @@ unit-tests = [ "beautifulsoup4", "lxml" ] +greentea = [ + ## Additional requirements to install into the Mbed environment when running Greentea tests + # For USB Device host tests + "hidapi>=0.7.99", + "pyusb>=1.2.0", + "wmi>=1.5; platform_system == 'Windows'", +] [tool.hatch.build.targets.wheel] packages = [ @@ -88,4 +95,4 @@ mbedhtrun = "mbed_host_tests.mbedhtrun:main" mbedls = "mbed_lstools.main:mbedls_main" mbed-tools = "mbed_tools.cli.main:cli" memap = "memap.memap:main" -ambiq_svl = "ambiq_svl.svl:cli" \ No newline at end of file +ambiq_svl = "ambiq_svl.svl:cli" From 9530880cb33f4c53cb613245b12eb2f1676699c9 Mon Sep 17 00:00:00 2001 From: JohnK1987 Date: Fri, 5 Sep 2025 21:51:18 +0200 Subject: [PATCH 2/6] Update Python package installation for Greentea tests Refactor Python package installation logic based on test configuration. --- tools/cmake/mbed_python_interpreter.cmake | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tools/cmake/mbed_python_interpreter.cmake b/tools/cmake/mbed_python_interpreter.cmake index 1d563c3ac28..f967f6b732d 100644 --- a/tools/cmake/mbed_python_interpreter.cmake +++ b/tools/cmake/mbed_python_interpreter.cmake @@ -92,10 +92,19 @@ if(MBED_CREATE_PYTHON_VENV) COMMAND ${Python3_EXECUTABLE} -m pip install --upgrade pip COMMAND_ERROR_IS_FATAL ANY ) - execute_process( - COMMAND ${Python3_EXECUTABLE} -m pip install -e ${MBED_CE_TOOLS_BASE_DIR} - COMMAND_ERROR_IS_FATAL ANY - ) + if(MBED_BUILD_GREENTEA_TESTS) + # Install basic and greentea dependencies + execute_process( + COMMAND ${Python3_EXECUTABLE} -m pip install -e "${MBED_CE_TOOLS_BASE_DIR}[greentea]" + COMMAND_ERROR_IS_FATAL ANY + ) + else() + # Install only basic dependencies + execute_process( + COMMAND ${Python3_EXECUTABLE} -m pip install -e "${MBED_CE_TOOLS_BASE_DIR}" + COMMAND_ERROR_IS_FATAL ANY + ) + endif() message(STATUS "Mbed: venv created successfully") file(TOUCH ${VENV_STAMP_FILE}) @@ -175,4 +184,4 @@ function(mbed_check_or_install_python_package FOUND_VAR PACKAGE_IMPORT_NAME PACK message(WARNING "Mbed: ${PACKAGE_IMPORT_NAME} cannot be installed because the Mbed virtualenv is not being used. Please install ${PACKAGE_INSTALL_CONSTRAINT} into Mbed's Python interpeter manually.") endif() endif() -endfunction(mbed_check_or_install_python_package) \ No newline at end of file +endfunction(mbed_check_or_install_python_package) From 68f651c0b9da268f27daf651a1d08523b38b43d1 Mon Sep 17 00:00:00 2001 From: JohnK1987 Date: Fri, 5 Sep 2025 21:55:03 +0200 Subject: [PATCH 3/6] Delete tools/requirements-greentea.txt --- tools/requirements-greentea.txt | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 tools/requirements-greentea.txt diff --git a/tools/requirements-greentea.txt b/tools/requirements-greentea.txt deleted file mode 100644 index b4ae78d2285..00000000000 --- a/tools/requirements-greentea.txt +++ /dev/null @@ -1,6 +0,0 @@ -## Additional requirements to install into the Mbed environment when running Greentea tests - -# For USB Device host tests -hidapi>=0.7.99 -pyusb>=1.2.0 -wmi>=1.5; platform_system == "Windows" \ No newline at end of file From 9b0e2eac3b26783a0b82f8835c8dd2d688aeda6f Mon Sep 17 00:00:00 2001 From: JohnK1987 Date: Sun, 7 Sep 2025 22:30:20 +0200 Subject: [PATCH 4/6] Update README with Python module setup details --- drivers/usb/tests/TESTS/usb_device/README.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/usb/tests/TESTS/usb_device/README.md b/drivers/usb/tests/TESTS/usb_device/README.md index 6af69a00c10..74c7b7d58c5 100644 --- a/drivers/usb/tests/TESTS/usb_device/README.md +++ b/drivers/usb/tests/TESTS/usb_device/README.md @@ -1,12 +1,8 @@ # Testing the Mbed OS USB device ## Setup -Before running tests, please make sure to install all the -required Python modules. - -``` -pip install -r mbed-os/tools/requirements-ci-build.txt -``` +> [!NOTE] +> all required Python modules are instaled into the Python virtual enviroment (venv) automatically with first build of Greentea. Additional, platform-specific setup is described below. See also [Known issues](#known-issues). From 9bbc0f8636acc756b9505bd60406ed4958b6b810 Mon Sep 17 00:00:00 2001 From: JohnK1987 Date: Sun, 7 Sep 2025 23:09:50 +0200 Subject: [PATCH 5/6] Enhance mbed_python_interpreter.cmake for greentea Added support for greentea dependencies with a separate stamp file. --- tools/cmake/mbed_python_interpreter.cmake | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tools/cmake/mbed_python_interpreter.cmake b/tools/cmake/mbed_python_interpreter.cmake index f967f6b732d..cca4c5fbf0f 100644 --- a/tools/cmake/mbed_python_interpreter.cmake +++ b/tools/cmake/mbed_python_interpreter.cmake @@ -19,6 +19,9 @@ if(MBED_CREATE_PYTHON_VENV) set(VENV_STAMP_FILE ${MBED_VENV_LOCATION}/mbed-venv.stamp) set(MBED_PYPROJECT_TOML_LOCATION "${MBED_CE_TOOLS_BASE_DIR}/pyproject.toml") + # a separate stamp file to track whether greentea dependencies + set(GT_STAMP_FILE ${MBED_VENV_LOCATION}/mbed-gt.stamp) + # Make it so modifying pyproject.toml will trigger a reconfigure set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${MBED_PYPROJECT_TOML_LOCATION}) @@ -66,6 +69,11 @@ if(MBED_CREATE_PYTHON_VENV) set(NEED_TO_INSTALL_PACKAGES TRUE) endif() + # If greentea tests are being built, we need to ensure greentea dependencies are installed + if(MBED_BUILD_GREENTEA_TESTS AND NOT EXISTS "${GT_STAMP_FILE}") + set(NEED_TO_INSTALL_PACKAGES TRUE) + endif() + if(NEED_TO_CREATE_VENV) # Create venv. # Using approach from here: https://discourse.cmake.org/t/possible-to-create-a-python-virtual-env-from-cmake-and-then-find-it-with-findpython3/1132/2 @@ -92,14 +100,16 @@ if(MBED_CREATE_PYTHON_VENV) COMMAND ${Python3_EXECUTABLE} -m pip install --upgrade pip COMMAND_ERROR_IS_FATAL ANY ) + + # if(MBED_BUILD_GREENTEA_TESTS) - # Install basic and greentea dependencies + # Enable the extra dependencies for the GT execute_process( COMMAND ${Python3_EXECUTABLE} -m pip install -e "${MBED_CE_TOOLS_BASE_DIR}[greentea]" COMMAND_ERROR_IS_FATAL ANY ) else() - # Install only basic dependencies + # The dependencies for regular build execute_process( COMMAND ${Python3_EXECUTABLE} -m pip install -e "${MBED_CE_TOOLS_BASE_DIR}" COMMAND_ERROR_IS_FATAL ANY @@ -108,6 +118,11 @@ if(MBED_CREATE_PYTHON_VENV) message(STATUS "Mbed: venv created successfully") file(TOUCH ${VENV_STAMP_FILE}) + if(MBED_BUILD_GREENTEA_TESTS) + # If greentea tests are being built, we need create a greentea stamp file + file(TOUCH ${GT_STAMP_FILE}) + endif() + endif() # When using the venv, scripts will always be installed to the directory where Python itself is installed From 7b1e7d3562951e5b63dd66c8a8ec32845a63752c Mon Sep 17 00:00:00 2001 From: JohnK1987 Date: Mon, 8 Sep 2025 19:16:02 +0200 Subject: [PATCH 6/6] Update comment for greentea dependencies tracking --- tools/cmake/mbed_python_interpreter.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/cmake/mbed_python_interpreter.cmake b/tools/cmake/mbed_python_interpreter.cmake index cca4c5fbf0f..6c5e2a5dd33 100644 --- a/tools/cmake/mbed_python_interpreter.cmake +++ b/tools/cmake/mbed_python_interpreter.cmake @@ -19,7 +19,7 @@ if(MBED_CREATE_PYTHON_VENV) set(VENV_STAMP_FILE ${MBED_VENV_LOCATION}/mbed-venv.stamp) set(MBED_PYPROJECT_TOML_LOCATION "${MBED_CE_TOOLS_BASE_DIR}/pyproject.toml") - # a separate stamp file to track whether greentea dependencies + # a separate stamp file to track whether greentea dependencies have been installed set(GT_STAMP_FILE ${MBED_VENV_LOCATION}/mbed-gt.stamp) # Make it so modifying pyproject.toml will trigger a reconfigure