Add a new utility for running the bvt: `cros_run_bvt`

This provides a simple command line interface for using `test_that` to
run the BVT.  The intent is to spare developers from some of the
command-line complexity of selecting the best set of suites for running
tests.

BUG=None
TEST=run the script

Change-Id: Ia3cc7056e20baf180291c8830d4bfc82d757eeab
Reviewed-on: https://chromium-review.googlesource.com/209989
Tested-by: Richard Barnette <jrbarnette@chromium.org>
Reviewed-by: Fang Deng <fdeng@chromium.org>
Reviewed-by: Bernie Thompson <bhthompson@chromium.org>
Commit-Queue: Richard Barnette <jrbarnette@chromium.org>
diff --git a/Makefile b/Makefile
index 6229995..73c541f 100644
--- a/Makefile
+++ b/Makefile
@@ -13,6 +13,7 @@
 	mkdir -p "${DESTDIR}/usr/share/crostestutils"
 	install -m 0644 lib/constants.py "${DESTDIR}/usr/lib/crostestutils"
 	install -m 0755 cros_run_unit_tests "${DESTDIR}/usr/bin"
+	install -m 0755 cros_run_bvt "${DESTDIR}/usr/bin"
 	install -m 0755 run_remote_tests.sh ${DESTDIR}/usr/bin
 	install -m 0755 test_that ${DESTDIR}/usr/bin
 	install -m 0755 bootperf-wrapper ${DESTDIR}/usr/bin/bootperf
diff --git a/cros_run_bvt b/cros_run_bvt
new file mode 100755
index 0000000..6ea39a2
--- /dev/null
+++ b/cros_run_bvt
@@ -0,0 +1,99 @@
+#!/bin/bash
+# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# This script requires that you run build_packages first.
+
+# Special because this can only run inside the chroot.
+if [ ! -r /usr/lib/crosutils/common.sh ]; then
+  echo "Must run within chroot" >&2
+  exit 1
+fi
+. /usr/lib/crosutils/common.sh
+
+
+# Flags
+DEFINE_string board "${DEFAULT_BOARD}" \
+  "Target board of DUT running the tests"
+DEFINE_boolean smoke "${FLAGS_FALSE}" \
+  "Run a minimal set of tests for sanity"
+DEFINE_boolean commit "${FLAGS_FALSE}" \
+  "Run the tests required to pass the Commit Queue"
+DEFINE_boolean canary "${FLAGS_FALSE}" \
+  "Run all tests required for canary builds to pass"
+DEFINE_boolean labqual "${FLAGS_FALSE}" \
+  "Run the BVT tests required for lab qualification"
+DEFINE_boolean debug "${FLAGS_FALSE}" \
+  "Debug and test support for this script"
+
+# These options only matter if we're using Servo, which only
+# happens when --labqual is specified.
+DEFINE_boolean usbkey "${FLAGS_TRUE}" \
+  "When running servo tests, assume a USB storage key is plugged in"
+DEFINE_string servo_host "" \
+  "When running servo tests, specifies the host running servod"
+DEFINE_string servo_port "" \
+  "When running servo tests, specifies the port for contacting servod"
+
+# Parse command line; die on errors
+FLAGS_HELP="usage: $(basename $0) [flags] <hostname-or-ipaddr>"
+FLAGS "${@}" || exit 1
+eval set -- "${FLAGS_ARGV}"
+set -e
+
+if [ -z "${FLAGS_board}" ]; then
+  die "--board required"
+fi
+
+if [ $# -ne 1 ]; then
+  die "Must specify exactly one DUT"
+fi
+
+DUT="$1"
+OPTIONS=( --board="${FLAGS_board}" )
+TESTS=( suite:bvt suite:qav )
+
+SUITE_CHECK=0
+if [ ${FLAGS_smoke} -eq ${FLAGS_TRUE} ]; then
+  SUITE_CHECK=$(( SUITE_CHECK + 1 ))
+  TESTS=( suite:smoke )
+fi
+if [ ${FLAGS_commit} -eq ${FLAGS_TRUE} ]; then
+  SUITE_CHECK=$(( SUITE_CHECK + 1 ))
+  TESTS=( suite:bvt_cq )
+fi
+if [ ${FLAGS_canary} -eq ${FLAGS_TRUE} ]; then
+  SUITE_CHECK=$(( SUITE_CHECK + 1 ))
+  # Use the default tests.
+fi
+if [ ${FLAGS_labqual} -eq ${FLAGS_TRUE} ]; then
+  SUITE_CHECK=$(( SUITE_CHECK + 1 ))
+  TESTS=( suite:bvt )
+  if [ ${FLAGS_usbkey} -eq ${FLAGS_TRUE} ]; then
+    TESTS+=( platform_ServoPowerStateController_USBPluggedin )
+  else
+    TESTS+=( platform_ServoPowerStateController_USBUnplugged )
+  fi
+
+  # Handle Servo options for the lab qualification tests.
+  if [ -n "${FLAGS_servo_host}" ]; then
+    SERVO_ARGS="--args=servo_host=${FLAGS_servo_host}"
+    if [ -n "${FLAGS_servo_port}" ]; then
+      SERVO_ARGS="${SERVO_ARGS} servo_port=${FLAGS_servo_port}"
+    fi
+    OPTIONS+=( "${SERVO_ARGS}" )
+  elif [ -n "${FLAGS_servo_port}" ]; then
+    OPTIONS+=( "--args=servo_port=${FLAGS_servo_port}" )
+  fi
+fi
+
+if [ ${SUITE_CHECK} -gt 1 ]; then
+  die "can specify at most one of --smoke --commit --canary or --labqual"
+fi
+
+DEBUG=
+if [ ${FLAGS_debug} -eq ${FLAGS_TRUE} ]; then
+  DEBUG=echo
+fi
+$DEBUG test_that "${OPTIONS[@]}" "$DUT" "${TESTS[@]}"