forked from dotnet/corefx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-test.sh
executable file
·292 lines (246 loc) · 7.42 KB
/
run-test.sh
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
#!/usr/bin/env bash
wait_on_pids()
{
# Wait on the last processes
for job in $1
do
wait $job
if [ "$?" -ne 0 ]
then
TestsFailed=$(($TestsFailed+1))
fi
done
}
usage()
{
echo "Runs tests on linux/mac that don't have native build support"
echo "usage: run-test [options]"
echo
echo "Input sources:"
echo " --coreclr-bins <location> Location of root of the binaries directory"
echo " containing the linux/mac coreclr build"
echo " default: <repo_root>/bin/Product/<OS>.x64.<Configuration>"
echo " --mscorlib-bins <location> Location of the root binaries directory containing"
echo " the linux/mac mscorlib.dll"
echo " default: <repo_root>/bin/Product/<OS>.x64.<Configuration>"
echo " --corefx-tests <location> Location of the root binaries location containing"
echo " the windows tests"
echo " default: <repo_root>/bin/tests/Windows_NT.AnyCPU.<Configuration>"
echo " --corefx-bins <location> Location of the linux/mac corefx binaries"
echo " default: <repo_root>/bin/<OS>.AnyCPU.<Configuration>"
echo
echo "Flavor/OS options:"
echo " --configuration <config> Configuration to run (Debug/Release)"
echo " default: Debug"
echo " --os <os> OS to run (OSX/Linux)"
echo " default: detect current OS"
echo
echo "Execution options:"
echo " --restrict-proj <regex> Run test projects that match regex"
echo " default: .* (all projects)"
echo
exit 1
}
ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Location parameters
# OS/Configuration defaults
Configuration="Debug"
OSName=$(uname -s)
case $OSName in
Linux)
OS=Linux
;;
Darwin)
OS=OSX
;;
*)
echo "Unsupported OS $OSName detected, configuring as if for Linux"
OS=Linux
;;
esac
# Misc defaults
TestHostVersion="0.0.2-prerelease"
TestSelection=".*"
TestsFailed=0
OverlayDir="$ProjectRoot/bin/tests/$OS.AnyCPU.$Configuration/TestOverlay/"
create_test_overlay()
{
# Creates the test overlay that will be copied on top of
# Each of the test directories.
local packageName="Microsoft.DotNet.CoreFx.$OS.TemporaryTestHost.$TestHostVersion.nupkg"
local packageDir="packages/Microsoft.DotNet.CoreFx.$OS.TemporaryTestHost.$TestHostVersion"
rm -rf $packageDir
mkdir -p $packageDir
pushd $packageDir > /dev/null
# Pull down the testhost package and unzip it.
echo "Pulling down $packageName"
wget -q https://www.myget.org/F/dotnet-buildtools/api/v2/package/Microsoft.DotNet.CoreFx.$OS.TemporaryTestHost/$TestHostVersion -O $packageName
echo "Unzipping to $packageDir"
unzip -q -o $packageName
popd > /dev/null
# Make the overlay
rm -rf $OverlayDir
mkdir -p $OverlayDir
local LowerConfiguration="$(echo $Configuration | awk '{print tolower($0)}')"
# First the temporary test host binaries
local packageLibDir="$packageDir/lib"
local mscorlibLocation="$MscorlibBins/mscorlib.dll"
if [ ! -d $packageLibDir ]
then
echo "Package not laid out as expected"
exit 1
fi
cp $packageLibDir/* $OverlayDir
# Then the CoreCLR native binaries
if [ ! -d $CoreClrBins ]
then
echo "Coreclr $OS binaries not found at $CoreClrBins"
exit 1
fi
cp -r $CoreClrBins/* $OverlayDir
# Then the mscorlib from the upstream build.
# TODO When the mscorlib flavors get properly changed then
if [ ! -f $mscorlibLocation ]
then
echo "Mscorlib not found at $mscorlibLocation"
exit 1
fi
cp -r $mscorlibLocation $OverlayDir
# Then the binaries from the linux build of corefx
if [ ! -d $CoreFxBins ]
then
echo "Corefx binaries not found at $CoreFxBins"
exit 1
fi
find $CoreFxBins -name '*.dll' -exec cp '{}' "$OverlayDir" ";"
}
copy_test_overlay()
{
testDir=$1
cp -r $OverlayDir/* $testDir/
}
# $1 is the name of the test project
runtest()
{
testProject=$1
# Check here to see whether we should run this project
if grep "UnsupportedPlatforms.*$OS.*" $1
then
echo "Test project file $1 indicates this test is not supported on $OS, skipping"
exit 0
fi
# Check for project restrictions
if [[ ! $testProject =~ $TestSelection ]]; then
echo "Skipping $testProject"
exit 0
fi
# Grab the directory name that would correspond to this test
lowerOS="$(echo $OS | awk '{print tolower($0)}')"
fileName="${file##*/}"
fileNameWithoutExtension="${fileName%.*}"
testDllName="$fileNameWithoutExtension.dll"
xunitOSCategory="non$lowerOS"
xunitOSCategory+="tests"
dirName="$CoreFxTests/$fileNameWithoutExtension/dnxcore50"
if [ ! -d "$dirName" ] || [ ! -f "$dirName/$testDllName" ]
then
echo "Did not find corresponding test dll for $testProject at $dirName/$testDllName"
exit 1
fi
copy_test_overlay $dirName
# Invoke xunit
pushd $dirName > /dev/null
echo
echo "Running tests in $dirName"
echo "./corerun xunit.console.netcore.exe $testDllName -xml testResults.xml -notrait category=failing -notrait category=OuterLoop -notrait category=$xunitOSCategory"
echo
./corerun xunit.console.netcore.exe $testDllName -xml testResults.xml -notrait category=failing -notrait category=OuterLoop -notrait category=$xunitOSCategory
exitCode=$?
popd > /dev/null
exit $exitCode
}
# Parse arguments
while [[ $# > 0 ]]
do
opt="$1"
case $opt in
-h|--help)
usage
;;
--coreclr-bins)
CoreClrBins=$2
;;
--mscorlib-bins)
MscorlibBins=$2
;;
--corefx-tests)
CoreFxTests=$2
;;
--corefx-bins)
CoreFxBins=$2
;;
--restrict-proj)
TestSelection=$2
;;
--configuration)
Configuration=$2
;;
--os)
OS=$2
;;
*)
;;
esac
shift
done
# Compute paths to the binaries if they haven't already been computed
if [ "$CoreClrBins" == "" ]
then
CoreClrBins="$ProjectRoot/bin/Product/$OS.x64.$Configuration"
fi
if [ "$MscorlibBins" == "" ]
then
MscorlibBins="$ProjectRoot/bin/Product/$OS.x64.$Configuration"
fi
if [ "$CoreFxTests" == "" ]
then
CoreFxTests="$ProjectRoot/bin/tests/Windows_NT.AnyCPU.$Configuration"
fi
if [ "$CoreFxBins" == "" ]
then
CoreFxBins="$ProjectRoot/bin/$OS.AnyCPU.$Configuration"
fi
# Check parameters up front for valid values:
if [ ! "$Configuration" == "Debug" ] && [ ! "$Configuration" == "Release" ]
then
echo "Configuration should be Debug or Release"
exit 1
fi
if [ ! "$OS" == "OSX" ] && [ ! "$OS" == "Linux" ]
then
echo "OS should be Linux or OSX"
exit 1
fi
create_test_overlay
# Walk the directory tree rooted at src bin/tests/Windows_NT.AnyCPU.$Configuration/
TestsFailed=0
numberOfProcesses=0
maxProcesses=$(($(getconf _NPROCESSORS_ONLN)+1))
for file in src/**/tests/*.Tests.csproj
do
runtest $file &
pids="$pids $!"
numberOfProcesses=$(($numberOfProcesses+1))
if [ "$numberOfProcesses" -ge $maxProcesses ]; then
wait_on_pids "$pids"
numberOfProcesses=0
pids=""
fi
done
# Wait on the last processes
wait_on_pids "$pids"
if [ "$TestsFailed" -gt 0 ]
then
echo "$TestsFailed test(s) failed"
fi
exit $TestsFailed