summaryrefslogtreecommitdiff
path: root/tests/runtest.sh
blob: 09170947109dfe20b9c0acbc2953abf7ad3d579b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
#!/usr/bin/env bash

function print_usage {
    echo ''
    echo 'CoreCLR test runner script.'
    echo ''
    echo 'Typical command line:'
    echo ''
    echo 'coreclr/tests/runtest.sh <arch> <configurations>'
    echo ''
    echo 'Optional arguments:'
    echo '  --testRootDir=<path>             : Root directory of the test build (e.g. coreclr/bin/tests/Windows_NT.x64.Debug).'
    echo '  --testNativeBinDir=<path>        : Directory of the native CoreCLR test build (e.g. coreclr/bin/obj/Linux.x64.Debug/tests).'
    echo '  --coreOverlayDir=<path>          : Directory containing core binaries and test dependencies.'
    echo '  --coreClrBinDir=<path>           : Directory of the CoreCLR build (e.g. coreclr/bin/Product/Linux.x64.Debug).'
    echo '  --build-overlay-only             : Build coreoverlay only, and skip running tests.'
    echo '  --generateLayoutOnly             : Build Core_Root only and skip running tests'
    echo '  --generateLayout                 : Force generating layout, even if core_root is passed.'
    echo '  --disableEventLogging            : Disable the events logged by both VM and Managed Code'
    echo '  --sequential                     : Run tests sequentially (default is to run in parallel).'
    echo '  -v, --verbose                    : Show output from each test.'
    echo '  -h|--help                        : Show usage information.'
    echo '  --useServerGC                    : Enable server GC for this test run'
    echo '  --test-env                       : Script to set environment variables for tests'
    echo '  --crossgen                       : Precompiles the framework managed assemblies'
    echo '  --runcrossgentests               : Runs the ready to run tests' 
    echo '  --jitstress=<n>                  : Runs the tests with COMPlus_JitStress=n'
    echo '  --jitstressregs=<n>              : Runs the tests with COMPlus_JitStressRegs=n'
    echo '  --jitminopts                     : Runs the tests with COMPlus_JITMinOpts=1'
    echo '  --jitforcerelocs                 : Runs the tests with COMPlus_ForceRelocs=1'
    echo '  --jitdisasm                      : Runs jit-dasm on the tests'
    echo '  --gcstresslevel=<n>              : Runs the tests with COMPlus_GCStress=n'
    echo '  --gcname=<n>                     : Runs the tests with COMPlus_GCName=n'
    echo '  --ilasmroundtrip                 : Runs ilasm round trip on the tests'
    echo '    0: None                                1: GC on all allocs and '"'easy'"' places'
    echo '    2: GC on transitions to preemptive GC  4: GC on every allowable JITed instr'
    echo '    8: GC on every allowable NGEN instr   16: GC only on a unique stack trace'
    echo '  --long-gc                        : Runs the long GC tests'
    echo '  --gcsimulator                    : Runs the GCSimulator tests'
    echo '  --tieredcompilation              : Runs the tests with COMPlus_TieredCompilation=1'
    echo '  --link <ILlink>                  : Runs the tests after linking via ILlink'
    echo '  --xunitOutputPath=<path>         : Create xUnit XML report at the specifed path (default: <test root>/coreclrtests.xml)'
    echo '  --buildXUnitWrappers             : Force creating the xunit wrappers, this is useful if there have been changes to issues.targets'
    echo '  --printLastResultsOnly           : Print the results of the last run'
    echo ''
    echo 'CoreFX Test Options '
    echo '  --corefxtests                    : Runs CoreFX tests'
    echo '  --corefxtestsall                 : Runs all available CoreFX tests'
    echo '  --corefxtestlist=<path>          : Runs the CoreFX tests specified in the passed list'   
    echo '  --testHostDir=<path>             : Directory containing a built test host including core binaries, test dependencies' 
    echo '                                     and a dotnet executable'
}

