From 77906ca8981edee76e2f1afe103068ea57914bd3 Mon Sep 17 00:00:00 2001 From: Davide De Tommaso Date: Mon, 1 Jun 2026 15:06:15 +0200 Subject: [PATCH] Added separated service for simulation no_gui --- .github/workflows/run_tests.yml | 13 +----- .gitignore | 1 + README.md | 12 ++--- docker/compose.yaml | 78 ++++++++++++++++----------------- docker/run_tests.sh | 13 ++++++ scripts/common.sh | 20 +++++++++ scripts/run_tests.sh | 9 ++++ scripts/start.sh | 7 +++ scripts/tests.sh | 24 ---------- 9 files changed, 97 insertions(+), 80 deletions(-) create mode 100755 docker/run_tests.sh create mode 100755 scripts/run_tests.sh delete mode 100755 scripts/tests.sh diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 3b1338d..6e5f2a2 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -13,15 +13,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 - - name: Run tests with Docker Compose + - name: Run tests working-directory: docker - run: | - echo "Building and running services for testing..." - COMPOSE_PROFILES=backend,test docker compose build - COMPOSE_PROFILES=test docker compose up - - - name: Clean up docker - working-directory: docker - run: | - echo "Cleaning up..." - docker compose down --volumes --remove-orphans + run: bash run_tests.sh diff --git a/.gitignore b/.gitignore index 8bc1d55..edd5422 100644 --- a/.gitignore +++ b/.gitignore @@ -46,6 +46,7 @@ coverage.xml *.cover .hypothesis/ .pytest_cache/ +pytest # Translations *.mo diff --git a/README.md b/README.md index d02e641..b2ff6d0 100644 --- a/README.md +++ b/README.md @@ -39,9 +39,11 @@ bash run.sh How to test pyicub ------------- -To run the tests you can run this command from your host machine, levearing docker containers. +To run the tests, use the dedicated script from your host machine. It will build the image, start a headless simulation container, wait for it to be healthy, run the test container, and tear everything down on completion. - ``` - cd pyicub/docker - COMPOSE_PROFILES=test ./run.sh - ``` +``` +cd pyicub/docker +bash run_tests.sh +``` + +The test results (HTML report) are written to `docker/shared/pytest/pytest_report.html`. diff --git a/docker/compose.yaml b/docker/compose.yaml index 80240c7..f66cf3b 100644 --- a/docker/compose.yaml +++ b/docker/compose.yaml @@ -5,46 +5,47 @@ x-pyicub-common: &pyicub-common network_mode: host privileged: true - +x-pyicub-build: &pyicub-build + context: .. + dockerfile: docker/Dockerfile.pyicub + args: + DOCKER_SRC: ${ROBOTOLOGY_IMAGE_NAME} + PYICUB_VERSION: ${PYICUB_VERSION:-master} + PYICUB_APPS_VERSION: ${PYICUB_APPS_VERSION:-master} + WORKDIR: ${WORKDIR:-/usr/local/src/robot} + +x-pyicub-headless: &pyicub-headless + <<: *pyicub-common + build: *pyicub-build + env_file: + - pyicub.env + environment: + - DISPLAY=:99 + services: pyicub-yarpserver: <<: *pyicub-common container_name: pyicub-yarpserver - command: ["/bin/bash", "-c", "yarpserver --write"] - restart: unless-stopped - healthcheck: test: ["CMD", "/bin/bash", "-c", "yarp detect"] interval: 10s timeout: 5s retries: 6 start_period: 1s - profiles: - backend - frontend pyicub-backend: <<: *pyicub-common - container_name: pyicub-backend - - build: - context: .. - dockerfile: docker/Dockerfile.pyicub - args: - DOCKER_SRC: ${ROBOTOLOGY_IMAGE_NAME} - PYICUB_VERSION: ${PYICUB_VERSION:-master} - PYICUB_APPS_VERSION: ${PYICUB_APPS_VERSION:-master} - WORKDIR: ${WORKDIR:-/usr/local/src/robot} - + container_name: pyicub-backend + build: *pyicub-build runtime: ${DOCKER_RUNTIME:-runc} - env_file: - pyicub.env - environment: - DISPLAY=${DISPLAY:-:0} - PULSE_SERVER=unix:${XDG_RUNTIME_DIR:?error}/pulse/native @@ -56,23 +57,18 @@ services: - NVIDIA_VISIBLE_DEVICES=${GPU_DEVICES:-none} - NVIDIA_DRIVER_CAPABILITIES=all - SSH_AUTH_SOCK=/ssh-agent - command: ["/bin/bash", "-c", "bash ${WORKDIR:?error}/pyicub/scripts/start.sh"] - profiles: - backend - healthcheck: test: ["CMD", "/bin/bash", "-c", "yarp ping /${PYICUB_NODE:?error}"] interval: 1m30s timeout: 30s retries: 5 start_period: 30s - depends_on: pyicub-yarpserver: condition: service_healthy - volumes: - /tmp/.X11-unix:/tmp/.X11-unix - ${HOME}/.config/pulse/cookie:/run/pulse/cookie @@ -84,48 +80,50 @@ services: pyicub.frontend: image: ${PYICUB_FRONTEND_IMAGE_NAME:?error} container_name: pyicub-frontend - build: context: . dockerfile: Dockerfile.pyicub-frontend args: - PYICUB_FRONTEND_VERSION=${PYICUB_FRONTEND_VERSION:?error} - environment: - SSH_AUTH_SOCK=/ssh-agent - network_mode: host - volumes: - pyicub-frontend-workspace:${WORKDIR:?error}/pyicub-frontend - ${HOME}/.gitconfig:/root/.gitconfig:ro - ${HOME}/.ssh:/root/.ssh:ro - ${SSH_AUTH_SOCK:-/dev/null}:/ssh-agent - profiles: - frontend - depends_on: pyicub-yarpserver: condition: service_healthy pyicub-backend: condition: service_healthy + pyicub.simulation-nogui: + <<: *pyicub-headless + container_name: pyicub-simulation-nogui + command: ["/bin/bash", "-c", "bash ${WORKDIR:?error}/pyicub/scripts/start.sh --simulation_nogui"] + healthcheck: + test: ["CMD", "/bin/bash", "-c", "yarp exists /icubSim/head/rpc:i"] + interval: 10s + timeout: 5s + retries: 12 + start_period: 30s + profiles: + - simulation_nogui + - test + pyicub.test: - <<: *pyicub-common + <<: *pyicub-headless container_name: pyicub-test - - command: ["/bin/bash", "-c", "bash ${WORKDIR:?error}/pyicub/scripts/tests.sh"] - - env_file: - - pyicub.env - - environment: - - DISPLAY=:99 - + command: ["/bin/bash", "-c", "bash ${WORKDIR:?error}/pyicub/scripts/run_tests.sh"] volumes: - ./shared:/shared - + depends_on: + pyicub.simulation-nogui: + condition: service_healthy profiles: - test diff --git a/docker/run_tests.sh b/docker/run_tests.sh new file mode 100755 index 0000000..e922343 --- /dev/null +++ b/docker/run_tests.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -e + +source "$(dirname "$0")/setup.sh" + +docker compose --profile simulation_nogui up --build -d + +docker compose --profile test up --build pyicub.test + +docker container stop pyicub-simulation-nogui + +docker compose --profile test down --remove-orphans diff --git a/scripts/common.sh b/scripts/common.sh index c1427b1..afc7821 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -92,6 +92,26 @@ ensure_ssh_key_installed() { ssh-copy-id -o StrictHostKeyChecking=no icub@"$ICUB_HOST" } +start_simulation() { + export DISPLAY=:99 + sudo Xvfb :99 -screen 0 1024x768x24 & + sleep 1 + + initialize_environment + start_yarpserver_detached >/dev/null 2>&1 + start_local_yarprun >/dev/null 2>&1 + + echo "Starting Gazebo simulation..." + gzserver ${ICUB_APPS}/gazebo/icub-world.sdf >/dev/null 2>&1 & + sleep 5 + + echo "Starting robot interface..." + yarprobotinterface --context gazeboCartesianControl --config no_legs.xml --portprefix /icubSim >/dev/null 2>&1 & + sleep 5 + + exec "$@" +} + check_existing_yarpserver() { for i in {1..5}; do if yarp detect --write >/dev/null 2>&1; then diff --git a/scripts/run_tests.sh b/scripts/run_tests.sh new file mode 100755 index 0000000..307363f --- /dev/null +++ b/scripts/run_tests.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +source "$(dirname "$0")/common.sh" + +initialize_environment +check_existing_yarpserver +cd $ROBOT_CODE/pyicub + +exec pytest --html=$PYTEST_OUTPUT_DIR/pytest_report.html diff --git a/scripts/start.sh b/scripts/start.sh index b16719c..700422a 100755 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -2,6 +2,13 @@ source "$(dirname "$0")/common.sh" +MODE="${1:-}" + +if [[ "$MODE" == "--simulation_nogui" ]]; then + start_simulation sleep infinity + exit 0 +fi + initialize_environment source "$(dirname "$0")/setup.sh" diff --git a/scripts/tests.sh b/scripts/tests.sh deleted file mode 100755 index 9c865d8..0000000 --- a/scripts/tests.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -source "$(dirname "$0")/common.sh" - -export DISPLAY=:99 -sudo Xvfb :99 -screen 0 1024x768x24 & -sleep 1 # Give it time to start - -initialize_environment -start_yarpserver_detached >/dev/null 2>&1 -start_local_yarprun >/dev/null 2>&1 - -echo "Starting Gazebo simulation..." -gzserver ${ICUB_APPS}/gazebo/icub-world.sdf >/dev/null 2>&1 & -sleep 5 - -echo "Starting robot interface..." -yarprobotinterface --context gazeboCartesianControl --config no_legs.xml --portprefix /icubSim >/dev/null 2>&1 & -sleep 5 - -echo "Running pytest..." -cd $ROBOT_CODE/pyicub || exit 1 - -pytest --html=$PYTEST_OUTPUT_DIR/pytest_report.html