2023-12-13 09:54:17 +08:00
|
|
|
def retryWithDelay(int maxRetries, int delay, Closure body) {
|
|
|
|
for (int i = 0; i < maxRetries; i++) {
|
|
|
|
try {
|
2023-12-13 10:12:19 +08:00
|
|
|
return body()
|
2023-12-13 09:54:17 +08:00
|
|
|
} catch (Exception e) {
|
|
|
|
sleep(delay)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw Exception("Failed after ${maxRetries} retries")
|
|
|
|
}
|
|
|
|
|
2023-09-10 12:30:21 +08:00
|
|
|
def device(String ip, String step_label, String cmd) {
|
2021-03-24 08:46:53 +08:00
|
|
|
withCredentials([file(credentialsId: 'id_rsa', variable: 'key_file')]) {
|
2021-01-24 10:34:18 +08:00
|
|
|
def ssh_cmd = """
|
2024-10-13 08:11:35 +08:00
|
|
|
ssh -o ConnectTimeout=5 -o ServerAliveInterval=5 -o ServerAliveCountMax=2 -o BatchMode=yes -o StrictHostKeyChecking=no -i ${key_file} 'comma@${ip}' exec /usr/bin/bash <<'END'
|
2021-01-24 10:34:18 +08:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2024-10-13 08:11:35 +08:00
|
|
|
export TERM=xterm-256color
|
|
|
|
|
2024-02-13 07:41:04 +08:00
|
|
|
shopt -s huponexit # kill all child processes when the shell exits
|
|
|
|
|
2021-01-24 10:34:18 +08:00
|
|
|
export CI=1
|
2023-08-13 08:15:16 +08:00
|
|
|
export PYTHONWARNINGS=error
|
2023-07-26 08:06:43 +08:00
|
|
|
export LOGPRINT=debug
|
2021-01-24 10:34:18 +08:00
|
|
|
export TEST_DIR=${env.TEST_DIR}
|
2021-07-05 11:26:38 +08:00
|
|
|
export SOURCE_DIR=${env.SOURCE_DIR}
|
2021-01-24 10:34:18 +08:00
|
|
|
export GIT_BRANCH=${env.GIT_BRANCH}
|
|
|
|
export GIT_COMMIT=${env.GIT_COMMIT}
|
2024-10-08 12:40:00 +08:00
|
|
|
export CI_ARTIFACTS_TOKEN=${env.CI_ARTIFACTS_TOKEN}
|
|
|
|
export GITHUB_COMMENTS_TOKEN=${env.GITHUB_COMMENTS_TOKEN}
|
2022-06-21 07:24:51 +08:00
|
|
|
export AZURE_TOKEN='${env.AZURE_TOKEN}'
|
2023-12-07 03:13:22 +08:00
|
|
|
# only use 1 thread for tici tests since most require HIL
|
2023-12-07 07:51:29 +08:00
|
|
|
export PYTEST_ADDOPTS="-n 0"
|
2023-11-14 02:45:24 +08:00
|
|
|
|
2021-01-24 10:34:18 +08:00
|
|
|
|
2023-02-06 07:45:01 +08:00
|
|
|
export GIT_SSH_COMMAND="ssh -i /data/gitkey"
|
|
|
|
|
2021-01-24 10:34:18 +08:00
|
|
|
source ~/.bash_profile
|
2021-03-27 04:23:18 +08:00
|
|
|
if [ -f /TICI ]; then
|
|
|
|
source /etc/profile
|
2023-07-22 09:35:29 +08:00
|
|
|
|
2024-01-19 14:09:55 +08:00
|
|
|
rm -rf /tmp/tmp*
|
2023-10-19 10:37:29 +08:00
|
|
|
rm -rf ~/.commacache
|
2024-01-21 07:24:34 +08:00
|
|
|
rm -rf /dev/shm/*
|
2024-04-18 07:33:13 +08:00
|
|
|
rm -rf /dev/tmp/tmp*
|
2023-10-19 10:37:29 +08:00
|
|
|
|
2023-07-22 09:35:29 +08:00
|
|
|
if ! systemctl is-active --quiet systemd-resolved; then
|
|
|
|
echo "restarting resolved"
|
|
|
|
sudo systemctl start systemd-resolved
|
|
|
|
sleep 3
|
|
|
|
fi
|
2023-07-27 06:11:20 +08:00
|
|
|
|
|
|
|
# restart aux USB
|
|
|
|
if [ -e /sys/bus/usb/drivers/hub/3-0:1.0 ]; then
|
|
|
|
echo "restarting aux usb"
|
|
|
|
echo "3-0:1.0" | sudo tee /sys/bus/usb/drivers/hub/unbind
|
|
|
|
sleep 0.5
|
|
|
|
echo "3-0:1.0" | sudo tee /sys/bus/usb/drivers/hub/bind
|
|
|
|
fi
|
2021-03-27 04:23:18 +08:00
|
|
|
fi
|
2023-05-08 06:43:45 +08:00
|
|
|
if [ -f /data/openpilot/launch_env.sh ]; then
|
2023-05-04 05:26:38 +08:00
|
|
|
source /data/openpilot/launch_env.sh
|
|
|
|
fi
|
|
|
|
|
2021-02-01 10:49:34 +08:00
|
|
|
ln -snf ${env.TEST_DIR} /data/pythonpath
|
|
|
|
|
2020-07-25 17:12:19 +08:00
|
|
|
cd ${env.TEST_DIR} || true
|
2024-11-03 12:19:05 +08:00
|
|
|
time ${cmd}
|
2021-12-05 13:07:57 +08:00
|
|
|
END"""
|
2021-01-24 10:34:18 +08:00
|
|
|
|
|
|
|
sh script: ssh_cmd, label: step_label
|
2020-07-25 17:12:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-15 12:41:11 +08:00
|
|
|
def deviceStage(String stageName, String deviceType, List extra_env, def steps) {
|
2023-09-10 12:30:21 +08:00
|
|
|
stage(stageName) {
|
|
|
|
if (currentBuild.result != null) {
|
|
|
|
return
|
2020-07-25 17:12:19 +08:00
|
|
|
}
|
2020-07-04 10:12:05 +08:00
|
|
|
|
2023-12-15 12:41:11 +08:00
|
|
|
def extra = extra_env.collect { "export ${it}" }.join('\n');
|
|
|
|
def branch = env.BRANCH_NAME ?: 'master';
|
2024-10-22 01:58:19 +08:00
|
|
|
def gitDiff = sh returnStdout: true, script: 'curl -s -H "Authorization: Bearer ${GITHUB_COMMENTS_TOKEN}" https://api.github.com/repos/commaai/openpilot/compare/master...${GIT_BRANCH} | jq .files[].filename || echo "/"', label: 'Getting changes'
|
2023-09-11 07:47:07 +08:00
|
|
|
|
2024-02-07 05:35:08 +08:00
|
|
|
lock(resource: "", label: deviceType, inversePrecedence: true, variable: 'device_ip', quantity: 1, resourceSelectStrategy: 'random') {
|
|
|
|
docker.image('ghcr.io/commaai/alpine-ssh').inside('--user=root') {
|
2024-07-19 10:26:22 +08:00
|
|
|
timeout(time: 35, unit: 'MINUTES') {
|
2023-10-31 00:58:57 +08:00
|
|
|
retry (3) {
|
2024-10-02 11:34:21 +08:00
|
|
|
def date = sh(script: 'date', returnStdout: true).trim();
|
|
|
|
device(device_ip, "set time", "date -s '" + date + "'")
|
2023-10-31 00:58:57 +08:00
|
|
|
device(device_ip, "git checkout", extra + "\n" + readFile("selfdrive/test/setup_device_ci.sh"))
|
|
|
|
}
|
2023-09-10 12:30:21 +08:00
|
|
|
steps.each { item ->
|
2024-11-01 11:23:16 +08:00
|
|
|
def name = item[0]
|
|
|
|
def cmd = item[1]
|
|
|
|
|
|
|
|
def args = item[2]
|
|
|
|
def diffPaths = args.diffPaths ?: []
|
|
|
|
def cmdTimeout = args.timeout ?: 9999
|
|
|
|
|
|
|
|
if (branch != "master" && diffPaths && !hasPathChanged(gitDiff, diffPaths)) {
|
|
|
|
println "Skipping ${name}: no changes in ${diffPaths}."
|
2024-10-19 10:12:43 +08:00
|
|
|
return
|
2024-10-06 10:28:09 +08:00
|
|
|
} else {
|
2024-11-01 11:23:16 +08:00
|
|
|
timeout(time: cmdTimeout, unit: 'SECONDS') {
|
|
|
|
device(device_ip, name, cmd)
|
|
|
|
}
|
2024-10-06 10:28:09 +08:00
|
|
|
}
|
2023-09-10 12:30:21 +08:00
|
|
|
}
|
|
|
|
}
|
2023-02-06 07:45:01 +08:00
|
|
|
}
|
|
|
|
}
|
2023-09-10 12:30:21 +08:00
|
|
|
}
|
|
|
|
}
|
2023-02-06 07:45:01 +08:00
|
|
|
|
2024-10-19 10:12:43 +08:00
|
|
|
def hasPathChanged(String gitDiff, List<String> paths) {
|
2024-10-06 10:28:09 +08:00
|
|
|
for (path in paths) {
|
2024-10-19 10:12:43 +08:00
|
|
|
if (gitDiff.contains(path)) {
|
|
|
|
return true
|
2024-10-06 10:28:09 +08:00
|
|
|
}
|
|
|
|
}
|
2024-10-19 10:12:43 +08:00
|
|
|
return false
|
2024-10-06 10:28:09 +08:00
|
|
|
}
|
|
|
|
|
2023-09-10 12:30:21 +08:00
|
|
|
def setupCredentials() {
|
|
|
|
withCredentials([
|
|
|
|
string(credentialsId: 'azure_token', variable: 'AZURE_TOKEN'),
|
|
|
|
]) {
|
|
|
|
env.AZURE_TOKEN = "${AZURE_TOKEN}"
|
|
|
|
}
|
2024-10-08 12:40:00 +08:00
|
|
|
|
|
|
|
withCredentials([
|
|
|
|
string(credentialsId: 'ci_artifacts_pat', variable: 'CI_ARTIFACTS_TOKEN'),
|
|
|
|
]) {
|
|
|
|
env.CI_ARTIFACTS_TOKEN = "${CI_ARTIFACTS_TOKEN}"
|
|
|
|
}
|
|
|
|
|
|
|
|
withCredentials([
|
|
|
|
string(credentialsId: 'post_comments_github_pat', variable: 'GITHUB_COMMENTS_TOKEN'),
|
|
|
|
]) {
|
|
|
|
env.GITHUB_COMMENTS_TOKEN = "${GITHUB_COMMENTS_TOKEN}"
|
|
|
|
}
|
2023-09-10 12:30:21 +08:00
|
|
|
}
|
2023-07-22 12:57:27 +08:00
|
|
|
|
2024-11-01 11:23:16 +08:00
|
|
|
def step(String name, String cmd, Map args = [:]) {
|
|
|
|
return [name, cmd, args]
|
|
|
|
}
|
2023-12-15 12:41:11 +08:00
|
|
|
|
2023-09-10 12:30:21 +08:00
|
|
|
node {
|
|
|
|
env.CI = "1"
|
|
|
|
env.PYTHONWARNINGS = "error"
|
|
|
|
env.TEST_DIR = "/data/openpilot"
|
|
|
|
env.SOURCE_DIR = "/data/openpilot_source/"
|
|
|
|
setupCredentials()
|
2023-07-22 12:57:27 +08:00
|
|
|
|
2023-09-10 12:30:21 +08:00
|
|
|
env.GIT_BRANCH = checkout(scm).GIT_BRANCH
|
|
|
|
env.GIT_COMMIT = checkout(scm).GIT_COMMIT
|
2023-04-06 02:07:42 +08:00
|
|
|
|
2023-09-10 12:30:21 +08:00
|
|
|
def excludeBranches = ['master-ci', 'devel', 'devel-staging', 'release3', 'release3-staging',
|
2024-01-20 06:05:03 +08:00
|
|
|
'testing-closet*', 'hotfix-*']
|
2023-09-10 12:30:21 +08:00
|
|
|
def excludeRegex = excludeBranches.join('|').replaceAll('\\*', '.*')
|
2022-06-12 06:32:12 +08:00
|
|
|
|
2024-05-07 07:42:35 +08:00
|
|
|
if (env.BRANCH_NAME != 'master') {
|
|
|
|
properties([
|
|
|
|
disableConcurrentBuilds(abortPrevious: true)
|
|
|
|
])
|
2023-09-10 12:30:21 +08:00
|
|
|
}
|
2022-11-12 13:50:09 +08:00
|
|
|
|
2023-09-10 12:30:21 +08:00
|
|
|
try {
|
|
|
|
if (env.BRANCH_NAME == 'devel-staging') {
|
2024-05-07 07:42:35 +08:00
|
|
|
deviceStage("build release3-staging", "tici-needs-can", [], [
|
2024-11-01 11:23:16 +08:00
|
|
|
step("build release3-staging", "RELEASE_BRANCH=release3-staging $SOURCE_DIR/release/build_release.sh"),
|
2024-05-07 07:42:35 +08:00
|
|
|
])
|
2023-09-10 12:30:21 +08:00
|
|
|
}
|
2022-06-12 06:32:12 +08:00
|
|
|
|
2023-09-10 12:30:21 +08:00
|
|
|
if (env.BRANCH_NAME == 'master-ci') {
|
2024-11-02 02:16:37 +08:00
|
|
|
parallel (
|
|
|
|
'nightly': {
|
|
|
|
deviceStage("build nightly", "tici-needs-can", [], [
|
|
|
|
step("build nightly", "RELEASE_BRANCH=nightly $SOURCE_DIR/release/build_release.sh"),
|
|
|
|
])
|
|
|
|
},
|
|
|
|
'nightly-dev': {
|
|
|
|
deviceStage("build nightly-dev", "tici-needs-can", [], [
|
|
|
|
step("build nightly-dev", "PANDA_DEBUG_BUILD=1 RELEASE_BRANCH=nightly-dev $SOURCE_DIR/release/build_release.sh"),
|
|
|
|
])
|
|
|
|
},
|
|
|
|
)
|
2023-09-10 12:30:21 +08:00
|
|
|
}
|
2022-11-03 07:34:02 +08:00
|
|
|
|
2023-09-10 12:30:21 +08:00
|
|
|
if (!env.BRANCH_NAME.matches(excludeRegex)) {
|
2024-05-07 07:42:35 +08:00
|
|
|
parallel (
|
|
|
|
// tici tests
|
|
|
|
'onroad tests': {
|
2024-11-14 06:40:42 +08:00
|
|
|
deviceStage("onroad", "tici-needs-can", ["UNSAFE=1"], [
|
2024-05-07 07:42:35 +08:00
|
|
|
// TODO: ideally, this test runs in master-ci, but it takes 5+m to build it
|
|
|
|
//["build master-ci", "cd $SOURCE_DIR/release && TARGET_DIR=$TEST_DIR $SOURCE_DIR/scripts/retry.sh ./build_devel.sh"],
|
2024-11-01 11:23:16 +08:00
|
|
|
step("build openpilot", "cd system/manager && ./build.py"),
|
|
|
|
step("check dirty", "release/check-dirty.sh"),
|
2024-11-03 12:19:05 +08:00
|
|
|
step("onroad tests", "pytest selfdrive/test/test_onroad.py -s", [timeout: 60]),
|
2024-10-04 05:25:48 +08:00
|
|
|
//["time to onroad", "pytest selfdrive/test/test_time_to_onroad.py"],
|
2024-05-07 07:42:35 +08:00
|
|
|
])
|
|
|
|
},
|
|
|
|
'HW + Unit Tests': {
|
|
|
|
deviceStage("tici-hardware", "tici-common", ["UNSAFE=1"], [
|
2024-11-01 11:23:16 +08:00
|
|
|
step("build", "cd system/manager && ./build.py"),
|
2024-11-14 04:03:27 +08:00
|
|
|
step("test pandad", "pytest selfdrive/pandad/tests/test_pandad.py", [diffPaths: ["panda", "selfdrive/pandad/"]]),
|
2024-11-01 11:23:16 +08:00
|
|
|
step("test power draw", "pytest -s system/hardware/tici/tests/test_power_draw.py"),
|
2024-11-14 04:03:27 +08:00
|
|
|
step("test encoder", "LD_LIBRARY_PATH=/usr/local/lib pytest system/loggerd/tests/test_encoder.py"),
|
2024-11-01 11:23:16 +08:00
|
|
|
step("test pigeond", "pytest system/ubloxd/tests/test_pigeond.py"),
|
|
|
|
step("test manager", "pytest system/manager/test/test_manager.py"),
|
2024-05-07 07:42:35 +08:00
|
|
|
])
|
|
|
|
},
|
|
|
|
'loopback': {
|
|
|
|
deviceStage("loopback", "tici-loopback", ["UNSAFE=1"], [
|
2024-11-01 11:23:16 +08:00
|
|
|
step("build openpilot", "cd system/manager && ./build.py"),
|
|
|
|
step("test pandad loopback", "pytest selfdrive/pandad/tests/test_pandad_loopback.py"),
|
2024-05-07 07:42:35 +08:00
|
|
|
])
|
|
|
|
},
|
|
|
|
'camerad': {
|
|
|
|
deviceStage("AR0231", "tici-ar0231", ["UNSAFE=1"], [
|
2024-11-01 11:23:16 +08:00
|
|
|
step("build", "cd system/manager && ./build.py"),
|
2024-11-06 02:52:47 +08:00
|
|
|
step("test camerad", "pytest system/camerad/test/test_camerad.py", [timeout: 60]),
|
2024-11-01 11:23:16 +08:00
|
|
|
step("test exposure", "pytest system/camerad/test/test_exposure.py"),
|
2024-05-07 07:42:35 +08:00
|
|
|
])
|
|
|
|
deviceStage("OX03C10", "tici-ox03c10", ["UNSAFE=1"], [
|
2024-11-01 11:23:16 +08:00
|
|
|
step("build", "cd system/manager && ./build.py"),
|
2024-11-06 02:52:47 +08:00
|
|
|
step("test camerad", "pytest system/camerad/test/test_camerad.py", [timeout: 60]),
|
2024-11-01 11:23:16 +08:00
|
|
|
step("test exposure", "pytest system/camerad/test/test_exposure.py"),
|
2024-05-07 07:42:35 +08:00
|
|
|
])
|
|
|
|
},
|
|
|
|
'sensord': {
|
|
|
|
deviceStage("LSM + MMC", "tici-lsmc", ["UNSAFE=1"], [
|
2024-11-01 11:23:16 +08:00
|
|
|
step("build", "cd system/manager && ./build.py"),
|
|
|
|
step("test sensord", "pytest system/sensord/tests/test_sensord.py"),
|
2024-05-07 07:42:35 +08:00
|
|
|
])
|
|
|
|
deviceStage("BMX + LSM", "tici-bmx-lsm", ["UNSAFE=1"], [
|
2024-11-01 11:23:16 +08:00
|
|
|
step("build", "cd system/manager && ./build.py"),
|
|
|
|
step("test sensord", "pytest system/sensord/tests/test_sensord.py"),
|
2024-05-07 07:42:35 +08:00
|
|
|
])
|
|
|
|
},
|
|
|
|
'replay': {
|
|
|
|
deviceStage("model-replay", "tici-replay", ["UNSAFE=1"], [
|
2024-11-14 04:03:27 +08:00
|
|
|
step("build", "cd system/manager && ./build.py", [diffPaths: ["selfdrive/modeld/", "tinygrad_repo", "selfdrive/test/process_replay/model_replay.py"]]),
|
2024-11-17 07:34:21 +08:00
|
|
|
step("model replay", "selfdrive/test/process_replay/model_replay.py", [diffPaths: ["selfdrive/modeld/", "tinygrad_repo", "selfdrive/test/process_replay/model_replay.py"]]),
|
2024-05-07 07:42:35 +08:00
|
|
|
])
|
|
|
|
},
|
|
|
|
'tizi': {
|
|
|
|
deviceStage("tizi", "tizi", ["UNSAFE=1"], [
|
2024-11-01 11:23:16 +08:00
|
|
|
step("build openpilot", "cd system/manager && ./build.py"),
|
|
|
|
step("test pandad loopback", "SINGLE_PANDA=1 pytest selfdrive/pandad/tests/test_pandad_loopback.py"),
|
|
|
|
step("test pandad spi", "pytest selfdrive/pandad/tests/test_pandad_spi.py"),
|
2024-11-14 04:03:27 +08:00
|
|
|
step("test pandad", "pytest selfdrive/pandad/tests/test_pandad.py", [diffPaths: ["panda", "selfdrive/pandad/"]]),
|
2024-11-01 11:23:16 +08:00
|
|
|
step("test amp", "pytest system/hardware/tici/tests/test_amplifier.py"),
|
2024-11-19 06:55:46 +08:00
|
|
|
step("test qcomgpsd", "pytest system/qcomgpsd/tests/test_qcomgpsd.py", [diffPaths: ["system/qcomgpsd/"]]),
|
2024-05-07 07:42:35 +08:00
|
|
|
])
|
|
|
|
},
|
|
|
|
|
|
|
|
)
|
2020-01-31 05:06:45 +08:00
|
|
|
}
|
2023-09-10 12:30:21 +08:00
|
|
|
} catch (Exception e) {
|
|
|
|
currentBuild.result = 'FAILED'
|
|
|
|
throw e
|
2020-01-31 05:06:45 +08:00
|
|
|
}
|
2024-05-07 08:30:33 +08:00
|
|
|
}
|