function create_testhost
{
    if [ ! -d "$testHostDir" ]; then
        exit_with_error "$errorSource" "Did not find the test host directory: $testHostDir"
    fi

    # Initialize test variables
    local buildToolsDir=$coreClrSrc/Tools
    local dotnetExe=$buildToolsDir/dotnetcli/dotnet
    local coreClrSrcTestDir=$coreClrSrc/tests
    
    if [ -z $coreClrBinDir ]; then
        local coreClrBinDir=${coreClrSrc}/bin
        export __CoreFXTestDir=${coreClrSrc}/bin/tests/CoreFX
    else
        export __CoreFXTestDir=${coreClrBinDir}/tests/CoreFX    
    fi

    local coreFXTestSetupUtilityName=CoreFX.TestUtils.TestFileSetup
    local coreFXTestSetupUtility="${coreClrSrcTestDir}/src/Common/CoreFX/TestFileSetup/${coreFXTestSetupUtilityName}.csproj"
    local coreFXTestSetupUtilityOutputPath=${__CoreFXTestDir}/TestUtilities
    local coreFXTestBinariesOutputPath=${__CoreFXTestDir}/tests_downloaded
    
    if [ -z $CoreFXTestList]; then
        local CoreFXTestList="${coreClrSrcTestDir}/CoreFX/CoreFX.issues.json"
    fi

    case "${OSName}" in
        # Check if we're running under OSX        
        Darwin)
            local coreFXTestRemoteURL=$(<${coreClrSrcTestDir}/CoreFX/CoreFXTestListURL_OSX.txt)
            local coreFXTestExclusionDef=nonosxtests
        ;;        
        # Default to Linux        
        *)
            local coreFXTestRemoteURL=$(<${coreClrSrcTestDir}/CoreFX/CoreFXTestListURL_Linux.txt)
            local coreFXTestExclusionDef=nonlinuxtests
        ;;
    esac

    local coreFXTestExecutable=xunit.console.netcore.exe
    local coreFXLogDir=${coreClrBinDir}/Logs/CoreFX/
    local coreFXTestExecutableArgs="--notrait category=nonnetcoreapptests --notrait category=${coreFXTestExclusionDef} --notrait category=failing --notrait category=IgnoreForCI --notrait category=OuterLoop --notrait Benchmark=true"

    chmod +x ${dotnetExe}
    resetCommandArgs=("msbuild /t:Restore ${coreFXTestSetupUtility}")
    echo "${dotnetExe} $resetCommandArgs"
    "${dotnetExe}" $resetCommandArgs

    buildCommandArgs=("msbuild ${coreFXTestSetupUtility} /p:OutputPath=${coreFXTestSetupUtilityOutputPath} /p:Platform=${_arch} /p:Configuration=Release")
    echo "${dotnetExe} $buildCommandArgs"
    "${dotnetExe}" $buildCommandArgs
    
    if [ "${RunCoreFXTestsAll}" == "1" ]; then
        local coreFXRunCommand=--runAllTests
    else
        local coreFXRunCommand=--runSpecifiedTests
    fi

    local buildTestSetupUtilArgs=("${coreFXTestSetupUtilityOutputPath}/${coreFXTestSetupUtilityName}.dll --clean --outputDirectory ${coreFXTestBinariesOutputPath} --testListJsonPath ${CoreFXTestList} ${coreFXRunCommand} --dotnetPath ${testHostDir}/dotnet --testUrl ${coreFXTestRemoteURL} --executable ${coreFXTestExecutable} --log ${coreFXLogDir} ${coreFXTestExecutableArgs}")
    echo "${dotnetExe} $buildTestSetupUtilArgs"
    "${dotnetExe}" $buildTestSetupUtilArgs

    local exitCode=$?
    if [ $exitCode != 0 ]; then
        echo Running CoreFX tests finished with failures
    else
        echo Running CoreFX tests finished successfully
    fi    
    
    echo Check ${coreFXLogDir} for test run logs

    exit ${exitCode}
}

