Repository navigation
Expand file tree
/
Copy pathauto-debug.sh
More file actions
executable file
·127 lines (114 loc) · 3.53 KB
/
Copy pathauto-debug.sh
File metadata and controls
executable file
·127 lines (114 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/data/data/com.termux/files/usr/bin/bash
# Automated hot-swap debug loop for the shim-only test APK.
#
# Every launch fingerprints all uploaded libraries with MD5 and prints the values
# to /sdcard/download/softisp-app.log. This script computes md5sum of the local
# build outputs and compares them with the log. On a mismatch it sends a
# dedicated control intent, waits for the app to terminate itself, rebuilds and
# re-pushes the core, and launches again.
set -euo pipefail
export JAVA_HOME=/data/data/com.termux/files/usr/lib/jvm/java-11-openjdk
export ANDROID_NDK_ROOT="$HOME/android-sdk/ndk/29.0.14206865"
export ANDROID_HOME="$HOME/android-sdk"
cd "$(dirname "$0")"
export RUSTC_WRAPPER="$PWD/scripts/libsoftisp-rustc-wrapper.sh"
COMPONENT="com.softisp.camera/com.softisp.camera.ShimActivity"
ACTION="com.softisp.camera.action.CONTROL"
EXTRA="softisp_cmd"
CORE="target/aarch64-linux-android/debug/libsoftisp.so"
MNN_DIR="cam-rust/lib/arm64-v8a"
LOG="/sdcard/download/softisp-app.log"
OUT=".tmp/auto-debug"
ATTEMPTS="${1:-3}"
WAIT_SECS="${2:-12}"
mkdir -p "$OUT"
capture_log() {
if [ -f "$LOG" ]; then
if [ -f "$LOG.1" ]; then
cat "$LOG.1" "$LOG" > "$OUT/app.log"
else
cp -f "$LOG" "$OUT/app.log"
fi
else
: > "$OUT/app.log"
fi
}
expected_sums() {
for file in "$CORE" "$MNN_DIR"/lib*.so; do
[ -f "$file" ] || continue
printf '%s %s\n' "$(basename "$file")" "$(md5sum "$file" | cut -d' ' -f1)"
done
}
launch() {
logcat -c 2>/dev/null || true
rm -f "$LOG"
am start -n "$COMPONENT" >/dev/null
sleep "$WAIT_SECS"
send_control log
for _ in $(seq 1 10); do
capture_log
if grep -q "md5 libsoftisp.so" "$OUT/app.log" 2>/dev/null; then
break
fi
sleep 1
done
logcat -d > "$OUT/logcat.txt" 2>/dev/null || true
capture_log
}
send_control() {
am start -a "$ACTION" -n "$COMPONENT" --es "$EXTRA" "$1" >/dev/null
}
wait_stopped() {
for _ in $(seq 1 30); do
capture_log
if grep -q "control intent '$1'" "$OUT/app.log" 2>/dev/null \
|| grep -q "forced exit after stop intent" "$OUT/app.log" 2>/dev/null; then
return 0
fi
sleep 1
done
echo " WARN: no confirmation for control intent '$1'" >&2
return 1
}
verify() {
expected_sums | sort > "$OUT/expected.txt"
awk '
BEGIN { start = 1 }
/\[shim\] launcher started/ { start = NR }
{ line[NR] = $0 }
END {
for (i = start; i <= NR; i++) {
n = split(line[i], field, " ")
if (field[3] == "md5") print field[4], field[5]
}
}
' "$OUT/app.log" | sort > "$OUT/actual.txt"
if diff -u "$OUT/expected.txt" "$OUT/actual.txt" > "$OUT/diff.txt"; then
echo " md5 verification: PASS ($(wc -l < "$OUT/actual.txt") libraries)"
return 0
fi
echo " md5 verification: FAIL" >&2
cat "$OUT/diff.txt" >&2
return 1
}
rebuild_and_push() {
echo " rebuilding $CORE"
./build-test-libs.sh --core-only >/dev/null
./push-test-libs.sh
}
for attempt in $(seq 1 "$ATTEMPTS"); do
echo "=== attempt $attempt/$ATTEMPTS ==="
launch
if verify; then
echo "OK: loaded libraries match local build outputs"
exit 0
fi
echo " sending stop intent"
send_control stop || true
wait_stopped || true
if [ "$attempt" -lt "$ATTEMPTS" ]; then
rebuild_and_push
fi
done
echo "ERROR: loaded libraries never matched after $ATTEMPTS attempts" >&2
exit 1