Ian Chamberlain
1 year ago
2 changed files with 62 additions and 42 deletions
@ -1,50 +1,64 @@
@@ -1,50 +1,64 @@
|
||||
#!/bin/bash |
||||
|
||||
# Clean up child processes on exit: https://stackoverflow.com/a/2173421/14436105 |
||||
trap "pkill -P $$" EXIT INT TERM |
||||
|
||||
mkdir -p ~/.config/citra-emu |
||||
cp /app/sdl2-config.ini ~/.config/citra-emu |
||||
# For some reason, log file is only written when this dir already exists, |
||||
# but it is only created after the first run of citra (our only run, in the container) |
||||
mkdir -p ~/.local/share/citra-emu/ |
||||
|
||||
ERRS=0 |
||||
# shellcheck disable=SC2068 |
||||
for EXE in $@; do |
||||
VIDEO_OUT="$(dirname "$EXE")/$(basename "$EXE" .elf)_capture.webm" |
||||
|
||||
# colored logs would be nice, but we can always just grab the plaintext log file |
||||
xvfb-run citra \ |
||||
--appimage-extract-and-run \ |
||||
--dump-video="$VIDEO_OUT" \ |
||||
"$EXE" \ |
||||
&>/dev/null & |
||||
PID=$! |
||||
|
||||
# Citra takes a little while to start up, so wait a little before we try to connect |
||||
sleep 3 |
||||
|
||||
arm-none-eabi-gdb --silent --batch-silent --command /app/test-runner.gdb "$EXE" |
||||
STATUS=$? |
||||
if [ $STATUS -ne 0 ]; then |
||||
echo >&2 "FAILED (exit status $STATUS): $EXE" |
||||
ERRS=$(( ERRS + 1 )) |
||||
fi |
||||
set -x |
||||
|
||||
kill -INT $PID &>/dev/null |
||||
sleep 1 |
||||
if kill -0 $PID &>/dev/null; then |
||||
kill -KILL $PID &>/dev/null |
||||
function cleanup_jobs() { |
||||
# shellcheck disable=SC2317 # Unreachable because it's only used in trap |
||||
if [ -n "$(jobs -p)" ]; then |
||||
sleep 5 & |
||||
wait -n |
||||
# shellcheck disable=SC2046 # We want to expand jobs here and for `wait` |
||||
kill -9 $(jobs -p) |
||||
# shellcheck disable=SC2046 |
||||
wait $(jobs -p) &>/dev/null |
||||
fi |
||||
} |
||||
|
||||
trap cleanup_jobs EXIT |
||||
|
||||
EXE_ELF=$1 |
||||
EXE_3DSX="$(dirname "$EXE")/$(basename "$EXE" .elf).3dsx" |
||||
|
||||
EXE_TO_RUN="$EXE_ELF" |
||||
if [ -f "$EXE_3DSX" ]; then |
||||
echo >&2 "Found $(basename "$EXE_3DSX"), it will be run instead of $(basename "$EXE_ELF")" |
||||
EXE_TO_RUN="$EXE_3DSX" |
||||
fi |
||||
|
||||
VIDEO_OUT="$(dirname "$EXE_ELF")/$(basename "$EXE_ELF" .elf)_capture.webm" |
||||
|
||||
CITRA_LOG_DIR=~/.local/share/citra-emu/log |
||||
CITRA_OUT="$CITRA_LOG_DIR/citra_output.txt" |
||||
|
||||
xvfb-run --auto-servernum \ |
||||
citra \ |
||||
--appimage-extract-and-run \ |
||||
--dump-video="$VIDEO_OUT" \ |
||||
"$EXE_TO_RUN" \ |
||||
&>"$CITRA_OUT" & |
||||
CITRA_PID=$! |
||||
|
||||
# Citra takes a little while to start up, so wait a little before we try to connect |
||||
sleep 5 |
||||
|
||||
arm-none-eabi-gdb --silent --batch-silent --command /app/test-runner.gdb "$EXE_ELF" |
||||
STATUS=$? |
||||
|
||||
kill $CITRA_PID |
||||
cleanup_jobs |
||||
|
||||
CITRA_LOG="$CITRA_LOG_DIR/citra_log.txt" |
||||
|
||||
CITRA_LOG=~/.local/share/citra-emu/log/citra_log.txt |
||||
CITRA_LOG_OUT="$(dirname "$EXE")/$(basename "$EXE" .elf)_citra_log.txt" |
||||
if test -f "$CITRA_LOG"; then |
||||
cp "$CITRA_LOG" "$CITRA_LOG_OUT" |
||||
for f in "$CITRA_LOG" "$CITRA_OUT"; do |
||||
OUT="$(dirname "$EXE_ELF")/$(basename "$EXE_ELF" .elf)_$(basename "$f")" |
||||
if test -f "$f"; then |
||||
cp "$f" "$OUT" |
||||
if [ $STATUS -ne 0 ]; then |
||||
echo >&2 "$(basename $f) copied to $OUT" |
||||
fi |
||||
else |
||||
echo "WARNING: citra log not found" |
||||
echo >&2 "WARNING: $(basename "$f") not found" |
||||
fi |
||||
done |
||||
|
||||
exit $ERRS |
||||
exit $STATUS |
||||
|
Loading…
Reference in new issue