From patchwork Wed Jul 26 00:18:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 9864047 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 39C92602B1 for ; Wed, 26 Jul 2017 00:19:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 18038286DC for ; Wed, 26 Jul 2017 00:19:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0CAE328726; Wed, 26 Jul 2017 00:19:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4CAA1286DC for ; Wed, 26 Jul 2017 00:19:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750964AbdGZATn (ORCPT ); Tue, 25 Jul 2017 20:19:43 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:33685 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750983AbdGZATm (ORCPT ); Tue, 25 Jul 2017 20:19:42 -0400 Received: by mail-pf0-f196.google.com with SMTP id k72so10659745pfj.0 for ; Tue, 25 Jul 2017 17:19:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=V2EmH0p2C/jiKxEgTDGVTpTse5z1zodfvlV34Y2azgo=; b=CuwvOHqgvi1oq2jKXMqqnpZH0bUOk/op/BKnzaEIbZpzp0MbVoPg3EuYfhzsOLiZa1 zLoqRDBSZkT68sPQhgCHyRsPXwOWgohGCb/8U3aNddGbA4HV0b56gUJ+j7kHB0Zy5qan nFq9rXR3yNRwdYvwBGt6ThCrEYxf/jsD0LNojsU7KI7H66CB7ntZSgrzkJN55OnUXD8k sEvi311YURIOb/UevTCzbOax9C7hqbR1UWWbLtGHQ8gCd+j4F/6jl0VIzoBRCVi4Te2E wMb59xm1byjZLcWrbzity0dIALkef2hR/rgiFL/y6CXImUWt5MdIhqNv70b+KwpulXGn H8WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=V2EmH0p2C/jiKxEgTDGVTpTse5z1zodfvlV34Y2azgo=; b=sPkt/d23I2tGO9lAKQgg0XWDmw2ByoWHxKBOLEYfWuul5F5hXu1zti0Rf8kZnjYcJV WsICTtM6AoG34GKw82ep10sy+NVkshEudQDtkc2e5w/w6jrxI7wiQ5Ravh57tafTM5Rb rCJNkNmZvv3l1T6UR0JojFJ7YnBErWtlQSY6INs397XkyvhD8xjQaTK5QNbMRldgiC58 EOrgTMQ4P/tB+0jNt44FhxGGDX/G7S9b8WkAQkmIu02gozTkaEoqvW80n/n4xgWV0NYR MYasdsV0wLWtR6v+rGeZ3mpwhusV+pvtzsrHVzSC1foB6YpjZinmCTwxATC9auFlRcU2 /Veg== X-Gm-Message-State: AIVw112Dx3Oxyg/7t5RbfbgjmayrfxSMsWjr8M0uYCjcn3gXVX3IeGkR 144nKOPFnkmv3vFlr1M= X-Received: by 10.99.119.12 with SMTP id s12mr20687450pgc.370.1501028381309; Tue, 25 Jul 2017 17:19:41 -0700 (PDT) Received: from ebiggers-linuxstation.kir.corp.google.com ([100.66.174.81]) by smtp.gmail.com with ESMTPSA id o8sm30726539pgn.52.2017.07.25.17.19.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 25 Jul 2017 17:19:40 -0700 (PDT) From: Eric Biggers To: Theodore Ts'o Cc: fstests@vger.kernel.org, Eric Biggers Subject: [PATCH 1/2] android-xfstests: support specifying a kernel to boot Date: Tue, 25 Jul 2017 17:18:37 -0700 Message-Id: <20170726001838.80452-1-ebiggers3@gmail.com> X-Mailer: git-send-email 2.14.0.rc0.400.g1c36432dff-goog Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Biggers Update android-xfstests to support specifying a kernel with KERNEL in ~/.config/android-xfstests or --kernel on the command line, similar to kvm-xfstests and gce-xfstests. If it's not already running, the kernel is booted using the 'fastboot boot' command. This unfortunately doesn't work on all devices, but it should still be useful to have. Signed-off-by: Eric Biggers --- kvm-xfstests/android-xfstests | 223 +++++++++++++++++++++++++++++++++++++----- kvm-xfstests/config.android | 5 + kvm-xfstests/util/parse_cli | 5 +- 3 files changed, 204 insertions(+), 29 deletions(-) diff --git a/kvm-xfstests/android-xfstests b/kvm-xfstests/android-xfstests index 6d41540..8e5b77c 100755 --- a/kvm-xfstests/android-xfstests +++ b/kvm-xfstests/android-xfstests @@ -50,27 +50,56 @@ die() ask_yesno() { local response - echo -n -e "$@ (y/n) " + echo -n -e "$@ (y/N) " read response if [ "$response" != y ]; then exit 1 fi } +adb_ready() +{ + adb devices | grep -q 'device$' +} + +fastboot_ready() +{ + fastboot devices | grep -q 'fastboot$' +} + wait_for_device() { + local want_adb=false + local want_fastboot=false + local waiting_for="" local unauthorized=false local waiting=false + + if [[ ,$1, == *,adb,* ]]; then + want_adb=true + waiting_for="adb to be ready" + fi + if [[ ,$1, == *,fastboot,* ]]; then + want_fastboot=true + waiting_for+="${waiting_for:+ or for }device to enter fastboot mode" + fi + : "${waiting_for:=device}" + while true; do - if adb devices | grep -q 'device$'; then - break + if $want_adb; then + if adb_ready; then + break + fi + if ! $unauthorized && adb devices | grep -q 'unauthorized$'; then + echo "adb is not authorized. Authorize it using the dialog on the device to continue." + unauthorized=true + fi fi - if adb devices | grep -q 'unauthorized$' && ! $unauthorized; then - echo "adb is not authorized. Authorize it using the dialog on the device to continue." - unauthorized=true + if $want_fastboot && fastboot_ready; then + return fi if ! $waiting && ! $unauthorized; then - echo "Waiting for device..." + echo "Waiting for $waiting_for..." waiting=true fi sleep 0.5 @@ -83,6 +112,115 @@ wait_for_device() adb shell "setenforce 0" } +wait_for_adb() +{ + wait_for_device adb +} + +wait_for_fastboot() +{ + wait_for_device fastboot +} + +wait_for_adb_or_fastboot() +{ + wait_for_device adb,fastboot +} + +reboot_into_fastboot_mode() +{ + adb reboot bootloader + wait_for_fastboot +} + +# Query the version of the kernel running on the device +query_kernel_version() +{ + adb shell "uname -r -v" +} + +# Try to extract the version information from the $KERNEL image by grepping for +# the linux_banner[] string. It's a hack, but there doesn't seem to be a better +# way, and scripts elsewhere supposedly have been doing this for a long time... +extract_kernel_version() +{ + local decompress + + # Note: we use the filename extension rather than the 'file' program to get + # the compression format because old versions of 'file' don't recognize + # LZ4-compressed files. + case "$(basename "$KERNEL")" in + Image.gz*) + decompress="gzip -d -c" + ;; + Image.bz2*) + decompress="bzip2 -d -c" + ;; + Image.xz*) + decompress="xz -d -c" + ;; + Image.lz4*) + decompress="lz4 -d" # no -c option; stdout is assumed when not a tty + ;; + *) + decompress="cat" + ;; + esac + local banner="$($decompress "$KERNEL" \ + | grep -a -m1 'Linux version [0-9]\+\.[0-9]\+.*#.*$')" + + if [ -n "$banner" ]; then + local krelease="$(echo "$banner" | awk '{print $3}')" + local kver="#${banner##*#}" + echo "$krelease $kver" + fi +} + +# If the specified $KERNEL isn't already running on the device, try to boot it +# using 'fastboot boot'. +boot_kernel() +{ + local version actual_version + local have_version=true + + if [ ! -f "$KERNEL" ]; then + die "The specified kernel image does not exist: $KERNEL" + fi + + version="$(extract_kernel_version "$KERNEL")" + if [ -z "$version" ]; then + cat 1>&2 < /dev/null ; then die "fastboot is not installed" fi -wait_for_device -setup_chroot -if ! xfstests_running; then - setup_partitions first_try -fi - case "$ARG" in cmd=shell*|cmd=maint*) - chroot_interactive_shell - exit 0 + want_shell=true + ;; + *) + want_shell=false + if adb_ready; then + stop_existing_tests + fi ;; esac -stop_existing_tests +# Set up the kernel, the chroot, and the xfstests partitions. + +tried_to_shrink_userdata=false +while true; do + + # Start by booting into the correct kernel. + if [ -n "$KERNEL" ]; then + boot_kernel + elif fastboot_ready; then + fastboot continue + fi + + wait_for_adb + + # Set up the chroot and xfstests partitions. Note: if an interactive shell + # is requested and tests are currently running, we won't mess around with + # the partitions. However, we'll still try to set up the chroot just in + # case a different ROOT_FS was specified (in which case the existing tests + # will need to be stopped). + setup_chroot + if $want_shell && xfstests_running; then + break + fi + if setup_partitions; then + break + fi + + # Need to shrink userdata to make space for the xfstests partitions! + if $tried_to_shrink_userdata; then + die "An unexpected problem occurred when shrinking userdata." + fi + try_shrink_userdata + tried_to_shrink_userdata=true + + # 'userdata' has just been formatted and the device is now in fastboot mode. + # Start the configuration over again. +done + +if $want_shell; then + chroot_interactive_shell + exit 0 +fi cat > "$tmpfile" <