function set_up_core_dump_generation {
    # We will only enable dump generation here if we're on Mac or Linux
    if [[ ! ( "$(uname -s)" == "Darwin" || "$(uname -s)" == "Linux" ) ]]; then
        return
    fi

    # We won't enable dump generation on OS X/macOS if the machine hasn't been
    # configured with the kern.corefile pattern we expect.
    if [[ ( "$(uname -s)" == "Darwin" && "$(sysctl -n kern.corefile)" != "core.%P" ) ]]; then
        echo "WARNING: Core dump generation not being enabled due to unexpected kern.corefile value."
        return
    fi

    # Allow dump generation
    ulimit -c unlimited

    if [ "$(uname -s)" == "Linux" ]; then
        if [ -e /proc/self/coredump_filter ]; then
            # Include memory in private and shared file-backed mappings in the dump.
            # This ensures that we can see disassembly from our shared libraries when
            # inspecting the contents of the dump. See 'man core' for details.
            echo 0x3F > /proc/self/coredump_filter
        fi
    fi
}

function check_cpu_architecture {
    local CPUName=$(uname -m)
    local __arch=

    case $CPUName in
        i686)
            __arch=x86
            ;;
        x86_64)
            __arch=x64
            ;;
        armv7l)
            __arch=arm
            ;;
        aarch64)
            __arch=arm64
            ;;
        *)
            echo "Unknown CPU $CPUName detected, configuring as if for x64"
            __arch=x64
            ;;
    esac

    echo "$__arch"
}

################################################################################
# Handle Arguments
################################################################################

ARCH=$(check_cpu_architecture)
echo "Running on  CPU- $ARCH"

# Exit code constants
readonly EXIT_CODE_SUCCESS=0       # Script ran normally.
readonly EXIT_CODE_EXCEPTION=1     # Script exited because something exceptional happened (e.g. bad arguments, Ctrl-C interrupt).
readonly EXIT_CODE_TEST_FAILURE=2  # Script completed successfully, but one or more tests failed.

# Argument variables
buildArch=$ARCH
buildConfiguration="Debug"
testRootDir=
testNativeBinDir=
coreOverlayDir=
coreClrBinDir=
mscorlibDir=
coreFxBinDir=
coreClrObjs=
coreClrSrc=
coverageOutputDir=
testEnv=
playlistFile=
showTime=
noLFConversion=
buildOverlayOnly=
gcsimulator=
longgc=
limitedCoreDumps=
illinker=
((disableEventLogging = 0))
((serverGC = 0))

# Handle arguments
verbose=0
doCrossgen=0
jitdisasm=0
ilasmroundtrip=
buildXUnitWrappers=
printLastResultsOnly=
generateLayoutOnly=
generateLayout=

