Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tests/all
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
# against stand-ins for docker and repo, tools/repo-publish --from-main's
# copy of the prebuilt binaries into a fixture's publish tree,
# tools/repo-publish's staging, tools/extract-vendor-firmware's output
# generations (made-up files, no factory image), the callers of
# generations (made-up files, no factory image), the two chroot
# extractors' message when build.prop can't be read, the callers of
# tools/alpine-fetch.py stopping when it fails, and its dependency
# resolution against synthetic indexes, and the tools' --help from their
# header comments (tools/lib/usage.sh).
Expand Down Expand Up @@ -86,3 +87,5 @@ echo "# tests/phone-demo-notes"
tests/phone-demo-notes
echo "# tests/install-guided" # the guided install, against stand-ins for the phone and this computer's network
tests/install-guided
echo "# tests/chroot-extractors"
tests/chroot-extractors
68 changes: 68 additions & 0 deletions tests/chroot-extractors
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash
# SPDX-License-Identifier: MIT
# Tests for tools/extract-vendor-chroot and tools/extract-fingerprint-vendor
# with made-up images (no factory image, no Google files): small files with
# the ext4 magic stand in for vendor.img and system.img in an image zip, a
# stand-in unzip reads it with Python's zipfile, and a stand-in debugfs
# fails the copy of build.prop as real debugfs does on a full work
# directory (an error message, an empty file, exit 0). Checked: each tool
# then says build.prop can't be read, not that the image has none.
# XVC=path and XFP=path run other copies of the tools (a negative control).
set -euo pipefail
cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.."
XVC=$(realpath -- "${XVC:-tools/extract-vendor-chroot}")
XFP=$(realpath -- "${XFP:-tools/extract-fingerprint-vendor}")
failed=0
fail() { printf 'not ok - %s\n' "$1" >&2; failed=$((failed + 1)); }
pass() { printf 'ok - %s\n' "$1"; }
t=$(mktemp -d)
trap 'rm -rf "$t"' EXIT

mkdir -p "$t/bin"
cat > "$t/bin/unzip" <<'EOF'
#!/bin/bash
# unzip -Z1 ZIP (list) or unzip -p ZIP MEMBER (to stdout)
exec python3 -I -c '
import sys, zipfile
with zipfile.ZipFile(sys.argv[2]) as z:
if sys.argv[1] == "-Z1":
print("\n".join(z.namelist()))
else:
sys.stdout.buffer.write(z.read(sys.argv[3]))
' "$@"
EOF
cat > "$t/bin/debugfs" <<'EOF'
#!/bin/bash
# debugfs -R "dump /build.prop OUT" IMG on a full disk: real debugfs's
# messages, an empty OUT, exit 0
read -r _ _ out <<<"$2"
out=${out#\"}; out=${out%\"}; out=${out//\"\"/\"} # debugfs's quoting
: > "$out"
echo "debugfs 1.47.2 (stand-in)" >&2
echo "dump: No space left on device while writing file" >&2
exit 0
EOF
chmod +x "$t/bin/unzip" "$t/bin/debugfs"

head -c 4096 /dev/zero > "$t/ext4.img"
printf '\x53\xef' | dd of="$t/ext4.img" bs=1 seek=1080 conv=notrunc status=none
python3 -I -c '
import sys, zipfile
with zipfile.ZipFile(sys.argv[1], "w") as z:
for p in ("vendor.img", "system.img"):
z.write(sys.argv[2], p)
' "$t/image-cheetah-fictional.zip" "$t/ext4.img"

for tool in "$XVC" "$XFP"; do
name=${tool##*/}
args=()
[[ $tool != "$XVC" ]] || args=(-p gnss)
if PATH=$t/bin:$PATH "$tool" "${args[@]}" -w "$t/work" -o "$t/out" "$t/image-cheetah-fictional.zip" > "$t/log" 2>&1; then
fail "$name: a build.prop whose copy fails is refused"
elif ! grep -qF "error: build.prop can't be read from vendor.img" "$t/log"; then
cat "$t/log"; fail "$name: a build.prop whose copy fails: says it can't be read"
else
pass "$name: a build.prop whose copy fails: refused, says it can't be read"
fi
done
((failed == 0)) || { echo "$failed check(s) failed" >&2; exit 1; }
2 changes: 1 addition & 1 deletion tools/extract-fingerprint-vendor
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ done
# The vendor partition says which device it was built for.
mkdir -p "$WORK/v"
debugfs -R "dump /build.prop $(dq "$WORK/v/build.prop")" "$WORK/vendor.img" 2>/dev/null
[[ -s "$WORK/v/build.prop" ]] || die "vendor.img has no build.prop"
[[ -s "$WORK/v/build.prop" ]] || die "build.prop can't be read from vendor.img"
dev=$(sed -n 's/^ro.product.vendor.device=//p' "$WORK/v/build.prop" | head -1)
[[ "$dev" == "$DEVICE" || -n "$FORCE" ]] ||
die "vendor partition is for '${dev:-unknown}', not $DEVICE; use -f to override"
Expand Down
2 changes: 1 addition & 1 deletion tools/extract-vendor-chroot
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ done
# The vendor partition says which device it was built for.
mkdir -p "$WORK/v"
debugfs -R "dump /build.prop $(dq "$WORK/v/build.prop")" "$WORK/vendor.img" 2>/dev/null
[[ -s "$WORK/v/build.prop" ]] || die "vendor.img has no build.prop"
[[ -s "$WORK/v/build.prop" ]] || die "build.prop can't be read from vendor.img"
dev=$(sed -n 's/^ro.product.vendor.device=//p' "$WORK/v/build.prop" | head -1)
[[ "$dev" == "$DEVICE" || -n "$FORCE" ]] ||
die "vendor partition is for '${dev:-unknown}', not $DEVICE; use -f to override"
Expand Down