diff --git a/fs_mgr/tests/adb-remount-test.sh b/fs_mgr/tests/adb-remount-test.sh index 5827b1d3e..ed55768f2 100755 --- a/fs_mgr/tests/adb-remount-test.sh +++ b/fs_mgr/tests/adb-remount-test.sh @@ -219,13 +219,31 @@ format_duration() { echo ${hours}:`expr ${minutes} / 10``expr ${minutes} % 10`:`expr ${seconds} / 10``expr ${seconds} % 10` } +[ "USAGE: USB_DEVICE=\`usb_devnum [--next]\` + +USB_DEVICE contains cache. Update if system changes. + +Returns: the devnum for the USB_SERIAL device" ] +usb_devnum() { + if [ -n "${USB_SERIAL}" ]; then + local usb_device=`cat ${USB_SERIAL%/serial}/devnum 2>/dev/null | tr -d ' \t\r\n'` + if [ -n "${usb_device}" ]; then + USB_DEVICE=dev${usb_device} + elif [ -n "${USB_DEVICE}" -a "${1}" ]; then + USB_DEVICE=dev`expr ${USB_DEVICE#dev} + 1` + fi + echo "${USB_DEVICE}" + fi +} + [ "USAGE: adb_wait [timeout] Returns: waits until the device has returned for adb or optional timeout" ] adb_wait() { local ret if [ -n "${1}" ]; then - echo -n ". . . waiting `format_duration ${1}`" ${ANDROID_SERIAL} ${USB_ADDRESS} "${CR}" + USB_DEVICE=`usb_devnum --next` + echo -n ". . . waiting `format_duration ${1}`" ${ANDROID_SERIAL} ${USB_ADDRESS} ${USB_DEVICE} "${CR}" timeout --preserve-status --signal=KILL ${1} adb wait-for-device 2>/dev/null ret=${?} echo -n " ${CR}" @@ -233,6 +251,7 @@ adb_wait() { adb wait-for-device ret=${?} fi + USB_DEVICE=`usb_devnum` if [ 0 = ${ret} -a -n "${ACTIVE_SLOT}" ]; then local active_slot=`get_active_slot` if [ X"${ACTIVE_SLOT}" != X"${active_slot}" ]; then @@ -242,12 +261,15 @@ adb_wait() { return ${ret} } -[ "USAGE: usb_status > stdout +[ "USAGE: usb_status > stdout 2> stderr -If adb_wait failed, check if device is in adb, recovery or fastboot mode -and report status string. +Assumes referenced right after adb_wait or fastboot_wait failued. +If wait failed, check if device is in adb, recovery or fastboot mode +and report status strings like \"(USB stack borken?)\", +\"(In fastboot mode)\", \"(In recovery mode)\" or \"(in adb mode)\". +Additional diagnostics may be provided to the stderr output. -Returns: \"(USB stack borken?)\", \"(In fastboot mode)\" or \"(in adb mode)\"" ] +Returns: USB status string" ] usb_status() { if inFastboot; then echo "(In fastboot mode)" @@ -256,7 +278,20 @@ usb_status() { elif inAdb; then echo "(In adb mode)" else - echo "(USB stack borken?)" + echo "(USB stack borken for ${USB_ADDRESS})" + USB_DEVICE=`usb_devnum` + if [ -n "${USB_DEVICE}" ]; then + echo "# lsusb -v -s ${USB_DEVICE#dev}" + local D=`lsusb -v -s ${USB_DEVICE#dev} 2>&1` + if [ -n "${D}" ]; then + echo "${D}" + else + lsusb -v + fi + else + echo "# lsusb -v (expected device missing)" + lsusb -v + fi >&2 fi } @@ -268,7 +303,8 @@ fastboot_wait() { # fastboot has no wait-for-device, but it does an automatic # wait and requires (even a nonsensical) command to do so. if [ -n "${1}" ]; then - echo -n ". . . waiting `format_duration ${1}`" ${ANDROID_SERIAL} ${USB_ADDRESS} "${CR}" + USB_DEVICE=`usb_devnum --next` + echo -n ". . . waiting `format_duration ${1}`" ${ANDROID_SERIAL} ${USB_ADDRESS} ${USB_DEVICE} "${CR}" timeout --preserve-status --signal=KILL ${1} fastboot wait-for-device >/dev/null 2>/dev/null ret=${?} echo -n " ${CR}" @@ -278,6 +314,7 @@ fastboot_wait() { fi || inFastboot ret=${?} + USB_DEVICE=`usb_devnum` if [ 0 = ${ret} -a -n "${ACTIVE_SLOT}" ]; then local active_slot=`get_active_slot` if [ X"${ACTIVE_SLOT}" != X"${active_slot}" ]; then @@ -293,7 +330,8 @@ Returns: waits until the device has returned for recovery or optional timeout" ] recovery_wait() { local ret if [ -n "${1}" ]; then - echo -n ". . . waiting `format_duration ${1}`" ${ANDROID_SERIAL} ${USB_ADDRESS} "${CR}" + USB_DEVICE=`usb_devnum --next` + echo -n ". . . waiting `format_duration ${1}`" ${ANDROID_SERIAL} ${USB_ADDRESS} ${USB_DEVICE} "${CR}" timeout --preserve-status --signal=KILL ${1} adb wait-for-recovery 2>/dev/null ret=${?} echo -n " ${CR}" @@ -301,6 +339,7 @@ recovery_wait() { adb wait-for-recovery ret=${?} fi + USB_DEVICE=`usb_devnum` if [ 0 = ${ret} -a -n "${ACTIVE_SLOT}" ]; then local active_slot=`get_active_slot` if [ X"${ACTIVE_SLOT}" != X"${active_slot}" ]; then @@ -631,7 +670,8 @@ if [ -n "${USB_SERIAL}" ]; then USB_ADDRESS=usb${USB_ADDRESS##*/} fi [ -z "${ANDROID_SERIAL}${USB_ADDRESS}" ] || - echo "${BLUE}[ INFO ]${NORMAL}" ${ANDROID_SERIAL} ${USB_ADDRESS} >&2 + USB_DEVICE=`usb_devnum` + echo "${BLUE}[ INFO ]${NORMAL}" ${ANDROID_SERIAL} ${USB_ADDRESS} ${USB_DEVICE} >&2 BUILD_DESCRIPTION=`get_property ro.build.description` [ -z "${BUILD_DESCRIPTION}" ] || echo "${BLUE}[ INFO ]${NORMAL} ${BUILD_DESCRIPTION}" >&2 @@ -1206,7 +1246,7 @@ echo "${GREEN}[ OK ]${NORMAL} mount -o rw,remount command works" >&2 # Prerequisite is a prepped device from above. adb_reboot && adb_wait 2m || - die "lost device after reboot to ro state (USB stack broken?)" + die "lost device after reboot to ro state `usb_status`" adb_sh grep " /vendor .* rw," /proc/mounts >/dev/null /dev/null