Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simulator: run simulator test in ci #24691

Merged
merged 36 commits into from
Jun 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
6fea109
run simulator test in ci
maxime-desroches May 31, 2022
ec26d32
block navd process
maxime-desroches Jun 1, 2022
aec94fc
block ui
maxime-desroches Jun 1, 2022
82c8f16
fix jenkins
maxime-desroches Jun 1, 2022
081f47d
build docker
maxime-desroches Jun 2, 2022
fda3c61
remove tty
maxime-desroches Jun 2, 2022
01f42c6
remove tty for carla
maxime-desroches Jun 2, 2022
aa1d8d4
detach carla_sim
maxime-desroches Jun 2, 2022
efc928e
more retries
maxime-desroches Jun 2, 2022
a6282b3
only build once
maxime-desroches Jun 3, 2022
27c9374
add more time for bridge
maxime-desroches Jun 3, 2022
a8c2d40
cleanup
maxime-desroches Jun 3, 2022
a02d0c1
use qt offscreen
maxime-desroches Jun 4, 2022
4132b21
expose to docker
maxime-desroches Jun 4, 2022
f59754f
block ui
maxime-desroches Jun 6, 2022
7b7c153
use new dockerimage
maxime-desroches Jun 7, 2022
03e7d59
fix
maxime-desroches Jun 7, 2022
0bb6405
from ubuntu20.04
maxime-desroches Jun 7, 2022
ba23bf6
install curl
maxime-desroches Jun 7, 2022
6f5c358
add ssh
maxime-desroches Jun 7, 2022
ee67952
add locales
maxime-desroches Jun 7, 2022
c0cbc9a
noninteractive
maxime-desroches Jun 7, 2022
1f94cb0
syntax
maxime-desroches Jun 7, 2022
9a6c084
use base
maxime-desroches Jun 7, 2022
97abd7b
smaller image
maxime-desroches Jun 7, 2022
65a8811
add git + git lfs
maxime-desroches Jun 7, 2022
f4a91e0
kill carla
maxime-desroches Jun 7, 2022
e3535ae
run in parallel
adeebshihadeh Jun 7, 2022
43eb35d
fix missing agents
adeebshihadeh Jun 7, 2022
1eafbc3
default agent?
adeebshihadeh Jun 11, 2022
1e4559e
little cleanup
adeebshihadeh Jun 11, 2022
770a1f9
default doesn't work
adeebshihadeh Jun 11, 2022
0cf1524
not in ci
adeebshihadeh Jun 11, 2022
95c8f6d
fix path
adeebshihadeh Jun 11, 2022
62ac833
fix path
adeebshihadeh Jun 11, 2022
8291168
new msg
adeebshihadeh Jun 11, 2022
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
129 changes: 74 additions & 55 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def phone_steps(String device_type, steps) {
pipeline {
agent none
environment {
CI = "1"
TEST_DIR = "/data/openpilot"
SOURCE_DIR = "/data/openpilot_source/"
}
Expand Down Expand Up @@ -74,71 +75,89 @@ pipeline {
}
}

stages {
stage('On-device Tests') {
agent { docker { image 'ghcr.io/commaai/alpine-ssh'; args '--user=root' } }
stages {
stage('parallel tests') {
parallel {
stage('build') {
environment {
R3_PUSH = "${env.BRANCH_NAME == 'master' ? '1' : ' '}"
}
steps {
phone_steps("tici", [
["build master-ci", "cd $SOURCE_DIR/release && TARGET_DIR=$TEST_DIR EXTRA_FILES='tools/' ./build_devel.sh"],
["build openpilot", "cd selfdrive/manager && ./build.py"],
["test manager", "python selfdrive/manager/test/test_manager.py"],
["onroad tests", "cd selfdrive/test/ && ./test_onroad.py"],
["test car interfaces", "cd selfdrive/car/tests/ && ./test_car_interfaces.py"],
])
}
}

stage('HW + Unit Tests') {
steps {
phone_steps("tici2", [
["build", "cd selfdrive/manager && ./build.py"],
["test power draw", "python selfdrive/hardware/tici/test_power_draw.py"],
["test boardd loopback", "python selfdrive/boardd/tests/test_boardd_loopback.py"],
["test loggerd", "python selfdrive/loggerd/tests/test_loggerd.py"],
["test encoder", "LD_LIBRARY_PATH=/usr/local/lib python selfdrive/loggerd/tests/test_encoder.py"],
["test sensord", "python selfdrive/sensord/test/test_sensord.py"],
])
}
}

stage('camerad') {
steps {
phone_steps("tici-party", [
["build", "cd selfdrive/manager && ./build.py"],
["test camerad", "python selfdrive/camerad/test/test_camerad.py"],
["test exposure", "python selfdrive/camerad/test/test_exposure.py"],
])
}
}

stage('replay') {
steps {
phone_steps("tici3", [
["build", "cd selfdrive/manager && ./build.py"],
["model replay", "cd selfdrive/test/process_replay && ./model_replay.py"],
])
}
}

}
parallel {

stage('simulator') {
agent {
dockerfile {
filename 'Dockerfile.sim_nvidia'
dir 'tools/sim'
args '--user=root'
}
}
steps {
sh "git config --global --add safe.directory ${WORKSPACE}"
sh "git lfs pull"
sh "${WORKSPACE}/tools/sim/build_container.sh"
sh "DETACH=1 ${WORKSPACE}/tools/sim/start_carla.sh"
sh "${WORKSPACE}/tools/sim/start_openpilot_docker.sh"
}

post {
always {
cleanWs()
sh "docker kill carla_sim || true"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's make sure the test properly cleans this up if it doesn't already

sh "rm -rf ${WORKSPACE}/* || true"
sh "rm -rf .* || true"
}
}
}

stage('build') {
agent { docker { image 'ghcr.io/commaai/alpine-ssh'; args '--user=root' } }
environment {
R3_PUSH = "${env.BRANCH_NAME == 'master' ? '1' : ' '}"
}
steps {
phone_steps("tici", [
["build master-ci", "cd $SOURCE_DIR/release && TARGET_DIR=$TEST_DIR EXTRA_FILES='tools/' ./build_devel.sh"],
["build openpilot", "cd selfdrive/manager && ./build.py"],
["test manager", "python selfdrive/manager/test/test_manager.py"],
["onroad tests", "cd selfdrive/test/ && ./test_onroad.py"],
["test car interfaces", "cd selfdrive/car/tests/ && ./test_car_interfaces.py"],
])
}
}

stage('HW + Unit Tests') {
agent { docker { image 'ghcr.io/commaai/alpine-ssh'; args '--user=root' } }
steps {
phone_steps("tici2", [
["build", "cd selfdrive/manager && ./build.py"],
["test power draw", "python selfdrive/hardware/tici/test_power_draw.py"],
["test boardd loopback", "python selfdrive/boardd/tests/test_boardd_loopback.py"],
["test loggerd", "python selfdrive/loggerd/tests/test_loggerd.py"],
["test encoder", "LD_LIBRARY_PATH=/usr/local/lib python selfdrive/loggerd/tests/test_encoder.py"],
["test sensord", "python selfdrive/sensord/test/test_sensord.py"],
])
}
}

stage('camerad') {
agent { docker { image 'ghcr.io/commaai/alpine-ssh'; args '--user=root' } }
steps {
phone_steps("tici-party", [
["build", "cd selfdrive/manager && ./build.py"],
["test camerad", "python selfdrive/camerad/test/test_camerad.py"],
["test exposure", "python selfdrive/camerad/test/test_exposure.py"],
])
}
}

stage('replay') {
agent { docker { image 'ghcr.io/commaai/alpine-ssh'; args '--user=root' } }
steps {
phone_steps("tici3", [
["build", "cd selfdrive/manager && ./build.py"],
["model replay", "cd selfdrive/test/process_replay && ./model_replay.py"],
])
}
}
}

post {
always {
cleanWs()
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tools/sim/Dockerfile.sim
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ COPY ./system $HOME/openpilot/system
COPY ./tools $HOME/openpilot/tools

WORKDIR $HOME/openpilot
RUN scons -j$(nproc)
RUN scons -j12

RUN python -c "from selfdrive.test.helpers import set_params_enabled; set_params_enabled()"
21 changes: 21 additions & 0 deletions tools/sim/Dockerfile.sim_nvidia
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM ubuntu:20.04

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y --no-install-recommends \
apt-utils \
sudo \
ssh \
curl \
ca-certificates \
git \
git-lfs && \
rm -rf /var/lib/apt/lists/*

RUN curl -fsSL https://get.docker.com -o get-docker.sh && \
sudo sh get-docker.sh && \
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) && \
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - && \
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list && \
sudo apt-get update && \
sudo apt-get install -y nvidia-docker2
4 changes: 4 additions & 0 deletions tools/sim/launch_openpilot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export SIMULATION="1"
export FINGERPRINT="HONDA CIVIC 2016"

export BLOCK="camerad,loggerd,encoderd"
if [[ "$CI" ]]; then
# TODO: offscreen UI should work
export BLOCK="${BLOCK},ui"
fi

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
cd ../../selfdrive/manager && exec ./manager.py
1 change: 1 addition & 0 deletions tools/sim/lib/can.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def can_function(pm, speed, angle, idx, cruise_button, is_engaged):
msg.append(packer.make_can_msg("SCM_FEEDBACK", 0, {"MAIN_ON": 1}, idx))
msg.append(packer.make_can_msg("POWERTRAIN_DATA", 0, {"ACC_STATUS": int(is_engaged)}, idx))
msg.append(packer.make_can_msg("HUD_SETTING", 0, {}))
msg.append(packer.make_can_msg("CAR_SPEED", 0, {}))

# *** cam bus ***
msg.append(packer.make_can_msg("STEERING_CONTROL", 2, {}, idx))
Expand Down
7 changes: 6 additions & 1 deletion tools/sim/start_carla.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ fi

docker pull carlasim/carla:0.9.12

EXTRA_ARGS="-it"
if [[ "$DETACH" ]]; then
EXTRA_ARGS="-d"
fi

docker run \
--name carla_sim \
--rm \
--gpus all \
--net=host \
-v /tmp/.X11-unix:/tmp/.X11-unix:rw \
-it \
$EXTRA_ARGS \
carlasim/carla:0.9.12 \
/bin/bash ./CarlaUE4.sh -opengl -nosound -RenderOffScreen -benchmark -fps=20 -quality-level=Low
22 changes: 13 additions & 9 deletions tools/sim/start_openpilot_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,26 @@
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
cd $DIR

# expose X to the container
xhost +local:root

docker pull ghcr.io/commaai/openpilot-sim:latest

OPENPILOT_DIR="/openpilot"
if ! [[ -z "$MOUNT_OPENPILOT" ]]
then
if ! [[ -z "$MOUNT_OPENPILOT" ]]; then
OPENPILOT_DIR="$(dirname $(dirname $DIR))"
EXTRA_ARGS="-v $OPENPILOT_DIR:$OPENPILOT_DIR -e PYTHONPATH=$OPENPILOT_DIR:$PYTHONPATH"
fi

if [[ "$CI" ]]; then
CMD="CI=1 ${OPENPILOT_DIR}/tools/sim/tests/test_carla_integration.py"
else
# expose X to the container
xhost +local:root

docker pull ghcr.io/commaai/openpilot-sim:latest
CMD="./tmux_script.sh $*"
EXTRA_ARGS="${EXTRA_ARGS} -it"
fi

docker run --net=host\
--name openpilot_client \
--rm \
-it \
--gpus all \
--device=/dev/dri:/dev/dri \
--device=/dev/input:/dev/input \
Expand All @@ -29,4 +33,4 @@ docker run --net=host\
-w "$OPENPILOT_DIR/tools/sim" \
$EXTRA_ARGS \
ghcr.io/commaai/openpilot-sim:latest \
/bin/bash -c "./tmux_script.sh $*"
/bin/bash -c "$CMD"
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
import subprocess
import time
import unittest
import os
from multiprocessing import Queue

from cereal import messaging
from common.basedir import BASEDIR
from selfdrive.manager.helpers import unblock_stdout
from tools.sim import bridge
from tools.sim.bridge import CarlaBridge

CI = "CI" in os.environ

SIM_DIR = os.path.join(BASEDIR, "tools/sim")

class TestCarlaIntegration(unittest.TestCase):
"""
Expand All @@ -19,27 +24,29 @@ class TestCarlaIntegration(unittest.TestCase):

def setUp(self):
self.processes = []
# We want to make sure that carla_sim docker isn't still running.
subprocess.run("docker rm -f carla_sim", shell=True, stderr=subprocess.PIPE, check=False)

self.carla_process = subprocess.Popen(".././start_carla.sh")
if not CI:
# We want to make sure that carla_sim docker isn't still running.
subprocess.run("docker rm -f carla_sim", shell=True, stderr=subprocess.PIPE, check=False)
self.carla_process = subprocess.Popen("./start_carla.sh", cwd=SIM_DIR)

# Too many lagging messages in bridge.py can cause a crash. This prevents it.
unblock_stdout()
# Wait 10 seconds to startup carla
time.sleep(10)

def test_engage(self):
# Startup manager and bridge.py. Check processes are running, then engage and verify.
p_manager = subprocess.Popen("./launch_openpilot.sh", cwd='../')
p_manager = subprocess.Popen("./launch_openpilot.sh", cwd=SIM_DIR)
self.processes.append(p_manager)

sm = messaging.SubMaster(['controlsState', 'carEvents', 'managerState'])
q = Queue()
carla_bridge = CarlaBridge(bridge.parse_args([]))
p_bridge = carla_bridge.run(q, retries=3)
p_bridge = carla_bridge.run(q, retries=10)
self.processes.append(p_bridge)

max_time_per_step = 20
max_time_per_step = 60

# Wait for bridge to startup
start_waiting = time.monotonic()
Expand Down