Files
d2r-mobile/dm/ios/tools/devlock_test.sh
T
jhaizhouandhubeiqiao 66c3a2fb70 Fix setup on stock macOS bash, shader step false success, battery gate misreport (#4, #5, #7)
- Brace every $NAME that is directly followed by a non-ASCII character in the shell scripts: bash 3.2 in a UTF-8 locale read the first byte of the following character as part of the variable name and aborted under set -u (#4, #6).
- setup.sh and d2rm_pack.py: the shader translation step is complete only when every entry in the completion marker is ok and every library file exists; the script's exit status is no longer hidden by a pipe (#5).
- devbattery.sh / devlock.sh: a missing local timeout or ideviceinfo is reported as such and stops at once, instead of being reported as an offline device and polled for up to an hour (#7).
- smoke_mac.sh builds its package for iPhone only regardless of the project default.

Reported by @SakuraToErii. The setup.sh part of #4 was also submitted by @hubeiqiao in #6.

Co-authored-by: hubeiqiao <12777592+hubeiqiao@users.noreply.github.com>
2026-10-13 03:17:23 +08:00

13 lines
1.9 KiB
Bash

#!/bin/bash
export DM_DEVBATTERY=0 DEVBATTERY_DIR=$(mktemp -d) # 锁单测不过电量闸、不写真电量日志(一次挂住的锁单测往真告警文件写了 18 条「读不到」) | Lock unit tests do not go through the battery gate and do not write the real battery log (a hung lock unit test once wrote 18 「读不到」(unreadable) entries into the real alert file)
# devlock.sh 排队次序自测(不碰手机):持锁者在跑时,先到的测量号、后到的冒烟号、再后到的旧版无类别号——放锁后的拿锁次序应为 冒烟 → 旧版 → 测量。
# Queue-order self-test for devlock.sh (does not touch the phone): while a holder is running, a measurement ticket arrives first, then a smoke test ticket, then an old-style classless ticket - after release the lock should be obtained in the order smoke test → old-style → measurement.
set -u; H=$(cd "$(dirname "$0")" && pwd); T=$(mktemp -d); export DM_DEVLOCK_DIR=$T/device.lock DM_DEVLOCK_QUEUE=$T/device.queue
w(){ ( unset DM_DEVLOCK_HELD; [ "$2" = measure ] && export DM_DEVLOCK_CLASS=measure; source $H/devlock.sh; devlock_acquire "$1" 2>/dev/null; echo "$1" >> $T/order; sleep 0.3; devlock_release ) & }
( source $H/devlock.sh; devlock_acquire 持锁者 2>/dev/null; sleep 4; devlock_release ) &
sleep 1; w 测量 measure; sleep 0.5; w 冒烟 smoke; sleep 0.5
( mkdir -p $DM_DEVLOCK_QUEUE; sleep 30 & P=$!; K=$DM_DEVLOCK_QUEUE/$(python3 -c 'import time;print(time.time_ns())')_$P; mkdir $K; echo 旧版 > $K/owner
until [ "$(ls $DM_DEVLOCK_QUEUE | LC_ALL=C sort | head -1 | sed 's/.*_//')" = $P ] && [ ! -d $DM_DEVLOCK_DIR ]; do sleep 0.1; done; echo 旧版 >> $T/order; kill $P; rm -rf $DM_DEVLOCK_QUEUE/*_$P ) &
wait; got=$(tr '\n' ' ' < $T/order); rm -rf $T
[ "$got" = "冒烟 旧版 测量 " ] && echo "devlock_test 通过:$got" || { echo "🔴 devlock_test 次序不对:期望「冒烟 旧版 测量」,实际「${got}」"; exit 1; }