PageRenderTime 28ms CodeModel.GetById 14ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 1ms

/core/externals/update-engine/externals/google-toolbox-for-mac/UnitTesting/RunIPhoneUnitTest.sh

http://macfuse.googlecode.com/
Shell | 207 lines | 91 code | 30 blank | 86 comment | 17 complexity | fbe61762ba8d72dc13bc3e8104bc15f6 MD5 | raw file
  1#!/bin/bash
  2#  RunIPhoneUnitTest.sh
  3#  Copyright 2008 Google Inc.
  4#
  5#  Licensed under the Apache License, Version 2.0 (the "License"); you may not
  6#  use this file except in compliance with the License.  You may obtain a copy
  7#  of the License at
  8#
  9#  http://www.apache.org/licenses/LICENSE-2.0
 10#
 11#  Unless required by applicable law or agreed to in writing, software
 12#  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 13#  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 14#  License for the specific language governing permissions and limitations under
 15#  the License.
 16#
 17#  Runs all unittests through the iPhone simulator. We don't handle running them
 18#  on the device. To run on the device just choose "run".
 19
 20set -o errexit
 21set -o nounset
 22# Uncomment the next line to trace execution.
 23#set -o verbose
 24
 25#  Controlling environment variables:
 26# GTM_DISABLE_ZOMBIES -
 27#   Set to a non-zero value to turn on zombie checks. You will probably
 28#   want to turn this off if you enable leaks.
 29GTM_DISABLE_ZOMBIES=${GTM_DISABLE_ZOMBIES:=1}
 30
 31# GTM_ENABLE_LEAKS -
 32#   Set to a non-zero value to turn on the leaks check. You will probably want
 33#   to disable zombies, otherwise you will get a lot of false positives.
 34
 35# GTM_DISABLE_TERMINATION
 36#   Set to a non-zero value so that the app doesn't terminate when it's finished
 37#   running tests. This is useful when using it with external tools such
 38#   as Instruments.
 39
 40# GTM_LEAKS_SYMBOLS_TO_IGNORE
 41#   List of comma separated symbols that leaks should ignore. Mainly to control
 42#   leaks in frameworks you don't have control over.
 43#   Search this file for GTM_LEAKS_SYMBOLS_TO_IGNORE to see examples.
 44#   Please feel free to add other symbols as you find them but make sure to
 45#   reference Radars or other bug systems so we can track them.
 46
 47# GTM_REMOVE_GCOV_DATA
 48#   Before starting the test, remove any *.gcda files for the current run so
 49#   you won't get errors when the source file has changed and the data can't
 50#   be merged.
 51#
 52GTM_REMOVE_GCOV_DATA=${GTM_REMOVE_GCOV_DATA:=0}
 53
 54# GTM_DISABLE_USERDIR_SETUP
 55#   Controls whether or not CFFIXED_USER_HOME is erased and set up from scratch
 56#   for you each time the script is run. In some cases you may have a wrapper
 57#   script calling this one that takes care of that for us so you can set up
 58#   a certain user configuration.
 59GTM_DISABLE_USERDIR_SETUP=${GTM_DISABLE_USERDIR_SETUP:=0}
 60
 61# GTM_DISABLE_IPHONE_LAUNCH_DAEMONS
 62#   Controls whether or not we launch up the iPhone Launch Daemons before
 63#   we start testing. You need Launch Daemons to test anything that interacts
 64#   with security. Note that it is OFF by default. Set
 65#   GTM_DISABLE_IPHONE_LAUNCH_DAEMONS=0 before calling this script
 66#   to turn it on.
 67GTM_DISABLE_IPHONE_LAUNCH_DAEMONS=${GTM_DISABLE_IPHONE_LAUNCH_DAEMONS:=1}
 68
 69# GTM_TEST_AFTER_BUILD
 70#   When set to 1, tests are run only when TEST_AFTER_BUILD is set to "YES".
 71#   This can be used to have tests run as an after build step when running
 72#   from the command line, but not when running from within XCode.
 73GTM_USE_TEST_AFTER_BUILD=${GTM_USE_TEST_AFTER_BUILD:=0}
 74
 75ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")
 76ScriptName=$(basename "$0")
 77ThisScript="${ScriptDir}/${ScriptName}"
 78XCODE_VERSION_MINOR=${XCODE_VERSION_MINOR:=0000}
 79
 80GTMXcodeNote() {
 81    echo "${ThisScript}:${1}: note: GTM ${2}"
 82}
 83
 84GTMXcodeError() {
 85    echo "${ThisScript}:${1}: error: GTM ${2}"
 86}
 87
 88# Creates a file containing the plist for the securityd daemon and prints the
 89# filename to stdout.
 90GTMCreateLaunchDaemonPlist() {
 91  local plist_file
 92  plist_file="$TMPDIR/securityd.$$.plist"
 93  echo $plist_file
 94
 95  # Create the plist file with PlistBuddy.
 96  /usr/libexec/PlistBuddy \
 97    -c "Add :Label string RunIPhoneLaunchDaemons" \
 98    -c "Add :ProgramArguments array" \
 99        -c "Add :ProgramArguments: string \"$IPHONE_SIMULATOR_ROOT/usr/libexec/securityd\"" \
100    -c "Add :EnvironmentVariables dict" \
101        -c "Add :EnvironmentVariables:DYLD_ROOT_PATH string \"$IPHONE_SIMULATOR_ROOT\"" \
102        -c "Add :EnvironmentVariables:IPHONE_SIMULATOR_ROOT string \"$IPHONE_SIMULATOR_ROOT\"" \
103        -c "Add :EnvironmentVariables:CFFIXED_USER_HOME string \"$CFFIXED_USER_HOME\"" \
104    -c "Add :MachServices dict" \
105        -c "Add :MachServices:com.apple.securityd bool YES" "$plist_file" > /dev/null
106}
107
108if [[ "$GTM_USE_TEST_AFTER_BUILD" == 1 && "$TEST_AFTER_BUILD" == "NO" ]]; then
109  GTMXcodeNote ${LINENO} "Skipping running of unittests since TEST_AFTER_BUILD=NO."
110elif [ "$PLATFORM_NAME" == "iphonesimulator" ]; then
111  # Xcode 4.5 changed how simulator app can be run. The way this script has
112  # been working results in them now just logging a message and calling exit(0)
113  # from Apple code. Report the error that the tests aren't going to work.
114  if [[ "${XCODE_VERSION_MINOR}" -ge "0450" ]]; then
115    GTMXcodeError ${LINENO} \
116      "Unit testing process not supported on Xcode >= 4.5 (${XCODE_VERSION_MINOR}). Use RuniOSUnitTestsUnderSimulator.sh."
117    exit 1
118  fi
119
120  # We kill the iPhone simulator because otherwise we run into issues where
121  # the unittests fail becuase the simulator is currently running, and
122  # at this time the iPhone SDK won't allow two simulators running at the same
123  # time.
124  set +e
125  /usr/bin/killall "iPhone Simulator"
126  set -e
127
128  if [ $GTM_REMOVE_GCOV_DATA -ne 0 ]; then
129    if [ "${OBJECT_FILE_DIR}-${CURRENT_VARIANT}" != "-" ]; then
130      if [ -d "${OBJECT_FILE_DIR}-${CURRENT_VARIANT}" ]; then
131        GTMXcodeNote ${LINENO} "Removing any .gcda files"
132        (cd "${OBJECT_FILE_DIR}-${CURRENT_VARIANT}" && \
133            find . -type f -name "*.gcda" -print0 | xargs -0 rm -f )
134      fi
135    fi
136  fi
137
138  export DYLD_ROOT_PATH="$SDKROOT"
139  export DYLD_FRAMEWORK_PATH="$CONFIGURATION_BUILD_DIR"
140  export IPHONE_SIMULATOR_ROOT="$SDKROOT"
141  export CFFIXED_USER_HOME="$TEMP_FILES_DIR/iPhone Simulator User Dir"
142
143  # See http://developer.apple.com/technotes/tn2004/tn2124.html for an
144  # explanation of these environment variables.
145
146  # NOTE: any setup work is done before turning on the environment variables
147  # to avoid having the setup work also get checked by what the variables
148  # enabled.
149
150  if [ $GTM_DISABLE_USERDIR_SETUP -eq 0 ]; then
151    # Cleanup user home directory
152    if [ -d "$CFFIXED_USER_HOME" ]; then
153      rm -rf "$CFFIXED_USER_HOME"
154    fi
155    mkdir "$CFFIXED_USER_HOME"
156    mkdir "$CFFIXED_USER_HOME/Documents"
157    mkdir -p "$CFFIXED_USER_HOME/Library/Caches"
158  fi
159
160  if [ $GTM_DISABLE_IPHONE_LAUNCH_DAEMONS -eq 0 ]; then
161    # Remove any instance of RunIPhoneLaunchDaemons left running in the case the
162    # 'trap' below fails. We first must check for RunIPhoneLaunchDaemons'
163    # presence as 'launchctl remove' will kill this script if run from within an
164    # Xcode build.
165    launchctl list | grep RunIPhoneLaunchDaemons && launchctl remove RunIPhoneLaunchDaemons
166
167    # If we want to test anything that interacts with the keychain, we need
168    # securityd up and running.
169    LAUNCH_DAEMON_PLIST="$(GTMCreateLaunchDaemonPlist)"
170    launchctl load $LAUNCH_DAEMON_PLIST
171    rm $LAUNCH_DAEMON_PLIST
172
173    # No matter how we exit, we want to shut down our launchctl job.
174    trap "launchctl remove RunIPhoneLaunchDaemons" INT TERM EXIT
175  fi
176
177  if [ $GTM_DISABLE_ZOMBIES -eq 0 ]; then
178    GTMXcodeNote ${LINENO} "Enabling zombies"
179    export CFZombieLevel=3
180    export NSZombieEnabled=YES
181  fi
182
183  export MallocScribble=YES
184  export MallocPreScribble=YES
185  export MallocGuardEdges=YES
186  export MallocStackLogging=YES
187  export NSAutoreleaseFreedObjectCheckEnabled=YES
188
189  # Turn on the mostly undocumented OBJC_DEBUG stuff.
190  export OBJC_DEBUG_FRAGILE_SUPERCLASSES=YES
191  export OBJC_DEBUG_UNLOAD=YES
192  # Turned off due to the amount of false positives from NS classes.
193  # export OBJC_DEBUG_FINALIZERS=YES
194  export OBJC_DEBUG_NIL_SYNC=YES
195  export OBJC_PRINT_REPLACED_METHODS=YES
196
197  # 6251475 iPhone simulator leaks @ CFHTTPCookieStore shutdown if
198  #         CFFIXED_USER_HOME empty
199  GTM_LEAKS_SYMBOLS_TO_IGNORE="CFHTTPCookieStore"
200
201  # Start our app.
202  "$TARGET_BUILD_DIR/$EXECUTABLE_PATH" -RegisterForSystemEvents
203
204else
205  GTMXcodeNote ${LINENO} "Skipping running of unittests for device build."
206fi
207exit 0