test-shell.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #!/bin/sh
  2. #
  3. # Copyright 2012 Google LLC
  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 LLC 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. # A special shell wrapper that can be used to run the Google Breakpad unit
  31. # tests on a connected Android device.
  32. #
  33. # This is designed to be called from the Makefile during 'make check'
  34. #
  35. PROGDIR=$(dirname "$0")
  36. PROGNAME=$(basename "$0")
  37. . $PROGDIR/common-functions.sh
  38. # Extract test program name first.
  39. TEST_PROGRAM=$1
  40. shift
  41. if [ -z "$TEST_PROGRAM" ]; then
  42. panic "No test program/script name on the command-line!"
  43. fi
  44. if [ ! -f "$TEST_PROGRAM" ]; then
  45. panic "Can't find test program/script: $TEST_PROGRAM"
  46. fi
  47. # Create test directory on the device
  48. TEST_DIR=/data/local/tmp/test-google-breakpad-$$
  49. adb_shell mkdir "$TEST_DIR" ||
  50. panic "Can't create test directory on device: $TEST_DIR"
  51. # Ensure that it is always removed when the script exits.
  52. clean_test_dir () {
  53. # Don't care about success/failure, use '$ADB shell' directly.
  54. adb_shell rm -r "$TEST_DIR"
  55. }
  56. atexit clean_test_dir
  57. TEST_PROGRAM_NAME=$(basename "$TEST_PROGRAM")
  58. TEST_PROGRAM_DIR=$(dirname "$TEST_PROGRAM")
  59. # Handle special case(s) here.
  60. DATA_FILES=
  61. case $TEST_PROGRAM_NAME in
  62. linux_client_unittest)
  63. # linux_client_unittest will call another executable at runtime, ensure
  64. # it is installed too.
  65. adb_install "$TEST_PROGRAM_DIR/linux_dumper_unittest_helper" "$TEST_DIR"
  66. # linux_client_unittest loads a shared library at runtime, ensure it is
  67. # installed too.
  68. adb_install "$TEST_PROGRAM_DIR/linux_client_unittest_shlib" "$TEST_DIR"
  69. ;;
  70. basic_source_line_resolver_unittest)
  71. DATA_FILES="module1.out \
  72. module2.out \
  73. module3_bad.out \
  74. module4_bad.out"
  75. ;;
  76. exploitability_unittest)
  77. DATA_FILES="scii_read_av.dmp \
  78. ascii_read_av_block_write.dmp \
  79. ascii_read_av_clobber_write.dmp \
  80. ascii_read_av_conditional.dmp \
  81. ascii_read_av_non_null.dmp \
  82. ascii_read_av_then_jmp.dmp \
  83. ascii_read_av_xchg_write.dmp \
  84. ascii_write_av.dmp \
  85. ascii_write_av_arg_to_call.dmp \
  86. exec_av_on_stack.dmp \
  87. null_read_av.dmp \
  88. null_write_av.dmp \
  89. read_av.dmp \
  90. null_read_av.dmp \
  91. write_av_non_null.dmp"
  92. ;;
  93. fast_source_line_resolver_unittest)
  94. DATA_FILES="module0.out \
  95. module1.out \
  96. module2.out \
  97. module3_bad.out \
  98. module4_bad.out"
  99. ;;
  100. minidump_processor_unittest|minidump_unittest)
  101. DATA_FILES="src/processor/testdata/minidump2.dmp"
  102. ;;
  103. esac
  104. # Install the data files, their path is relative to the environment
  105. # variable 'srcdir'
  106. for FILE in $DATA_FILES; do
  107. FILEDIR=src/processor/testdata/$(dirname "$FILE")
  108. adb_shell mkdir -p "$TEST_DIR/$FILEDIR"
  109. adb_install "${srcdir:-.}/$FILE" "$TEST_DIR"/"$FILE"
  110. done
  111. # Copy test program to device
  112. adb_install "$TEST_PROGRAM" "$TEST_DIR"
  113. # Run it
  114. adb_shell "cd $TEST_DIR && LD_LIBRARY_PATH=. ./$TEST_PROGRAM_NAME $@"
  115. # Note: exiting here will call cleanup_exit which will remove the temporary
  116. # files from the device.