for i in "$@"
do
    case $i in
        -h|--help)
            print_usage
            exit $EXIT_CODE_SUCCESS
            ;;
        -v|--verbose)
            verbose=1
            ;;
        x64)
            buildArch="x64"
            ;;
        x86)
            buildArch="x86"
            ;;
        arm)
            buildArch="arm"
            ;;
        arm64)
            buildArch="arm64"
            ;;
        debug|Debug)
            buildConfiguration="Debug"
            ;;
        checked|Checked)
            buildConfiguration="Checked"
            ;;
        release|Release)
            buildConfiguration="Release"
            ;;
        --buildXUnitWrappers)
            buildXUnitWrappers=1
            ;;
        --printLastResultsOnly)
            printLastResultsOnly=1
            ;;
        --crossgen)
            doCrossgen=1
            ;;
        --jitstress=*)
            export COMPlus_JitStress=${i#*=}
            ;;
        --jitstressregs=*)
            export COMPlus_JitStressRegs=${i#*=}
            ;;
        --jitminopts)
            export COMPlus_JITMinOpts=1
            ;;
        --copyNativeTestBin)
            export copyNativeTestBin=1
            ;;
        --jitforcerelocs)
            export COMPlus_ForceRelocs=1
            ;;
        --link=*)
            export ILLINK=${i#*=}
            export DoLink=true
            ;;
        --tieredcompilation)
            export COMPlus_TieredCompilation=1
            ;;
        --jitdisasm)
            jitdisasm=1
            ;;
        --ilasmroundtrip)
            ((ilasmroundtrip = 1))
            ;;
        --testRootDir=*)
            testRootDir=${i#*=}
            ;;
        --testNativeBinDir=*)
            testNativeBinDir=${i#*=}
            ;;
        --coreOverlayDir=*)
            coreOverlayDir=${i#*=}
            ;;
        --coreClrBinDir=*)
            coreClrBinDir=${i#*=}
            ;;
        --mscorlibDir=*)
            mscorlibDir=${i#*=}
            ;;
        --coreFxBinDir=*)
            coreFxBinDir=${i#*=}
            ;;
        --testDir=*)
            testDirectories[${#testDirectories[@]}]=${i#*=}
            ;;
        --testDirFile=*)
            set_test_directories "${i#*=}"
            ;;
        --runFailingTestsOnly)
            ((runFailingTestsOnly = 1))
            ;;
        --disableEventLogging)
            ((disableEventLogging = 1))
            ;;
        --runcrossgentests)
            export RunCrossGen=1
            ;;
        --corefxtests)
            export RunCoreFXTests=1
            ;;
        --corefxtestsall)
            export RunCoreFXTests=1
            export RunCoreFXTestsAll=1
            ;;
        --corefxtestlist)
            export RunCoreFXTests=1
            export CoreFXTestList=${i#*=} 
            ;;
        --testHostDir=*)
            export testHostDir=${i#*=}
            ;;
        --sequential)
            ((maxProcesses = 1))
            ;;
        --useServerGC)
            ((serverGC = 1))
            ;;
        --long-gc)
            ((longgc = 1))
            ;;
        --gcsimulator)
            ((gcsimulator = 1))
            ;;
        --playlist=*)
            playlistFile=${i#*=}
            ;;
        --coreclr-coverage)
            CoreClrCoverage=ON
            ;;
        --coreclr-objs=*)
            coreClrObjs=${i#*=}
            ;;
        --coreclr-src=*)
            coreClrSrc=${i#*=}
            ;;
        --coverage-output-dir=*)
            coverageOutputDir=${i#*=}
            ;;
        --test-env=*)
            testEnv=${i#*=}
            ;;            
        --gcstresslevel=*)
            export COMPlus_GCStress=${i#*=}
            ;;            
        --gcname=*)
            export COMPlus_GCName=${i#*=}
            ;;
        --show-time)
            showTime=ON
            ;;
        --no-lf-conversion)
            noLFConversion=ON
            ;;
        --build-overlay-only)
            buildOverlayOnly=ON
            ;;
        --generateLayoutOnly)
            generateLayoutOnly=1
            ;;
        --generateLayout)
            generateLayout=1
            ;;
        --limitedDumpGeneration)
            limitedCoreDumps=ON
            ;;
        --xunitOutputPath=*)
            xunitOutputPath=${i#*=}
            ;;
        *)
            echo "Unknown switch: $i"
            print_usage
            exit $EXIT_CODE_SUCCESS
            ;;
    esac
done

################################################################################
# Runtests
################################################################################

if ((disableEventLogging == 0)); then
    export COMPlus_EnableEventLog=1
fi

export COMPlus_gcServer="$serverGC"

################################################################################
# CoreFX
################################################################################

if [ "$RunCoreFXTests" == 1 ];
then 
    if [ -z "$coreClrSrc" ]
    then
        echo "Coreclr src files are required to run CoreFX tests"
        echo "Coreclr src files root path can be passed using '--coreclr-src' argument"
        print_usage
        exit $EXIT_CODE_EXCEPTION
    fi

    if [ -z "$testHostDir" ]; then
        echo "--testHostDir is required to run CoreFX tests"
        print_usage
        exit $EXIT_CODE_EXCEPTION
    fi
    
    if [ ! -f "$testHostDir/dotnet" ]; then
        echo "Executable dotnet not found in $testHostDir"
        exit $EXIT_CODE_EXCEPTION
    fi

    if [ ! -d "$testHostDir" ]; then
        echo "Directory specified by --testHostDir does not exist: $testRootDir"
        exit $EXIT_CODE_EXCEPTION
    fi

    create_testhost
    exit 0
