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
4 changes: 2 additions & 2 deletions bin/omamobile
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ cmd_fastboot() {
die "fastboot refuses BOOT_METHOD=qcom-abl (panic path uncharacterized on this ABL; use the buttons — see device/$DEVICE/BRINGUP-M1.md)"
in_fastboot && { say "Already in fastboot"; return 0; }
for i in $(seq 1 12); do
if adb get-state 2>/dev/null | grep -q device; then
if adb get-state 2>/dev/null | grep -c device >/dev/null; then
say "Stock Android: adb reboot bootloader"
adb reboot bootloader
elif "$ssh" true 2>/dev/null; then
Expand All @@ -1138,7 +1138,7 @@ cmd_fastboot() {
local t
for t in $(seq 1 40); do
in_fastboot && { say "In fastboot"; return 0; }
adb get-state 2>/dev/null | grep -q device && break
adb get-state 2>/dev/null | grep -c device >/dev/null && break
"$ssh" true 2>/dev/null && break
sleep 2
done
Expand Down
2 changes: 1 addition & 1 deletion packages/omamobile-device-husky/test/all
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ grep -q '^ConditionPathExists=/sys/bus/platform/devices/154b0000.aoc$' vendor/sy
[[ $(readlink "$tmp/root/usr/lib/systemd/system/multi-user.target.wants/omamobile-husky-aoc.service") == ../omamobile-husky-aoc.service ]] \
|| fail "the AoC unit is enabled by a vendor wants link"
! grep -qE '^install ' vendor/modprobe.d/omamobile-husky-aoc.conf || fail "the AoC file only blacklists"
! grep -hv '^ *#' bin/omamobile-husky-aoc-start vendor/modprobe.d/omamobile-husky-aoc.conf | grep -q 'speaker_protection' \
! grep -hv '^ *#' bin/omamobile-husky-aoc-start vendor/modprobe.d/omamobile-husky-aoc.conf | grep -c 'speaker_protection' >/dev/null \
|| fail "the AoC start never raises the speaker ceiling"
for m in gsa aoc_core aoc_alsa_dev snd_soc_cs35l41_spi gs201_aoc_boot; do
grep -qx "blacklist $m" vendor/modprobe.d/omamobile-husky-aoc.conf || fail "$m is kept from autoloading"
Expand Down
2 changes: 1 addition & 1 deletion packages/omamobile-waydroid/test/all
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ if CONFIG_FILE=$t/config LXC_CONF=$t/old-binder.conf RENDER_RDEV=226:128 lib/oma
fail "check passes with a binder major instead of the binder path"
fi
# The render node: its major and minor must be the ones the conf allows
CONFIG_FILE=$t/config LXC_CONF=lib/lxc-omamobile.conf RENDER_RDEV=226:128 lib/omamobile-waydroid-check | grep -q '^ok render node 226:128 is allowed' \
CONFIG_FILE=$t/config LXC_CONF=lib/lxc-omamobile.conf RENDER_RDEV=226:128 lib/omamobile-waydroid-check | grep -c '^ok render node 226:128 is allowed' >/dev/null \
|| fail "check does not report the render node"
if CONFIG_FILE=$t/config LXC_CONF=lib/lxc-omamobile.conf RENDER_RDEV=226:129 lib/omamobile-waydroid-check > "$t/binder.log"; then
fail "check passes when the render node is not the allowed one"
Expand Down
2 changes: 1 addition & 1 deletion rootfs/build-inside
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ echo omamobile > "$T/etc/hostname"
say "Removing per-machine state"
# No account but root, and root locked: the user comes from firstboot.conf
grep -q '^alarm:' "$T/etc/passwd" && die "an alarm account in the image"
awk -F: '$3 >= 1000 && $3 != 65534 {print $1}' "$T/etc/passwd" | grep -q . && die "a user account in the image"
awk -F: '$3 >= 1000 && $3 != 65534 {print $1}' "$T/etc/passwd" | grep -c . >/dev/null && die "a user account in the image"
sed -i 's/^root:[^:]*:/root:!*:/' "$T/etc/shadow"
rm -rf "$T/etc/pacman.d/gnupg" # firstboot makes the phone's own keyring
rm -f "$T"/etc/ssh/ssh_host_* # sshd makes the phone's own host keys
Expand Down
2 changes: 1 addition & 1 deletion tests/all
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# against a stand-in phone tree,
# tools/phone-install-package against a stand-in phone, the initramfs's
# first-boot growth, the bring-up overlays, the simplefb trigger, the init's per-board steps, the storage guard's packed
# allowlist and the USB product string, no test script piping into grep -q,
# allowlist and the USB product string, no pipefail script piping into grep -q,
# bin/omamobile's boot-image layouts
# (and omamobile-boot-update building the same bytes on the phone)
# and flash against a fake fastboot, omamobile-firstboot's own tests, and the
Expand Down
31 changes: 19 additions & 12 deletions tests/grep-q-pipes
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#!/bin/bash
# SPDX-License-Identifier: MIT
# No test script that sets pipefail pipes into grep -q (AGENTS.md section 4,
# Userspace): grep -q exits at the first match, the writer can get SIGPIPE,
# and pipefail then fails the pipeline, so a check fails at random, or an
# "&& fail" check passes. Use grep -c ... >/dev/null, which reads all its
# input. packages/omamobile-modem/test/nv-overlay is left out until the fix
# for #457 lands.
# No test script, and no laptop-side script in bin/, tools/ or rootfs/, that
# sets pipefail pipes into grep -q (AGENTS.md section 4, Userspace): grep -q
# exits at the first match, the writer can get SIGPIPE, and pipefail then
# fails the pipeline, so a check fails at random, or an "&& fail" check
# passes. Use grep -c ... >/dev/null, which reads all its input. Comment lines
# don't count. Left out: packages/omamobile-modem/test/nv-overlay until the
# fix for #457 lands; and acpm-stage, aoc-stage, fingerprint-capture,
# husky-deadman and wifi-w1-capture in tools/, whose remaining hits are
# command strings run on the phone through tools/phone-ssh, in the phone's
# shell without pipefail. tools/lib's files are sourced by pipefail scripts,
# so they count too.
set -euo pipefail
cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.."
fail() { printf 'not ok - %s\n' "$1" >&2; exit 1; }
Expand All @@ -19,11 +24,13 @@ for good in 'x | grep -c y >/dev/null' 'x || grep -q y f' 'grep -q y <<<"$x"'; d
grep -cE "$pattern" <<<"$good" >/dev/null && fail "the pattern leaves '$good' alone"
done

mapfile -t scripts < <(git grep -l 'set -[a-z]*o pipefail' -- tests 'packages/*/test' \
':(exclude)tests/grep-q-pipes' ':(exclude)packages/omamobile-modem/test/nv-overlay')
[[ ${#scripts[@]} -gt 0 ]] || fail "found the pipefail test scripts"
if hits=$(git grep -nE "$pattern" -- "${scripts[@]}"); then
mapfile -t scripts < <({ git grep -l 'set -[a-z]*o pipefail' -- tests 'packages/*/test/*' bin tools rootfs \
':(exclude)tests/grep-q-pipes' ':(exclude)packages/omamobile-modem/test/nv-overlay' \
':(exclude)tools/'{acpm-stage,aoc-stage,fingerprint-capture,husky-deadman,wifi-w1-capture}
git ls-files tools/lib; } | sort -u)
[[ ${#scripts[@]} -gt 0 ]] || fail "found the pipefail scripts"
if hits=$(git grep -nE "$pattern" -- "${scripts[@]}" | grep -vE '^[^:]+:[0-9]+:[[:space:]]*#'); then
printf '%s\n' "$hits" >&2
fail "no test script under pipefail pipes into grep -q (use grep -c ... >/dev/null)"
fail "no script under pipefail pipes into grep -q (use grep -c ... >/dev/null)"
fi
pass "no pipe into grep -q in ${#scripts[@]} pipefail test scripts"
pass "no pipe into grep -q in ${#scripts[@]} pipefail scripts"
4 changes: 2 additions & 2 deletions tools/extract-fingerprint-vendor
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ fetch_images() {
fi
m=$(zip_member "$src" "android-info\.txt")
if [[ -n "$m" && -z "$FORCE" ]]; then
unzip -p "$src" "$m" | grep -qE "^require board=(.*\|)?$DEVICE(\|.*)?\$" ||
unzip -p "$src" "$m" | grep -cE "^require board=(.*\|)?$DEVICE(\|.*)?\$" >/dev/null ||
die "this image is not for $DEVICE (android-info.txt); use -f to override"
fi
for part in vendor system; do
Expand Down Expand Up @@ -339,7 +339,7 @@ done < <(find "$root" -type l)

# Sanity checks: the TA is a signed Trusty app; the HAL is the Goodix one.
ta=g7.app; [[ $DEVICE == tegu ]] && ta=g7a.app
head -c 64 "$root/vendor/firmware/$ta" | grep -aq TrustyApp ||
head -c 64 "$root/vendor/firmware/$ta" | grep -ac TrustyApp >/dev/null ||
die "$ta does not look like a Trusty application package"
grep -aq 'g7_trusty' "$root/vendor/bin/hw/android.hardware.biometrics.fingerprint-service.goodix" ||
die "the fingerprint HAL is not the Goodix G7 one"
Expand Down
2 changes: 1 addition & 1 deletion tools/extract-vendor-chroot
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ fetch_images() {
fi
m=$(zip_member "$src" "android-info\.txt")
if [[ -n "$m" && -z "$FORCE" ]]; then
unzip -p "$src" "$m" | grep -qE "^require board=(.*\|)?$DEVICE(\|.*)?\$" ||
unzip -p "$src" "$m" | grep -cE "^require board=(.*\|)?$DEVICE(\|.*)?\$" >/dev/null ||
die "this image is not for $DEVICE (android-info.txt); use -f to override"
fi
for part in vendor system; do
Expand Down
2 changes: 1 addition & 1 deletion tools/extract-vendor-firmware
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ fetch_vendor() {
fi
m=$(zip_member "$src" "android-info\.txt")
if [[ -n "$m" && -z "$FORCE" ]]; then
unzip -p "$src" "$m" | grep -qE "^require board=(.*\|)?$DEVICE(\|.*)?\$" ||
unzip -p "$src" "$m" | grep -cE "^require board=(.*\|)?$DEVICE(\|.*)?\$" >/dev/null ||
die "this image is not for $DEVICE (android-info.txt); use -f to override"
fi
m=$(zip_member "$src" "vendor\.img")
Expand Down
2 changes: 1 addition & 1 deletion tools/fingerprint-capture
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ since_start() { sed -n "/fingerprint-capture: start $step/,\$p" "$log"; }
result=
while (( $(date +%s) - start < wait_s )); do
sleep 1
if since_start | grep -Eq "$done_re"; then result=done; break; fi
if since_start | grep -Ec "$done_re" >/dev/null; then result=done; break; fi
done
wait "$step_pid" 2>/dev/null
sleep 2
Expand Down
4 changes: 2 additions & 2 deletions tools/lib/signing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ signing_key_load() {
echo "error: keys/fingerprint.release does not hold a 40-digit fingerprint" >&2
return 1
fi
if ! cut -d: -f1 "$keyring/omamobile-trusted" 2>/dev/null | grep -qx "$fpr"; then
if ! cut -d: -f1 "$keyring/omamobile-trusted" 2>/dev/null | grep -cx "$fpr" >/dev/null; then
echo "error: omamobile-keyring does not trust $fpr (keys/fingerprint.release): phones would refuse what it signs" >&2
return 1
fi
if cut -d: -f1 "$keyring/omamobile-revoked" 2>/dev/null | grep -qx "$fpr"; then
if cut -d: -f1 "$keyring/omamobile-revoked" 2>/dev/null | grep -cx "$fpr" >/dev/null; then
echo "error: $fpr (keys/fingerprint.release) is revoked in omamobile-keyring" >&2
return 1
fi
Expand Down