#!/bin/bash # Drives gamemode-session in dryrun against a temp state dir and asserts the # reference-counting state machine. No live effects run. set -u HERE=$(cd "$(dirname "$0")/.." && pwd) SCRIPT="$HERE/gamemode-session.sh" TMP=$(mktemp -d) trap 'rm -rf "$TMP"' EXIT export GAMEMODE_STATE_DIR="$TMP/state" export GAMEMODE_DRYRUN=1 fail=0 check() { # desc, actual, expected if [ "$2" = "$3" ]; then printf 'ok - %s\n' "$1" else printf 'FAIL - %s (got [%s] want [%s])\n' "$1" "$2" "$3"; fail=1; fi } active() { "$SCRIPT" status >/dev/null 2>&1 && echo active || echo inactive; } check "starts inactive" "$(active)" "inactive" "$SCRIPT" add feral >/dev/null 2>&1 check "feral activates" "$(active)" "active" check "src.feral marker set" "$([ -e "$GAMEMODE_STATE_DIR/src.feral" ] && echo y)" "y" check "baseline captured" "$([ -e "$GAMEMODE_STATE_DIR/baseline.profile" ] && echo y)" "y" "$SCRIPT" add manual >/dev/null 2>&1 check "manual keeps active" "$(active)" "active" "$SCRIPT" del feral >/dev/null 2>&1 check "still active on 1 left" "$(active)" "active" "$SCRIPT" del manual >/dev/null 2>&1 check "last del deactivates" "$(active)" "inactive" check "baseline cleared" "$([ -e "$GAMEMODE_STATE_DIR/baseline.profile" ] && echo y || echo n)" "n" "$SCRIPT" toggle >/dev/null 2>&1 check "toggle on activates" "$(active)" "active" "$SCRIPT" toggle >/dev/null 2>&1 check "toggle off deactivates" "$(active)" "inactive" "$SCRIPT" reset >/dev/null 2>&1 check "reset leaves inactive" "$(active)" "inactive" exit $fail