ui-monkey.sh 1.5 KB

12345678910111213141516171819202122
  1. #!/usr/bin/env bash
  2. # The seeded UI monkey test (tools/ui_monkey.py, round 190rb) inside a sandbox: a user + mount namespace (no root
  3. # needed) where every folder in MONKEY_RO (default: $HOME and every drive mounted under /mnt) is read-only, so whatever the random clicks reach
  4. # (Save as..., the file browser, Delete in a folder view) cannot change a file outside the run's own folder. The run
  5. # folder must therefore be outside those folders (e.g. under /tmp).
  6. #
  7. # scripts/ui-monkey.sh <run folder> [ui_monkey.py arguments: --app --display --seed --minutes --layout --project ...]
  8. #
  9. # env: MONKEY_RO="..." read-only folders; APP_LD_LIBRARY_PATH for LYNX (a devroot without system packages)
  10. set -euo pipefail
  11. here="$(cd "$(dirname "$0")/.." && pwd)"
  12. out="$1"; shift
  13. mkdir -p "$out"
  14. ro="${MONKEY_RO:-$HOME $(findmnt -rn -o TARGET | grep -E "^/mnt/[a-z]$" | tr "\n" " ")}"
  15. for d in $ro; do
  16. case "$(realpath "$out")/" in "$(realpath "$d")"/*) echo "ui-monkey: the run folder must be outside $d (it is read-only in the sandbox)" >&2; exit 2 ;; esac
  17. done
  18. export MONKEY_RO_LIST="$ro" LD_LIBRARY_PATH="${APP_LD_LIBRARY_PATH:-${LD_LIBRARY_PATH:-}}"
  19. exec unshare --user --map-root-user --mount bash -c '
  20. for d in $MONKEY_RO_LIST; do [ -d "$d" ] && mount --bind -o ro "$d" "$d"; done
  21. for d in $MONKEY_RO_LIST; do [ -d "$d" ] && touch "$d/.ui-monkey-rw-check" 2> /dev/null && { echo "ui-monkey: $d is still writable" >&2; exit 3; }; done
  22. exec python3 "$0" --out "$1" "${@:2}"' "$here/tools/ui_monkey.py" "$out" "$@"