Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ coverage.xml
*.cover
.hypothesis/
.pytest_cache/
pytest

# Translations
*.mo
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
78 changes: 38 additions & 40 deletions docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
13 changes: 13 additions & 0 deletions docker/run_tests.sh
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions scripts/run_tests.sh
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
24 changes: 0 additions & 24 deletions scripts/tests.sh

This file was deleted.

Loading