test: b_side进程断开现象

This commit is contained in:
2026-04-14 00:34:56 +08:00
parent 71c026ccf3
commit 6ccd9e9fa1

View File

@@ -14,6 +14,26 @@ main_pid_for_service() {
systemctl show --property MainPID --value "${service_name}"
}
wait_for_service_pid_change() {
local service_name="$1"
local previous_pid="$2"
local timeout_sec="${3:-10}"
local waited=0
local current_pid=""
while (( waited < timeout_sec )); do
current_pid="$(main_pid_for_service "${service_name}")"
if [[ -n "${current_pid}" && "${current_pid}" != "0" && "${current_pid}" != "${previous_pid}" ]]; then
printf '%s\n' "${current_pid}"
return 0
fi
sleep 1
waited=$(( waited + 1 ))
done
return 1
}
require_running_pid() {
local service_name="$1"
local pid
@@ -46,10 +66,21 @@ blitz_prepare_runtime_dir
case "${1:-}" in
bside-crash)
kill -9 "$(require_running_pid "${B_SIDE_SERVICE}")"
target_pid="$(require_running_pid "${B_SIDE_SERVICE}")"
blitz_log "${STEP}" "bside-crash" "start" "service=${B_SIDE_SERVICE} pid=${target_pid}" 0
kill -9 "${target_pid}"
if restarted_pid="$(wait_for_service_pid_change "${B_SIDE_SERVICE}" "${target_pid}")"; then
blitz_log "${STEP}" "bside-crash" "success" "old_pid=${target_pid} new_pid=${restarted_pid}" 0
else
blitz_log "${STEP}" "bside-crash" "failure" "old_pid=${target_pid} restart_not_observed_within=10s" 1
exit 1
fi
;;
bside-process-freeze)
kill -STOP "$(require_running_pid "${B_SIDE_SERVICE}")"
target_pid="$(require_running_pid "${B_SIDE_SERVICE}")"
blitz_log "${STEP}" "bside-process-freeze" "start" "service=${B_SIDE_SERVICE} pid=${target_pid}" 0
kill -STOP "${target_pid}"
blitz_log "${STEP}" "bside-process-freeze" "success" "service=${B_SIDE_SERVICE} pid=${target_pid}" 0
;;
bside-video-thread-stall)
write_fault_flag "fault-injection-bside-video-thread-stall"
@@ -58,10 +89,21 @@ case "${1:-}" in
write_fault_flag "fault-injection-bside-control-thread-stall"
;;
ros-crash)
kill -9 "$(require_running_pid "${ROS_SERVICE}")"
target_pid="$(require_running_pid "${ROS_SERVICE}")"
blitz_log "${STEP}" "ros-crash" "start" "service=${ROS_SERVICE} pid=${target_pid}" 0
kill -9 "${target_pid}"
if restarted_pid="$(wait_for_service_pid_change "${ROS_SERVICE}" "${target_pid}")"; then
blitz_log "${STEP}" "ros-crash" "success" "old_pid=${target_pid} new_pid=${restarted_pid}" 0
else
blitz_log "${STEP}" "ros-crash" "failure" "old_pid=${target_pid} restart_not_observed_within=10s" 1
exit 1
fi
;;
ros-freeze)
kill -STOP "$(require_running_pid "${ROS_SERVICE}")"
target_pid="$(require_running_pid "${ROS_SERVICE}")"
blitz_log "${STEP}" "ros-freeze" "start" "service=${ROS_SERVICE} pid=${target_pid}" 0
kill -STOP "${target_pid}"
blitz_log "${STEP}" "ros-freeze" "success" "service=${ROS_SERVICE} pid=${target_pid}" 0
;;
network-down)
if [[ "${BLITZ_WATCHDOG_ALLOW_FAULT_INJECTION}" != "1" ]]; then