PageRenderTime 45ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

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