run_fuchsia_tests.sh 4.12 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#!/usr/bin/env bash
# Copyright 2014 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# This script has been adapted from:
# https://github.com/flutter/engine/blob/master/testing/fuchsia/run_tests.sh
# Any modifications made to this file might be applicable there as well.

# This expects the device to be in zedboot mode, with a zedboot that is
# is compatible with the Fuchsia system image provided.
#
# The first and only parameter should be the path to the Fuchsia system image
# tarball, e.g. `./run_fuchsia_tests.sh generic-x64.tgz`.
#
16
# This script expects `pm`, `device-finder`, and `fuchsia_ctl` to all be in the
17
# same directory as the script.
18 19 20
#
# This script also expects a private key available at:
# "/etc/botanist/keys/id_rsa_infra".
21

22 23 24
set -Eex

script_dir=$(dirname "$(readlink -f "$0")")
25

26 27 28
# Bot key to pave and ssh the device.
pkey="/etc/botanist/keys/id_rsa_infra"

29 30 31 32
# This is longer than the test timeout as dumping the
# logs can sometimes take longer.
ssh_timeout_seconds=360

33 34 35 36 37 38 39 40 41 42 43
# The nodes are named blah-blah--four-word-fuchsia-id
device_name=${SWARMING_BOT_ID#*--}

if [ -z "$device_name" ]
then
  echo "No device found. Aborting."
  exit 1
else
  echo "Connecting to device $device_name"
fi

44 45 46 47 48 49
# Wrapper function to pass common args to fuchsia_ctl.
fuchsia_ctl() {
  $script_dir/fuchsia_ctl -d $device_name \
      --device-finder-path $script_dir/device-finder "$@"
}

50
reboot() {
51 52
  echo "$(date) START:DEVICE_LOGS ------------------------------------------"
  fuchsia_ctl ssh \
53
      --timeout-seconds $ssh_timeout_seconds \
54 55
      --identity-file $pkey \
      -c "log_listener --dump_logs yes --file /tmp/log.txt"
56 57 58 59
  # As we are not using recipes we don't have a way to know the location
  # to upload the log to isolated. We are saving the log to a file to avoid dart
  # hanging when running the process and then just using printing the content to
  # the console.
60
  fuchsia_ctl ssh \
61
       --timeout-seconds $ssh_timeout_seconds \
62 63 64
       --identity-file $pkey \
       -c "cat /tmp/log.txt"
  echo "$(date) END:DEVICE_LOGS ------------------------------------------"
65
  echo "$(date) START:REBOOT ------------------------------------------"
66
  # note: this will set an exit code of 255, which we can ignore.
67 68
  fuchsia_ctl ssh \
      --identity-file $pkey \
69
      -c "dm reboot-recovery" || true
70
  echo "$(date) END:REBOOT --------------------------------------------"
71 72 73 74
}

trap reboot EXIT

75 76
echo "$(date) START:PAVING ------------------------------------------"
ssh-keygen -y -f $pkey > key.pub
77
fuchsia_ctl pave -i $1 --public-key "key.pub"
78 79
echo "$(date) END:PAVING --------------------------------------------"

80 81 82 83 84 85 86
echo "$(date) START:WAIT_DEVICE_READY -------------------------------"
for i in {1..10}; do
  fuchsia_ctl ssh \
      --identity-file $pkey \
      -c "echo up" && break || sleep 15;
done
echo "$(date) END:WAIT_DEVICE_READY ---------------------------------"
87

88
echo "$(date) START:PUSH_PACKAGES -------------------------------"
89
fuchsia_ctl push-packages \
90 91 92 93
    --identity-file $pkey \
    --repoArchive generic-x64.tar.gz \
    -p tiles -p tiles_ctl
echo "$(date) END:PUSH_PACKAGES ---------------------------------"
94 95 96 97 98 99 100 101 102 103 104 105

# set fuchsia ssh config
cat > $script_dir/fuchsia_ssh_config << EOF
Host *
  CheckHostIP no
  StrictHostKeyChecking no
  ForwardAgent no
  ForwardX11 no
  GSSAPIDelegateCredentials no
  UserKnownHostsFile /dev/null
  User fuchsia
  IdentitiesOnly yes
106
  IdentityFile $pkey
107 108 109 110 111 112 113 114 115 116 117 118
  ControlPersist yes
  ControlMaster auto
  ControlPath /tmp/fuchsia--%r@%h:%p
  ConnectTimeout 10
  ServerAliveInterval 1
  ServerAliveCountMax 10
  LogLevel ERROR
EOF

export FUCHSIA_SSH_CONFIG=$script_dir/fuchsia_ssh_config

# Run the driver test
119
echo "$(date) START:DRIVER_TEST -------------------------------------"
120 121 122 123 124 125 126
flutter_dir=$script_dir/flutter
flutter_bin=$flutter_dir/bin/flutter

# remove all out dated .packages references
find $flutter_dir -name ".packages" | xargs rm
cd $flutter_dir/dev/benchmarks/test_apps/stocks/
$flutter_bin pub get
127
$flutter_bin drive -v -d $device_name --target=test_driver/stock_view.dart
128
echo "$(date) END:DRIVER_TEST ---------------------------------------"