maybe_threads_unittest.sh 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/sh
  2. # Copyright (c) 2007, Google Inc.
  3. # All rights reserved.
  4. #
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions are
  7. # met:
  8. #
  9. # * Redistributions of source code must retain the above copyright
  10. # notice, this list of conditions and the following disclaimer.
  11. # * Redistributions in binary form must reproduce the above
  12. # copyright notice, this list of conditions and the following disclaimer
  13. # in the documentation and/or other materials provided with the
  14. # distribution.
  15. # * Neither the name of Google Inc. nor the names of its
  16. # contributors may be used to endorse or promote products derived from
  17. # this software without specific prior written permission.
  18. #
  19. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. # ---
  31. # Author: Craig Silverstein
  32. #
  33. # maybe_threads.cc was written to allow LD_PRELOAD=libtcmalloc.so to
  34. # work even on binaries that were not linked with pthreads. This
  35. # unittest tests that, by running low_level_alloc_unittest with an
  36. # LD_PRELOAD. (low_level_alloc_unittest was chosen because it doesn't
  37. # link in tcmalloc.)
  38. #
  39. # We assume all the .so files are in the same directory as both
  40. # addressmap_unittest and profiler1_unittest. The reason we need
  41. # profiler1_unittest is because it's instrumented to show the directory
  42. # it's "really" in when run without any args. In practice this will either
  43. # be BINDIR, or, when using libtool, BINDIR/.lib.
  44. # We expect BINDIR to be set in the environment.
  45. # If not, we set them to some reasonable values.
  46. BINDIR="${BINDIR:-.}"
  47. if [ "x$1" = "x-h" -o "x$1" = "x--help" ]; then
  48. echo "USAGE: $0 [unittest dir]"
  49. echo " By default, unittest_dir=$BINDIR"
  50. exit 1
  51. fi
  52. UNITTEST_DIR=${1:-$BINDIR}
  53. # Figure out the "real" unittest directory. Also holds the .so files.
  54. UNITTEST_DIR=`$UNITTEST_DIR/low_level_alloc_unittest --help 2>&1 \
  55. | awk '{print $2; exit;}' \
  56. | xargs dirname`
  57. # Figure out where libtcmalloc lives. It should be in UNITTEST_DIR,
  58. # but with libtool it might be in a subdir.
  59. if [ -r "$UNITTEST_DIR/libtcmalloc_minimal.so" ]; then
  60. LIB_PATH="$UNITTEST_DIR/libtcmalloc_minimal.so"
  61. elif [ -r "$UNITTEST_DIR/.libs/libtcmalloc_minimal.so" ]; then
  62. LIB_PATH="$UNITTEST_DIR/.libs/libtcmalloc_minimal.so"
  63. elif [ -r "$UNITTEST_DIR/libtcmalloc_minimal.dylib" ]; then # for os x
  64. LIB_PATH="$UNITTEST_DIR/libtcmalloc_minimal.dylib"
  65. elif [ -r "$UNITTEST_DIR/.libs/libtcmalloc_minimal.dylib" ]; then
  66. LIB_PATH="$UNITTEST_DIR/.libs/libtcmalloc_minimal.dylib"
  67. else
  68. echo "Cannot run $0: cannot find libtcmalloc_minimal.so"
  69. exit 2
  70. fi
  71. LD_PRELOAD="$LIB_PATH" $UNITTEST_DIR/low_level_alloc_unittest