Skip to content

Commit 02c1783

Browse files
Merge pull request dotnet#4909 from lemmaa/unit-test-enhancement
Add extra options to 'runtest.sh' for effective test monitoring.
2 parents 39425de + 4abde70 commit 02c1783

File tree

1 file changed

+41
-15
lines changed

1 file changed

+41
-15
lines changed

tests/runtest.sh

+41-15
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ function print_usage {
4646
echo ' --useServerGC : Enable server GC for this test run'
4747
echo ' --test-env : Script to set environment variables for tests'
4848
echo ' --runcrossgentests : Runs the ready to run tests'
49-
echo ''
5049
echo ' --jitstress=<n> : Runs the tests with COMPlus_JitStress=n'
5150
echo ' --jitstressregs=<n> : Runs the tests with COMPlus_JitStressRegs=n'
5251
echo ' --jitminopts : Runs the tests with COMPlus_JITMinOpts=1'
@@ -55,6 +54,8 @@ function print_usage {
5554
echo ' 0: None 1: GC on all allocs and 'easy' places'
5655
echo ' 2: GC on transitions to preemptive GC 4: GC on every allowable JITed instr'
5756
echo ' 8: GC on every allowable NGEN instr 16: GC only on a unique stack trace'
57+
echo ' --show-time : Print execution sequence and running time for each test'
58+
echo ' --no-lf-conversion : Do not execute LF conversion before running test script'
5859
echo ''
5960
echo 'Runtime Code Coverage options:'
6061
echo ' --coreclr-coverage : Optional argument to get coreclr code coverage reports'
@@ -381,9 +382,9 @@ function create_core_overlay {
381382
function precompile_overlay_assemblies {
382383

383384
if [ $doCrossgen == 1 ]; then
384-
385+
385386
local overlayDir=$CORE_ROOT
386-
387+
387388
filesToPrecompile=$(ls -trh $overlayDir/*.dll)
388389
for fileToPrecompile in ${filesToPrecompile}
389390
do
@@ -395,7 +396,7 @@ function precompile_overlay_assemblies {
395396
$overlayDir/crossgen /Platform_Assemblies_Paths $overlayDir $filename 2>/dev/null
396397
local exitCode=$?
397398
if [ $exitCode == -2146230517 ]; then
398-
echo $filename is not a managed assembly.
399+
echo $filename is not a managed assembly.
399400
elif [ $exitCode != 0 ]; then
400401
echo Unable to precompile $filename.
401402
else
@@ -406,7 +407,7 @@ function precompile_overlay_assemblies {
406407
done
407408
else
408409
echo Skipping crossgen of FX assemblies.
409-
fi
410+
fi
410411
}
411412

412413
function copy_test_native_bin_to_test_root {
@@ -554,6 +555,7 @@ fi
554555
declare -a scriptFilePaths
555556
declare -a outputFilePaths
556557
declare -a processIds
558+
declare -a testStartTimes
557559

558560
function finish_test {
559561
wait ${processIds[$nextProcessIndex]}
@@ -564,26 +566,36 @@ function finish_test {
564566
local outputFilePath=${outputFilePaths[$nextProcessIndex]}
565567
local scriptFileName=$(basename "$scriptFilePath")
566568

569+
local testEndTime=
570+
local testRunningTime=
571+
local header=
572+
573+
if [ "$showTime" == "ON" ]; then
574+
testEndTime=$(date +%s)
575+
testRunningTime=$(echo "$testEndTime - ${testStartTimes[$nextProcessIndex]}" | bc)
576+
header=$(printf "[%03d:%4.0fs] " "$countTotalTests" "$testRunningTime")
577+
fi
578+
567579
local xunitTestResult
568580
case $testScriptExitCode in
569581
0)
570582
let countPassedTests++
571583
xunitTestResult='Pass'
572584
if ((verbose == 1 || runFailingTestsOnly == 1)); then
573-
echo "PASSED - $scriptFilePath"
585+
echo "PASSED - ${header}${scriptFilePath}"
574586
else
575-
echo " - $scriptFilePath"
587+
echo " - ${header}${scriptFilePath}"
576588
fi
577589
;;
578590
2)
579591
let countSkippedTests++
580592
xunitTestResult='Skip'
581-
echo "SKIPPED - $scriptFilePath"
593+
echo "SKIPPED - ${header}${scriptFilePath}"
582594
;;
583595
*)
584596
let countFailedTests++
585597
xunitTestResult='Fail'
586-
echo "FAILED - $scriptFilePath"
598+
echo "FAILED - ${header}${scriptFilePath}"
587599
;;
588600
esac
589601
let countTotalTests++
@@ -614,9 +626,11 @@ function prep_test {
614626

615627
test "$verbose" == 1 && echo "Preparing $scriptFilePath"
616628

617-
# Convert DOS line endings to Unix if needed
618-
perl -pi -e 's/\r\n|\n|\r/\n/g' "$scriptFilePath"
619-
629+
if [ ! "$noLFConversion" == "ON" ]; then
630+
# Convert DOS line endings to Unix if needed
631+
perl -pi -e 's/\r\n|\n|\r/\n/g' "$scriptFilePath"
632+
fi
633+
620634
# Add executable file mode bit if needed
621635
chmod +x "$scriptFilePath"
622636

@@ -630,7 +644,7 @@ function start_test {
630644
if ((runFailingTestsOnly == 1)) && ! is_failing_test "$scriptFilePath"; then
631645
return
632646
fi
633-
647+
634648
# Skip any test that's not in the current playlist, if a playlist was
635649
# given to us.
636650
if [ -n "$playlistFile" ] && ! is_playlist_test "$scriptFilePath"; then
@@ -646,6 +660,10 @@ function start_test {
646660
local outputFilePath=$(dirname "$scriptFilePath")/${scriptFileName}.out
647661
outputFilePaths[$nextProcessIndex]=$outputFilePath
648662

663+
if [ "$showTime" == "ON" ]; then
664+
testStartTimes[$nextProcessIndex]=$(date +%s)
665+
fi
666+
649667
test "$verbose" == 1 && echo "Starting $scriptFilePath"
650668
if is_unsupported_test "$scriptFilePath"; then
651669
skip_unsupported_test "$scriptFilePath" "$outputFilePath" &
@@ -742,6 +760,8 @@ coreClrSrc=
742760
coverageOutputDir=
743761
testEnv=
744762
playlistFile=
763+
showTime=
764+
noLFConversion=
745765

746766
((disableEventLogging = 0))
747767
((serverGC = 0))
@@ -838,6 +858,12 @@ do
838858
--gcstresslevel=*)
839859
export COMPlus_GCStress=${i#*=}
840860
;;
861+
--show-time)
862+
showTime=ON
863+
;;
864+
--no-lf-conversion)
865+
noLFConversion=ON
866+
;;
841867
*)
842868
echo "Unknown switch: $i"
843869
print_usage
@@ -868,7 +894,7 @@ if [ -z "$mscorlibDir" ]; then
868894
mscorlibDir=$coreClrBinDir
869895
fi
870896
if [ -d $mscorlibDir/bin ]; then
871-
cp $mscorlibDir/bin/* $mscorlibDir
897+
cp $mscorlibDir/bin/* $mscorlibDir
872898
fi
873899

874900
# If this is a coverage run, make sure the appropriate args have been passed
@@ -928,7 +954,7 @@ cd "$testRootDir"
928954
time_start=$(date +"%s")
929955
if [ -z "$testDirectories" ]
930956
then
931-
# No test directories were specified, so run everything in the current
957+
# No test directories were specified, so run everything in the current
932958
# directory and its subdirectories.
933959
run_tests_in_directory "."
934960
else

0 commit comments

Comments
 (0)