blob: 62ffe2d6b20e5a6619244a901337c82cb8696958 [file] [log] [blame]
#!/bin/bash
# Copyright 2017 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
### build a test package and run on target.
## usage: fx run-test PKG_TARGET [runtests flags]
##
## Builds the update package group, updates the device as necessary, and then
## executes the test as specified by [runtests flags] (or all tests in
## PKG_TARGET if no flags are given).
##
## Arguments:
## PKG_TARGET A package name as appears in `fx list-packages`
## All later arguments are passed directly to `runtests`, see `fx run-test -h` for all flags.
##
## Known Bugs:
## PKG-592: After run-test, performing a pave without executing 'fx build'
## results in "appmgr not started after 20s", as this command only builds new
## packages, it avoids creating new paver artifacts, as such, a pave without a
## fresh build produces a system with inconsistent state.
set -e
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $?
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/updates.sh || exit $?
fx-config-read
# Determine if the given package name ($1) is in the base package list
function is-in-base {
grep "^$1$" "${FUCHSIA_BUILD_DIR}/base_packages.list" > /dev/null
}
function main {
if [[ $# -lt 1 ]]; then
fx-command-help
exit 1
fi
case "$1" in
-h|--help)
fx-command-help
echo -e >&2 "\nRuntests help follows:"
fx-command-run shell runtests -h
exit 0
;;
-*)
fx-error "first given argument \"$1\" looks like a flag, a package name must be supplied before all flags."
exit 1
;;
*)
target="$1"
shift
esac
check-for-amber-server || return -1
if is-in-base "${target}"; then
fx-warn "As ${target} is in 'base'. An OTA will follow."
fi
echo >&2 "Building ..."
# build all packages as there is no way to only build one and push it to
# update repository.
fx-command-run build updates
# TODO: once incremental workflow lands, `fx-command-run update` should
# instead always execute.
if is-in-base "${target}"; then
echo >&2 "Package ${target} is in 'base', performing system update..."
fx-command-run update
echo >&2 "System update complete, waiting for device to return"
fx-command-run wait
else
echo >&2 "Updating ${target} cache on device"
fx-command-run push-package "${target}"
fi
# TODO: remove reliance on pkgfs/packages.
fx-command-run shell runtests "pkgfs/packages/${target}/0/test" "$@"
}
main "$@"