ci/android: handle premature exit of .gitlab-ci/cuttlefish-runner.sh

Save some logs and stop cuttlefish more cleanly when
.gitlab-ci/cuttlefish-runner.sh exits prematurely because of some
errors.

This makes it possible to have the logs available as artifacts even if
the script didn't run to completion.

This approach also leaves the system in a cleaner state and makes it
possible to relaunch the script and have launch_cvd work even if it had
been run in the past both with or without errors.

This is especially useful for local experiments.

Reviewed-by: Eric Engestrom <None>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30895>
This commit is contained in:
Antonio Ospite
2024-08-22 13:35:31 +02:00
committed by Marge Bot
parent c4fd424a2b
commit 03f15ca6eb

View File

@@ -20,6 +20,25 @@ chown root.kvm /dev/kvm
cd /cuttlefish
# Add a function to perform some tasks when exiting the script
function my_atexit()
{
# shellcheck disable=SC2317
cp /cuttlefish/cuttlefish/instances/cvd-1/logs/logcat $RESULTS_DIR || true
# shellcheck disable=SC2317
cp /cuttlefish/cuttlefish/instances/cvd-1/kernel.log $RESULTS_DIR || true
# shellcheck disable=SC2317
cp /cuttlefish/cuttlefish/instances/cvd-1/logs/launcher.log $RESULTS_DIR || true
# shellcheck disable=SC2317
/cuttlefish/bin/stop_cvd -wait_for_launcher=10
}
# stop cuttlefish if the script ends prematurely or is interrupted
trap 'my_atexit' EXIT
trap 'exit 2' HUP INT PIPE TERM
launch_cvd --verbosity=DEBUG --report_anonymous_usage_stats=n --cpus=8 --memory_mb=8192 --gpu_mode="$ANDROID_GPU_MODE" --daemon --enable_minimal_mode=true --guest_enforce_security=false --use_overlay=false
sleep 1
@@ -129,9 +148,5 @@ section_switch cuttlefish_results "cuttlefish: gathering the results"
$ADB pull $RESULTS $RESULTS_DIR
cp /cuttlefish/cuttlefish/instances/cvd-1/logs/logcat $RESULTS_DIR
cp /cuttlefish/cuttlefish/instances/cvd-1/kernel.log $RESULTS_DIR
cp /cuttlefish/cuttlefish/instances/cvd-1/logs/launcher.log $RESULTS_DIR
section_end cuttlefish_results
exit $EXIT_CODE