5 echo 'CoreCLR parallel test runner script.'
7 echo 'Required arguments:'
8 echo ' --testRootDir=<path> : Root directory of the test build (e.g. coreclr/bin/tests/Windows_NT.x64.Debug).'
9 echo ' --coreOverlayDir=<path> : Directory containing core binaries and test dependencies. If not specified, the'
10 echo ' default is testRootDir/Tests/coreoverlay. This switch overrides --coreClrBinDir,'
11 echo ' --mscorlibDir, --coreFxBinDir, and --coreFxNativeBinDir.'
12 echo ' --playlist=<path> : Run only the tests that are specified in the file at <path>, in the same format as'
14 echo 'Optional arguments:'
15 echo ' -h|--help : Show usage information.'
16 echo ' --test-env : Script to set environment variables for tests'
20 function print_results {
22 "Results @ $(date +%r)\n\t"\
23 "Pass:$countPassedTests\t"\
24 "Fail:$countFailedTests\n\t"\
25 "Finish:$countFinishedTests\t"\
26 "Incomplete: $countIncompleteTests\n\t"\
27 "Total: $countTotalTests"
30 function update_results {
31 # Initialize counters for bookkeeping.
32 countTotalTests=$(wc -l < $playlistFile)
34 countFinishedTests=$(cd results.int; grep -r 'RUN_TEST_EXIT_CODE' . | wc -l)
35 countPassedTests=$(cd results.int; grep -r 'RUN_TEST_EXIT_CODE=0' . | wc -l)
36 countFailedTests=$((countFinishedTests - countPassedTests))
37 countIncompleteTests=$((countTotalTests - countFinishedTests))
42 function print_elapsed_time {
43 time_end=$(date +"%s")
44 time_diff=$(($time_end-$time_start))
45 echo "$(($time_diff / 60)) minutes and $(($time_diff % 60)) seconds taken to run CoreCLR tests."
50 # Handle Ctrl-C. We will stop execution and print the results that
52 function handle_ctrl_c {
53 local errorSource='handle_ctrl_c'
56 echo "*** Stopping... ***"
59 echo "$errorSource" "Test run aborted by Ctrl+C."
68 kill -TERM % >/dev/null
69 mv results.int results.$(date +%F_%I%M%p)
74 # This function runs in a background process. It should not echo anything, and should not use global variables.
77 rm -f $(dirname "$1")/*.ni.*
81 # This function runs in a background process. It should not echo anything, and should not use global variables.
83 local scriptFilePath=$1
85 local scriptFileName=$(basename "$scriptFilePath")
86 local outputFileName=$PWD/results.int/${scriptFilePath////.}
88 nice "$scriptFilePath" -debug=$(which time) >"$outputFileName" 2>&1
90 echo RUN_TEST_EXIT_CODE="$?" >>"$outputFileName"
104 exit $EXIT_CODE_SUCCESS
106 --coreOverlayDir=*)# Exit code constants
107 coreOverlayDir=${i#*=}
119 echo "Unknown switch: $i"
121 exit $EXIT_CODE_SUCCESS
126 if [ -z "$coreOverlayDir" ]; then
127 echo "--coreOverlayDir is required."
129 exit $EXIT_CODE_EXCEPTION
132 if [ ! -d "$coreOverlayDir" ]; then
133 echo "Directory specified by --coreOverlayDir does not exist: $coreOverlayDir"
134 exit $EXIT_CODE_EXCEPTION
137 if [ -z "$playlistFile" ]; then
138 echo "--playlist is required."
140 exit $EXIT_CODE_EXCEPTION
143 if [ ! -e "$playlistFile" ]; then
144 echo "File specified by --playlist does not exist: $playlistFile"
145 exit $EXIT_CODE_EXCEPTION
148 if [ -z "$testRootDir" ]; then
149 echo "--testRootDir is required."
151 exit $EXIT_CODE_EXCEPTION
154 if [ ! -d "$testRootDir" ]; then
155 echo "Directory specified by --testRootDir does not exist: $testRootDir"
156 exit $EXIT_CODE_EXCEPTION
159 if [ ! -z "$testEnv" ] && [ ! -e "$testEnv" ]; then
160 echo "File specified by --playlist does not exist: $testEnv"
161 exit $EXIT_CODE_EXCEPTION
164 export CORE_ROOT="$coreOverlayDir"
165 export __TestEnv=$testEnv
168 # Variables for running tests in the background
169 if [ `uname` = "NetBSD" ]; then
170 NumProc=$(getconf NPROCESSORS_ONLN)
172 NumProc=$(getconf _NPROCESSORS_ONLN)
175 export TIME='<Command time="%U %S %e" mem="%M %t %K" swap="%W %c %w" fault="%F %R %k %r %s" IO="%I %O" exit="%x"/>'
181 time_start=$(date +"%s")
183 rm -rf results.int/* results.int
185 echo "Prepping tests $(date +%r)"
186 xargs -d "\n" -P $NumProc -I{} bash -c prep_test {} < $playlistFile
191 echo $$ > results.int/pid
192 cp $testEnv results.int
194 trap handle_ctrl_c INT TERM
196 xargs -d "\n" -P $NumProc -I{} bash -c 'run_test "{}" >/dev/null 2>&1' < $playlistFile &
203 if (( $(jobs %xargs 2>/dev/null | wc -l) == 0 )) ;