You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

164 lines
6.1 KiB

  1. #!/bin/sh
  2. #
  3. # Copyright 2005-2013 Intel Corporation. All Rights Reserved.
  4. #
  5. # This file is part of Threading Building Blocks.
  6. #
  7. # Threading Building Blocks is free software; you can redistribute it
  8. # and/or modify it under the terms of the GNU General Public License
  9. # version 2 as published by the Free Software Foundation.
  10. #
  11. # Threading Building Blocks is distributed in the hope that it will be
  12. # useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  13. # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Threading Building Blocks; if not, write to the Free Software
  18. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. #
  20. # As a special exception, you may use this file as part of a free software
  21. # library without restriction. Specifically, if other files instantiate
  22. # templates or use macros or inline functions from this file, or you compile
  23. # this file and link it with other files to produce an executable, this
  24. # file does not by itself cause the resulting executable to be covered by
  25. # the GNU General Public License. This exception does not however
  26. # invalidate any other reasons why the executable file might be covered by
  27. # the GNU General Public License.
  28. # Usage:
  29. # android.linux.launcher.sh [-v] [-u] [-l <library>] <executable> <arg1> <arg2> <argN>
  30. # where: -l <library> specfies the library name to be assigned to LD_PRELOAD
  31. # where: -v enables verbose output when running the test (where supported)
  32. # where: -u is ignored on Android
  33. #
  34. # Libs and executable necessary for testing should be present in the current directory before running.
  35. # ANDROID_SERIAL must be set to the connected Android target device name for file transfer and test runs.
  36. # ANDROID_TEST_DIRECTORY may be set to the directory used for testing on the Android target device; otherwise,
  37. # the default directory used is "/data/local/tmp/$(basename $PWD)".
  38. # Note: Do not remove the redirections to '/dev/null' in the script, otherwise the nightly test system will fail.
  39. do_cleanup()
  40. {
  41. adb pull $targetdir/events.txt events.txt > /dev/null 2>&1
  42. # Remove target directory on the device
  43. adb shell "rm -r ${targetdir}; mkdir -p ${targetdir}" > /dev/null 2>&1
  44. }
  45. do_trap_cleanup()
  46. {
  47. do_cleanup
  48. exit -1
  49. }
  50. # Process the optional arguments if present
  51. if [ "x$1" = "x-v" ]; then {
  52. verb="$1"
  53. shift 1
  54. }; fi
  55. if [ "x$1" = "x-u" ]; then {
  56. shift 1
  57. }; fi
  58. if [ "x$1" = "x-l" ]; then {
  59. ldpreload="$2"
  60. shift 2
  61. }; fi
  62. # Collect the executable name
  63. exename=$(basename $1)
  64. shift
  65. # Prepare the target directory on the device
  66. currentdir=$(basename $PWD)
  67. targetdir=${ANDROID_TEST_DIRECTORY:-/data/local/tmp/$currentdir}
  68. do_cleanup
  69. trap do_trap_cleanup INT # if someone hits control-c, cleanup the device
  70. # Collect the list of files to transfer to the target device, starting with executable itself.
  71. fnamelist="$exename"
  72. # Add the C++ standard library from the NDK, which is required for all tests on Android.
  73. if [ ! -z "${LIB_GNU_STL_ANDROID}" ]; then
  74. fnamelist="$fnamelist ${LIB_GNU_STL_ANDROID}/libgnustl_shared.so"
  75. else
  76. fnamelist="$fnamelist libgnustl_shared.so"
  77. fi
  78. # Find the TBB libraries and add them to the list.
  79. # Add TBB libraries from the current directory that contains libtbb* files
  80. files="$(/bin/ls libtbb* 2> /dev/null)"
  81. if [ ! -z "$files" ]; then fnamelist="$fnamelist $files"; fi
  82. mallocfiles="$(/bin/ls libtbbmalloc* 2> /dev/null)"
  83. if [ ! -z "$mallocfiles" ]; then {
  84. #TODO: any better workaround instead calling echo
  85. #(without echo there is error: /system/bin/sh: libtbbmalloc_proxy.so: not found)
  86. ldpreload="$ldpreload $(echo $mallocfiles)"
  87. }; fi
  88. if [ ! -z "$ldpreload" ]; then ldpreload="export LD_PRELOAD=$ldpreload;"; fi
  89. # Add any libraries built for specific tests.
  90. exeroot=${exename%\.*}
  91. files="$(/bin/ls ${exeroot}*.so ${exeroot}*.so.* 2> /dev/null)"
  92. if [ ! -z "$files" ]; then {
  93. fnamelist="$fnamelist $files"
  94. }; fi
  95. # TODO: Add extra libraries from the Intel(R) Compiler for certain tests
  96. # found=$(echo $exename | egrep 'test_malloc_atexit\|test_malloc_lib_unload' 2> /dev/null)
  97. # if [ ! -z $found ] ; then
  98. # fnamelist="$fnamelist ${compiler_path_lib}/libimf.so \
  99. # ${compiler_path_lib}/libsvml.so \
  100. # ${compiler_path_lib}/libintlc.so.5"
  101. # fi
  102. # Transfer collected executable and library files to the target device.
  103. transfers_ok=1
  104. for fullname in $fnamelist; do {
  105. if [ -r $fullname ]; then {
  106. # Transfer the executable and libraries to top-level target directory
  107. adb push $fullname ${targetdir}/$(basename $fullname) > /dev/null 2>&1
  108. }; else {
  109. echo "Error: required file ${currentdir}/${fullname} for test $exename not available for transfer."
  110. transfers_ok=0
  111. }; fi
  112. }; done
  113. if [ "${transfers_ok}" = "0" ]; then {
  114. do_cleanup
  115. exit -1
  116. }; fi
  117. # Transfer input files used by example codes by scanning the executable argument list.
  118. for fullname in "$@"; do {
  119. if [ -r $fullname ]; then {
  120. directory=$(dirname $fullname)
  121. filename=$(basename $fullname)
  122. # strip leading "." from fullname if present
  123. if [ "$directory" = "\." ]; then {
  124. directory=""
  125. fullname=$filename
  126. }; fi
  127. # Create the target directory to hold input file if necessary
  128. if [ ! -z $directory ]; then {
  129. adb shell "mkdir $directory" > /dev/null 2>&1
  130. }; fi
  131. # Transfer the input file to corresponding directory on target device
  132. adb push $fullname ${targetdir}/$fullname > /dev/null 2>&1
  133. }; fi
  134. }; done
  135. # The return_code file is the best way found to return the status of the test execution when using adb shell.
  136. (adb shell "cd $targetdir; $ldpreload export LD_LIBRARY_PATH=.; ./$exename $verb $*; echo \$? > return_code") | sed -e "s/\\r$//"
  137. # Capture the return code string and remove the trailing \r from the return_code file contents
  138. exitcode=`(adb shell "cat $targetdir/return_code 2> /dev/null") | sed -e "s/\\r$//"`
  139. do_cleanup
  140. # Return the exit code of the test.
  141. exit $exitcode