5 echo 'CoreFX test runner script.'
7 echo 'Typical Tizen command:'
8 echo ' corefx/runtest.sh'
9 echo ' --testRootDir="/opt/usr/corefx-tc/tests"'
10 echo ' --coreOverlayDir="/opt/usr/corefx-tc/coreroot"'
11 echo ' --outerloop=on/off'
12 echo ' --netcoreDir="/usr/share/dotnet.tizen/netcoreapp"'
13 echo ' --copy-netcore-to-coreroot'
14 echo ' --outputDir="/opt/usr/corefx-tc/results"'
15 echo ' --tmpDir="/opt/usr/corefx-tc/tmp"'
17 echo 'Required arguments:'
18 echo ' --testRootDir=<path> : Root directory of the test build (default: /opt/usr/corefx-tc/tests).'
19 echo ' --coreOverlayDir=<path> : Directory containing CLR and FX (default: /opt/usr/corefx-tc/coreroot).'
20 echo " --outerloop=<value> : OuterLoop category: on/off"
22 echo 'Optional arguments:'
23 echo ' --netcoreDir=<path> : Netcore (CLR and FX) system dir (default: /usr/share/dotnet.tizen/netcoreapp).'
24 echo ' --copy-netcore-to-coreroot : Copy netcore (CLR and FX) from netcore system dir to coreroot.'
25 echo ' --testDir=<path> : Run tests only in the specified directory. The path is relative to the directory'
26 echo ' specified by --testRootDir. Multiple of this switch may be specified.'
27 echo ' --testDirFile=<path> : Run tests only in the directories specified by the file at <path>. Paths are listed'
28 echo ' one line, relative to the directory specified by --testRootDir.'
29 echo ' --num-procs=<N> : Run N test processes at the same time (default is 1).'
30 echo ' -h, --help : Show usage information.'
31 echo ' --outputDir : Dir to save results to (default: /opt/usr/corefx-tc/results).'
32 echo ' --tmpDir : Local tmp dir (default: /opt/usr/corefx-tc/tmp).'
35 function print_results {
37 echo "======================="
39 echo "======================="
40 echo "# Overlay : $coreOverlayDir"
41 echo "# Tests Discovered : $countTotalTests"
42 echo "# Passed : $countPassedTests"
43 echo "# Errored : $countErroredTests"
44 echo "# Failed : $countFailedTests"
45 echo "# Skipped : $countSkippedTests"
47 echo "# Errored dlls : $countErroredDlls"
48 echo "======================="
51 # Initialize counters for bookkeeping.
59 # Variables for running tests in the background
60 ((maxProcesses = 1)) # long tests delay process creation, use a few more processors
63 declare -a testDirPaths
72 for (( i=0; i<$maxProcesses; i++ )); do
74 if [ -z "$pid" ] || [ "$pid" == "$pidNone" ]; then
77 if ! kill -0 $pid 2>/dev/null; then
81 processIds[$i]=$pidNone
89 function get_available_process_index {
92 for (( i=0; i<$maxProcesses; i++ )); do
94 if [ -z "$pid" ] || [ "$pid" == "$pidNone" ]; then
101 function finish_test {
103 local testScriptExitCode=$?
104 local finishedProcessIndex=$waitProcessIndex
107 local dirName=${testDirPaths[$finishedProcessIndex]}
108 local testProject=`basename $dirName`
109 local outputFilePath="$testsOutputDir/$testProject/log.out"
111 local resultsStr=$(grep "Total:.*Errors:.*Failed:.*Skipped:.*Time:" $outputFilePath)
113 if [ "$resultsStr" == "" ]; then
114 if [ $testScriptExitCode -ne 0 ]
116 echo "$testProject: dll errored, see log $outputFilePath"
117 countErroredDlls=$(($countErroredDlls+1))
119 # No appropriate tests were found in dll
120 echo "$testProject: no tests found, see log $outputFilePath"
123 local curTotal=$(echo $resultsStr | awk '{print $4}' | sed 's/,//')
124 local curErrored=$(echo $resultsStr | awk '{print $6}' | sed 's/,//')
125 local curFailed=$(echo $resultsStr | awk '{print $8}' | sed 's/,//')
126 local curSkipped=$(echo $resultsStr | awk '{print $10}' | sed 's/,//')
127 local curTime=$(echo $resultsStr | awk '{print $12}' | sed 's/s//')
128 local curPassed=$(echo $curTotal $curErrored $curFailed $curSkipped | awk '{print $1-$2-$3-$4}')
130 countTotalTests=$(echo $countTotalTests $curTotal | awk '{print $1+$2}')
131 countPassedTests=$(echo $countPassedTests $curPassed | awk '{print $1+$2}')
132 countErroredTests=$(echo $countErroredTests $curErrored | awk '{print $1+$2}')
133 countFailedTests=$(echo $countFailedTests $curFailed | awk '{print $1+$2}')
134 countSkippedTests=$(echo $countSkippedTests $curSkipped | awk '{print $1+$2}')
136 if [ $testScriptExitCode -ne 0 ]
138 echo "$testProject: failed, Total:$curTotal Passed:$curPassed Errored:$curErrored Failed:$curFailed Skipped:$curSkipped Time:$curTime, see log $outputFilePath"
140 echo "$testProject: ok, Total:$curTotal Passed:$curPassed Errored:$curErrored Failed:$curFailed Skipped:$curSkipped Time:$curTime, see log $outputFilePath"
145 function finish_remaining_tests {
146 # Finish the remaining tests in the order in which they were started
147 while ((processCount > 0)); do
152 function start_test {
153 local nextProcessIndex=$(get_available_process_index)
155 local testProject=`basename $dirName`
157 if ((nextProcessIndex == maxProcesses)); then
159 nextProcessIndex=$(get_available_process_index)
162 testDirPaths[$nextProcessIndex]=$dirName
164 run_test "$dirName" &
165 processIds[$nextProcessIndex]=$!
171 function handle_ctrl_c
174 echo "*** Stopping... ***"
176 exit $EXIT_CODE_EXCEPTION
179 # $1 is the path of list file
180 function read_array()
184 if [ ! -f "$1" ]; then
188 # bash in Mac OS X doesn't support 'readarray', so using alternate way instead.
189 # readarray -t theArray < "$1"
190 # Any line that starts with '#' is ignored.
191 while IFS='' read -r line || [ -n "$line" ]; do
192 if [[ $line != "#"* ]]; then
193 theArray[${#theArray[@]}]=$line
199 # Get a list of directories in which to scan for tests by reading the
200 # specified file line by line.
201 function set_test_directories {
202 local listFileName=$1
204 if [ ! -f "$listFileName" ]
206 echo "Test directories file not found at $listFileName"
207 exit $EXIT_CODE_EXCEPTION
209 testDirectories=($(read_array "$listFileName"))
212 # $1 is the name of the platform folder (e.g Unix.AnyCPU.Debug)
217 start_test $testFolder
221 # $1 is the path to the test folder
225 local testProject=`basename $1`
226 local outputDir="$testsOutputDir/$testProject"
230 local outputFilePath="$outputDir/log.out"
231 local outputXmlPath="$outputDir/testResults.xml"
233 if [ ! -d "$dirName" ]; then
234 echo "Nothing to test in $testProject" > $outputFilePath 2>&1
235 return $EXIT_CODE_EXCEPTION
238 if [ ! -e "$dirName/RunTests.sh" ]; then
239 echo "Cannot find $dirName/RunTests.sh" > $outputFilePath 2>&1
240 return $EXIT_CODE_EXCEPTION
245 ./RunTests.sh "$coreOverlayDir" "$outerloop" "$outputXmlPath" "$tmpDir" > $outputFilePath 2>&1
246 local testScriptExitCode=$?
248 return $testScriptExitCode
251 # Register the Ctrl-C handler
252 trap handle_ctrl_c INT
254 # Exit code constants
255 readonly EXIT_CODE_SUCCESS=0 # Script ran normally.
256 readonly EXIT_CODE_EXCEPTION=1 # Script exited because something exceptional happened (e.g. bad arguments, Ctrl-C interrupt).
257 readonly EXIT_CODE_TEST_FAILURE=2 # Script completed successfully, but one or more tests failed.
260 testRootDir="/opt/usr/corefx-tc/tests"
261 coreOverlayDir="/opt/usr/corefx-tc/coreroot/"
262 doCopyNetcoreToCoreroot=0
263 netcoreDir="/usr/share/dotnet.tizen/netcoreapp"
264 outputDir="/opt/usr/corefx-tc/results"
265 tmpDir="/opt/usr/corefx-tc/tmp"
272 exit $EXIT_CODE_SUCCESS
278 coreOverlayDir=${i#*=}
286 --copy-netcore-to-coreroot)
287 doCopyNetcoreToCoreroot=1
290 testDirectories[${#testDirectories[@]}]=${i#*=}
293 set_test_directories "${i#*=}"
296 ((maxProcesses = ${i#*=}))
305 echo "Unknown switch: $i"
307 exit $EXIT_CODE_SUCCESS
312 if [ -z "$testRootDir" ]; then
313 echo "--testRootDir is required."
315 exit $EXIT_CODE_EXCEPTION
317 if [ ! -d "$testRootDir" ]; then
318 echo "Directory specified by --testRootDir does not exist: $testRootDir"
319 exit $EXIT_CODE_EXCEPTION
322 if [ -z "$coreOverlayDir" ]; then
323 echo "--coreOverlayDir is required."
325 exit $EXIT_CODE_EXCEPTION
327 if [ ! -d "$coreOverlayDir" ]; then
328 echo "Directory specified by --coreOverlayDir does not exist: $coreOverlayDir"
329 exit $EXIT_CODE_EXCEPTION
332 if [ -z "$outerloop" ]; then
333 echo "--outerloop is required."
335 exit $EXIT_CODE_EXCEPTION
338 export CORE_ROOT="$coreOverlayDir"
340 echo "! Make sure CLR/FX are copied to $coreOverlayDir !"
342 export PAL_OUTPUTDEBUGSTRING="1"
346 export LANG="en_US.UTF-8"
349 if [ $doCopyNetcoreToCoreroot == 1 ]; then
350 echo "Copying netcore ($netcoreDir) to coreroot ($coreOverlayDir)"
351 cp $netcoreDir/* $coreOverlayDir
354 echo "Cleanup old ni.dll"
355 for file in `find $testRootDir $coreOverlayDir -name "*.ni.*"`; do
359 testsOutputDir="$outputDir/tests"
360 mkdir -p $testsOutputDir
363 time_start=$(date +"%s")
364 if [ -z "$testDirectories" ]
366 # No test directories were specified, so run everything
367 testDirectories=( $(ls "$testRootDir/" | grep .Tests) )
370 for testDir in "${testDirectories[@]}"
372 run_tests "$testRootDir/$testDir"
375 finish_remaining_tests
378 time_end=$(date +"%s")
379 time_diff=$(($time_end-$time_start))
380 echo "$(($time_diff / 60)) minutes and $(($time_diff % 60)) seconds taken to run CoreFX tests."
382 if [ "$countErroredDlls" -gt 0 ] || [ "$countErroredTests" -gt 0 ] || [ "$countFailedTests" -gt 0 ]
384 exit $EXIT_CODE_TEST_FAILURE
387 exit $EXIT_CODE_SUCCESS