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.

111 lines
4.9 KiB

  1. #!/bin/bash
  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. # mic.linux.launcher.sh [-v] [-s] [-r <repeats>] [-u] [-l <library>] <executable> <arg1> <arg2> <argN>
  30. # where: -v enables verbose output
  31. # where: -s enables stress testing unless ctrl-c is pressed
  32. # where: -r <repeats> specifies number of times to repeat execution
  33. # where: -u is ignored
  34. # where: -l <library> specifies the library name to be assigned to LD_PRELOAD
  35. #
  36. # Libs and executable necessary for testing should be present in the current directory before running.
  37. # Note: Do not remove the redirections to '/dev/null' in the script, otherwise the nightly test system will fail.
  38. #
  39. trap 'echo Error at line $LINENO while executing "$BASH_COMMAND"' ERR #
  40. trap 'echo -e "\n*** Interrupted ***" && exit 1' SIGINT SIGQUIT #
  41. # Process the optional arguments if present
  42. if [ "x$1" = "x-v" ]; then shift 1; else SUPPRESS='>/dev/null'; fi #
  43. if [ "x$1" = "x-s" ]; then shift 1; echo Doing stress testing. Press Ctrl-C to terminate
  44. run_prefix+='rep() { while :; do $*; done; }; rep '; fi #
  45. if [ "x$1" = "x-r" ]; then #
  46. run_prefix+="rep() { for i in \$(seq 1 $2); do echo \$i of $2:; \$*; done; }; rep " #
  47. shift 2; fi #
  48. [ "x$1" = "x-u" ] && shift 1 #
  49. if [ "x$1" = "x-l" ]; then { #
  50. ldd_list+="$2 "#
  51. run_prefix+=" LD_PRELOAD=$2" #
  52. shift 2 #
  53. }; fi #
  54. # Collect the executable name
  55. fexename="$1" #
  56. exename=`basename $1` #
  57. shift #
  58. #
  59. RSH="sudo ssh mic0" #
  60. RCP="sudo scp" #
  61. #
  62. # Prepare the target directory on the device
  63. currentdir=`basename $PWD` #
  64. targetdir=${TEST_DIRECTORY:-/mic0fs/$USER/$currentdir} #
  65. #
  66. # Remove leftover target directory on the device
  67. eval "$RSH \"rm -r $targetdir; mkdir -p $targetdir\" $SUPPRESS 2>&1 || exit \$?" #
  68. eval "$RCP $fexename mic0:$targetdir/ $SUPPRESS || exit \$?" #
  69. #
  70. # Collect the list of files to transfer to the target device, starting with executable itself.
  71. ldd_list+="libtbbmalloc*.so* `$RSH ldd $targetdir/$exename | grep = | cut -d= -f1 2>/dev/null`" #
  72. fnamelist="" #
  73. #
  74. # Find the libraries and add them to the list.
  75. # For example, go through MIC_LD_LIBRARY_PATH and add TBB libraries from the first
  76. # directory that contains tbb files
  77. mic_dir_list=`echo .:$MIC_LD_LIBRARY_PATH | tr : " "` #
  78. for name in $ldd_list; do # adds the first matched name in specified dirs
  79. fnamelist+="`find $mic_dir_list -name $name -a -readable -print -quit 2>/dev/null` " #
  80. done #
  81. #
  82. # Add any libraries built for specific tests.
  83. exeroot=${exename%\.*} #
  84. fnamelist+=`ls ${exeroot}*.so ${exeroot}*.so.* 2>/dev/null`||: #
  85. #
  86. # Transfer collected executable and library files to the target device.
  87. eval "$RCP $fnamelist mic0:$targetdir/ $SUPPRESS || exit \$?" #
  88. #
  89. # Transfer input files used by example codes by scanning the executable argument list.
  90. for fullname in "$@"; do if [ -r $fullname ]; then { #
  91. directory=$(dirname $fullname) #
  92. filename=$(basename $fullname) #
  93. # strip leading "." from fullname if present
  94. [ "$directory" = "." ] && directory="" && fullname="$filename" #
  95. # Create the target directory to hold input file if necessary
  96. [ ! -z "$directory" ] && $RSH "mkdir -p $targetdir/$directory" $SUPPRESS 2>&1 #
  97. # Transfer the input file to corresponding directory on target device
  98. eval "$RCP $fullname mic0:$targetdir/$fullname $SUPPRESS 2>&1 || exit \$?" #
  99. }; fi; done #
  100. #
  101. args=$* #
  102. # Run the test on the target device
  103. kill_interrupt() { #
  104. echo -e "\n*** Killing remote $exename ***" && $RSH "killall $exename" #
  105. } # kill target process
  106. trap 'kill_interrupt' SIGINT SIGQUIT # trap keyboard interrupt (control-c)
  107. trap - ERR #
  108. $RSH "cd $targetdir; export LD_LIBRARY_PATH=.:\$LD_LIBRARY_PATH; $run_prefix ./$exename $args" #
  109. # Return the exit code of the test.
  110. exit $? #