blob: 063178ab76bd4ab2bd2a9273146907eb24987f9d [file] [log] [blame]
Kaushik Iskaccbce982020-01-08 12:25:38 -08001#!/usr/bin/env bash
2# Copyright 2014 The Flutter Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6# This script has been adapted from:
7# https://github.com/flutter/engine/blob/master/testing/fuchsia/run_tests.sh
8# Any modifications made to this file might be applicable there as well.
9
10# This expects the device to be in zedboot mode, with a zedboot that is
11# is compatible with the Fuchsia system image provided.
12#
13# The first and only parameter should be the path to the Fuchsia system image
14# tarball, e.g. `./run_fuchsia_tests.sh generic-x64.tgz`.
15#
Andrew Davies52e0d982020-01-14 09:41:16 -080016# This script expects `pm`, `device-finder`, and `fuchsia_ctl` to all be in the
Kaushik Iskaccbce982020-01-08 12:25:38 -080017# same directory as the script.
godofredoc900c7c12020-04-22 16:48:01 -070018#
19# This script also expects a private key available at:
20# "/etc/botanist/keys/id_rsa_infra".
Kaushik Iskaccbce982020-01-08 12:25:38 -080021
Kaushik Iskaacabf9d2020-02-03 17:55:45 -080022set -Eex
23
24script_dir=$(dirname "$(readlink -f "$0")")
Kaushik Iskaccbce982020-01-08 12:25:38 -080025
godofredoc900c7c12020-04-22 16:48:01 -070026# Bot key to pave and ssh the device.
27pkey="/etc/botanist/keys/id_rsa_infra"
28
Casey Hillersf35a8b72020-08-26 21:33:03 -070029# This is longer than the test timeout as dumping the
30# logs can sometimes take longer.
31ssh_timeout_seconds=360
32
Kaushik Iskaccbce982020-01-08 12:25:38 -080033# The nodes are named blah-blah--four-word-fuchsia-id
34device_name=${SWARMING_BOT_ID#*--}
35
36if [ -z "$device_name" ]
37then
38 echo "No device found. Aborting."
39 exit 1
40else
41 echo "Connecting to device $device_name"
42fi
43
Casey Hillers4a33ce72020-08-28 10:53:04 -070044# Wrapper function to pass common args to fuchsia_ctl.
45fuchsia_ctl() {
46 $script_dir/fuchsia_ctl -d $device_name \
47 --device-finder-path $script_dir/device-finder "$@"
48}
49
Kaushik Iskaccbce982020-01-08 12:25:38 -080050reboot() {
Casey Hillers4a33ce72020-08-28 10:53:04 -070051 echo "$(date) START:DEVICE_LOGS ------------------------------------------"
52 fuchsia_ctl ssh \
Casey Hillersf35a8b72020-08-26 21:33:03 -070053 --timeout-seconds $ssh_timeout_seconds \
Casey Hillers4a33ce72020-08-28 10:53:04 -070054 --identity-file $pkey \
55 -c "log_listener --dump_logs yes --file /tmp/log.txt"
Casey Hillersf35a8b72020-08-26 21:33:03 -070056 # As we are not using recipes we don't have a way to know the location
57 # to upload the log to isolated. We are saving the log to a file to avoid dart
58 # hanging when running the process and then just using printing the content to
59 # the console.
Casey Hillers4a33ce72020-08-28 10:53:04 -070060 fuchsia_ctl ssh \
Casey Hillersf35a8b72020-08-26 21:33:03 -070061 --timeout-seconds $ssh_timeout_seconds \
Casey Hillers4a33ce72020-08-28 10:53:04 -070062 --identity-file $pkey \
63 -c "cat /tmp/log.txt"
64 echo "$(date) END:DEVICE_LOGS ------------------------------------------"
godofredoc900c7c12020-04-22 16:48:01 -070065 echo "$(date) START:REBOOT ------------------------------------------"
Casey Hillersf35a8b72020-08-26 21:33:03 -070066 # note: this will set an exit code of 255, which we can ignore.
Casey Hillers4a33ce72020-08-28 10:53:04 -070067 fuchsia_ctl ssh \
68 --identity-file $pkey \
Casey Hillersf35a8b72020-08-26 21:33:03 -070069 -c "dm reboot-recovery" || true
godofredoc900c7c12020-04-22 16:48:01 -070070 echo "$(date) END:REBOOT --------------------------------------------"
Kaushik Iskaccbce982020-01-08 12:25:38 -080071}
72
73trap reboot EXIT
74
godofredoc900c7c12020-04-22 16:48:01 -070075echo "$(date) START:PAVING ------------------------------------------"
76ssh-keygen -y -f $pkey > key.pub
Casey Hillers4a33ce72020-08-28 10:53:04 -070077fuchsia_ctl pave -i $1 --public-key "key.pub"
godofredoc900c7c12020-04-22 16:48:01 -070078echo "$(date) END:PAVING --------------------------------------------"
79
Casey Hillersef3440b2020-08-31 09:48:05 -070080echo "$(date) START:WAIT_DEVICE_READY -------------------------------"
81for i in {1..10}; do
82 fuchsia_ctl ssh \
83 --identity-file $pkey \
84 -c "echo up" && break || sleep 15;
85done
86echo "$(date) END:WAIT_DEVICE_READY ---------------------------------"
godofredoc900c7c12020-04-22 16:48:01 -070087
Casey Hillersf35a8b72020-08-26 21:33:03 -070088echo "$(date) START:PUSH_PACKAGES -------------------------------"
Casey Hillers4a33ce72020-08-28 10:53:04 -070089fuchsia_ctl push-packages \
Casey Hillersf35a8b72020-08-26 21:33:03 -070090 --identity-file $pkey \
91 --repoArchive generic-x64.tar.gz \
92 -p tiles -p tiles_ctl
93echo "$(date) END:PUSH_PACKAGES ---------------------------------"
Kaushik Iskaacabf9d2020-02-03 17:55:45 -080094
95# set fuchsia ssh config
Kaushik Iskaacabf9d2020-02-03 17:55:45 -080096cat > $script_dir/fuchsia_ssh_config << EOF
97Host *
98 CheckHostIP no
99 StrictHostKeyChecking no
100 ForwardAgent no
101 ForwardX11 no
102 GSSAPIDelegateCredentials no
103 UserKnownHostsFile /dev/null
104 User fuchsia
105 IdentitiesOnly yes
godofredoc900c7c12020-04-22 16:48:01 -0700106 IdentityFile $pkey
Kaushik Iskaacabf9d2020-02-03 17:55:45 -0800107 ControlPersist yes
108 ControlMaster auto
109 ControlPath /tmp/fuchsia--%r@%h:%p
110 ConnectTimeout 10
111 ServerAliveInterval 1
112 ServerAliveCountMax 10
113 LogLevel ERROR
114EOF
115
116export FUCHSIA_SSH_CONFIG=$script_dir/fuchsia_ssh_config
117
118# Run the driver test
godofredoc900c7c12020-04-22 16:48:01 -0700119echo "$(date) START:DRIVER_TEST -------------------------------------"
Kaushik Iskaacabf9d2020-02-03 17:55:45 -0800120flutter_dir=$script_dir/flutter
121flutter_bin=$flutter_dir/bin/flutter
122
123# remove all out dated .packages references
124find $flutter_dir -name ".packages" | xargs rm
Kaushik Iskaacabf9d2020-02-03 17:55:45 -0800125cd $flutter_dir/dev/benchmarks/test_apps/stocks/
Kaushik Iskaacabf9d2020-02-03 17:55:45 -0800126$flutter_bin pub get
Kaushik Iskab16fd132020-02-06 12:04:08 -0800127$flutter_bin drive -v -d $device_name --target=test_driver/stock_view.dart
godofredoc900c7c12020-04-22 16:48:01 -0700128echo "$(date) END:DRIVER_TEST ---------------------------------------"