5 echo 'CoreCLR test runner script.'
7 echo 'Typical command line:'
9 echo 'coreclr/tests/runtest.sh'
10 echo ' --testRootDir="temp/Windows_NT.x64.Debug"'
11 echo ' --testNativeBinDir="coreclr/bin/obj/Linux.x64.Debug/tests"'
12 echo ' --coreClrBinDir="coreclr/bin/Product/Linux.x64.Debug"'
13 echo ' --mscorlibDir="windows/coreclr/bin/Product/Linux.x64.Debug"'
14 echo ' --coreFxBinDir="corefx/bin/runtime/netcoreapp-Linux-Debug-x64'
16 echo 'Required arguments:'
17 echo ' --testRootDir=<path> : Root directory of the test build (e.g. coreclr/bin/tests/Windows_NT.x64.Debug).'
18 echo ' --testNativeBinDir=<path> : Directory of the native CoreCLR test build (e.g. coreclr/bin/obj/Linux.x64.Debug/tests).'
19 echo ' (Also required: Either --coreOverlayDir, or all of the switches --coreOverlayDir overrides)'
21 echo 'Optional arguments:'
22 echo ' --coreOverlayDir=<path> : Directory containing core binaries and test dependencies. If not specified, the'
23 echo ' default is testRootDir/Tests/coreoverlay. This switch overrides --coreClrBinDir,'
24 echo ' --mscorlibDir, and --coreFxBinDir.'
25 echo ' --coreClrBinDir=<path> : Directory of the CoreCLR build (e.g. coreclr/bin/Product/Linux.x64.Debug).'
26 echo ' --mscorlibDir=<path> : Directory containing the built mscorlib.dll. If not specified, it is expected to be'
27 echo ' in the directory specified by --coreClrBinDir.'
28 echo ' --coreFxBinDir="<path>" : Directory with CoreFX build outputs'
29 echo ' (e.g. "corefx/bin/runtime/netcoreapp-Linux-Debug-x64")'
30 echo ' If files with the same name are present in multiple directories, the first one wins.'
31 echo ' --testDir=<path> : Run tests only in the specified directory. The path is relative to the directory'
32 echo ' specified by --testRootDir. Multiple of this switch may be specified.'
33 echo ' --testDirFile=<path> : Run tests only in the directories specified by the file at <path>. Paths are listed'
34 echo ' one line, relative to the directory specified by --testRootDir.'
35 echo ' --build-overlay-only : Build coreoverlay only, and skip running tests.'
36 echo ' --runFailingTestsOnly : Run only the tests that are disabled on this platform due to unexpected failures.'
37 echo ' Failing tests are listed in coreclr/tests/failingTestsOutsideWindows.txt, one per'
38 echo ' line, as paths to .sh files relative to the directory specified by --testRootDir.'
39 echo ' --disableEventLogging : Disable the events logged by both VM and Managed Code'
40 echo ' --sequential : Run tests sequentially (default is to run in parallel).'
41 echo ' --playlist=<path> : Run only the tests that are specified in the file at <path>, in the same format as'
42 echo ' runFailingTestsOnly'
43 echo ' -v, --verbose : Show output from each test.'
44 echo ' -h|--help : Show usage information.'
45 echo ' --useServerGC : Enable server GC for this test run'
46 echo ' --test-env : Script to set environment variables for tests'
47 echo ' --crossgen : Precompiles the framework managed assemblies'
48 echo ' --runcrossgentests : Runs the ready to run tests'
49 echo ' --jitstress=<n> : Runs the tests with COMPlus_JitStress=n'
50 echo ' --jitstressregs=<n> : Runs the tests with COMPlus_JitStressRegs=n'
51 echo ' --jitminopts : Runs the tests with COMPlus_JITMinOpts=1'
52 echo ' --jitforcerelocs : Runs the tests with COMPlus_ForceRelocs=1'
53 echo ' --jitdisasm : Runs jit-dasm on the tests'
54 echo ' --gcstresslevel=<n> : Runs the tests with COMPlus_GCStress=n'
55 echo ' --ilasmroundtrip : Runs ilasm round trip on the tests'
56 echo ' 0: None 1: GC on all allocs and '"'easy'"' places'
57 echo ' 2: GC on transitions to preemptive GC 4: GC on every allowable JITed instr'
58 echo ' 8: GC on every allowable NGEN instr 16: GC only on a unique stack trace'
59 echo ' --long-gc : Runs the long GC tests'
60 echo ' --gcsimulator : Runs the GCSimulator tests'
61 echo ' --link <ILlink> : Runs the tests after linking via ILlink'
62 echo ' --show-time : Print execution sequence and running time for each test'
63 echo ' --no-lf-conversion : Do not execute LF conversion before running test script'
64 echo ' --build-overlay-only : Exit after overlay directory is populated'
65 echo ' --limitedDumpGeneration : Enables the generation of a limited number of core dumps if test(s) crash, even if ulimit'
66 echo ' is zero when launching this script. This option is intended for use in CI.'
67 echo ' --xunitOutputPath=<path> : Create xUnit XML report at the specifed path (default: <test root>/coreclrtests.xml)'
69 echo 'Runtime Code Coverage options:'
70 echo ' --coreclr-coverage : Optional argument to get coreclr code coverage reports'
71 echo ' --coreclr-objs=<path> : Location of root of the object directory'
72 echo ' containing the linux/mac coreclr build'
73 echo ' --coreclr-src=<path> : Location of root of the directory'
74 echo ' containing the coreclr source files'
75 echo ' --coverage-output-dir=<path> : Directory where coverage output will be written to'
79 function print_results {
81 echo "======================="
83 echo "======================="
84 echo "# CoreCLR Bin Dir : $coreClrBinDir"
85 echo "# Tests Discovered : $countTotalTests"
86 echo "# Passed : $countPassedTests"
87 echo "# Failed : $countFailedTests"
88 echo "# Skipped : $countSkippedTests"
89 echo "======================="
92 # Initialize counters for bookkeeping.
98 # Variables for xUnit-style XML output. XML format: https://xunit.github.io/docs/format-xml-v2.html
102 # libExtension determines extension for dynamic library files
103 # runtimeName determines where CoreFX Runtime files will be located
120 echo "Unsupported OS $OSName detected, configuring as if for Linux"
125 function xunit_output_begin {
126 xunitOutputPath=$testRootDir/coreclrtests.xml
127 xunitTestOutputPath=${xunitOutputPath}.test
128 if [ -e "$xunitOutputPath" ]; then
129 rm -f -r "$xunitOutputPath"
131 if [ -e "$xunitTestOutputPath" ]; then
132 rm -f -r "$xunitTestOutputPath"
136 function xunit_output_add_test {
140 # <test .../> <!-- Write this element here -->
142 local scriptFilePath=$1
143 local outputFilePath=$2
144 local testResult=$3 # Pass, Fail, or Skip
145 local testScriptExitCode=$4
147 local testPath=${scriptFilePath%.sh} # Remove trailing ".sh"
148 local testDir=$(dirname "$testPath")
149 local testName=$(basename "$testPath")
151 # Replace '/' with '.'
152 testPath=$(echo "$testPath" | tr / .)
153 testDir=$(echo "$testDir" | tr / .)
159 line="${line} name=\"${testPath}\""
160 line="${line} type=\"${testDir}\""
161 line="${line} method=\"${testName}\""
162 line="${line} result=\"${testResult}\""
164 if [ "$testResult" == "Pass" ]; then
166 echo "$line" >>"$xunitTestOutputPath"
171 echo "$line" >>"$xunitTestOutputPath"
174 if [ "$testResult" == "Skip" ]; then
175 line="${line}<reason><![CDATA[$(cat "$outputFilePath")]]></reason>"
176 echo "$line" >>"$xunitTestOutputPath"
178 line="${line}<failure exception-type=\"Exit code: ${testScriptExitCode}\">"
179 echo "$line" >>"$xunitTestOutputPath"
182 line="${line}<message>"
183 echo "$line" >>"$xunitTestOutputPath"
185 line="${line}<![CDATA["
186 echo "$line" >>"$xunitTestOutputPath"
187 cat "$outputFilePath" >>"$xunitTestOutputPath"
190 echo "$line" >>"$xunitTestOutputPath"
192 line="${line}</message>"
193 echo "$line" >>"$xunitTestOutputPath"
196 line="${line}</failure>"
197 echo "$line" >>"$xunitTestOutputPath"
201 line="${line}</test>"
202 echo "$line" >>"$xunitTestOutputPath"
205 function xunit_output_end {
207 local errorMessage=$2
210 if [ -z "$errorSource" ]; then
216 echo '<?xml version="1.0" encoding="utf-8"?>' >>"$xunitOutputPath"
217 echo '<assemblies>' >>"$xunitOutputPath"
223 line="${line}<assembly"
224 line="${line} name=\"CoreClrTestAssembly\""
225 line="${line} total=\"${countTotalTests}\""
226 line="${line} passed=\"${countPassedTests}\""
227 line="${line} failed=\"${countFailedTests}\""
228 line="${line} skipped=\"${countSkippedTests}\""
229 line="${line} errors=\"${errorCount}\""
231 echo "$line" >>"$xunitOutputPath"
235 line="${line}<collection"
236 line="${line} name=\"CoreClrTestCollection\""
237 line="${line} total=\"${countTotalTests}\""
238 line="${line} passed=\"${countPassedTests}\""
239 line="${line} failed=\"${countFailedTests}\""
240 line="${line} skipped=\"${countSkippedTests}\""
242 echo "$line" >>"$xunitOutputPath"
244 # <test .../> <test .../> ...
245 if [ -f "$xunitTestOutputPath" ]; then
246 cat "$xunitTestOutputPath" >>"$xunitOutputPath"
247 rm -f "$xunitTestOutputPath"
252 line="${line}</collection>"
253 echo "$line" >>"$xunitOutputPath"
255 if [ -n "$errorSource" ]; then
258 line="${line}<errors>"
259 echo "$line" >>"$xunitOutputPath"
264 line="${line} type=\"TestHarnessError\""
265 line="${line} name=\"${errorSource}\""
267 echo "$line" >>"$xunitOutputPath"
271 line="${line}<failure>${errorMessage}</failure>"
272 echo "$line" >>"$xunitOutputPath"
276 line="${line}</error>"
277 echo "$line" >>"$xunitOutputPath"
281 line="${line}</errors>"
282 echo "$line" >>"$xunitOutputPath"
287 line="${line}</assembly>"
288 echo "$line" >>"$xunitOutputPath"
291 echo '</assemblies>' >>"$xunitOutputPath"
294 function exit_with_error {
296 local errorMessage=$2
299 if [ -z "$printUsage" ]; then
304 xunit_output_end "$errorSource" "$errorMessage"
305 if ((printUsage != 0)); then
308 exit $EXIT_CODE_EXCEPTION
311 # Handle Ctrl-C. We will stop execution and print the results that
312 # we gathered so far.
313 function handle_ctrl_c {
314 local errorSource='handle_ctrl_c'
317 echo "*** Stopping... ***"
319 exit_with_error "$errorSource" "Test run aborted by Ctrl+C."
322 # Register the Ctrl-C handler
323 trap handle_ctrl_c INT
325 function create_core_overlay {
326 local errorSource='create_core_overlay'
329 if [ -n "$coreOverlayDir" ]; then
330 export CORE_ROOT="$coreOverlayDir"
334 # Check inputs to make sure we have enough information to create the core layout. $testRootDir/Tests/Core_Root should
335 # already exist and contain test dependencies that are not built.
336 local testDependenciesDir=$testRootDir/Tests/Core_Root
337 if [ ! -d "$testDependenciesDir" ]; then
338 exit_with_error "$errorSource" "Did not find the test dependencies directory: $testDependenciesDir"
340 if [ -z "$coreClrBinDir" ]; then
341 exit_with_error "$errorSource" "One of --coreOverlayDir or --coreClrBinDir must be specified." "$printUsage"
343 if [ ! -d "$coreClrBinDir" ]; then
344 exit_with_error "$errorSource" "Directory specified by --coreClrBinDir does not exist: $coreClrBinDir"
346 if [ -z "$coreFxBinDir" ]; then
347 exit_with_error "$errorSource" "One of --coreOverlayDir or --coreFxBinDir must be specified." "$printUsage"
351 coreOverlayDir=$testRootDir/Tests/coreoverlay
352 export CORE_ROOT="$coreOverlayDir"
353 if [ -e "$coreOverlayDir" ]; then
354 rm -f -r "$coreOverlayDir"
356 mkdir "$coreOverlayDir"
358 cp -f -v "$coreFxBinDir/"* "$coreOverlayDir/" 2>/dev/null
359 cp -f -p -v "$coreClrBinDir/"* "$coreOverlayDir/" 2>/dev/null
360 if [ -d "$mscorlibDir/bin" ]; then
361 cp -f -v "$mscorlibDir/bin/"* "$coreOverlayDir/" 2>/dev/null
363 cp -f -v "$testDependenciesDir/"xunit* "$coreOverlayDir/" 2>/dev/null
364 cp -n -v "$testDependenciesDir/"* "$coreOverlayDir/" 2>/dev/null
365 if [ -f "$coreOverlayDir/mscorlib.ni.dll" ]; then
366 # Test dependencies come from a Windows build, and mscorlib.ni.dll would be the one from Windows
367 rm -f "$coreOverlayDir/mscorlib.ni.dll"
369 if [ -f "$coreOverlayDir/System.Private.CoreLib.ni.dll" ]; then
370 # Test dependencies come from a Windows build, and System.Private.CoreLib.ni.dll would be the one from Windows
371 rm -f "$coreOverlayDir/System.Private.CoreLib.ni.dll"
373 copy_test_native_bin_to_test_root
376 declare -a skipCrossGenFiles
378 function is_skip_crossgen_test {
379 for skip in "${skipCrossGenFiles[@]}"; do
380 if [ "$1" == "$skip" ]; then
387 function precompile_overlay_assemblies {
388 skipCrossGenFiles=($(read_array "$(dirname "$0")/skipCrossGenFiles.$ARCH.txt"))
390 if [ $doCrossgen == 1 ]; then
391 local overlayDir=$CORE_ROOT
393 filesToPrecompile=$(find -L $overlayDir -iname \*.dll -not -iname \*.ni.dll -not -iname \*-ms-win-\* -type f )
394 for fileToPrecompile in ${filesToPrecompile}
396 local filename=${fileToPrecompile}
397 if [ $jitdisasm == 1 ]; then
398 $overlayDir/corerun $overlayDir/jit-dasm.dll --crossgen $overlayDir/crossgen --platform $overlayDir --output $testRootDir/dasm $filename
400 if [ $exitCode != 0 ]; then
401 echo Unable to generate dasm for $filename
404 if is_skip_crossgen_test "$(basename $filename)"; then
407 echo Precompiling $filename
408 $overlayDir/crossgen /Platform_Assemblies_Paths $overlayDir $filename 1> $filename.stdout 2>$filename.stderr
410 if [[ $exitCode != 0 ]]; then
411 if grep -q -e '0x80131018' $filename.stderr; then
412 printf "\n\t$filename is not a managed assembly.\n\n"
414 echo Unable to precompile $filename.
420 rm $filename.{stdout,stderr}
425 echo Skipping crossgen of FX assemblies.
429 function copy_test_native_bin_to_test_root {
430 local errorSource='copy_test_native_bin_to_test_root'
432 if [ -z "$testNativeBinDir" ]; then
433 exit_with_error "$errorSource" "--testNativeBinDir is required."
435 testNativeBinDir=$testNativeBinDir/src
436 if [ ! -d "$testNativeBinDir" ]; then
437 exit_with_error "$errorSource" "Directory specified by --testNativeBinDir does not exist: $testNativeBinDir"
440 # Copy native test components from the native test build into the respective test directory in the test root directory
441 find "$testNativeBinDir" -type f -iname '*.$libExtension' |
442 while IFS='' read -r filePath || [ -n "$filePath" ]; do
443 local dirPath=$(dirname "$filePath")
444 local destinationDirPath=${testRootDir}${dirPath:${#testNativeBinDir}}
445 if [ ! -d "$destinationDirPath" ]; then
446 exit_with_error "$errorSource" "Cannot copy native test bin '$filePath' to '$destinationDirPath/', as the destination directory does not exist."
448 cp -f "$filePath" "$destinationDirPath/"
452 # Variables for unsupported and failing tests
453 declare -a unsupportedTests
454 declare -a failingTests
455 declare -a playlistTests
456 ((runFailingTestsOnly = 0))
458 # Get an array of items by reading the specified file line by line.
459 function read_array {
462 # bash in Mac OS X doesn't support 'readarray', so using alternate way instead.
463 # readarray -t theArray < "$1"
464 while IFS='' read -r line || [ -n "$line" ]; do
465 theArray[${#theArray[@]}]=$line
470 function load_unsupported_tests {
471 # Load the list of tests that are not supported on this platform. These tests are disabled (skipped) permanently.
472 unsupportedTests=($(read_array "$(dirname "$0")/testsUnsupportedOutsideWindows.txt"))
473 if [ "$ARCH" == "arm" ]; then
474 unsupportedTests+=($(read_array "$(dirname "$0")/testsUnsupportedOnARM32.txt"))
478 function load_failing_tests {
479 # Load the list of tests that fail on this platform. These tests are disabled (skipped) temporarily, pending investigation.
480 failingTests=($(read_array "$(dirname "$0")/testsFailingOutsideWindows.txt"))
483 function load_playlist_tests {
484 # Load the list of tests that are enabled as a part of this test playlist.
485 playlistTests=($(read_array "${playlistFile}"))
488 function is_unsupported_test {
489 for unsupportedTest in "${unsupportedTests[@]}"; do
490 if [ "$1" == "$unsupportedTest" ]; then
497 function is_failing_test {
498 for failingTest in "${failingTests[@]}"; do
499 if [ "$1" == "$failingTest" ]; then
506 function is_playlist_test {
507 for playlistTest in "${playlistTests[@]}"; do
508 if [ "$1" == "$playlistTest" ]; then
515 function skip_unsupported_test {
516 # This function runs in a background process. It should not echo anything, and should not use global variables. This
517 # function is analogous to run_test, and causes the test to be skipped with the message below.
519 local scriptFilePath=$1
520 local outputFilePath=$2
522 echo "Not supported on this platform." >"$outputFilePath"
523 return 2 # skip the test
526 function skip_failing_test {
527 # This function runs in a background process. It should not echo anything, and should not use global variables. This
528 # function is analogous to run_test, and causes the test to be skipped with the message below.
530 local scriptFilePath=$1
531 local outputFilePath=$2
533 echo "Temporarily disabled on this platform due to unexpected failures." >"$outputFilePath"
534 return 2 # skip the test
537 function skip_non_playlist_test {
538 # This function runs in a background process. It should not echo anything, and should not use global variables. This
539 # function is analogous to run_test, and causes the test to be skipped with the message below.
541 local scriptFilePath=$1
542 local outputFilePath=$2
544 echo "Test is not included in the running playlist." >"$outputFilePath"
545 return 2 # skip the test
548 function set_up_core_dump_generation {
549 # We will only enable dump generation here if we're on Mac or Linux
550 if [[ ! ( "$(uname -s)" == "Darwin" || "$(uname -s)" == "Linux" ) ]]; then
554 # We won't enable dump generation on OS X/macOS if the machine hasn't been
555 # configured with the kern.corefile pattern we expect.
556 if [[ ( "$(uname -s)" == "Darwin" && "$(sysctl -n kern.corefile)" != "core.%P" ) ]]; then
557 echo "WARNING: Core dump generation not being enabled due to unexpected kern.corefile value."
561 # Allow dump generation
564 if [ "$(uname -s)" == "Linux" ]; then
565 if [ -e /proc/self/coredump_filter ]; then
566 # Include memory in private and shared file-backed mappings in the dump.
567 # This ensures that we can see disassembly from our shared libraries when
568 # inspecting the contents of the dump. See 'man core' for details.
569 echo 0x3F > /proc/self/coredump_filter
574 function print_info_from_core_file {
575 local core_file_name=$1
576 local executable_name=$2
578 if ! [ -e $executable_name ]; then
579 echo "Unable to find executable $executable_name"
581 elif ! [ -e $core_file_name ]; then
582 echo "Unable to find core file $core_file_name"
586 # Use LLDB to inspect the core dump on Mac, and GDB everywhere else.
587 if [[ "$OSName" == "Darwin" ]]; then
588 hash lldb 2>/dev/null || { echo >&2 "LLDB was not found. Unable to print core file."; return; }
590 echo "Printing info from core file $core_file_name"
591 lldb -c $core_file_name -b -o 'bt'
593 # Use GDB to print the backtrace from the core file.
594 hash gdb 2>/dev/null || { echo >&2 "GDB was not found. Unable to print core file."; return; }
596 echo "Printing info from core file $core_file_name"
597 gdb --batch -ex "thread apply all bt full" -ex "quit" $executable_name $core_file_name
601 function download_dumpling_script {
602 echo "Downloading latest version of dumpling script."
603 wget "https://dumpling.azurewebsites.net/api/client/dumpling.py"
605 local dumpling_script="dumpling.py"
606 chmod +x $dumpling_script
609 function upload_core_file_to_dumpling {
610 local core_file_name=$1
611 local dumpling_script="dumpling.py"
612 local dumpling_file="local_dumplings.txt"
614 # dumpling requires that the file exist before appending.
615 touch ./$dumpling_file
617 if [ ! -x $dumpling_script ]; then
618 download_dumpling_script
621 if [ ! -x $dumpling_script ]; then
622 echo "Failed to download dumpling script. Dump cannot be uploaded."
626 echo "Uploading $core_file_name to dumpling service."
628 local paths_to_add=""
629 if [ -d "$coreClrBinDir" ]; then
630 echo "Uploading CoreCLR binaries with dump."
631 paths_to_add=$coreClrBinDir
634 # Ensure the script has Unix line endings
635 perl -pi -e 's/\r\n|\n|\r/\n/g' "$dumpling_script"
637 # The output from this will include a unique ID for this dump.
638 ./$dumpling_script "upload" "--dumppath" "$core_file_name" "--incpaths" $paths_to_add "--properties" "Project=CoreCLR" "--squelch" | tee -a $dumpling_file
641 function preserve_core_file {
642 local core_file_name=$1
643 local storage_location="/tmp/coredumps_coreclr"
645 # Create the directory (this shouldn't fail even if it already exists).
646 mkdir -p $storage_location
648 # Only preserve the dump if the directory is empty. Otherwise, do nothing.
649 # This is a way to prevent us from storing/uploading too many dumps.
650 if [ ! "$(ls -A $storage_location)" ]; then
651 echo "Copying core file $core_file_name to $storage_location"
652 cp $core_file_name $storage_location
654 upload_core_file_to_dumpling $core_file_name
658 function inspect_and_delete_core_files {
659 # This function prints some basic information from core files in the current
660 # directory and deletes them immediately. Based on the state of the system, it may
661 # also upload a core file to the dumpling service.
662 # (see preserve_core_file).
664 # Depending on distro/configuration, the core files may either be named "core"
665 # or "core.<PID>" by default. We will read /proc/sys/kernel/core_uses_pid to
666 # determine which one it is.
667 # On OS X/macOS, we checked the kern.corefile value before enabling core dump
668 # generation, so we know it always includes the PID.
669 local core_name_uses_pid=0
670 if [[ (( -e /proc/sys/kernel/core_uses_pid ) && ( "1" == $(cat /proc/sys/kernel/core_uses_pid) ))
671 || ( "$(uname -s)" == "Darwin" ) ]]; then
675 if [ $core_name_uses_pid == "1" ]; then
676 # We don't know what the PID of the process was, so let's look at all core
677 # files whose name matches core.NUMBER
679 [[ $f =~ core.[0-9]+ ]] && print_info_from_core_file "$f" $CORE_ROOT/"corerun" && preserve_core_file "$f" && rm "$f"
681 elif [ -f core ]; then
682 print_info_from_core_file "core" $CORE_ROOT/"corerun"
683 preserve_core_file "core"
689 # This function runs in a background process. It should not echo anything, and should not use global variables.
691 local scriptFilePath=$1
692 local outputFilePath=$2
694 # Switch to directory where the script is
695 cd "$(dirname "$scriptFilePath")"
697 local scriptFileName=$(basename "$scriptFilePath")
698 local outputFileName=$(basename "$outputFilePath")
700 if [ "$limitedCoreDumps" == "ON" ]; then
701 set_up_core_dump_generation
704 "./$scriptFileName" >"$outputFileName" 2>&1
705 local testScriptExitCode=$?
707 # We will try to print some information from generated core dumps if a debugger
708 # is available, and possibly store a dump in a non-transient location.
709 if [ "$limitedCoreDumps" == "ON" ]; then
710 inspect_and_delete_core_files
713 return $testScriptExitCode
716 # Variables for running tests in the background
717 if [ `uname` = "NetBSD" ]; then
718 NumProc=$(getconf NPROCESSORS_ONLN)
720 NumProc=$(getconf _NPROCESSORS_ONLN)
722 ((maxProcesses = $NumProc * 3 / 2)) # long tests delay process creation, use a few more processors
724 ((nextProcessIndex = 0))
726 declare -a scriptFilePaths
727 declare -a outputFilePaths
728 declare -a processIds
729 declare -a testStartTimes
731 function finish_test {
732 wait ${processIds[$nextProcessIndex]}
733 local testScriptExitCode=$?
736 local scriptFilePath=${scriptFilePaths[$nextProcessIndex]}
737 local outputFilePath=${outputFilePaths[$nextProcessIndex]}
738 local scriptFileName=$(basename "$scriptFilePath")
741 local testRunningTime=
744 if ((verbose == 1)); then
745 header=$(printf "[%4d]" $countTotalTests)
748 if [ "$showTime" == "ON" ]; then
749 testEndTime=$(date +%s)
750 testRunningTime=$(( $testEndTime - ${testStartTimes[$nextProcessIndex]} ))
751 header=$header$(printf "[%4ds]" $testRunningTime)
754 local xunitTestResult
755 case $testScriptExitCode in
757 let countPassedTests++
758 xunitTestResult='Pass'
759 if ((verbose == 1 || runFailingTestsOnly == 1)); then
760 echo "PASSED - ${header}${scriptFilePath}"
762 echo " - ${header}${scriptFilePath}"
766 let countSkippedTests++
767 xunitTestResult='Skip'
768 echo "SKIPPED - ${header}${scriptFilePath}"
771 let countFailedTests++
772 xunitTestResult='Fail'
773 echo "FAILED - ${header}${scriptFilePath}"
776 let countTotalTests++
778 if ((verbose == 1 || testScriptExitCode != 0)); then
779 while IFS='' read -r line || [ -n "$line" ]; do
781 done <"$outputFilePath"
784 xunit_output_add_test "$scriptFilePath" "$outputFilePath" "$xunitTestResult" "$testScriptExitCode"
787 function finish_remaining_tests {
788 # Finish the remaining tests in the order in which they were started
789 if ((nextProcessIndex >= processCount)); then
790 ((nextProcessIndex = 0))
792 while ((processCount > 0)); do
794 ((nextProcessIndex = (nextProcessIndex + 1) % maxProcesses))
796 ((nextProcessIndex = 0))
800 local scriptFilePath=$1
801 local scriptFileDir=$(dirname "$scriptFilePath")
803 test "$verbose" == 1 && echo "Preparing $scriptFilePath"
805 if [ ! "$noLFConversion" == "ON" ]; then
806 # Convert DOS line endings to Unix if needed
807 perl -pi -e 's/\r\n|\n|\r/\n/g' "$scriptFilePath"
810 # Add executable file mode bit if needed
811 chmod +x "$scriptFilePath"
813 #remove any NI and Locks
814 rm -f $scriptFileDir/*.ni.*
815 rm -rf $scriptFileDir/lock
818 function start_test {
819 local scriptFilePath=$1
820 if ((runFailingTestsOnly == 1)) && ! is_failing_test "$scriptFilePath"; then
824 # Skip any test that's not in the current playlist, if a playlist was
826 if [ -n "$playlistFile" ] && ! is_playlist_test "$scriptFilePath"; then
830 if ((nextProcessIndex < processCount)); then
834 scriptFilePaths[$nextProcessIndex]=$scriptFilePath
835 local scriptFileName=$(basename "$scriptFilePath")
836 local outputFilePath=$(dirname "$scriptFilePath")/${scriptFileName}.out
837 outputFilePaths[$nextProcessIndex]=$outputFilePath
839 if [ "$showTime" == "ON" ]; then
840 testStartTimes[$nextProcessIndex]=$(date +%s)
843 test "$verbose" == 1 && echo "Starting $scriptFilePath"
844 if is_unsupported_test "$scriptFilePath"; then
845 skip_unsupported_test "$scriptFilePath" "$outputFilePath" &
846 elif ((runFailingTestsOnly == 0)) && is_failing_test "$scriptFilePath"; then
847 skip_failing_test "$scriptFilePath" "$outputFilePath" &
849 run_test "$scriptFilePath" "$outputFilePath" &
851 processIds[$nextProcessIndex]=$!
853 ((nextProcessIndex = (nextProcessIndex + 1) % maxProcesses))
857 # Get a list of directories in which to scan for tests by reading the
858 # specified file line by line.
859 function set_test_directories {
860 local errorSource='set_test_directories'
862 local listFileName=$1
864 if [ ! -f "$listFileName" ]
866 exit_with_error "$errorSource" "Test directories file not found at $listFileName"
868 testDirectories=($(read_array "$listFileName"))
871 function run_tests_in_directory {
874 # Recursively search through directories for .sh files to prepare them.
875 # Note: This needs to occur before any test runs as some of the .sh files
876 # depend on other .sh files
877 for scriptFilePath in $(find "$testDir" -type f -iname '*.sh' | sort)
879 prep_test "${scriptFilePath:2}"
881 echo "The tests have been prepared"
882 # Recursively search through directories for .sh files to run.
883 for scriptFilePath in $(find "$testDir" -type f -iname '*.sh' | sort)
885 start_test "${scriptFilePath:2}"
889 function coreclr_code_coverage {
890 local coverageDir="$coverageOutputDir/Coverage"
891 local toolsDir="$coverageOutputDir/Coverage/tools"
892 local reportsDir="$coverageOutputDir/Coverage/reports"
893 local packageName="unix-code-coverage-tools.1.0.0.nupkg"
896 mkdir -p $coverageDir
899 pushd $toolsDir > /dev/null
901 echo "Pulling down code coverage tools"
902 wget -q https://www.myget.org/F/dotnet-buildtools/api/v2/package/unix-code-coverage-tools/1.0.0 -O $packageName
903 echo "Unzipping to $toolsDir"
904 unzip -q -o $packageName
908 chmod a+rwx ./$OSName/llvm-cov
911 echo "Generating coreclr code coverage reports at $reportsDir/coreclr.html"
912 echo "./gcovr $coreClrObjs --gcov-executable=$toolsDir/$OS/llvm-cov -r $coreClrSrc --html --html-details -o $reportsDir/coreclr.html"
914 ./gcovr $coreClrObjs --gcov-executable=$toolsDir/$OSName/llvm-cov -r $coreClrSrc --html --html-details -o $reportsDir/coreclr.html
920 function check_cpu_architecture {
921 local CPUName=$(uname -m)
938 echo "Unknown CPU $CPUName detected, configuring as if for x64"
946 ARCH=$(check_cpu_architecture)
947 echo "Running on CPU- $ARCH"
949 # Exit code constants
950 readonly EXIT_CODE_SUCCESS=0 # Script ran normally.
951 readonly EXIT_CODE_EXCEPTION=1 # Script exited because something exceptional happened (e.g. bad arguments, Ctrl-C interrupt).
952 readonly EXIT_CODE_TEST_FAILURE=2 # Script completed successfully, but one or more tests failed.
973 ((disableEventLogging = 0))
987 exit $EXIT_CODE_SUCCESS
996 export COMPlus_JitStress=${i#*=}
999 export COMPlus_JitStressRegs=${i#*=}
1002 export COMPlus_JITMinOpts=1
1005 export COMPlus_ForceRelocs=1
1008 export ILLINK=${i#*=}
1015 ((ilasmroundtrip = 1))
1020 --testNativeBinDir=*)
1021 testNativeBinDir=${i#*=}
1024 coreOverlayDir=${i#*=}
1027 coreClrBinDir=${i#*=}
1033 coreFxBinDir=${i#*=}
1036 testDirectories[${#testDirectories[@]}]=${i#*=}
1039 set_test_directories "${i#*=}"
1041 --runFailingTestsOnly)
1042 ((runFailingTestsOnly = 1))
1044 --disableEventLogging)
1045 ((disableEventLogging = 1))
1048 export RunCrossGen=1
1051 ((maxProcesses = 1))
1063 playlistFile=${i#*=}
1074 --coverage-output-dir=*)
1075 coverageOutputDir=${i#*=}
1081 export COMPlus_GCStress=${i#*=}
1089 --build-overlay-only)
1092 --limitedDumpGeneration)
1095 --xunitOutputPath=*)
1096 xunitOutputPath=${i#*=}
1099 echo "Unknown switch: $i"
1101 exit $EXIT_CODE_SUCCESS
1106 if [ -n "$coreOverlayDir" ] && [ "$buildOverlayOnly" == "ON" ]; then
1107 echo "Can not use \'--coreOverlayDir=<path>\' and \'--build-overlay-only\' at the same time."
1108 exit $EXIT_CODE_EXCEPTION
1111 if ((disableEventLogging == 0)); then
1112 export COMPlus_EnableEventLog=1
1115 export CORECLR_SERVER_GC="$serverGC"
1117 if [ -z "$testRootDir" ]; then
1118 echo "--testRootDir is required."
1120 exit $EXIT_CODE_EXCEPTION
1122 if [ ! -d "$testRootDir" ]; then
1123 echo "Directory specified by --testRootDir does not exist: $testRootDir"
1124 exit $EXIT_CODE_EXCEPTION
1127 # Copy native interop test libraries over to the mscorlib path in
1128 # order for interop tests to run on linux.
1129 if [ -z "$mscorlibDir" ]; then
1130 mscorlibDir=$coreClrBinDir
1133 if [ ! -z "$longgc" ]; then
1134 echo "Running Long GC tests"
1135 export RunningLongGCTests=1
1138 if [ ! -z "$gcsimulator" ]; then
1139 echo "Running GC simulator tests"
1140 export RunningGCSimulatorTests=1
1143 if [[ ! "$jitdisasm" -eq 0 ]]; then
1144 echo "Running jit disasm"
1145 export RunningJitDisasm=1
1148 if [ ! -z "$ilasmroundtrip" ]; then
1149 echo "Running Ilasm round trip"
1150 export RunningIlasmRoundTrip=1
1153 # If this is a coverage run, make sure the appropriate args have been passed
1154 if [ "$CoreClrCoverage" == "ON" ]
1156 echo "Code coverage is enabled for this run"
1158 if [ ! "$OSName" == "Darwin" ] && [ ! "$OSName" == "Linux" ]
1160 echo "Code Coverage not supported on $OS"
1164 if [ -z "$coreClrObjs" ]
1166 echo "Coreclr obj files are required to generate code coverage reports"
1167 echo "Coreclr obj files root path can be passed using '--coreclr-obj' argument"
1171 if [ -z "$coreClrSrc" ]
1173 echo "Coreclr src files are required to generate code coverage reports"
1174 echo "Coreclr src files root path can be passed using '--coreclr-src' argument"
1178 if [ -z "$coverageOutputDir" ]
1180 echo "Output directory for coverage results must be specified"
1181 echo "Output path can be specified '--coverage-output-dir' argument"
1188 precompile_overlay_assemblies
1190 if [ "$buildOverlayOnly" == "ON" ];
1192 echo "Build overlay directory \'$coreOverlayDir\' complete."
1196 if [ -n "$playlistFile" ]
1198 # Use a playlist file exclusively, if it was provided
1199 echo "Executing playlist $playlistFile"
1202 load_unsupported_tests
1206 export __TestEnv=$testEnv
1210 dumplingsListPath="$testRootDir/dumplings.txt"
1212 # clean up any existing dumpling remnants from previous runs.
1213 rm -f "$dumplingsListPath"
1214 find $testRootDir -type f -name "local_dumplings.txt" -exec rm {} \;
1216 time_start=$(date +"%s")
1217 if [ -z "$testDirectories" ]
1219 # No test directories were specified, so run everything in the current
1220 # directory and its subdirectories.
1221 run_tests_in_directory "."
1223 # Otherwise, run all the tests in each specified test directory.
1224 for testDir in "${testDirectories[@]}"
1226 if [ ! -d "$testDir" ]; then
1227 echo "Test directory does not exist: $testDir"
1229 run_tests_in_directory "./$testDir"
1233 finish_remaining_tests
1237 find $testRootDir -type f -name "local_dumplings.txt" -exec cat {} \; > $dumplingsListPath
1239 if [ -s $dumplingsListPath ]; then
1240 cat $dumplingsListPath
1242 rm $dumplingsListPath
1245 time_end=$(date +"%s")
1246 time_diff=$(($time_end-$time_start))
1247 echo "$(($time_diff / 60)) minutes and $(($time_diff % 60)) seconds taken to run CoreCLR tests."
1251 if [ "$CoreClrCoverage" == "ON" ]
1253 coreclr_code_coverage
1256 if ((countFailedTests > 0)); then
1257 exit $EXIT_CODE_TEST_FAILURE
1260 exit $EXIT_CODE_SUCCESS