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"'
18 echo 'Required arguments:'
19 echo ' --testRootDir=<path> : Root directory of the test build (default: /opt/usr/corefx-tc/tests).'
20 echo ' --coreOverlayDir=<path> : Directory containing CLR and FX (default: /opt/usr/corefx-tc/coreroot).'
21 echo " --outerloop=<value> : OuterLoop category: on/off"
23 echo 'Optional arguments:'
24 echo ' --netcoreDir=<path> : Netcore (CLR and FX) system dir (default: /usr/share/dotnet.tizen/netcoreapp).'
25 echo ' --copy-netcore-to-coreroot : Copy netcore (CLR and FX) from netcore system dir to coreroot.'
26 echo ' --testDir=<path> : Run tests only in the specified directory. The path is relative to the directory'
27 echo ' specified by --testRootDir. Multiple of this switch may be specified.'
28 echo ' --testDirFile=<path> : Run tests only in the directories specified by the file at <path>. Paths are listed'
29 echo ' one line, relative to the directory specified by --testRootDir.'
30 echo ' --num-procs=<N> : Run N test processes at the same time (default is 1).'
31 echo ' -h, --help : Show usage information.'
32 echo ' --outputDir : Dir to save results to (default: /opt/usr/corefx-tc/results).'
33 echo ' --tmpDir : Local tmp dir (default: /opt/usr/corefx-tc/tmp).'
34 echo ' --user : User under which to run tests (default: root). This is needed because sdb shell <script> does not set USER env variable'
35 echo ' --pal-debug : Enable PAL_OUTPUTDEBUGSTRING=1 which prints pal debug messages to stderr (e.g. messages from Environment.FailFast)'
38 function print_results {
40 echo "======================="
42 echo "======================="
43 echo "# Overlay : $coreOverlayDir"
44 echo "# Tests Discovered : $countTotalTests"
45 echo "# Passed : $countPassedTests"
46 echo "# Errored : $countErroredTests"
47 echo "# Failed : $countFailedTests"
48 echo "# Skipped : $countSkippedTests"
50 echo "# Errored dlls : $countErroredDlls"
51 echo "======================="
54 # Initialize counters for bookkeeping.
62 # Variables for running tests in the background
63 ((maxProcesses = 1)) # long tests delay process creation, use a few more processors
66 declare -a testDirPaths
75 for (( i=0; i<$maxProcesses; i++ )); do
77 if [ -z "$pid" ] || [ "$pid" == "$pidNone" ]; then
80 if ! kill -0 $pid 2>/dev/null; then
84 processIds[$i]=$pidNone
92 function get_available_process_index {
95 for (( i=0; i<$maxProcesses; i++ )); do
97 if [ -z "$pid" ] || [ "$pid" == "$pidNone" ]; then
104 function finish_test {
106 local testScriptExitCode=$?
107 local finishedProcessIndex=$waitProcessIndex
110 local dirName=${testDirPaths[$finishedProcessIndex]}
111 local testProject=`basename $dirName`
112 local outputFilePath="$testsOutputDir/$testProject/log.out"
114 local resultsStr=$(grep "Total:.*Errors:.*Failed:.*Skipped:.*Time:" $outputFilePath)
116 if [ "$resultsStr" == "" ]; then
117 if [ $testScriptExitCode -ne 0 ]
119 echo "$testProject: dll errored, see log $outputFilePath"
120 countErroredDlls=$(($countErroredDlls+1))
122 # No appropriate tests were found in dll
123 echo "$testProject: no tests found, see log $outputFilePath"
126 local curTotal=$(echo $resultsStr | awk '{print $4}' | sed 's/,//')
127 local curErrored=$(echo $resultsStr | awk '{print $6}' | sed 's/,//')
128 local curFailed=$(echo $resultsStr | awk '{print $8}' | sed 's/,//')
129 local curSkipped=$(echo $resultsStr | awk '{print $10}' | sed 's/,//')
130 local curTime=$(echo $resultsStr | awk '{print $12}' | sed 's/s//')
131 local curPassed=$(echo $curTotal $curErrored $curFailed $curSkipped | awk '{print $1-$2-$3-$4}')
133 countTotalTests=$(echo $countTotalTests $curTotal | awk '{print $1+$2}')
134 countPassedTests=$(echo $countPassedTests $curPassed | awk '{print $1+$2}')
135 countErroredTests=$(echo $countErroredTests $curErrored | awk '{print $1+$2}')
136 countFailedTests=$(echo $countFailedTests $curFailed | awk '{print $1+$2}')
137 countSkippedTests=$(echo $countSkippedTests $curSkipped | awk '{print $1+$2}')
139 if [ $testScriptExitCode -ne 0 ]
141 echo "$testProject: failed, Total:$curTotal Passed:$curPassed Errored:$curErrored Failed:$curFailed Skipped:$curSkipped Time:$curTime, see log $outputFilePath"
143 echo "$testProject: ok, Total:$curTotal Passed:$curPassed Errored:$curErrored Failed:$curFailed Skipped:$curSkipped Time:$curTime, see log $outputFilePath"
148 function finish_remaining_tests {
149 # Finish the remaining tests in the order in which they were started
150 while ((processCount > 0)); do
155 function start_test {
156 local nextProcessIndex=$(get_available_process_index)
158 local testProject=`basename $dirName`
160 if ((nextProcessIndex == maxProcesses)); then
162 nextProcessIndex=$(get_available_process_index)
165 testDirPaths[$nextProcessIndex]=$dirName
167 run_test "$dirName" &
168 processIds[$nextProcessIndex]=$!
174 function handle_ctrl_c
177 echo "*** Stopping... ***"
179 exit $EXIT_CODE_EXCEPTION
182 # $1 is the path of list file
183 function read_array()
187 if [ ! -f "$1" ]; then
191 # bash in Mac OS X doesn't support 'readarray', so using alternate way instead.
192 # readarray -t theArray < "$1"
193 # Any line that starts with '#' is ignored.
194 while IFS='' read -r line || [ -n "$line" ]; do
195 if [[ $line != "#"* ]]; then
196 theArray[${#theArray[@]}]=$line
202 # Get a list of directories in which to scan for tests by reading the
203 # specified file line by line.
204 function set_test_directories {
205 local listFileName=$1
207 if [ ! -f "$listFileName" ]
209 echo "Test directories file not found at $listFileName"
210 exit $EXIT_CODE_EXCEPTION
212 testDirectories=($(read_array "$listFileName"))
215 # $1 is the name of the platform folder (e.g Unix.AnyCPU.Debug)
220 start_test $testFolder
224 # $1 is the path to the test folder
228 local testProject=`basename $1`
229 local outputDir="$testsOutputDir/$testProject"
233 local outputFilePath="$outputDir/log.out"
234 local outputXmlPath="$outputDir/testResults.xml"
236 if [ ! -d "$dirName" ]; then
237 echo "Nothing to test in $testProject" > $outputFilePath 2>&1
238 return $EXIT_CODE_EXCEPTION
241 if [ ! -e "$dirName/RunTests.sh" ]; then
242 echo "Cannot find $dirName/RunTests.sh" > $outputFilePath 2>&1
243 return $EXIT_CODE_EXCEPTION
248 ./RunTests.sh "$coreOverlayDir" "$outerloop" "$outputXmlPath" "$tmpDir" > $outputFilePath 2>&1
249 local testScriptExitCode=$?
251 return $testScriptExitCode
254 # Register the Ctrl-C handler
255 trap handle_ctrl_c INT
257 # Exit code constants
258 readonly EXIT_CODE_SUCCESS=0 # Script ran normally.
259 readonly EXIT_CODE_EXCEPTION=1 # Script exited because something exceptional happened (e.g. bad arguments, Ctrl-C interrupt).
260 readonly EXIT_CODE_TEST_FAILURE=2 # Script completed successfully, but one or more tests failed.
263 testRootDir="/opt/usr/corefx-tc/tests"
264 coreOverlayDir="/opt/usr/corefx-tc/coreroot/"
265 doCopyNetcoreToCoreroot=0
266 netcoreDir="/usr/share/dotnet.tizen/netcoreapp"
267 outputDir="/opt/usr/corefx-tc/results"
268 tmpDir="/opt/usr/corefx-tc/tmp"
276 exit $EXIT_CODE_SUCCESS
282 coreOverlayDir=${i#*=}
290 --copy-netcore-to-coreroot)
291 doCopyNetcoreToCoreroot=1
294 testDirectories[${#testDirectories[@]}]=${i#*=}
297 set_test_directories "${i#*=}"
300 ((maxProcesses = ${i#*=}))
312 export PAL_OUTPUTDEBUGSTRING="1"
315 echo "Unknown switch: $i"
317 exit $EXIT_CODE_SUCCESS
322 if [ -z "$testRootDir" ]; then
323 echo "--testRootDir is required."
325 exit $EXIT_CODE_EXCEPTION
327 if [ ! -d "$testRootDir" ]; then
328 echo "Directory specified by --testRootDir does not exist: $testRootDir"
329 exit $EXIT_CODE_EXCEPTION
332 if [ -z "$coreOverlayDir" ]; then
333 echo "--coreOverlayDir is required."
335 exit $EXIT_CODE_EXCEPTION
337 if [ ! -d "$coreOverlayDir" ]; then
338 echo "Directory specified by --coreOverlayDir does not exist: $coreOverlayDir"
339 exit $EXIT_CODE_EXCEPTION
342 if [ -z "$outerloop" ]; then
343 echo "--outerloop is required."
345 exit $EXIT_CODE_EXCEPTION
348 export CORE_ROOT="$coreOverlayDir"
350 export SUDO_USER="$user"
352 echo "! Make sure CLR/FX are copied to $coreOverlayDir !"
356 export LANG="en_US.UTF-8"
359 if [ $doCopyNetcoreToCoreroot == 1 ]; then
360 echo "Copying netcore ($netcoreDir) to coreroot ($coreOverlayDir)"
361 cp $netcoreDir/* $coreOverlayDir
364 echo "Cleanup old ni.dll"
365 for file in `find $testRootDir $coreOverlayDir -name "*.ni.*"`; do
369 testsOutputDir="$outputDir/tests"
370 mkdir -p $testsOutputDir
373 time_start=$(date +"%s")
374 if [ -z "$testDirectories" ]
376 # No test directories were specified, so run everything
377 testDirectories=( $(ls "$testRootDir/" | grep .Tests) )
380 for testDir in "${testDirectories[@]}"
382 run_tests "$testRootDir/$testDir"
385 finish_remaining_tests
388 time_end=$(date +"%s")
389 time_diff=$(($time_end-$time_start))
390 echo "$(($time_diff / 60)) minutes and $(($time_diff % 60)) seconds taken to run CoreFX tests."
392 if [ "$countErroredDlls" -gt 0 ] || [ "$countErroredTests" -gt 0 ] || [ "$countFailedTests" -gt 0 ]
394 exit $EXIT_CODE_TEST_FAILURE
397 exit $EXIT_CODE_SUCCESS