Moving the Sse max/min tests to use the template.
[platform/upstream/coreclr.git] / tests / runtest.sh
1 #!/usr/bin/env bash
2
3 function print_usage {
4     echo ''
5     echo 'CoreCLR test runner script.'
6     echo ''
7     echo 'Typical command line:'
8     echo ''
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 '    --coreOverlayDir="coreclr/bin/tests/Linux.x64.Debug/Tests/Core_Root"'
13     echo '    --copyNativeTestBin'
14     echo ''
15     echo 'Required arguments:'
16     echo '  --testRootDir=<path>             : Root directory of the test build (e.g. coreclr/bin/tests/Windows_NT.x64.Debug).'
17     echo '  --testNativeBinDir=<path>        : Directory of the native CoreCLR test build (e.g. coreclr/bin/obj/Linux.x64.Debug/tests).'
18     echo '  (Also required: Either --coreOverlayDir, or all of the switches --coreOverlayDir overrides)'
19     echo ''
20     echo 'Optional arguments:'
21     echo '  --coreOverlayDir=<path>          : Directory containing core binaries and test dependencies. If not specified, the'
22     echo '                                     default is testRootDir/Tests/coreoverlay. This switch overrides --coreClrBinDir,'
23     echo '                                     --mscorlibDir, and --coreFxBinDir.'
24     echo '  --coreClrBinDir=<path>           : Directory of the CoreCLR build (e.g. coreclr/bin/Product/Linux.x64.Debug).'
25     echo '  --mscorlibDir=<path>             : Directory containing the built mscorlib.dll. If not specified, it is expected to be'
26     echo '                                       in the directory specified by --coreClrBinDir.'
27     echo '  --coreFxBinDir="<path>"          : Directory with CoreFX build outputs'
28     echo '                                     (e.g. "corefx/bin/runtime/netcoreapp-Linux-Debug-x64")'
29     echo '                                     If files with the same name are present in multiple directories, the first one wins.'
30     echo '  --testDir=<path>                 : Run tests only in the specified directory. The path is relative to the directory'
31     echo '                                     specified by --testRootDir. Multiple of this switch may be specified.'
32     echo '  --testDirFile=<path>             : Run tests only in the directories specified by the file at <path>. Paths are listed'
33     echo '                                     one line, relative to the directory specified by --testRootDir.'
34     echo '  --build-overlay-only             : Build coreoverlay only, and skip running tests.'
35     echo '  --runFailingTestsOnly            : Run only the tests that are disabled on this platform due to unexpected failures.'
36     echo '                                     Failing tests are listed in coreclr/tests/failingTestsOutsideWindows.txt, one per'
37     echo '                                     line, as paths to .sh files relative to the directory specified by --testRootDir.'
38     echo '  --disableEventLogging            : Disable the events logged by both VM and Managed Code'
39     echo '  --sequential                     : Run tests sequentially (default is to run in parallel).'
40     echo '  --playlist=<path>                : Run only the tests that are specified in the file at <path>, in the same format as'
41     echo '                                     runFailingTestsOnly'
42     echo '  -v, --verbose                    : Show output from each test.'
43     echo '  -h|--help                        : Show usage information.'
44     echo '  --useServerGC                    : Enable server GC for this test run'
45     echo '  --test-env                       : Script to set environment variables for tests'
46     echo '  --copyNativeTestBin              : Explicitly copy native test components into the test dir'
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 '  --gcname=<n>                     : Runs the tests with COMPlus_GCName=n'
56     echo '  --ilasmroundtrip                 : Runs ilasm round trip on the tests'
57     echo '    0: None                                1: GC on all allocs and '"'easy'"' places'
58     echo '    2: GC on transitions to preemptive GC  4: GC on every allowable JITed instr'
59     echo '    8: GC on every allowable NGEN instr   16: GC only on a unique stack trace'
60     echo '  --long-gc                        : Runs the long GC tests'
61     echo '  --gcsimulator                    : Runs the GCSimulator tests'
62     echo '  --tieredcompilation              : Runs the tests with COMPlus_EXPERIMENTAL_TieredCompilation=1'
63     echo '  --link <ILlink>                  : Runs the tests after linking via ILlink'
64     echo '  --show-time                      : Print execution sequence and running time for each test'
65     echo '  --no-lf-conversion               : Do not execute LF conversion before running test script'
66     echo '  --limitedDumpGeneration          : Enables the generation of a limited number of core dumps if test(s) crash, even if ulimit'
67     echo '                                     is zero when launching this script. This option is intended for use in CI.'
68     echo '  --xunitOutputPath=<path>         : Create xUnit XML report at the specifed path (default: <test root>/coreclrtests.xml)'
69     echo ''
70     echo 'Runtime Code Coverage options:'
71     echo '  --coreclr-coverage               : Optional argument to get coreclr code coverage reports'
72     echo '  --coreclr-objs=<path>            : Location of root of the object directory'
73     echo '                                     containing the linux/mac coreclr build'
74     echo '  --coreclr-src=<path>             : Location of root of the directory'
75     echo '                                     containing the coreclr source files'
76     echo '  --coverage-output-dir=<path>     : Directory where coverage output will be written to'
77     echo ''
78 }
79
80 function print_results {
81     echo ""
82     echo "======================="
83     echo "     Test Results"
84     echo "======================="
85     echo "# CoreCLR Bin Dir  : $coreClrBinDir"
86     echo "# Tests Discovered : $countTotalTests"
87     echo "# Passed           : $countPassedTests"
88     echo "# Failed           : $countFailedTests"
89     echo "# Skipped          : $countSkippedTests"
90     echo "======================="
91 }
92
93 # Initialize counters for bookkeeping.
94 countTotalTests=0
95 countPassedTests=0
96 countFailedTests=0
97 countSkippedTests=0
98
99 # Variables for xUnit-style XML output. XML format: https://xunit.github.io/docs/format-xml-v2.html
100 xunitOutputPath=
101 xunitTestOutputPath=
102
103 # libExtension determines extension for dynamic library files
104 # runtimeName determines where CoreFX Runtime files will be located
105 OSName=$(uname -s)
106 libExtension=
107 case $OSName in
108     Darwin)
109         libExtension="dylib"
110         ;;
111
112     Linux)
113         libExtension="so"
114         ;;
115
116     NetBSD)
117         libExtension="so"
118         ;;
119
120     *)
121         echo "Unsupported OS $OSName detected, configuring as if for Linux"
122         libExtension="so"
123         ;;
124 esac
125
126 function xunit_output_begin {
127     if [ -z "$xunitOutputPath" ]; then
128         xunitOutputPath=$testRootDir/coreclrtests.xml
129     fi
130     if ! [ -e $(basename "$xunitOutputPath") ]; then
131         xunitOutputPath=$testRootDir/coreclrtests.xml
132     fi
133     xunitTestOutputPath=${xunitOutputPath}.test
134     if [ -e "$xunitOutputPath" ]; then
135         rm -f -r "$xunitOutputPath"
136     fi
137     if [ -e "$xunitTestOutputPath" ]; then
138         rm -f -r "$xunitTestOutputPath"
139     fi
140 }
141
142 function xunit_output_add_test {
143     # <assemblies>
144     #   <assembly>
145     #     <collection>
146     #       <test .../> <!-- Write this element here -->
147
148     local scriptFilePath=$1
149     local outputFilePath=$2
150     local testResult=$3 # Pass, Fail, or Skip
151     local testScriptExitCode=$4
152     local testRunningTime=$5
153
154     local testPath=${scriptFilePath%.sh} # Remove trailing ".sh"
155     local testDir=$(dirname "$testPath")
156     local testName=$(basename "$testPath")
157
158     # Replace '/' with '.'
159     testPath=$(echo "$testPath" | tr / .)
160     testDir=$(echo "$testDir" | tr / .)
161
162     local line
163
164     line="      "
165     line="${line}<test"
166     line="${line} name=\"${testPath}\""
167     line="${line} type=\"${testDir}\""
168     line="${line} method=\"${testName}\""
169     line="${line} result=\"${testResult}\""
170     if [ -n "$testRunningTime" ] && [ "$testResult" != "Skip" ]; then
171         line="${line} time=\"${testRunningTime}\""
172     fi
173
174     if [ "$testResult" == "Pass" ]; then
175         line="${line}/>"
176         echo "$line" >>"$xunitTestOutputPath"
177         return
178     fi
179
180     line="${line}>"
181     echo "$line" >>"$xunitTestOutputPath"
182
183     line="        "
184     if [ "$testResult" == "Skip" ]; then
185         line="${line}<reason><![CDATA[$(cat "$outputFilePath")]]></reason>"
186         echo "$line" >>"$xunitTestOutputPath"
187     else
188         line="${line}<failure exception-type=\"Exit code: ${testScriptExitCode}\">"
189         echo "$line" >>"$xunitTestOutputPath"
190
191         line="          "
192         line="${line}<message>"
193         echo "$line" >>"$xunitTestOutputPath"
194         line="            "
195         line="${line}<![CDATA["
196         echo "$line" >>"$xunitTestOutputPath"
197         cat "$outputFilePath" >>"$xunitTestOutputPath"
198         line="            "
199         line="${line}]]>"
200         echo "$line" >>"$xunitTestOutputPath"
201         line="          "
202         line="${line}</message>"
203         echo "$line" >>"$xunitTestOutputPath"
204
205         line="        "
206         line="${line}</failure>"
207         echo "$line" >>"$xunitTestOutputPath"
208     fi
209
210     line="      "
211     line="${line}</test>"
212     echo "$line" >>"$xunitTestOutputPath"
213 }
214
215 function xunit_output_end {
216     local errorSource=$1
217     local errorMessage=$2
218
219     local errorCount
220     if [ -z "$errorSource" ]; then
221         ((errorCount = 0))
222     else
223         ((errorCount = 1))
224     fi
225
226     echo '<?xml version="1.0" encoding="utf-8"?>' >>"$xunitOutputPath"
227     echo '<assemblies>' >>"$xunitOutputPath"
228
229     local line
230
231     # <assembly ...>
232     line="  "
233     line="${line}<assembly"
234     line="${line} name=\"CoreClrTestAssembly\""
235     line="${line} total=\"${countTotalTests}\""
236     line="${line} passed=\"${countPassedTests}\""
237     line="${line} failed=\"${countFailedTests}\""
238     line="${line} skipped=\"${countSkippedTests}\""
239     line="${line} errors=\"${errorCount}\""
240     line="${line}>"
241     echo "$line" >>"$xunitOutputPath"
242
243     # <collection ...>
244     line="    "
245     line="${line}<collection"
246     line="${line} name=\"CoreClrTestCollection\""
247     line="${line} total=\"${countTotalTests}\""
248     line="${line} passed=\"${countPassedTests}\""
249     line="${line} failed=\"${countFailedTests}\""
250     line="${line} skipped=\"${countSkippedTests}\""
251     line="${line}>"
252     echo "$line" >>"$xunitOutputPath"
253
254     # <test .../> <test .../> ...
255     if [ -f "$xunitTestOutputPath" ]; then
256         cat "$xunitTestOutputPath" >>"$xunitOutputPath"
257         rm -f "$xunitTestOutputPath"
258     fi
259
260     # </collection>
261     line="    "
262     line="${line}</collection>"
263     echo "$line" >>"$xunitOutputPath"
264
265     if [ -n "$errorSource" ]; then
266         # <errors>
267         line="    "
268         line="${line}<errors>"
269         echo "$line" >>"$xunitOutputPath"
270
271         # <error ...>
272         line="      "
273         line="${line}<error"
274         line="${line} type=\"TestHarnessError\""
275         line="${line} name=\"${errorSource}\""
276         line="${line}>"
277         echo "$line" >>"$xunitOutputPath"
278
279         # <failure .../>
280         line="        "
281         line="${line}<failure>${errorMessage}</failure>"
282         echo "$line" >>"$xunitOutputPath"
283
284         # </error>
285         line="      "
286         line="${line}</error>"
287         echo "$line" >>"$xunitOutputPath"
288
289         # </errors>
290         line="    "
291         line="${line}</errors>"
292         echo "$line" >>"$xunitOutputPath"
293     fi
294
295     # </assembly>
296     line="  "
297     line="${line}</assembly>"
298     echo "$line" >>"$xunitOutputPath"
299
300     # </assemblies>
301     echo '</assemblies>' >>"$xunitOutputPath"
302 }
303
304 function exit_with_error {
305     local errorSource=$1
306     local errorMessage=$2
307     local printUsage=$3
308
309     if [ -z "$printUsage" ]; then
310         ((printUsage = 0))
311     fi
312
313     echo "$errorMessage"
314     xunit_output_end "$errorSource" "$errorMessage"
315     if ((printUsage != 0)); then
316         print_usage
317     fi
318     exit $EXIT_CODE_EXCEPTION
319 }
320
321 # Handle Ctrl-C. We will stop execution and print the results that
322 # we gathered so far.
323 function handle_ctrl_c {
324     local errorSource='handle_ctrl_c'
325
326     echo ""
327     echo "*** Stopping... ***"
328     print_results
329     exit_with_error "$errorSource" "Test run aborted by Ctrl+C."
330 }
331
332 # Register the Ctrl-C handler
333 trap handle_ctrl_c INT
334
335 function create_core_overlay {
336     local errorSource='create_core_overlay'
337     local printUsage=1
338
339     if [ -n "$coreOverlayDir" ]; then
340         export CORE_ROOT="$coreOverlayDir"
341
342         if [ -n "$copyNativeTestBin" ]; then
343             copy_test_native_bin_to_test_root $coreOverlayDir
344         fi
345
346         return
347     fi
348
349     # Check inputs to make sure we have enough information to create the core layout. $testRootDir/Tests/Core_Root should
350     # already exist and contain test dependencies that are not built.
351     local testDependenciesDir=$testRootDir/Tests/Core_Root
352     if [ ! -d "$testDependenciesDir" ]; then
353         exit_with_error "$errorSource" "Did not find the test dependencies directory: $testDependenciesDir"
354     fi
355     if [ -z "$coreClrBinDir" ]; then
356         exit_with_error "$errorSource" "One of --coreOverlayDir or --coreClrBinDir must be specified." "$printUsage"
357     fi
358     if [ ! -d "$coreClrBinDir" ]; then
359         exit_with_error "$errorSource" "Directory specified by --coreClrBinDir does not exist: $coreClrBinDir"
360     fi
361     if [ -z "$coreFxBinDir" ]; then
362         exit_with_error "$errorSource" "One of --coreOverlayDir or --coreFxBinDir must be specified." "$printUsage"
363     fi
364
365     # Create the overlay
366     coreOverlayDir=$testRootDir/Tests/coreoverlay
367     export CORE_ROOT="$coreOverlayDir"
368     if [ -e "$coreOverlayDir" ]; then
369         rm -f -r "$coreOverlayDir"
370     fi
371     mkdir "$coreOverlayDir"
372
373     cp -f -v "$coreFxBinDir/"* "$coreOverlayDir/" 2>/dev/null
374     cp -f -p -v "$coreClrBinDir/"* "$coreOverlayDir/" 2>/dev/null
375     if [ -d "$mscorlibDir/bin" ]; then
376         cp -f -v "$mscorlibDir/bin/"* "$coreOverlayDir/" 2>/dev/null
377     fi
378     cp -f -v "$testDependenciesDir/"xunit* "$coreOverlayDir/" 2>/dev/null
379     cp -n -v "$testDependenciesDir/"* "$coreOverlayDir/" 2>/dev/null
380     if [ -f "$coreOverlayDir/mscorlib.ni.dll" ]; then
381         # Test dependencies come from a Windows build, and mscorlib.ni.dll would be the one from Windows
382         rm -f "$coreOverlayDir/mscorlib.ni.dll"
383     fi
384     if [ -f "$coreOverlayDir/System.Private.CoreLib.ni.dll" ]; then
385         # Test dependencies come from a Windows build, and System.Private.CoreLib.ni.dll would be the one from Windows
386         rm -f "$coreOverlayDir/System.Private.CoreLib.ni.dll"
387     fi
388     copy_test_native_bin_to_test_root $coreOverlayDir
389 }
390
391 declare -a skipCrossGenFiles
392
393 function is_skip_crossgen_test {
394     for skip in "${skipCrossGenFiles[@]}"; do
395         if [ "$1" == "$skip" ]; then
396             return 0
397         fi
398     done
399     return 1
400 }
401
402 function precompile_overlay_assemblies {
403     skipCrossGenFiles=($(read_array "$(dirname "$0")/skipCrossGenFiles.$ARCH.txt"))
404
405     if [ $doCrossgen == 1 ]; then
406         local overlayDir=$CORE_ROOT
407
408         filesToPrecompile=$(find -L $overlayDir -iname \*.dll -not -iname \*.ni.dll -not -iname \*-ms-win-\* -type f )
409         for fileToPrecompile in ${filesToPrecompile}
410         do
411             local filename=${fileToPrecompile}
412             if [ $jitdisasm == 1 ]; then
413                 $overlayDir/corerun $overlayDir/jit-dasm.dll --crossgen $overlayDir/crossgen --platform $overlayDir --output $testRootDir/dasm $filename
414                 local exitCode=$?
415                 if [ $exitCode != 0 ]; then
416                     echo Unable to generate dasm for $filename
417                 fi
418             else
419                 if is_skip_crossgen_test "$(basename $filename)"; then
420                     continue
421                 fi
422                 echo Precompiling $filename
423                 $overlayDir/crossgen /Platform_Assemblies_Paths $overlayDir $filename 1> $filename.stdout 2>$filename.stderr
424                 local exitCode=$?
425                 if [[ $exitCode != 0 ]]; then
426                     if grep -q -e '0x80131018' $filename.stderr; then
427                         printf "\n\t$filename is not a managed assembly.\n\n"
428                     else
429                         echo Unable to precompile $filename.
430                         cat $filename.stdout
431                         cat $filename.stderr
432                         exit $exitCode
433                     fi
434                 else
435                     rm $filename.{stdout,stderr}
436                 fi
437             fi
438         done
439     else
440         echo Skipping crossgen of FX assemblies.
441     fi
442 }
443
444 function copy_test_native_bin_to_test_root {
445     local errorSource='copy_test_native_bin_to_test_root'
446     local coreRootDir=$1
447
448     if [ -z "$testNativeBinDir" ]; then
449         exit_with_error "$errorSource" "--testNativeBinDir is required."
450     fi
451     testNativeBinDir=$testNativeBinDir/src
452     if [ ! -d "$testNativeBinDir" ]; then
453         exit_with_error "$errorSource" "Directory specified by --testNativeBinDir does not exist: $testNativeBinDir"
454     fi
455
456     # Copy native test components from the native test build into the respective test directory in the test root directory
457     find "$testNativeBinDir" -type f -iname "*.$libExtension" |
458         while IFS='' read -r filePath || [ -n "$filePath" ]; do
459             local dirPath=$(dirname "$filePath")
460             cp -f "$filePath" "$coreRootDir"
461         done
462 }
463
464 # Variables for unsupported and failing tests
465 declare -a unsupportedTests
466 declare -a failingTests
467 declare -a playlistTests
468 ((runFailingTestsOnly = 0))
469
470 # Get an array of items by reading the specified file line by line.
471 function read_array {
472     local theArray=()
473
474     # bash in Mac OS X doesn't support 'readarray', so using alternate way instead.
475     # readarray -t theArray < "$1"
476     while IFS='' read -r line || [ -n "$line" ]; do
477         theArray[${#theArray[@]}]=$line
478     done < "$1"
479     echo ${theArray[@]}
480 }
481
482 function load_unsupported_tests {
483     # Load the list of tests that are not supported on this platform. These tests are disabled (skipped) permanently.
484     unsupportedTests=($(read_array "$(dirname "$0")/testsUnsupportedOutsideWindows.txt"))
485     if [ "$ARCH" == "arm" ]; then
486         unsupportedTests+=($(read_array "$(dirname "$0")/testsUnsupportedOnARM32.txt"))
487     fi
488 }
489
490 function load_failing_tests {
491     # Load the list of tests that fail on this platform. These tests are disabled (skipped) temporarily, pending investigation.
492     failingTests=($(read_array "$(dirname "$0")/testsFailingOutsideWindows.txt"))
493    
494     if [ "$ARCH" == "arm64" ]; then
495         failingTests+=($(read_array "$(dirname "$0")/testsFailingOnArm64.txt"))
496     fi
497 }
498
499 function load_playlist_tests {
500     # Load the list of tests that are enabled as a part of this test playlist.
501     playlistTests=($(read_array "${playlistFile}"))
502 }
503
504 function is_unsupported_test {
505     for unsupportedTest in "${unsupportedTests[@]}"; do
506         if [ "$1" == "$unsupportedTest" ]; then
507             return 0
508         fi
509     done
510     return 1
511 }
512
513 function is_failing_test {
514     for failingTest in "${failingTests[@]}"; do
515         if [ "$1" == "$failingTest" ]; then
516             return 0
517         fi
518     done
519     return 1
520 }
521
522 function is_playlist_test {
523     for playlistTest in "${playlistTests[@]}"; do
524         if [ "$1" == "$playlistTest" ]; then
525             return 0
526         fi
527     done
528     return 1
529 }
530
531 function skip_unsupported_test {
532     # This function runs in a background process. It should not echo anything, and should not use global variables. This
533     # function is analogous to run_test, and causes the test to be skipped with the message below.
534
535     local scriptFilePath=$1
536     local outputFilePath=$2
537
538     echo "Not supported on this platform." >"$outputFilePath"
539     return 2 # skip the test
540 }
541
542 function skip_failing_test {
543     # This function runs in a background process. It should not echo anything, and should not use global variables. This
544     # function is analogous to run_test, and causes the test to be skipped with the message below.
545
546     local scriptFilePath=$1
547     local outputFilePath=$2
548
549     echo "Temporarily disabled on this platform due to unexpected failures." >"$outputFilePath"
550     return 2 # skip the test
551 }
552
553 function skip_non_playlist_test {
554     # This function runs in a background process. It should not echo anything, and should not use global variables. This
555     # function is analogous to run_test, and causes the test to be skipped with the message below.
556
557     local scriptFilePath=$1
558     local outputFilePath=$2
559
560     echo "Test is not included in the running playlist." >"$outputFilePath"
561     return 2 # skip the test
562 }
563
564 function set_up_core_dump_generation {
565     # We will only enable dump generation here if we're on Mac or Linux
566     if [[ ! ( "$(uname -s)" == "Darwin" || "$(uname -s)" == "Linux" ) ]]; then
567         return
568     fi
569
570     # We won't enable dump generation on OS X/macOS if the machine hasn't been
571     # configured with the kern.corefile pattern we expect.
572     if [[ ( "$(uname -s)" == "Darwin" && "$(sysctl -n kern.corefile)" != "core.%P" ) ]]; then
573         echo "WARNING: Core dump generation not being enabled due to unexpected kern.corefile value."
574         return
575     fi
576
577     # Allow dump generation
578     ulimit -c unlimited
579
580     if [ "$(uname -s)" == "Linux" ]; then
581         if [ -e /proc/self/coredump_filter ]; then
582             # Include memory in private and shared file-backed mappings in the dump.
583             # This ensures that we can see disassembly from our shared libraries when
584             # inspecting the contents of the dump. See 'man core' for details.
585             echo 0x3F > /proc/self/coredump_filter
586         fi
587     fi
588 }
589
590 function print_info_from_core_file {
591
592     #### temporary
593     if [ "$ARCH" == "arm64" ]; then
594         echo "Not inspecting core dumps on arm64 at the moment."
595         return
596     fi
597     ####
598
599     local core_file_name=$1
600     local executable_name=$2
601
602     if ! [ -e $executable_name ]; then
603         echo "Unable to find executable $executable_name"
604         return
605     elif ! [ -e $core_file_name ]; then
606         echo "Unable to find core file $core_file_name"
607         return
608     fi
609
610     # Use LLDB to inspect the core dump on Mac, and GDB everywhere else.
611     if [[ "$OSName" == "Darwin" ]]; then
612         hash lldb 2>/dev/null || { echo >&2 "LLDB was not found. Unable to print core file."; return; }
613
614         echo "Printing info from core file $core_file_name"
615         lldb -c $core_file_name -b -o 'bt'
616     else
617         # Use GDB to print the backtrace from the core file.
618         hash gdb 2>/dev/null || { echo >&2 "GDB was not found. Unable to print core file."; return; }
619
620         echo "Printing info from core file $core_file_name"
621         gdb --batch -ex "thread apply all bt full" -ex "quit" $executable_name $core_file_name
622     fi
623 }
624
625 function download_dumpling_script {
626     echo "Downloading latest version of dumpling script."
627     wget "https://dumpling.azurewebsites.net/api/client/dumpling.py"
628
629     local dumpling_script="dumpling.py"
630     chmod +x $dumpling_script
631 }
632
633 function upload_core_file_to_dumpling {
634     local core_file_name=$1
635     local dumpling_script="dumpling.py"
636     local dumpling_file="local_dumplings.txt"
637
638     # dumpling requires that the file exist before appending.
639     touch ./$dumpling_file
640
641     if [ ! -x $dumpling_script ]; then
642         download_dumpling_script
643     fi
644
645     if [ ! -x $dumpling_script ]; then
646         echo "Failed to download dumpling script. Dump cannot be uploaded."
647         return
648     fi
649
650     echo "Uploading $core_file_name to dumpling service."
651
652     local paths_to_add=""
653     if [ -d "$coreClrBinDir" ]; then
654         echo "Uploading CoreCLR binaries with dump."
655         paths_to_add=$coreClrBinDir
656     fi
657
658     # Ensure the script has Unix line endings
659     perl -pi -e 's/\r\n|\n|\r/\n/g' "$dumpling_script"
660
661     # The output from this will include a unique ID for this dump.
662     ./$dumpling_script "upload" "--dumppath" "$core_file_name" "--incpaths" $paths_to_add "--properties" "Project=CoreCLR" "--squelch" | tee -a $dumpling_file
663 }
664
665 function preserve_core_file {
666     local core_file_name=$1
667     local storage_location="/tmp/coredumps_coreclr"
668
669     # Create the directory (this shouldn't fail even if it already exists).
670     mkdir -p $storage_location
671
672     # Only preserve the dump if the directory is empty. Otherwise, do nothing.
673     # This is a way to prevent us from storing/uploading too many dumps.
674     if [ ! "$(ls -A $storage_location)" ]; then
675         echo "Copying core file $core_file_name to $storage_location"
676         cp $core_file_name $storage_location
677
678         upload_core_file_to_dumpling $core_file_name
679     fi
680 }
681
682 function inspect_and_delete_core_files {
683     # This function prints some basic information from core files in the current
684     # directory and deletes them immediately. Based on the state of the system, it may
685     # also upload a core file to the dumpling service.
686     # (see preserve_core_file).
687     
688     # Depending on distro/configuration, the core files may either be named "core"
689     # or "core.<PID>" by default. We will read /proc/sys/kernel/core_uses_pid to 
690     # determine which one it is.
691     # On OS X/macOS, we checked the kern.corefile value before enabling core dump
692     # generation, so we know it always includes the PID.
693     local core_name_uses_pid=0
694     if [[ (( -e /proc/sys/kernel/core_uses_pid ) && ( "1" == $(cat /proc/sys/kernel/core_uses_pid) )) 
695           || ( "$(uname -s)" == "Darwin" ) ]]; then
696         core_name_uses_pid=1
697     fi
698
699     if [ $core_name_uses_pid == "1" ]; then
700         # We don't know what the PID of the process was, so let's look at all core
701         # files whose name matches core.NUMBER
702         for f in core.*; do
703             [[ $f =~ core.[0-9]+ ]] && print_info_from_core_file "$f" $CORE_ROOT/"corerun" && preserve_core_file "$f" && rm "$f"
704         done
705     elif [ -f core ]; then
706         print_info_from_core_file "core" $CORE_ROOT/"corerun"
707         preserve_core_file "core"
708         rm "core"
709     fi
710 }
711
712 function run_test {
713     # This function runs in a background process. It should not echo anything, and should not use global variables.
714
715     local scriptFilePath=$1
716     local outputFilePath=$2
717
718     # Switch to directory where the script is
719     cd "$(dirname "$scriptFilePath")"
720
721     local scriptFileName=$(basename "$scriptFilePath")
722     local outputFileName=$(basename "$outputFilePath")
723
724     if [ "$limitedCoreDumps" == "ON" ]; then
725         set_up_core_dump_generation
726     fi
727
728     "./$scriptFileName" >"$outputFileName" 2>&1
729     local testScriptExitCode=$?
730
731     # We will try to print some information from generated core dumps if a debugger
732     # is available, and possibly store a dump in a non-transient location.
733     if [ "$limitedCoreDumps" == "ON" ]; then
734         inspect_and_delete_core_files
735     fi
736
737     return $testScriptExitCode
738 }
739
740 # Variables for running tests in the background
741 if [ `uname` = "NetBSD" ]; then
742     NumProc=$(getconf NPROCESSORS_ONLN)
743 elif [ `uname` = "Darwin" ]; then
744     NumProc=$(getconf _NPROCESSORS_ONLN)
745 else
746     if [ -x "$(command -v nproc)" ]; then
747         NumProc=$(nproc --all)
748     elif [ -x "$(command -v getconf)" ]; then
749         NumProc=$(getconf _NPROCESSORS_ONLN)
750     else
751         NumProc=1
752     fi
753 fi
754 ((maxProcesses = $NumProc * 3 / 2)) # long tests delay process creation, use a few more processors
755
756 ((processCount = 0))
757 declare -a scriptFilePaths
758 declare -a outputFilePaths
759 declare -a processIds
760 declare -a testStartTimes
761 waitProcessIndex=
762 pidNone=0
763
764 function waitany {
765     local pid
766     local exitcode
767     while true; do
768         for (( i=0; i<$maxProcesses; i++ )); do
769             pid=${processIds[$i]}
770             if [ -z "$pid" ] || [ "$pid" == "$pidNone" ]; then
771                 continue
772             fi
773             if ! kill -0 $pid 2>/dev/null; then
774                 wait $pid
775                 exitcode=$?
776                 waitProcessIndex=$i
777                 processIds[$i]=$pidNone
778                 return $exitcode
779             fi
780         done
781         sleep 0.1
782     done
783 }
784
785 function get_available_process_index {
786     local pid
787     local i=0
788     for (( i=0; i<$maxProcesses; i++ )); do
789         pid=${processIds[$i]}
790         if [ -z "$pid" ] || [ "$pid" == "$pidNone" ]; then
791             break
792         fi
793     done
794     echo $i
795 }
796
797 function finish_test {
798     waitany
799     local testScriptExitCode=$?
800     local finishedProcessIndex=$waitProcessIndex
801     ((--processCount))
802
803     local scriptFilePath=${scriptFilePaths[$finishedProcessIndex]}
804     local outputFilePath=${outputFilePaths[$finishedProcessIndex]}
805     local scriptFileName=$(basename "$scriptFilePath")
806
807     local testEndTime=
808     local testRunningTime=
809     local header=
810
811     if ((verbose == 1)); then
812         header=$(printf "[%4d]" $countTotalTests)
813     fi
814
815     if [ "$showTime" == "ON" ]; then
816         testEndTime=$(date +%s)
817         testRunningTime=$(( $testEndTime - ${testStartTimes[$finishedProcessIndex]} ))
818         header=$header$(printf "[%4ds]" $testRunningTime)
819     fi
820
821     local xunitTestResult
822     case $testScriptExitCode in
823         0)
824             let countPassedTests++
825             xunitTestResult='Pass'
826             if ((verbose == 1 || runFailingTestsOnly == 1)); then
827                 echo "PASSED   - ${header}${scriptFilePath}"
828             else
829                 echo "         - ${header}${scriptFilePath}"
830             fi
831             ;;
832         2)
833             let countSkippedTests++
834             xunitTestResult='Skip'
835             echo "SKIPPED  - ${header}${scriptFilePath}"
836             ;;
837         *)
838             let countFailedTests++
839             xunitTestResult='Fail'
840             echo "FAILED   - ${header}${scriptFilePath}"
841             ;;
842     esac
843     let countTotalTests++
844
845     if ((verbose == 1 || testScriptExitCode != 0)); then
846         while IFS='' read -r line || [ -n "$line" ]; do
847             echo "               $line"
848         done <"$outputFilePath"
849     fi
850
851     xunit_output_add_test "$scriptFilePath" "$outputFilePath" "$xunitTestResult" "$testScriptExitCode" "$testRunningTime"
852 }
853
854 function finish_remaining_tests {
855     # Finish the remaining tests in the order in which they were started
856     while ((processCount > 0)); do
857         finish_test
858     done
859 }
860
861 function prep_test {
862     local scriptFilePath=$1
863     local scriptFileDir=$(dirname "$scriptFilePath")
864
865     test "$verbose" == 1 && echo "Preparing $scriptFilePath"
866
867     if [ ! "$noLFConversion" == "ON" ]; then
868         # Convert DOS line endings to Unix if needed
869         perl -pi -e 's/\r\n|\n|\r/\n/g' "$scriptFilePath"
870     fi
871         
872     # Add executable file mode bit if needed
873     chmod +x "$scriptFilePath"
874
875     #remove any NI and Locks
876     rm -f $scriptFileDir/*.ni.*
877     rm -rf $scriptFileDir/lock
878 }
879
880 function start_test {
881     local nextProcessIndex=$(get_available_process_index)
882     local scriptFilePath=$1
883     if ((runFailingTestsOnly == 1)) && ! is_failing_test "$scriptFilePath"; then
884         return
885     fi
886
887     # Skip any test that's not in the current playlist, if a playlist was
888     # given to us.
889     if [ -n "$playlistFile" ] && ! is_playlist_test "$scriptFilePath"; then
890         return
891     fi
892
893     if ((nextProcessIndex == maxProcesses)); then
894         finish_test
895         nextProcessIndex=$(get_available_process_index)
896     fi
897
898     scriptFilePaths[$nextProcessIndex]=$scriptFilePath
899     local scriptFileName=$(basename "$scriptFilePath")
900     local outputFilePath=$(dirname "$scriptFilePath")/${scriptFileName}.out
901     outputFilePaths[$nextProcessIndex]=$outputFilePath
902
903     if [ "$showTime" == "ON" ]; then
904         testStartTimes[$nextProcessIndex]=$(date +%s)
905     fi
906
907     test "$verbose" == 1 && echo "Starting $scriptFilePath"
908     if is_unsupported_test "$scriptFilePath"; then
909         skip_unsupported_test "$scriptFilePath" "$outputFilePath" &
910     elif ((runFailingTestsOnly == 0)) && is_failing_test "$scriptFilePath"; then
911         skip_failing_test "$scriptFilePath" "$outputFilePath" &
912     else
913         run_test "$scriptFilePath" "$outputFilePath" &
914     fi
915     processIds[$nextProcessIndex]=$!
916
917     ((++processCount))
918 }
919
920 # Get a list of directories in which to scan for tests by reading the
921 # specified file line by line.
922 function set_test_directories {
923     local errorSource='set_test_directories'
924
925     local listFileName=$1
926
927     if [ ! -f "$listFileName" ]
928     then
929         exit_with_error "$errorSource" "Test directories file not found at $listFileName"
930     fi
931     testDirectories=($(read_array "$listFileName"))
932 }
933
934 function run_tests_in_directory {
935     local testDir=$1
936
937     # Recursively search through directories for .sh files to prepare them.
938     # Note: This needs to occur before any test runs as some of the .sh files
939     # depend on other .sh files
940     for scriptFilePath in $(find "$testDir" -type f -iname '*.sh' | sort)
941     do
942         prep_test "${scriptFilePath:2}"
943     done
944     echo "The tests have been prepared"
945     # Recursively search through directories for .sh files to run.
946     for scriptFilePath in $(find "$testDir" -type f -iname '*.sh' | sort)
947     do
948         start_test "${scriptFilePath:2}"
949     done
950 }
951
952 function coreclr_code_coverage {
953     local coverageDir="$coverageOutputDir/Coverage"
954     local toolsDir="$coverageOutputDir/Coverage/tools"
955     local reportsDir="$coverageOutputDir/Coverage/reports"
956     local packageName="unix-code-coverage-tools.1.0.0.nupkg"
957
958     rm -rf $coverageDir
959     mkdir -p $coverageDir
960     mkdir -p $toolsDir
961     mkdir -p $reportsDir
962     pushd $toolsDir > /dev/null
963
964     echo "Pulling down code coverage tools"
965     wget -q https://www.myget.org/F/dotnet-buildtools/api/v2/package/unix-code-coverage-tools/1.0.0 -O $packageName
966     echo "Unzipping to $toolsDir"
967     unzip -q -o $packageName
968
969     # Invoke gcovr
970     chmod a+rwx ./gcovr
971     chmod a+rwx ./$OSName/llvm-cov
972
973     echo
974     echo "Generating coreclr code coverage reports at $reportsDir/coreclr.html"
975     echo "./gcovr $coreClrObjs --gcov-executable=$toolsDir/$OS/llvm-cov -r $coreClrSrc --html --html-details -o $reportsDir/coreclr.html"
976     echo
977     ./gcovr $coreClrObjs --gcov-executable=$toolsDir/$OSName/llvm-cov -r $coreClrSrc --html --html-details -o $reportsDir/coreclr.html
978     exitCode=$?
979     popd > /dev/null
980     exit $exitCode
981 }
982
983 function check_cpu_architecture {
984     local CPUName=$(uname -m)
985     local __arch=
986
987     case $CPUName in
988         i686)
989             __arch=x86
990             ;;
991         x86_64)
992             __arch=x64
993             ;;
994         armv7l)
995             __arch=arm
996             ;;
997         aarch64)
998             __arch=arm64
999             ;;
1000         *)
1001             echo "Unknown CPU $CPUName detected, configuring as if for x64"
1002             __arch=x64
1003             ;;
1004     esac
1005
1006     echo "$__arch"
1007 }
1008
1009 ARCH=$(check_cpu_architecture)
1010 echo "Running on  CPU- $ARCH"
1011
1012 # Exit code constants
1013 readonly EXIT_CODE_SUCCESS=0       # Script ran normally.
1014 readonly EXIT_CODE_EXCEPTION=1     # Script exited because something exceptional happened (e.g. bad arguments, Ctrl-C interrupt).
1015 readonly EXIT_CODE_TEST_FAILURE=2  # Script completed successfully, but one or more tests failed.
1016
1017 # Argument variables
1018 testRootDir=
1019 testNativeBinDir=
1020 coreOverlayDir=
1021 coreClrBinDir=
1022 mscorlibDir=
1023 coreFxBinDir=
1024 coreClrObjs=
1025 coreClrSrc=
1026 coverageOutputDir=
1027 testEnv=
1028 playlistFile=
1029 showTime=
1030 noLFConversion=
1031 buildOverlayOnly=
1032 gcsimulator=
1033 longgc=
1034 limitedCoreDumps=
1035 illinker=
1036 ((disableEventLogging = 0))
1037 ((serverGC = 0))
1038
1039 # Handle arguments
1040 verbose=0
1041 doCrossgen=0
1042 jitdisasm=0
1043 ilasmroundtrip=
1044
1045 for i in "$@"
1046 do
1047     case $i in
1048         -h|--help)
1049             print_usage
1050             exit $EXIT_CODE_SUCCESS
1051             ;;
1052         -v|--verbose)
1053             verbose=1
1054             ;;
1055         --crossgen)
1056             doCrossgen=1
1057             ;;
1058         --jitstress=*)
1059             export COMPlus_JitStress=${i#*=}
1060             ;;
1061         --jitstressregs=*)
1062             export COMPlus_JitStressRegs=${i#*=}
1063             ;;
1064         --jitminopts)
1065             export COMPlus_JITMinOpts=1
1066             ;;
1067         --copyNativeTestBin)
1068             export copyNativeTestBin=1
1069             ;;
1070         --jitforcerelocs)
1071             export COMPlus_ForceRelocs=1
1072             ;;
1073         --link=*)
1074             export ILLINK=${i#*=}
1075             export DoLink=true
1076             ;;
1077         --tieredcompilation)
1078             export COMPlus_EXPERIMENTAL_TieredCompilation=1
1079             ;;
1080         --jitdisasm)
1081             jitdisasm=1
1082             ;;
1083         --ilasmroundtrip)
1084             ((ilasmroundtrip = 1))
1085             ;;
1086         --testRootDir=*)
1087             testRootDir=${i#*=}
1088             ;;
1089         --testNativeBinDir=*)
1090             testNativeBinDir=${i#*=}
1091             ;;
1092         --coreOverlayDir=*)
1093             coreOverlayDir=${i#*=}
1094             ;;
1095         --coreClrBinDir=*)
1096             coreClrBinDir=${i#*=}
1097             ;;
1098         --mscorlibDir=*)
1099             mscorlibDir=${i#*=}
1100             ;;
1101         --coreFxBinDir=*)
1102             coreFxBinDir=${i#*=}
1103             ;;
1104         --testDir=*)
1105             testDirectories[${#testDirectories[@]}]=${i#*=}
1106             ;;
1107         --testDirFile=*)
1108             set_test_directories "${i#*=}"
1109             ;;
1110         --runFailingTestsOnly)
1111             ((runFailingTestsOnly = 1))
1112             ;;
1113         --disableEventLogging)
1114             ((disableEventLogging = 1))
1115             ;;
1116         --runcrossgentests)
1117             export RunCrossGen=1
1118             ;;
1119         --sequential)
1120             ((maxProcesses = 1))
1121             ;;
1122         --useServerGC)
1123             ((serverGC = 1))
1124             ;;
1125         --long-gc)
1126             ((longgc = 1))
1127             ;;
1128         --gcsimulator)
1129             ((gcsimulator = 1))
1130             ;;
1131         --playlist=*)
1132             playlistFile=${i#*=}
1133             ;;
1134         --coreclr-coverage)
1135             CoreClrCoverage=ON
1136             ;;
1137         --coreclr-objs=*)
1138             coreClrObjs=${i#*=}
1139             ;;
1140         --coreclr-src=*)
1141             coreClrSrc=${i#*=}
1142             ;;
1143         --coverage-output-dir=*)
1144             coverageOutputDir=${i#*=}
1145             ;;
1146         --test-env=*)
1147             testEnv=${i#*=}
1148             ;;            
1149         --gcstresslevel=*)
1150             export COMPlus_GCStress=${i#*=}
1151             ;;            
1152         --gcname=*)
1153             export COMPlus_GCName=${i#*=}
1154             ;;
1155         --show-time)
1156             showTime=ON
1157             ;;
1158         --no-lf-conversion)
1159             noLFConversion=ON
1160             ;;
1161         --build-overlay-only)
1162             buildOverlayOnly=ON
1163             ;;
1164         --limitedDumpGeneration)
1165             limitedCoreDumps=ON
1166             ;;
1167         --xunitOutputPath=*)
1168             xunitOutputPath=${i#*=}
1169             ;;
1170         *)
1171             echo "Unknown switch: $i"
1172             print_usage
1173             exit $EXIT_CODE_SUCCESS
1174             ;;
1175     esac
1176 done
1177
1178 if [ -n "$coreOverlayDir" ] && [ "$buildOverlayOnly" == "ON" ]; then
1179     echo "Can not use \'--coreOverlayDir=<path>\' and \'--build-overlay-only\' at the same time."
1180     exit $EXIT_CODE_EXCEPTION
1181 fi
1182
1183 if ((disableEventLogging == 0)); then
1184     export COMPlus_EnableEventLog=1
1185 fi
1186
1187 export CORECLR_SERVER_GC="$serverGC"
1188
1189 if [ -z "$testRootDir" ]; then
1190     echo "--testRootDir is required."
1191     print_usage
1192     exit $EXIT_CODE_EXCEPTION
1193 fi
1194 if [ ! -d "$testRootDir" ]; then
1195     echo "Directory specified by --testRootDir does not exist: $testRootDir"
1196     exit $EXIT_CODE_EXCEPTION
1197 fi
1198
1199 # Copy native interop test libraries over to the mscorlib path in
1200 # order for interop tests to run on linux.
1201 if [ -z "$mscorlibDir" ]; then
1202     mscorlibDir=$coreClrBinDir
1203 fi
1204
1205 if [ ! -z "$longgc" ]; then
1206     echo "Running Long GC tests"
1207     export RunningLongGCTests=1
1208 fi
1209
1210 if [ ! -z "$gcsimulator" ]; then
1211     echo "Running GC simulator tests"
1212     export RunningGCSimulatorTests=1
1213 fi
1214
1215 if [[ ! "$jitdisasm" -eq 0 ]]; then
1216     echo "Running jit disasm"
1217     export RunningJitDisasm=1
1218 fi
1219
1220 if [ ! -z "$ilasmroundtrip" ]; then
1221     echo "Running Ilasm round trip"
1222     export RunningIlasmRoundTrip=1
1223 fi
1224
1225 # If this is a coverage run, make sure the appropriate args have been passed
1226 if [ "$CoreClrCoverage" == "ON" ]
1227 then
1228     echo "Code coverage is enabled for this run"
1229     echo ""
1230     if [ ! "$OSName" == "Darwin" ] && [ ! "$OSName" == "Linux" ]
1231     then
1232         echo "Code Coverage not supported on $OS"
1233         exit 1
1234     fi
1235
1236     if [ -z "$coreClrObjs" ]
1237     then
1238         echo "Coreclr obj files are required to generate code coverage reports"
1239         echo "Coreclr obj files root path can be passed using '--coreclr-obj' argument"
1240         exit 1
1241     fi
1242
1243     if [ -z "$coreClrSrc" ]
1244     then
1245         echo "Coreclr src files are required to generate code coverage reports"
1246         echo "Coreclr src files root path can be passed using '--coreclr-src' argument"
1247         exit 1
1248     fi
1249
1250     if [ -z "$coverageOutputDir" ]
1251     then
1252         echo "Output directory for coverage results must be specified"
1253         echo "Output path can be specified '--coverage-output-dir' argument"
1254         exit 1
1255     fi
1256 fi
1257
1258 xunit_output_begin
1259 create_core_overlay
1260 precompile_overlay_assemblies
1261
1262 if [ "$buildOverlayOnly" == "ON" ];
1263 then
1264     echo "Build overlay directory '$coreOverlayDir' complete."
1265     exit 0
1266 fi
1267
1268 if [ -n "$playlistFile" ]
1269 then
1270     # Use a playlist file exclusively, if it was provided
1271     echo "Executing playlist $playlistFile"
1272     load_playlist_tests
1273 else
1274     load_unsupported_tests
1275     load_failing_tests
1276 fi
1277
1278 # Other architectures are not supported yet.
1279 if [ "$ARCH" == "x64" ]
1280 then
1281     scriptPath=$(dirname $0)
1282     ${scriptPath}/setup-stress-dependencies.sh --outputDir=$coreOverlayDir
1283 else
1284     if [ "$ARCH" != "arm64" ]
1285     then
1286         echo "Skip preparing for GC stress test. Dependent package is not supported on this architecture."
1287     fi
1288 fi
1289
1290 export __TestEnv=$testEnv
1291
1292 cd "$testRootDir"
1293
1294 dumplingsListPath="$testRootDir/dumplings.txt"
1295
1296 # clean up any existing dumpling remnants from previous runs.
1297 rm -f "$dumplingsListPath"
1298 find $testRootDir -type f -name "local_dumplings.txt" -exec rm {} \;
1299
1300 time_start=$(date +"%s")
1301 if [ -z "$testDirectories" ]
1302 then
1303     # No test directories were specified, so run everything in the current
1304     # directory and its subdirectories.
1305     run_tests_in_directory "."
1306 else
1307     # Otherwise, run all the tests in each specified test directory.
1308     for testDir in "${testDirectories[@]}"
1309     do
1310         if [ ! -d "$testDir" ]; then
1311             echo "Test directory does not exist: $testDir"
1312         else
1313             run_tests_in_directory "./$testDir"
1314         fi
1315     done
1316 fi
1317 finish_remaining_tests
1318
1319 print_results
1320
1321 find $testRootDir -type f -name "local_dumplings.txt" -exec cat {} \; > $dumplingsListPath
1322
1323 if [ -s $dumplingsListPath ]; then
1324     cat $dumplingsListPath
1325 else
1326     rm $dumplingsListPath
1327 fi
1328
1329 time_end=$(date +"%s")
1330 time_diff=$(($time_end-$time_start))
1331 echo "$(($time_diff / 60)) minutes and $(($time_diff % 60)) seconds taken to run CoreCLR tests."
1332
1333 xunit_output_end
1334
1335 if [ "$CoreClrCoverage" == "ON" ]
1336 then
1337     coreclr_code_coverage
1338 fi
1339
1340 if ((countFailedTests > 0)); then
1341     exit $EXIT_CODE_TEST_FAILURE
1342 fi
1343
1344 exit $EXIT_CODE_SUCCESS