fi

################################################################################
# Runtest.py
################################################################################

runtestPyArguments=("-arch" "${buildArch}" "-build_type" "${buildConfiguration}")
scriptPath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"

if [ -z "$testRootDir" ]; then
    echo "testRootDir and other existing arguments is no longer required. If the "
    echo "default location is incorrect or does not exist, please use "
    echo "--testRootDir to explicitly override the defaults."

    echo ""
fi

echo "Build Architecture            : ${buildArch}"
echo "Build Configuration           : ${buildConfiguration}"
    
if [ ! -z "$testRootDir" ]; then
    runtestPyArguments+=("-test_location" "$testRootDir")
    echo "Test Location                 : ${testRootDir}"
fi

if [ ! -z "$coreClrBinDir" ]; then
    runtestPyArguments+=("-product_location" "$coreClrBinDir")
    echo "Product Location              : ${coreClrBinDir}"
fi

if [ -z "$coreOverlayDir" ]; then
    runtestPyArguments+=("--generate_layout")
else
    runtestPyArguments+=("-core_root" "$coreOverlayDir")
    echo "Core Root Location            : ${coreOverlayDir}"
fi

if [ ! -z "$testNativeBinDir" ]; then
    runtestPyArguments+=("-test_native_bin_location" "$testNativeBinDir")
    echo "Test Native Bin Location      : ${testNativeBinDir}"
fi

if [ ! -z "${testEnv}" ]; then
    runtestPyArguments+=("-test_env" "${testEnv}")
    echo "Test Env                      : ${testEnv}"
fi

echo ""

if [ ! -z "$longgc" ]; then
    echo "Running Long GC tests"
    runtestPyArguments+=("--long_gc")
fi

if [ ! -z "$gcsimulator" ]; then
    echo "Running GC simulator tests"
    runtestPyArguments+=("--gcsimulator")
fi

if [[ ! "$jitdisasm" -eq 0 ]]; then
    echo "Running jit disasm"
    runtestPyArguments+=("--jitdisasm")
fi

if [ ! -z "$ilasmroundtrip" ]; then
    echo "Running Ilasm round trip"
    runtestPyArguments+=("--ilasmroundtrip")
fi

if [ ! -z "$buildXUnitWrappers" ]; then
    runtestPyArguments+=("--build_xunit_test_wrappers")
else
    echo "Skipping xunit wrapper build. If build-test was called on a different"
    echo "host_os or arch the test run will most likely have failures."
fi

if (($verbose!=0)); then
    runtestPyArguments+=("--verbose")
fi

if [ ! -z "$buildOverlayOnly" ] || [ ! -z "$generateLayoutOnly" ]; then
    echo "Will only Generate Core_Root"
    runtestPyArguments+=("--generate_layout_only")
fi

if [ ! -z "$generateLayout" ]; then
    runtestPyArguments+=("--generate_layout")
fi

if [ ! -z "$sequential" ]; then
    echo "Run tests sequentially."
    runtestPyArguments+=("--sequential")
fi

if [ ! -z "$printLastResultsOnly" ]; then
    runtestPyArguments+=("--analyze_results_only")
fi

if [ ! -z "$RunCrossGen" ]; then
    runtestPyArguments+=("--run_crossgen_tests")
fi

if (($doCrossgen!=0)); then
    runtestPyArguments+=("--precompile_core_root")
fi

# Run the tests using cross platform runtest.py
echo "python ${scriptPath}/runtest.py ${runtestPyArguments[@]}"
python "${scriptPath}/runtest.py" "${runtestPyArguments[@]}"
exit "$?"