blob: 9cb6d0b8456db46f44341663b1cd68b2b23e72ce [file] [log] [blame]
#!/bin/bash
# Copyright 2018 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 and run tests on host
##
## Usage: fx run-host-tests [-z] [host test names ...] [-- [test runner flags]]
## Builds and runs the given host tests.
## With "-z" passed, only Zircon tests will be run - and
## without it only tests from Garnet and above.
## If no host test names are provided, then all available
## host tests will be run.
## Test runner flags can typically be --gtest_filter=TestSuiteName.TestName
## to restrict to a particular test or set of tests.
##
set -o errexit
set -o pipefail
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $?
fx-config-read
ARGS=()
TEST_NAMES=()
function main {
while [[ -n "$1" ]]; do
case "$1" in
-v) ARGS+=("-v");;
-z) ZIRCON=1 ;;
# break at bare double dash
# allow passing args to runtests
--) shift
break
;;
*) TEST_NAMES+=("$1");;
esac
shift
done
if [[ $ZIRCON -eq 1 ]]; then
host_test_dir="${ZIRCON_BUILDROOT}/host_tests"
fx-command-run build-zircon "-v"
else
host_test_dir="${FUCHSIA_BUILD_DIR}/host_tests"
fx-command-run build :copy_host_tests
fi
runtests_cmd=("${ZIRCON_TOOLS_DIR}/runtests" "${ARGS[@]}")
if [[ -n "$TEST_NAMES" ]]; then
# Comma-separated list of host test names to filter by.
IFS="," runtests_cmd+=("-t" "${TEST_NAMES[*]}")
fi
# remaining arguments after -- are passed to test runner
"${runtests_cmd[@]}" "${host_test_dir}" -- "$@"
}
main "$@"