diff --git a/automated-testing/evaluate-scenarios.sh b/automated-testing/evaluate-scenarios.sh new file mode 100755 index 0000000..fba73e1 --- /dev/null +++ b/automated-testing/evaluate-scenarios.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +set -e + +usage() { + echo "Usage: $0 [-d maxdepth] [-e exclude-path] STARTING-POINT QUERY-STRING" + echo "STARTING-POINT : Location from where search should start" + echo "QUERY-STRING : UNIX pattern used for matching and selecting results. Needs to be \"quoted\"" + echo "max-depth : Descend at most max-depth levels from STARTING-POINT" + echo "exclude-string : Exclude paths matching this UNIX pattern from final result. Needs to be \"quoted\"" + echo "-----" + echo "Example: $0 -d 3 . \"*.xosc\"" +} + +trap cleanup EXIT +trap cleanup 0 + +cleanup() { + echo "Cleaning up..." + docker compose -f $COMPOSE_TEMPLATE_PATH kill + docker compose -f $COMPOSE_TEMPLATE_PATH down + xhost -local: + echo "Done cleaning up." +} + +restart-simulator() { + echo "Restarting simulator..." + docker compose -f $COMPOSE_TEMPLATE_PATH kill + docker compose -f $COMPOSE_TEMPLATE_PATH down + docker compose -f $COMPOSE_TEMPLATE_PATH up -d carla-simulator +} + +export SCENARIO_DIRECTORY="${1:-"../utils/scenarios"}" +export COMPOSE_TEMPLATE_PATH="${2:-"./template.yml"}" +echo $SCENARIO_DIRECTORY + +scenarios=($(find $SCENARIO_DIRECTORY -maxdepth 1 -type f -name "*.xosc*" -exec basename {} \;)) + +if [ ${#scenarios[@]} -eq 0 ]; then + echo "No scenarios found. Exiting..." + exit 1 +fi +xhost +local: +echo "Starting simulator..." +docker compose -f $COMPOSE_TEMPLATE_PATH up -d carla-simulator + +for scenario in "${scenarios[@]}"; do + echo "Evaluating $scenario ..." + + export SCENARIO_NAME=$scenario + docker compose -f $COMPOSE_TEMPLATE_PATH run --rm carla-scenario-runner || true + + if [ "$RESTART_SIMULATOR" = true ]; then + restart-simulator + fi +done diff --git a/automated-testing/template.yml b/automated-testing/template.yml new file mode 100644 index 0000000..4294732 --- /dev/null +++ b/automated-testing/template.yml @@ -0,0 +1,28 @@ +services: + + carla-simulator: + deploy: + resources: + reservations: + devices: + - driver: nvidia + count: 1 + capabilities: [gpu] + environment: + DISPLAY: $DISPLAY + XAUTHORITY: /.Xauthority + volumes: + - /tmp/.X11-unix:/tmp/.X11-unix + - $XAUTHORITY:/.Xauthority:ro + privileged: True + image: carla-health # TODO: Change to rwthika/carla-simulator:server + command: bash -ic './CarlaUE4.sh -nosound $SIMULATOR_FLAGS 2>/dev/null' + + carla-scenario-runner: + depends_on: + carla-simulator: + condition: service_healthy + volumes: + - $SCENARIO_DIRECTORY:/scenarios + image: rwthika/carla-scenario-runner:latest + command: bash -ic "python ./scenario_runner.py --host carla-simulator --openscenario /scenarios/$SCENARIO_NAME --output"