Skip to content

Commit 6c4f8e6

Browse files
committed
Fixed array access
1 parent efac22f commit 6c4f8e6

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

scripts/run-android-instrumentation-tests.sh

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,32 @@ count_chunks() {
2020

2121
# Extract ordered CN1SS payload (by 6-digit index) and decode to PNG
2222
# Usage: extract_cn1ss_stream <input-file> > <png>
23+
# Extract ordered CN1SS payload (by 6-digit index) from ANYWHERE in the line
24+
# Usage: extract_cn1ss_stream <input-file> > <concatenated-base64>
2325
extract_cn1ss_stream() {
2426
local f="$1"
25-
# stderr: pass through INFO/META for visibility
26-
awk -F: '
27-
/^CN1SS:[0-9]{6}:/ {
28-
idx = substr($0, 8, 6) + 0
29-
data = substr($0, 16)
30-
gsub(/[ \t\r\n]/, "", data)
31-
gsub(/[^A-Za-z0-9+\/=]/, "", data)
32-
printf "%06d %s\n", idx, data
33-
next
27+
awk '
28+
{
29+
# Find CN1SS:<6digits>: anywhere in the line
30+
if (match($0, /CN1SS:[0-9][0-9][0-9][0-9][0-9][0-9]:/)) {
31+
# Extract the 6-digit index just after CN1SS:
32+
idx = substr($0, RSTART + 6, 6) + 0
33+
# Payload is everything after the matched token
34+
payload = substr($0, RSTART + RLENGTH)
35+
gsub(/[ \t\r\n]/, "", payload)
36+
gsub(/[^A-Za-z0-9+\/=]/, "", payload)
37+
printf "%06d %s\n", idx, payload
38+
next
39+
}
40+
# Pass through CN1SS meta lines for debugging (INFO/END/etc), even if prefixed
41+
if (index($0, "CN1SS:") > 0) {
42+
print "#META " $0 > "/dev/stderr"
43+
}
3444
}
35-
/^CN1SS:END$/ { print "#META END" > "/dev/stderr"; next }
36-
/^CN1SS:/ { print "#META " $0 > "/dev/stderr"; next }
3745
' "$f" \
3846
| sort -n \
3947
| awk '{ $1=""; sub(/^ /,""); printf "%s", $0 }' \
40-
| tr -d '\r\n'
48+
| tr -d "\r\n"
4149
}
4250

4351
# Verify PNG signature + non-zero size
@@ -137,7 +145,7 @@ fi
137145
# ---- Chunk accounting (diagnostics) ---------------------------------------
138146

139147
XML_CHUNKS_TOTAL=0
140-
for x in "${XMLS[@]:-}"; do
148+
for x in "${XMLS[@]}"; do
141149
c="$(count_chunks "$x")"; c="${c//[^0-9]/}"; : "${c:=0}"
142150
XML_CHUNKS_TOTAL=$(( XML_CHUNKS_TOTAL + c ))
143151
done
@@ -161,8 +169,8 @@ fi
161169
: > "$SCREENSHOT_OUT"
162170
SOURCE=""
163171

164-
if [ "${#XMLS[@]:-0}" -gt 0 ] && [ "${XML_CHUNKS_TOTAL:-0}" -gt 0 ]; then
165-
for x in "${XMLS[@]:-}"; do
172+
if [ "${#XMLS[@]}" -gt 0 ] && [ "${XML_CHUNKS_TOTAL:-0}" -gt 0 ]; then
173+
for x in "${XMLS[@]}"; do
166174
c="$(count_chunks "$x")"; c="${c//[^0-9]/}"; : "${c:=0}"
167175
[ "$c" -gt 0 ] || continue
168176
ra_log "Reassembling from XML: $x (chunks=$c)"
@@ -197,7 +205,7 @@ if [ -z "$SOURCE" ]; then
197205
if [ "${LOGCAT_CHUNKS:-0}" -gt 0 ]; then extract_cn1ss_stream "$LOGCAT_FILE"; fi
198206
if [ "${XML_CHUNKS_TOTAL:-0}" -gt 0 ] && [ "${LOGCAT_CHUNKS:-0}" -eq 0 ]; then
199207
# concatenate all XMLs
200-
for x in "${XMLS[@]:-}"; do
208+
for x in "${XMLS[@]}"; do
201209
if [ "$(count_chunks "$x")" -gt 0 ]; then extract_cn1ss_stream "$x"; fi
202210
done
203211
fi
@@ -225,7 +233,7 @@ ra_log "SUCCESS -> screenshot saved (${SOURCE}), size: $(stat -c '%s' "$SCREENSH
225233

226234
# Copy useful artifacts for GH Actions
227235
cp -f "$LOGCAT_FILE" "$ARTIFACTS_DIR/$(basename "$LOGCAT_FILE")" 2>/dev/null || true
228-
for x in "${XMLS[@]:-}"; do
236+
for x in "${XMLS[@]}"; do
229237
cp -f "$x" "$ARTIFACTS_DIR/$(basename "$x")" 2>/dev/null || true
230238
done
231239
[ -n "${TEST_EXEC_LOG:-}" ] && cp -f "$TEST_EXEC_LOG" "$ARTIFACTS_DIR/test-results.log" 2>/dev/null || true

0 commit comments

Comments
 (0)