diff options
author | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-26 11:52:27 +0000 |
---|---|---|
committer | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-26 11:52:27 +0000 |
commit | 58cddec2e966620674519cb1d0cc56861687b380 (patch) | |
tree | 1020fadcf53e0e482c100fe2722705dd0be24827 /testing | |
parent | 0045b0f431a65956e1207fbab1999b97f44f7bb9 (diff) | |
download | chromium_src-58cddec2e966620674519cb1d0cc56861687b380.zip chromium_src-58cddec2e966620674519cb1d0cc56861687b380.tar.gz chromium_src-58cddec2e966620674519cb1d0cc56861687b380.tar.bz2 |
Add a helper script to run unit test targets for iOS
This allows easily running a unit test target on multiple simulator configurations.
BUG=None
TEST=None
Review URL: https://chromiumcodereview.appspot.com/10832030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148532 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'testing')
-rw-r--r-- | testing/gtest.gyp | 2 | ||||
-rwxr-xr-x | testing/gtest_ios/run-unittest.sh | 87 |
2 files changed, 88 insertions, 1 deletions
diff --git a/testing/gtest.gyp b/testing/gtest.gyp index de32937..5c5ae8a 100644 --- a/testing/gtest.gyp +++ b/testing/gtest.gyp @@ -154,7 +154,7 @@ # Use a variable so the path gets fixed up so it is always # correct when the action finally gets used. 'ios_run_unittest_script_path': - '<(DEPTH)/testing/gtest_ios/RunUnittest.sh', + '<(DEPTH)/testing/gtest_ios/run-unittest.sh', }, 'run_as': { 'action????': ['>(ios_run_unittest_script_path)'], diff --git a/testing/gtest_ios/run-unittest.sh b/testing/gtest_ios/run-unittest.sh new file mode 100755 index 0000000..b1d28fc --- /dev/null +++ b/testing/gtest_ios/run-unittest.sh @@ -0,0 +1,87 @@ +#!/bin/bash -p + +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +set -eu + +# Environment sanitization. Set a known-safe PATH. Clear environment variables +# that might impact the interpreter's operation. The |bash -p| invocation +# on the #! line takes the bite out of BASH_ENV, ENV, and SHELLOPTS (among +# other features), but clearing them here ensures that they won't impact any +# shell scripts used as utility programs. SHELLOPTS is read-only and can't be +# unset, only unexported. +export PATH="/usr/bin:/bin:/usr/sbin:/sbin" +unset BASH_ENV CDPATH ENV GLOBIGNORE IFS POSIXLY_CORRECT +export -n SHELLOPTS + +readonly ScriptDir=$(dirname "$(echo ${0} | sed -e "s,^\([^/]\),$(pwd)/\1,")") +readonly ScriptName=$(basename "${0}") +readonly ThisScript="${ScriptDir}/${ScriptName}" +readonly SimExecutable="${BUILD_DIR}/${CONFIGURATION}/iossim" + +# Helper to print a line formatted for Xcodes build output parser. +XcodeNote() { + echo "${ThisScript}:${1}: note: ${2}" +} + +# Helper to print a divider to make things stick out in a busy output window. +XcodeHeader() { + echo "note: _________________________________________________________________" + echo "note: _________________________________________________________________" + echo "note: _________________________________________________________________" + XcodeNote "$1" ">>>>> $2" + echo "note: _________________________________________________________________" + echo "note: _________________________________________________________________" + echo "note: _________________________________________________________________" +} + +# Kills the iPhone Simulator if it is running. +KillSimulator() { + /usr/bin/killall "iPhone Simulator" 2> /dev/null || true +} + +# Runs tests via the iPhone Simulator for multiple devices. +RunTests() { + local -r appPath="${TARGET_BUILD_DIR}/${PRODUCT_NAME}.app" + + if [[ ! -x "${SimExecutable}" ]]; then + echo "Unable to run tests: ${SimExecutable} was not found/executable." + exit 1 + fi + + for device in 'iPhone' 'iPad'; do + iosVersion="5.1" + KillSimulator + local command=( + "${SimExecutable}" "-d${device}" "-s${iosVersion}" "${appPath}" + ) + # Pass along any command line flags + if [[ "$#" -gt 0 ]]; then + command+=( "--" "${@}" ) + fi + XcodeHeader ${LINENO} "Launching tests for ${device} (iOS ${iosVersion})" + "${command[@]}" + + # If the command didn't exit successfully, abort. + if [[ $? -ne 0 ]]; then + exit $?; + fi + done +} + +# Time to get to work. + +if [[ "${PLATFORM_NAME}" != "iphonesimulator" ]]; then + XcodeNote ${LINENO} "Skipping running of unittests for device build." +else + if [[ "$#" -gt 0 ]]; then + RunTests "${@}" + else + RunTests + fi + KillSimulator +fi + +exit 0 |