test-shell.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/bin/sh
  2. #
  3. # Copyright (c) 2012 Google Inc.
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are
  8. # met:
  9. #
  10. # * Redistributions of source code must retain the above copyright
  11. # notice, this list of conditions and the following disclaimer.
  12. # * Redistributions in binary form must reproduce the above
  13. # copyright notice, this list of conditions and the following disclaimer
  14. # in the documentation and/or other materials provided with the
  15. # distribution.
  16. # * Neither the name of Google Inc. nor the names of its
  17. # contributors may be used to endorse or promote products derived from
  18. # this software without specific prior written permission.
  19. #
  20. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. # A special shell wrapper that can be used to run the Google Breakpad unit
  32. # tests on a connected Android device.
  33. #
  34. # This is designed to be called from the Makefile during 'make check'
  35. #
  36. PROGDIR=$(dirname "$0")
  37. PROGNAME=$(basename "$0")
  38. . $PROGDIR/common-functions.sh
  39. # Extract test program name first.
  40. TEST_PROGRAM=$1
  41. shift
  42. if [ -z "$TEST_PROGRAM" ]; then
  43. panic "No test program/script name on the command-line!"
  44. fi
  45. if [ ! -f "$TEST_PROGRAM" ]; then
  46. panic "Can't find test program/script: $TEST_PROGRAM"
  47. fi
  48. # Create test directory on the device
  49. TEST_DIR=/data/local/tmp/test-google-breakpad-$$
  50. adb_shell mkdir "$TEST_DIR" ||
  51. panic "Can't create test directory on device: $TEST_DIR"
  52. # Ensure that it is always removed when the script exits.
  53. clean_test_dir () {
  54. # Don't care about success/failure, use '$ADB shell' directly.
  55. adb_shell rm -r "$TEST_DIR"
  56. }
  57. atexit clean_test_dir
  58. TEST_PROGRAM_NAME=$(basename "$TEST_PROGRAM")
  59. TEST_PROGRAM_DIR=$(dirname "$TEST_PROGRAM")
  60. # Handle special case(s) here.
  61. DATA_FILES=
  62. case $TEST_PROGRAM_NAME in
  63. linux_client_unittest)
  64. # linux_client_unittest will call another executable at runtime, ensure
  65. # it is installed too.
  66. adb_install "$TEST_PROGRAM_DIR/linux_dumper_unittest_helper" "$TEST_DIR"
  67. # linux_client_unittest loads a shared library at runtime, ensure it is
  68. # installed too.
  69. adb_install "$TEST_PROGRAM_DIR/linux_client_unittest_shlib" "$TEST_DIR"
  70. ;;
  71. basic_source_line_resolver_unittest)
  72. DATA_FILES="module1.out \
  73. module2.out \
  74. module3_bad.out \
  75. module4_bad.out"
  76. ;;
  77. exploitability_unittest)
  78. DATA_FILES="scii_read_av.dmp \
  79. ascii_read_av_block_write.dmp \
  80. ascii_read_av_clobber_write.dmp \
  81. ascii_read_av_conditional.dmp \
  82. ascii_read_av_non_null.dmp \
  83. ascii_read_av_then_jmp.dmp \
  84. ascii_read_av_xchg_write.dmp \
  85. ascii_write_av.dmp \
  86. ascii_write_av_arg_to_call.dmp \
  87. exec_av_on_stack.dmp \
  88. null_read_av.dmp \
  89. null_write_av.dmp \
  90. read_av.dmp \
  91. null_read_av.dmp \
  92. write_av_non_null.dmp"
  93. ;;
  94. fast_source_line_resolver_unittest)
  95. DATA_FILES="module0.out \
  96. module1.out \
  97. module2.out \
  98. module3_bad.out \
  99. module4_bad.out"
  100. ;;
  101. minidump_processor_unittest|minidump_unittest)
  102. DATA_FILES="src/processor/testdata/minidump2.dmp"
  103. ;;
  104. esac
  105. # Install the data files, their path is relative to the environment
  106. # variable 'srcdir'
  107. for FILE in $DATA_FILES; do
  108. FILEDIR=src/processor/testdata/$(dirname "$FILE")
  109. adb_shell mkdir -p "$TEST_DIR/$FILEDIR"
  110. adb_install "${srcdir:-.}/$FILE" "$TEST_DIR"/"$FILE"
  111. done
  112. # Copy test program to device
  113. adb_install "$TEST_PROGRAM" "$TEST_DIR"
  114. # Run it
  115. adb_shell "cd $TEST_DIR && LD_LIBRARY_PATH=. ./$TEST_PROGRAM_NAME $@"
  116. # Note: exiting here will call cleanup_exit which will remove the temporary
  117. # files from the device.