blob: ef4d4c10fd8f658306e43bccb14ac80fff82352f [file] [log] [blame]
#!/bin/bash
# Copyright 2019 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
### Entry point for all Fuchsia tests (host, target and end-to-end)
## Usage: fx test [testName ...]
##
## This is an incomplete list of options. Run 'fx test --help' for the complete set of options.
## Options:
## -h, --help
## --test-filter Runs specific test cases in v2 suite. Can be specified multiple
## times to pass in multiple patterns.
## example: --test-filter glob1 --test-filter glob2
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/dart_utils.sh || exit $?
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/host_symbolizer.sh || exit $?
fx-config-read
# Device discovery and building missing symbolizer are slow operations that
# don't need to happen when the user requests specific operations, like help and
# info, or runs tests that only affect the host.
# In future, we should consider moving these within fx test, which can better determine
# whether or not the target device is affected by reading tests.json.
info_only=false
has_e2e=false
host_tests_only=false
for arg in "$@"; do
if [[ "$arg" == "--help" || "$arg" == "-h" || "$arg" == "--info" || "$arg" == "--dry" ]]; then
info_only=true
elif [[ "$arg" == "--e2e" || "$arg" == "--only-e2e" ]]; then
has_e2e=true
elif [[ "$arg" == "--host" ]]; then
host_tests_only=true
fi
if [[ "$arg" == "--" ]]; then
break
fi
done
if $info_only || ( ! $has_e2e && $host_tests_only ); then
# skip slow operations when not necessary.
:
else
# force build of required symbolizer host tools if they don't exist:
fx-command-run host-tool --print symbolizer > /dev/null
fx-command-run host-tool --print symbol-index > /dev/null
# initialize some variables required for E2E tests:
export FUCHSIA_DEVICE_ADDR="$(get-fuchsia-device-addr)"
if [[ "$FUCHSIA_DEVICE_ADDR" == "::1" && -z "$SL4F_HTTP_PORT" ]]; then
# Device addr is localhost, assume that means that ports were forwarded with
# fx serve-remote from a remote workstation/laptop with a device attached.
export SL4F_HTTP_PORT=9080
fi
port="$(get-device-ssh-port)"
if [[ -n "${port}" ]]; then
export FUCHSIA_SSH_PORT="${port}"
fi
FUCHSIA_SSH_KEY="$(get-ssh-privkey)" || exit $?
export FUCHSIA_SSH_KEY
export FUCHSIA_TEST_OUTDIR="${FUCHSIA_OUT_DIR}/test_out/$(date +'%F-%H:%M:%S')"
fi
args=()
# TODO(fxbug.dev/53267): Using tput colors is more reliable than letting Dart do its
# own terminal detection. Remove once Dart can do its own detection more
# robustly.
if [[ ! -t 1 ]] || ! tput colors >/dev/null 2>&1; then
args+=("--simple")
fi
run-dart-tool fxtest "${args[@]}" "$@"