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

http://macfuse.googlecode.com/ · Shell · 273 lines · 156 code · 35 blank · 82 comment · 27 complexity · 66a59cc324f1c90733c259a19fd6e777 MD5 · raw file

  1. #!/bin/bash
  2. #
  3. # RunMacOSUnitTests.sh
  4. # Copyright 2008 Google Inc.
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License"); you may not
  7. # use this file except in compliance with the License. You may obtain a copy
  8. # of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  15. # License for the specific language governing permissions and limitations under
  16. # the License.
  17. #
  18. # Run the unit tests in this test bundle.
  19. # Set up some env variables to make things as likely to crash as possible.
  20. # See http://developer.apple.com/technotes/tn2004/tn2124.html for details.
  21. #
  22. set -o errexit
  23. set -o nounset
  24. # Uncomment the next line to trace execution.
  25. #set -o verbose
  26. # Controlling environment variables:
  27. #
  28. # GTM_DISABLE_ZOMBIES -
  29. # Set to a non-zero value to turn on zombie checks. You will probably
  30. # want to turn this off if you enable leaks.
  31. GTM_DISABLE_ZOMBIES=${GTM_DISABLE_ZOMBIES:=0}
  32. # GTM_ENABLE_LEAKS -
  33. # Set to a non-zero value to turn on the leaks check. You will probably want
  34. # to disable zombies, otherwise you will get a lot of false positives.
  35. GTM_ENABLE_LEAKS=${GTM_ENABLE_LEAKS:=0}
  36. # GTM_LEAKS_SYMBOLS_TO_IGNORE
  37. # List of comma separated symbols that leaks should ignore. Mainly to control
  38. # leaks in frameworks you don't have control over.
  39. # Search this file for GTM_LEAKS_SYMBOLS_TO_IGNORE to see examples.
  40. # Please feel free to add other symbols as you find them but make sure to
  41. # reference Radars or other bug systems so we can track them.
  42. GTM_LEAKS_SYMBOLS_TO_IGNORE=${GTM_LEAKS_SYMBOLS_TO_IGNORE:=""}
  43. # GTM_DO_NOT_REMOVE_GCOV_DATA
  44. # By default before starting the test, we remove any *.gcda files for the
  45. # current project build configuration so you won't get errors when a source
  46. # file has changed and the gcov data can't be merged.
  47. # We remove all the gcda files for the current configuration for the entire
  48. # project so that if you are building a test bundle to test another separate
  49. # bundle we make sure to clean up the files for the test bundle and the bundle
  50. # that you are testing.
  51. # If you DO NOT want this to occur, set GTM_DO_NOT_REMOVE_GCOV_DATA to a
  52. # non-zero value.
  53. GTM_DO_NOT_REMOVE_GCOV_DATA=${GTM_DO_NOT_REMOVE_GCOV_DATA:=0}
  54. # GTM_REMOVE_TARGET_GCOV_ONLY
  55. # By default all *.gcda files are removed form the project. Setting this to
  56. # 1 causes only the *.gcda files for the target to be removed.
  57. # If GTM_DO_NOT_REMOVE_GCOV_DATA is set, this has no effect.
  58. GTM_REMOVE_TARGET_GCOV_ONLY=${GTM_REMOVE_TARGET_GCOV_ONLY:=0}
  59. # GTM_ONE_TEST_AT_A_TIME
  60. # By default your tests run how ever parallel your projects/targets are
  61. # setup. Setting this to 1 will cause only one to run at a time, this is
  62. # useful if you are doing UI tests with the helper that controls the
  63. # colorsync profile, or any other machine wide state.
  64. GTM_ONE_TEST_AT_A_TIME=${GTM_ONE_TEST_AT_A_TIME:=0}
  65. ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")
  66. ScriptName=$(basename "$0")
  67. ThisScript="${ScriptDir}/${ScriptName}"
  68. GTMXcodeNote() {
  69. echo ${ThisScript}:${1}: note: GTM ${2}
  70. }
  71. # Helper that works like the linux flock util, so you can run something, but
  72. # have only one run at a time.
  73. MaybeFlock() {
  74. if [ $GTM_ONE_TEST_AT_A_TIME -ne 0 ]; then
  75. GTMXcodeNote ${LINENO} "Serializing test execution."
  76. python -c "import fcntl, subprocess, sys
  77. file = open('$TMPDIR/GTM_one_test_at_a_time', 'a')
  78. fcntl.flock(file.fileno(), fcntl.LOCK_EX)
  79. sys.exit(subprocess.call(sys.argv[1:]))" "${@}"
  80. else
  81. GTMXcodeNote ${LINENO} "Allowing parallel test execution."
  82. "${@}"
  83. fi
  84. }
  85. # The workaround below is due to
  86. # Radar 6248062 otest won't run with MallocHistory enabled under rosetta
  87. # Basically we go through and check what architecture we are running on
  88. # and which architectures we can support
  89. AppendToSymbolsLeaksShouldIgnore() {
  90. if [ "${GTM_LEAKS_SYMBOLS_TO_IGNORE}" = "" ]; then
  91. GTM_LEAKS_SYMBOLS_TO_IGNORE="${1}"
  92. else
  93. GTM_LEAKS_SYMBOLS_TO_IGNORE="${GTM_LEAKS_SYMBOLS_TO_IGNORE}, ${1}"
  94. fi
  95. }
  96. AppendToLeakTestArchs() {
  97. if [ "${LEAK_TEST_ARCHS}" = "" ]; then
  98. LEAK_TEST_ARCHS="${1}"
  99. else
  100. LEAK_TEST_ARCHS="${LEAK_TEST_ARCHS} ${1}"
  101. fi
  102. }
  103. AppendToNoLeakTestArchs() {
  104. if [ "${NO_LEAK_TEST_ARCHS}" = "" ]; then
  105. NO_LEAK_TEST_ARCHS="${1}"
  106. else
  107. NO_LEAK_TEST_ARCHS="${NO_LEAK_TEST_ARCHS} ${1}"
  108. fi
  109. }
  110. UpdateArchitecturesToTest() {
  111. case "${NATIVE_ARCH_ACTUAL}" in
  112. ppc)
  113. if [ "${1}" = "ppc" ]; then
  114. AppendToLeakTestArchs "${1}"
  115. fi
  116. ;;
  117. ppc64)
  118. if [ "${1}" = "ppc" -o "${1}" = "ppc64" ]; then
  119. AppendToLeakTestArchs "${1}"
  120. fi
  121. ;;
  122. i386)
  123. if [ "${1}" = "i386" ]; then
  124. AppendToLeakTestArchs "${1}"
  125. elif [ "${1}" = "ppc" ]; then
  126. AppendToNoLeakTestArchs "${1}"
  127. fi
  128. ;;
  129. x86_64)
  130. if [ "${1}" = "i386" -o "${1}" = "x86_64" ]; then
  131. AppendToLeakTestArchs "${1}"
  132. elif [ "${1}" = "ppc" -o "${1}" = "ppc64" ]; then
  133. AppendToNoLeakTestArchs "${1}"
  134. fi
  135. ;;
  136. *)
  137. echo "RunMacOSUnitTests.sh Unknown native architecture: ${NATIVE_ARCH_ACTUAL}"
  138. exit 1
  139. ;;
  140. esac
  141. }
  142. SetMemoryVariables() {
  143. # Jack up some memory stress so we can catch more bugs.
  144. # This is done via a helper so it can be invoked in two places at the
  145. # last possible moment to avoid the variables causing tracing from other
  146. # processes that are invoked along the way.
  147. if [ $GTM_DISABLE_ZOMBIES -eq 0 ]; then
  148. GTMXcodeNote ${LINENO} "Enabling zombies"
  149. # CFZombieLevel disabled because it doesn't play well with the
  150. # security framework
  151. # export CFZombieLevel=3
  152. export NSZombieEnabled=YES
  153. fi
  154. export MallocScribble=YES
  155. export MallocPreScribble=YES
  156. export MallocGuardEdges=YES
  157. export NSAutoreleaseFreedObjectCheckEnabled=YES
  158. # Turn on the mostly undocumented OBJC_DEBUG stuff.
  159. export OBJC_DEBUG_FRAGILE_SUPERCLASSES=YES
  160. export OBJC_DEBUG_UNLOAD=YES
  161. # Turned off due to the amount of false positives from NS classes.
  162. # export OBJC_DEBUG_FINALIZERS=YES
  163. export OBJC_DEBUG_NIL_SYNC=YES
  164. }
  165. RunTests() {
  166. if [ "${CURRENT_ARCH}" = "" ]; then
  167. CURRENT_ARCH=`arch`
  168. fi
  169. if [ "${ONLY_ACTIVE_ARCH}" = "YES" ]; then
  170. ARCHS="${CURRENT_ARCH}"
  171. fi
  172. if [ "${ARCHS}" = "" ]; then
  173. ARCHS=`arch`
  174. fi
  175. if [ "${VALID_ARCHS}" = "" ]; then
  176. VALID_ARCHS=`arch`
  177. fi
  178. if [ "${NATIVE_ARCH_ACTUAL}" = "" ]; then
  179. NATIVE_ARCH_ACTUAL=`arch`
  180. fi
  181. LEAK_TEST_ARCHS=""
  182. NO_LEAK_TEST_ARCHS=""
  183. for TEST_ARCH in ${ARCHS}; do
  184. for TEST_VALID_ARCH in ${VALID_ARCHS}; do
  185. if [ "${TEST_VALID_ARCH}" = "${TEST_ARCH}" ]; then
  186. UpdateArchitecturesToTest "${TEST_ARCH}"
  187. fi
  188. done
  189. done
  190. # These are symbols that leak on OS 10.5.5
  191. # radar 6247293 NSCollatorElement leaks in +initialize.
  192. AppendToSymbolsLeaksShouldIgnore "+[NSCollatorElement initialize]"
  193. # radar 6247911 The first call to udat_open leaks only on x86_64
  194. AppendToSymbolsLeaksShouldIgnore "icu::TimeZone::initDefault()"
  195. # radar 6263983 +[IMService allServices] leaks
  196. AppendToSymbolsLeaksShouldIgnore "-[IMServiceAgentImpl allServices]"
  197. # radar 6264034 +[IKSFEffectDescription initialize] Leaks
  198. AppendToSymbolsLeaksShouldIgnore "+[IKSFEffectDescription initialize]"
  199. # radar 7598715 Leak when creating new NSColor using lab color space.
  200. AppendToSymbolsLeaksShouldIgnore "CMSSetLabCLUT"
  201. # Running leaks on architectures that support leaks.
  202. export MallocStackLogging=YES
  203. export GTM_LEAKS_SYMBOLS_TO_IGNORE="${GTM_LEAKS_SYMBOLS_TO_IGNORE}"
  204. ARCHS="${LEAK_TEST_ARCHS}"
  205. VALID_ARCHS="${LEAK_TEST_ARCHS}"
  206. GTMXcodeNote ${LINENO} "Leak checking enabled for $ARCHS. Ignoring leaks from $GTM_LEAKS_SYMBOLS_TO_IGNORE."
  207. SetMemoryVariables
  208. MaybeFlock "${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests"
  209. # Running leaks on architectures that don't support leaks.
  210. unset MallocStackLogging
  211. unset GTM_ENABLE_LEAKS
  212. ARCHS="${NO_LEAK_TEST_ARCHS}"
  213. VALID_ARCHS="${NO_LEAK_TEST_ARCHS}"
  214. GTMXcodeNote ${LINENO} "Leak checking disabled for $ARCHS due to no support for leaks on platform".
  215. MaybeFlock "${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests"
  216. }
  217. if [ ! $GTM_DO_NOT_REMOVE_GCOV_DATA ]; then
  218. GTM_GCOV_CLEANUP_DIR="${CONFIGURATION_TEMP_DIR}"
  219. if [ $GTM_REMOVE_TARGET_GCOV_ONLY ]; then
  220. GTM_GCOV_CLEANUP_DIR="${OBJECT_FILE_DIR}-${CURRENT_VARIANT}"
  221. fi
  222. if [ "${GTM_GCOV_CLEANUP_DIR}" != "-" ]; then
  223. if [ -d "${GTM_GCOV_CLEANUP_DIR}" ]; then
  224. GTMXcodeNote ${LINENO} "Removing gcov data files from ${GTM_GCOV_CLEANUP_DIR}"
  225. (cd "${GTM_GCOV_CLEANUP_DIR}" && \
  226. find . -type f -name "*.gcda" -print0 | xargs -0 rm -f )
  227. fi
  228. fi
  229. fi
  230. # If leaks testing is enabled, we have to go through our convoluted path
  231. # to handle architectures that don't allow us to do leak testing.
  232. if [ $GTM_ENABLE_LEAKS -ne 0 ]; then
  233. RunTests
  234. else
  235. GTMXcodeNote ${LINENO} "Leak checking disabled."
  236. SetMemoryVariables
  237. MaybeFlock "${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests"
  238. fi