Roll WebRTC 9745:9761, Libjingle 9742:9761
[chromium-blink-merge.git] / testing / gtest_ios / run-unittest.sh
blob15986309840bfb9f8a6b59fe73d40b53b676a4c1
1 #!/bin/bash -p
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 set -eu
9 # Environment sanitization. Set a known-safe PATH. Clear environment variables
10 # that might impact the interpreter's operation. The |bash -p| invocation
11 # on the #! line takes the bite out of BASH_ENV, ENV, and SHELLOPTS (among
12 # other features), but clearing them here ensures that they won't impact any
13 # shell scripts used as utility programs. SHELLOPTS is read-only and can't be
14 # unset, only unexported.
15 export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
16 unset BASH_ENV CDPATH ENV GLOBIGNORE IFS POSIXLY_CORRECT
17 export -n SHELLOPTS
19 readonly ScriptDir=$(dirname "$(echo ${0} | sed -e "s,^\([^/]\),$(pwd)/\1,")")
20 readonly ScriptName=$(basename "${0}")
21 readonly ThisScript="${ScriptDir}/${ScriptName}"
22 readonly SimExecutable="${BUILD_DIR}/ninja-iossim/${CONFIGURATION}/iossim"
24 # Helper to print a line formatted for Xcodes build output parser.
25 XcodeNote() {
26 echo "${ThisScript}:${1}: note: ${2}"
29 # Helper to print a divider to make things stick out in a busy output window.
30 XcodeHeader() {
31 echo "note: _________________________________________________________________"
32 echo "note: _________________________________________________________________"
33 echo "note: _________________________________________________________________"
34 XcodeNote "$1" ">>>>> $2"
35 echo "note: _________________________________________________________________"
36 echo "note: _________________________________________________________________"
37 echo "note: _________________________________________________________________"
40 # Kills the iPhone Simulator if it is running.
41 KillSimulator() {
42 /usr/bin/killall "iPhone Simulator" 2> /dev/null || true
45 # Runs tests via the iPhone Simulator for multiple devices.
46 RunTests() {
47 local -r appPath="${TARGET_BUILD_DIR}/${PRODUCT_NAME}.app"
49 if [[ ! -x "${SimExecutable}" ]]; then
50 echo "Unable to run tests: ${SimExecutable} was not found/executable."
51 exit 1
54 for device in 'iPhone' 'iPad'; do
55 iosVersion="6.1"
56 KillSimulator
57 local command=(
58 "${SimExecutable}" "-d${device}" "-s${iosVersion}" "${appPath}"
60 # Pass along any command line flags
61 if [[ "$#" -gt 0 ]]; then
62 command+=( "--" "${@}" )
64 XcodeHeader ${LINENO} "Launching tests for ${device} (iOS ${iosVersion})"
65 "${command[@]}"
67 # If the command didn't exit successfully, abort.
68 if [[ $? -ne 0 ]]; then
69 exit $?;
71 done
74 # Time to get to work.
76 if [[ "${PLATFORM_NAME}" != "iphonesimulator" ]]; then
77 XcodeNote ${LINENO} "Skipping running of unittests for device build."
78 else
79 if [[ "$#" -gt 0 ]]; then
80 RunTests "${@}"
81 else
82 RunTests
84 KillSimulator
87 exit 0