blob: d64bb69b2a018fe2e0bdd2fe60d4ea9c110062a6 [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.
#### CATEGORY=Test
#### DEPRECATED
### build a test package and run on target.
## usage: fx run-test PKG_TARGET [runtests flags]
##
## This command is being deprecated in favor of `fx test`. Read more at:
## https://fuchsia.dev/fuchsia-src/development/testing/running_tests_as_components#converting_from_run-test_or_run-host-tests
##
## 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:
## fxbug.dev/22526: 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
fx-warn "This command is being deprecated in favor of \`fx test\`.\n Usage: fx test <TEST_NAME>\n For more information, visit: https://fuchsia.dev/fuchsia-src/development/testing/run_fuchsia_tests\n"
local test_specs="$(fx-command-run test --exact --info "${target}")"
if [[ -z "${test_specs}" ]]; then
fx-error "Cannot find an exact match in test specs for \"${target}\". " \
"Try using \`fx test ${target}\` if you need partial matches."
exit 3
fi
# concatenate all package_urls found in a comma-separated list
local package_urls=( $(sed -n 's/^package_url: \(.*\)/\1/p' <<< "${test_specs}") )
if [[ ${#package_urls[@]} -eq 0 ]]; then
fx-error "Test spec for \"${target}\" doesn't have a Fuchsia component URI. " \
"Try running it using \`fx test ${target}\` instead."
exit 3
fi
check-for-package-server || return 1
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
if ! fx-command-run update-if-in-base "${target}"; then
return 2
fi
echo >&2 "Updating ${target} cache on device"
if ! fx-command-run push-package "${target}"; then
return 2
fi
fx-command-run shell runtests "${package_urls[@]}" "$@" 2>&1 \
| fx-command-run symbolize
}
main "$@"