Skip to content

Commit 5add0c6

Browse files
simulator: run simulator test in ci (#24691)
* run simulator test in ci * block navd process * block ui * fix jenkins * build docker * remove tty * remove tty for carla * detach carla_sim * more retries * only build once * add more time for bridge * cleanup * use qt offscreen * expose to docker * block ui * use new dockerimage * fix * from ubuntu20.04 * install curl * add ssh * add locales * noninteractive * syntax * use base * smaller image * add git + git lfs * kill carla * run in parallel * fix missing agents * default agent? * little cleanup * default doesn't work * not in ci * fix path * fix path * new msg Co-authored-by: Adeeb Shihadeh <[email protected]>
1 parent 1c238e8 commit 5add0c6

File tree

9 files changed

+133
-72
lines changed

9 files changed

+133
-72
lines changed

Jenkinsfile

Lines changed: 74 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def phone_steps(String device_type, steps) {
4242
pipeline {
4343
agent none
4444
environment {
45+
CI = "1"
4546
TEST_DIR = "/data/openpilot"
4647
SOURCE_DIR = "/data/openpilot_source/"
4748
}
@@ -74,71 +75,89 @@ pipeline {
7475
}
7576
}
7677

77-
stages {
78-
stage('On-device Tests') {
79-
agent { docker { image 'ghcr.io/commaai/alpine-ssh'; args '--user=root' } }
80-
stages {
81-
stage('parallel tests') {
82-
parallel {
83-
stage('build') {
84-
environment {
85-
R3_PUSH = "${env.BRANCH_NAME == 'master' ? '1' : ' '}"
86-
}
87-
steps {
88-
phone_steps("tici", [
89-
["build master-ci", "cd $SOURCE_DIR/release && TARGET_DIR=$TEST_DIR EXTRA_FILES='tools/' ./build_devel.sh"],
90-
["build openpilot", "cd selfdrive/manager && ./build.py"],
91-
["test manager", "python selfdrive/manager/test/test_manager.py"],
92-
["onroad tests", "cd selfdrive/test/ && ./test_onroad.py"],
93-
["test car interfaces", "cd selfdrive/car/tests/ && ./test_car_interfaces.py"],
94-
])
95-
}
96-
}
97-
98-
stage('HW + Unit Tests') {
99-
steps {
100-
phone_steps("tici2", [
101-
["build", "cd selfdrive/manager && ./build.py"],
102-
["test power draw", "python selfdrive/hardware/tici/test_power_draw.py"],
103-
["test boardd loopback", "python selfdrive/boardd/tests/test_boardd_loopback.py"],
104-
["test loggerd", "python selfdrive/loggerd/tests/test_loggerd.py"],
105-
["test encoder", "LD_LIBRARY_PATH=/usr/local/lib python selfdrive/loggerd/tests/test_encoder.py"],
106-
["test sensord", "python selfdrive/sensord/test/test_sensord.py"],
107-
])
108-
}
109-
}
110-
111-
stage('camerad') {
112-
steps {
113-
phone_steps("tici-party", [
114-
["build", "cd selfdrive/manager && ./build.py"],
115-
["test camerad", "python selfdrive/camerad/test/test_camerad.py"],
116-
["test exposure", "python selfdrive/camerad/test/test_exposure.py"],
117-
])
118-
}
119-
}
120-
121-
stage('replay') {
122-
steps {
123-
phone_steps("tici3", [
124-
["build", "cd selfdrive/manager && ./build.py"],
125-
["model replay", "cd selfdrive/test/process_replay && ./model_replay.py"],
126-
])
127-
}
128-
}
129-
130-
}
78+
parallel {
79+
80+
stage('simulator') {
81+
agent {
82+
dockerfile {
83+
filename 'Dockerfile.sim_nvidia'
84+
dir 'tools/sim'
85+
args '--user=root'
13186
}
13287
}
88+
steps {
89+
sh "git config --global --add safe.directory ${WORKSPACE}"
90+
sh "git lfs pull"
91+
sh "${WORKSPACE}/tools/sim/build_container.sh"
92+
sh "DETACH=1 ${WORKSPACE}/tools/sim/start_carla.sh"
93+
sh "${WORKSPACE}/tools/sim/start_openpilot_docker.sh"
94+
}
13395

13496
post {
13597
always {
136-
cleanWs()
98+
sh "docker kill carla_sim || true"
99+
sh "rm -rf ${WORKSPACE}/* || true"
100+
sh "rm -rf .* || true"
137101
}
138102
}
103+
}
139104

105+
stage('build') {
106+
agent { docker { image 'ghcr.io/commaai/alpine-ssh'; args '--user=root' } }
107+
environment {
108+
R3_PUSH = "${env.BRANCH_NAME == 'master' ? '1' : ' '}"
109+
}
110+
steps {
111+
phone_steps("tici", [
112+
["build master-ci", "cd $SOURCE_DIR/release && TARGET_DIR=$TEST_DIR EXTRA_FILES='tools/' ./build_devel.sh"],
113+
["build openpilot", "cd selfdrive/manager && ./build.py"],
114+
["test manager", "python selfdrive/manager/test/test_manager.py"],
115+
["onroad tests", "cd selfdrive/test/ && ./test_onroad.py"],
116+
["test car interfaces", "cd selfdrive/car/tests/ && ./test_car_interfaces.py"],
117+
])
118+
}
119+
}
120+
121+
stage('HW + Unit Tests') {
122+
agent { docker { image 'ghcr.io/commaai/alpine-ssh'; args '--user=root' } }
123+
steps {
124+
phone_steps("tici2", [
125+
["build", "cd selfdrive/manager && ./build.py"],
126+
["test power draw", "python selfdrive/hardware/tici/test_power_draw.py"],
127+
["test boardd loopback", "python selfdrive/boardd/tests/test_boardd_loopback.py"],
128+
["test loggerd", "python selfdrive/loggerd/tests/test_loggerd.py"],
129+
["test encoder", "LD_LIBRARY_PATH=/usr/local/lib python selfdrive/loggerd/tests/test_encoder.py"],
130+
["test sensord", "python selfdrive/sensord/test/test_sensord.py"],
131+
])
132+
}
140133
}
141134

135+
stage('camerad') {
136+
agent { docker { image 'ghcr.io/commaai/alpine-ssh'; args '--user=root' } }
137+
steps {
138+
phone_steps("tici-party", [
139+
["build", "cd selfdrive/manager && ./build.py"],
140+
["test camerad", "python selfdrive/camerad/test/test_camerad.py"],
141+
["test exposure", "python selfdrive/camerad/test/test_exposure.py"],
142+
])
143+
}
144+
}
145+
146+
stage('replay') {
147+
agent { docker { image 'ghcr.io/commaai/alpine-ssh'; args '--user=root' } }
148+
steps {
149+
phone_steps("tici3", [
150+
["build", "cd selfdrive/manager && ./build.py"],
151+
["model replay", "cd selfdrive/test/process_replay && ./model_replay.py"],
152+
])
153+
}
154+
}
155+
}
156+
157+
post {
158+
always {
159+
cleanWs()
160+
}
142161
}
143162
}
144163
}

tools/sim/Dockerfile.sim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ COPY ./system $HOME/openpilot/system
2727
COPY ./tools $HOME/openpilot/tools
2828

2929
WORKDIR $HOME/openpilot
30-
RUN scons -j$(nproc)
30+
RUN scons -j12
3131

3232
RUN python -c "from selfdrive.test.helpers import set_params_enabled; set_params_enabled()"

tools/sim/Dockerfile.sim_nvidia

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM ubuntu:20.04
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
RUN apt-get update && \
5+
apt-get install -y --no-install-recommends \
6+
apt-utils \
7+
sudo \
8+
ssh \
9+
curl \
10+
ca-certificates \
11+
git \
12+
git-lfs && \
13+
rm -rf /var/lib/apt/lists/*
14+
15+
RUN curl -fsSL https://get.docker.com -o get-docker.sh && \
16+
sudo sh get-docker.sh && \
17+
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) && \
18+
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - && \
19+
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list && \
20+
sudo apt-get update && \
21+
sudo apt-get install -y nvidia-docker2

tools/sim/launch_openpilot.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ export SIMULATION="1"
66
export FINGERPRINT="HONDA CIVIC 2016"
77

88
export BLOCK="camerad,loggerd,encoderd"
9+
if [[ "$CI" ]]; then
10+
# TODO: offscreen UI should work
11+
export BLOCK="${BLOCK},ui"
12+
fi
913

1014
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
1115
cd ../../selfdrive/manager && exec ./manager.py

tools/sim/lib/can.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def can_function(pm, speed, angle, idx, cruise_button, is_engaged):
6363
msg.append(packer.make_can_msg("SCM_FEEDBACK", 0, {"MAIN_ON": 1}, idx))
6464
msg.append(packer.make_can_msg("POWERTRAIN_DATA", 0, {"ACC_STATUS": int(is_engaged)}, idx))
6565
msg.append(packer.make_can_msg("HUD_SETTING", 0, {}))
66+
msg.append(packer.make_can_msg("CAR_SPEED", 0, {}))
6667

6768
# *** cam bus ***
6869
msg.append(packer.make_can_msg("STEERING_CONTROL", 2, {}, idx))

tools/sim/start_carla.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@ fi
1717

1818
docker pull carlasim/carla:0.9.12
1919

20+
EXTRA_ARGS="-it"
21+
if [[ "$DETACH" ]]; then
22+
EXTRA_ARGS="-d"
23+
fi
24+
2025
docker run \
2126
--name carla_sim \
2227
--rm \
2328
--gpus all \
2429
--net=host \
2530
-v /tmp/.X11-unix:/tmp/.X11-unix:rw \
26-
-it \
31+
$EXTRA_ARGS \
2732
carlasim/carla:0.9.12 \
2833
/bin/bash ./CarlaUE4.sh -opengl -nosound -RenderOffScreen -benchmark -fps=20 -quality-level=Low

tools/sim/start_openpilot_docker.sh

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,26 @@
33
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
44
cd $DIR
55

6-
# expose X to the container
7-
xhost +local:root
8-
9-
docker pull ghcr.io/commaai/openpilot-sim:latest
10-
116
OPENPILOT_DIR="/openpilot"
12-
if ! [[ -z "$MOUNT_OPENPILOT" ]]
13-
then
7+
if ! [[ -z "$MOUNT_OPENPILOT" ]]; then
148
OPENPILOT_DIR="$(dirname $(dirname $DIR))"
159
EXTRA_ARGS="-v $OPENPILOT_DIR:$OPENPILOT_DIR -e PYTHONPATH=$OPENPILOT_DIR:$PYTHONPATH"
1610
fi
1711

12+
if [[ "$CI" ]]; then
13+
CMD="CI=1 ${OPENPILOT_DIR}/tools/sim/tests/test_carla_integration.py"
14+
else
15+
# expose X to the container
16+
xhost +local:root
17+
18+
docker pull ghcr.io/commaai/openpilot-sim:latest
19+
CMD="./tmux_script.sh $*"
20+
EXTRA_ARGS="${EXTRA_ARGS} -it"
21+
fi
22+
1823
docker run --net=host\
1924
--name openpilot_client \
2025
--rm \
21-
-it \
2226
--gpus all \
2327
--device=/dev/dri:/dev/dri \
2428
--device=/dev/input:/dev/input \
@@ -29,4 +33,4 @@ docker run --net=host\
2933
-w "$OPENPILOT_DIR/tools/sim" \
3034
$EXTRA_ARGS \
3135
ghcr.io/commaai/openpilot-sim:latest \
32-
/bin/bash -c "./tmux_script.sh $*"
36+
/bin/bash -c "$CMD"
File renamed without changes.

tools/sim/test/test_carla_integration.py renamed to tools/sim/tests/test_carla_integration.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
import subprocess
33
import time
44
import unittest
5+
import os
56
from multiprocessing import Queue
67

78
from cereal import messaging
9+
from common.basedir import BASEDIR
810
from selfdrive.manager.helpers import unblock_stdout
911
from tools.sim import bridge
1012
from tools.sim.bridge import CarlaBridge
1113

14+
CI = "CI" in os.environ
15+
16+
SIM_DIR = os.path.join(BASEDIR, "tools/sim")
1217

1318
class TestCarlaIntegration(unittest.TestCase):
1419
"""
@@ -19,27 +24,29 @@ class TestCarlaIntegration(unittest.TestCase):
1924

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

25-
self.carla_process = subprocess.Popen(".././start_carla.sh")
28+
if not CI:
29+
# We want to make sure that carla_sim docker isn't still running.
30+
subprocess.run("docker rm -f carla_sim", shell=True, stderr=subprocess.PIPE, check=False)
31+
self.carla_process = subprocess.Popen("./start_carla.sh", cwd=SIM_DIR)
32+
2633
# Too many lagging messages in bridge.py can cause a crash. This prevents it.
2734
unblock_stdout()
2835
# Wait 10 seconds to startup carla
2936
time.sleep(10)
3037

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

3643
sm = messaging.SubMaster(['controlsState', 'carEvents', 'managerState'])
3744
q = Queue()
3845
carla_bridge = CarlaBridge(bridge.parse_args([]))
39-
p_bridge = carla_bridge.run(q, retries=3)
46+
p_bridge = carla_bridge.run(q, retries=10)
4047
self.processes.append(p_bridge)
4148

42-
max_time_per_step = 20
49+
max_time_per_step = 60
4350

4451
# Wait for bridge to startup
4552
start_waiting = time.monotonic()

0 commit comments

Comments
 (0)