[run-test] delegate all arguments to runtests
This approach prevents argument escaping / corruption problems by largely
avoiding parsing any extra arguments. This also enables access to more
runtests arguments, such as those associated with asan and so on.
Change-Id: I7662ac43a45013d054f8965252fa6f5c4cd8f0fa
diff --git a/devshell/run-test b/devshell/run-test
index 4f1649c..ea5c198 100755
--- a/devshell/run-test
+++ b/devshell/run-test
@@ -6,90 +6,58 @@
### build a test package and run on target.
### PKG_TARGET is fully qualified or under fuchsia-pkg://fuchsia.com/
-## usage: fx run-test [-t|--test <test_name>] PKG_TARGET -- [-args -to -test]
+## usage: fx run-test PKG_TARGET [runtests flags]
## Builds the specified test package (e.g., appmgr_integration_tests), copies it to the
## target, and executes it.
##
## If using this command, please run 'fx build' again before paving your device
## because 'fx build updates' used by this script does not build images so it
## can leave paver in weird state.
+##
## Arguments:
-## -t|--test Test to run. If not specified, it will run all tests in PKG_TARGET.
-## Only pass this flag when your test is a component.
+## All arguments are passed directly to `runtests`, see `fx run-test -h` for all flags.
set -e
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $?
fx-config-read
-function usage {
- fx-command-help run-test
-}
-
-
function main {
- all_args="$@"
- test_args="${all_args#* -- }"
-
- fx-standard-switches "$@"
- set -- "${FX_ARGV[@]}"
-
- test=""
- target=""
-
- while (($#)); do
- case $1 in
- -t|--test)
- shift # name
- if [[ -z "$1" ]]; then
- echo "Missing parameter: <test_name>" >&2
- usage
- exit 1
- fi
- test="$1"
- ;;
- --)
- break
- ;;
- *)
- if [[ "$target" == "" ]]; then
- target="$1"
- else
- usage
- exit 1
- fi
- ;;
- esac
- shift # value
- done
-
- if [[ $target == "" ]]; then
- usage
- return 1
+ 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
+ ;;
+ -*)
+ echo >&2 "error: first given argument \"$1\" looks like a flag, a package name must be supplied before all flags."
+ exit 1
+ ;;
+ *)
+ target="$1"
+ shift
+ esac
+
if [[ -z "$(pgrep -f "amber-files/repository")" ]]; then
echo "WARNING: It looks like amber-srv is not running."
echo "WARNING: You probably need to start \"fx serve-updates\""
exit 1
fi
- echo -e "Building ${target}"
+ echo -e "Building ..."
# build all packages as there is no way to only build one and push it to
# update repository.
fx-command-run build updates
echo -e "\nPush package to device"
fx-command-run push-package "${target}"
- if [[ "${test}" == "" ]]; then
- echo -e "\nRun all tests in ${target}"
- fx-command-run shell runtests "pkgfs/packages/${target}/0/test" -- "$test_args"
- else
- url="fuchsia-pkg://fuchsia.com/${target}#meta/${test}.cmx"
- echo -e "\nRunning ${url}"
- fx-command-run shell run_test_component "${url}" "$test_args"
- fi
+ fx-command-run shell runtests "pkgfs/packages/${target}/0/test" "$@"
}
-
main "$@"