forked from dotnet/source-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmoke-test.sh
executable file
·380 lines (334 loc) · 11.7 KB
/
smoke-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
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
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_ROOT="$(cd -P "$( dirname "$0" )" && pwd)"
TARBALL_PREFIX=dotnet-sdk-
VERSION_PREFIX=3.0
# See https://github.com/dotnet/source-build/issues/579, this version
# needs to be compatible with the runtime produced from source-build
DEV_CERTS_VERSION_DEFAULT=3.0.0-preview8-28405-07
__ROOT_REPO=$(cat "$SCRIPT_ROOT/bin/obj/rootrepo.txt" | sed 's/\r$//') # remove CR if mounted repo on Windows drive
export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
projectOutput=false
keepProjects=false
dotnetDir=""
configuration="Release"
excludeNonWebTests=false
excludeWebTests=false
excludeWebNoHttpsTests=false
excludeWebHttpsTests=false
excludeLocalTests=false
excludeOnlineTests=false
devCertsVersion="$DEV_CERTS_VERSION_DEFAULT"
testingDir="$SCRIPT_ROOT/testing-smoke"
cliDir="$testingDir/builtCli"
logFile="$testingDir/smoke-test.log"
restoredPackagesDir="$testingDir/packages"
testingHome="$testingDir/home"
archiveRestoredPackages=false
archivedPackagesDir="$testingDir/smoke-test-packages"
smokeTestPrebuilts="$SCRIPT_ROOT/prebuilt/smoke-test-packages"
function usage() {
echo ""
echo "usage:"
echo " --dotnetDir the directory from which to run dotnet"
echo " --configuration the configuration being tested (default=Release)"
echo " --projectOutput echo dotnet's output to console"
echo " --keepProjects keep projects after tests are complete"
echo " --minimal run minimal set of tests - local sources only, no web"
echo " --excludeNonWebTests don't run tests for non-web projects"
echo " --excludeWebTests don't run tests for web projects"
echo " --excludeWebNoHttpsTests don't run web project tests with --no-https"
echo " --excludeWebHttpsTests don't run web project tests with https using dotnet-dev-certs"
echo " --excludeLocalTests exclude tests that use local sources for nuget packages"
echo " --excludeOnlineTests exclude test that use online sources for nuget packages"
echo " --devCertsVersion <version> use dotnet-dev-certs <version> instead of default $DEV_CERTS_VERSION_DEFAULT"
echo " --prodConBlobFeedUrl <url> override the prodcon blob feed specified in ProdConFeed.txt, removing it if empty"
echo " --archiveRestoredPackages capture all restored packages to $archivedPackagesDir"
echo "environment:"
echo " prodConBlobFeedUrl override the prodcon blob feed specified in ProdConFeed.txt, removing it if empty"
echo ""
}
while :; do
if [ $# -le 0 ]; then
break
fi
lowerI="$(echo $1 | awk '{print tolower($0)}')"
case $lowerI in
-?|-h|--help)
usage
exit 0
;;
--dotnetdir)
shift
dotnetDir="$1"
;;
--configuration)
shift
configuration="$1"
;;
--projectoutput)
projectOutput=true
;;
--keepprojects)
keepProjects=true
;;
--minimal)
excludeOnlineTests=true
;;
--excludenonwebtests)
excludeNonWebTests=true
;;
--excludewebtests)
excludeWebTests=true
;;
--excludewebnohttpstests)
excludeWebNoHttpsTests=true
;;
--excludewebhttpstests)
excludeWebHttpsTests=true
;;
--excludelocaltests)
excludeLocalTests=true
;;
--excludeonlinetests)
excludeOnlineTests=true
;;
--devcertsversion)
shift
devCertsVersion="$1"
;;
--prodconblobfeedurl)
shift
prodConBlobFeedUrl="$1"
;;
--archiverestoredpackages)
archiveRestoredPackages=true
;;
*)
echo "Unrecognized argument '$1'"
usage
exit 1
;;
esac
shift
done
prodConBlobFeedUrl="${prodConBlobFeedUrl-$(cat "$SCRIPT_ROOT/ProdConFeed.txt")}"
function doCommand() {
lang=$1
proj=$2
shift; shift;
echo "starting language $lang, type $proj" | tee -a smoke-test.log
dotnetCmd=${dotnetDir}/dotnet
mkdir "${lang}_${proj}"
cd "${lang}_${proj}"
newArgs="new $proj -lang $lang"
while :; do
if [ $# -le 0 ]; then
break
fi
case "$1" in
--new-arg)
shift
newArgs="$newArgs $1"
;;
*)
break
;;
esac
shift
done
while :; do
if [ $# -le 0 ]; then
break
fi
echo " running $1" | tee -a "$logFile"
if [ "$1" == "new" ]; then
if [ "$projectOutput" == "true" ]; then
"${dotnetCmd}" $newArgs | tee -a "$logFile"
else
"${dotnetCmd}" $newArgs >> "$logFile" 2>&1
fi
elif [[ "$1" == "run" && "$proj" =~ ^(web|mvc|webapi|razor)$ ]]; then
if [ "$projectOutput" == "true" ]; then
"${dotnetCmd}" $1 &
else
"${dotnetCmd}" $1 >> "$logFile" 2>&1 &
fi
webPid=$!
killCommand="pkill -SIGTERM -P $webPid"
echo " waiting up to 20 seconds for web project with pid $webPid..."
echo " to clean up manually after an interactive cancellation, run: $killCommand"
for seconds in $(seq 20); do
if [ "$(tail -n 1 "$logFile")" = 'Application started. Press Ctrl+C to shut down.' ]; then
echo " app ready for shutdown after $seconds seconds"
break
fi
sleep 1
done
echo " stopping $webPid" | tee -a "$logFile"
$killCommand
wait $!
echo " terminated with exit code $?" | tee -a "$logFile"
else
if [ "$projectOutput" == "true" ]; then
"${dotnetCmd}" $1 | tee -a "$logFile"
else
"${dotnetCmd}" $1 >> "$logFile" 2>&1
fi
fi
if [ $? -eq 0 ]; then
echo " $1 succeeded" >> "$logFile"
else
echo " $1 failed with exit code $?" | tee -a "$logFile"
fi
shift
done
cd ..
if [ "$keepProjects" == "false" ]; then
rm -rf "${lang}_${proj}"
fi
echo "finished language $lang, type $proj" | tee -a smoke-test.log
}
function setupDevCerts() {
echo "Setting up dotnet-dev-certs $devCertsVersion to generate dev certificate" | tee -a "$logFile"
(
set -x
"$dotnetDir/dotnet" tool install -g dotnet-dev-certs --version "$devCertsVersion" --add-source https://dotnet.myget.org/F/dotnet-core/api/v3/index.json
export DOTNET_ROOT="$dotnetDir"
"$testingHome/.dotnet/tools/dotnet-dev-certs" https
) >> "$logFile" 2>&1
}
function runAllTests() {
# Run tests for each language and template
if [ "$excludeNonWebTests" == "false" ]; then
doCommand C# console new restore run
doCommand C# classlib new restore build
doCommand C# xunit new restore test
doCommand C# mstest new restore test
doCommand VB console new restore run
doCommand VB classlib new restore build
doCommand VB xunit new restore test
doCommand VB mstest new restore test
doCommand F# console new restore run
doCommand F# classlib new restore build
doCommand F# xunit new restore test
doCommand F# mstest new restore test
fi
if [ "$excludeWebTests" == "false" ]; then
if [ "$excludeWebNoHttpsTests" == "false" ]; then
runWebTests --new-arg --no-https
fi
if [ "$excludeWebHttpsTests" == "false" ]; then
setupDevCerts
runWebTests
fi
fi
}
function resetCaches() {
rm -rf "$testingHome"
mkdir "$testingHome"
HOME="$testingHome"
# clean restore path
rm -rf "$restoredPackagesDir"
}
function runWebTests() {
doCommand C# web "$@" new restore run
doCommand C# mvc "$@" new restore run
doCommand C# webapi "$@" new restore run
doCommand C# razor "$@" new restore run
doCommand F# web "$@" new restore run
doCommand F# mvc "$@" new restore run
doCommand F# webapi "$@" new restore run
}
function resetCaches() {
rm -rf "$testingHome"
mkdir "$testingHome"
HOME="$testingHome"
# clean restore path
rm -rf "$restoredPackagesDir"
}
function setupProdConFeed() {
if [ "$prodConBlobFeedUrl" ]; then
sed -i.bakProdCon "s|PRODUCT_CONTRUCTION_PACKAGES|$prodConBlobFeedUrl|g" "$testingDir/NuGet.Config"
else
sed -i.bakProdCon "/PRODUCT_CONTRUCTION_PACKAGES/d" "$testingDir/NuGet.Config"
fi
}
function setupSmokeTestFeed() {
# Setup smoke-test-packages if they exist
if [ -e "$smokeTestPrebuilts" ]; then
sed -i.bakSmokeTestFeed "s|SMOKE_TEST_PACKAGE_FEED|$smokeTestPrebuilts|g" "$testingDir/NuGet.Config"
else
sed -i.bakSmokeTestFeed "/SMOKE_TEST_PACKAGE_FEED/d" "$testingDir/NuGet.Config"
fi
}
function copyRestoredPackages() {
if [ "$archiveRestoredPackages" == "true" ]; then
mkdir -p "$archivedPackagesDir"
cp -rf "$restoredPackagesDir"/* "$archivedPackagesDir"
fi
}
if [ "$__ROOT_REPO" != "known-good" ]; then
echo "Skipping smoke-tests since cli was not built";
exit
fi
# Clean up and create directory
if [ -e "$testingDir" ]; then
read -p "testing-smoke directory exists, remove it? [Y]es / [n]o" -n 1 -r
echo
if [[ $REPLY == "" || $REPLY == " " || $REPLY =~ ^[Yy]$ ]]; then
rm -rf "$testingDir"
fi
fi
mkdir -p "$testingDir"
cd "$testingDir"
# Unzip dotnet if the dotnetDir is not specified
if [ "$dotnetDir" == "" ]; then
OUTPUT_DIR="$SCRIPT_ROOT/bin/x64/$configuration/"
DOTNET_TARBALL="$(ls ${OUTPUT_DIR}dotnet-sdk-${VERSION_PREFIX}*)"
mkdir -p "$cliDir"
tar xzf "$DOTNET_TARBALL" -C "$cliDir"
dotnetDir="$cliDir"
else
if ! [[ "$dotnetDir" = /* ]]; then
dotnetDir="$SCRIPT_ROOT/$dotnetDir"
fi
fi
# setup restore path
export NUGET_PACKAGES="$restoredPackagesDir"
SOURCE_BUILT_PKGS_PATH="$SCRIPT_ROOT/bin/obj/x64/$configuration/blob-feed/packages/"
# Run all tests, local restore sources first, online restore sources second
if [ "$excludeLocalTests" == "false" ]; then
resetCaches
# Setup NuGet.Config with local restore source
if [ -e "$SCRIPT_ROOT/smoke-testNuGet.Config" ]; then
cp "$SCRIPT_ROOT/smoke-testNuGet.Config" "$testingDir/NuGet.Config"
sed -i.bak "s|SOURCE_BUILT_PACKAGES|$SOURCE_BUILT_PKGS_PATH|g" "$testingDir/NuGet.Config"
setupProdConFeed
setupSmokeTestFeed
echo "$testingDir/NuGet.Config Contents:"
cat "$testingDir/NuGet.Config"
fi
echo "RUN ALL TESTS - LOCAL RESTORE SOURCE"
runAllTests
copyRestoredPackages
echo "LOCAL RESTORE SOURCE - ALL TESTS PASSED!"
fi
if [ "$excludeOnlineTests" == "false" ]; then
resetCaches
# Setup NuGet.Config to use online restore sources
if [ -e "$SCRIPT_ROOT/smoke-testNuGet.Config" ]; then
cp "$SCRIPT_ROOT/smoke-testNuGet.Config" "$testingDir/NuGet.Config"
sed -i.bak "/SOURCE_BUILT_PACKAGES/d" "$testingDir/NuGet.Config"
setupProdConFeed
setupSmokeTestFeed
echo "$testingDir/NuGet.Config Contents:"
cat "$testingDir/NuGet.Config"
fi
echo "RUN ALL TESTS - ONLINE RESTORE SOURCE"
runAllTests
copyRestoredPackages
echo "ONLINE RESTORE SOURCE - ALL TESTS PASSED!"
fi
echo "ALL TESTS PASSED!"