-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
Copy pathRunnerTemplate.sh
262 lines (226 loc) · 9.16 KB
/
RunnerTemplate.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
#!/usr/bin/env bash
usage()
{
echo "Usage: RunTests.sh {-r|--runtime-path} <runtime-path> [{--rsp-file} <rsp-file>]"
echo ""
echo "Parameters:"
echo "--runtime-path (Mandatory) Testhost containing the test runtime used during test execution (short: -r)"
echo "--rsp-file RSP file to pass in additional arguments"
echo "--help Print help and exit (short: -h)"
}
EXECUTION_DIR=$(dirname "$0")
RUNTIME_PATH=''
RSP_FILE=''
while [[ $# > 0 ]]; do
opt="$(echo "${1}" | tr "[:upper:]" "[:lower:]")"
case "$opt" in
--help|-h)
usage
exit 0
;;
--runtime-path|-r)
RUNTIME_PATH=$2
shift
;;
--rsp-file)
RSP_FILE=\@$2
shift
;;
*)
echo "Invalid argument: $1"
usage
exit -1
;;
esac
shift
done
if [[ -z "$RUNTIME_PATH" ]]; then
echo "error: -r|--runtime-path argument is required."
usage
exit -1
fi
# Don't use a globally installed SDK.
export DOTNET_MULTILEVEL_LOOKUP=0
exitcode_list[0]="Exited Successfully"
exitcode_list[130]="SIGINT Ctrl-C occurred. Likely tests timed out."
exitcode_list[131]="SIGQUIT Ctrl-\ occurred. Core dumped."
exitcode_list[132]="SIGILL Illegal Instruction. Core dumped. Likely codegen issue."
exitcode_list[133]="SIGTRAP Breakpoint hit. Core dumped."
exitcode_list[134]="SIGABRT Abort. Managed or native assert, or runtime check such as heap corruption, caused call to abort(). Core dumped."
exitcode_list[135]="IGBUS Unaligned memory access. Core dumped."
exitcode_list[136]="SIGFPE Bad floating point arguments. Core dumped."
exitcode_list[137]="SIGKILL Killed either due to out of memory/resources (see /var/log/messages) or by explicit kill. No dump will be available for this."
exitcode_list[139]="SIGSEGV Illegal memory access. Deref invalid pointer, overrunning buffer, stack overflow etc. Core dumped."
exitcode_list[143]="SIGTERM Terminated. Usually before SIGKILL."
exitcode_list[159]="SIGSYS Bad System Call."
function move_core_file_to_temp_location {
local core_file_name=$1
# Append the dmp extension to ensure XUnitLogChecker finds it
local new_location=$HELIX_DUMP_FOLDER/$core_file_name.dmp
echo "Copying dump file '$core_file_name' to '$new_location'"
cp $core_file_name $new_location
# Delete the old one
rm $core_file_name
}
xunitlogchecker_exit_code=0
function invoke_xunitlogchecker {
local dump_folder=$1
total_dumps=$(find $dump_folder -name "*.dmp" | wc -l)
if [[ $total_dumps > 0 ]]; then
echo "Total dumps found in $dump_folder: $total_dumps"
xunitlogchecker_file_name="$HELIX_CORRELATION_PAYLOAD/XUnitLogChecker"
if [[ ! -f $xunitlogchecker_file_name ]]; then
echo "XUnitLogChecker does not exist in the expected location: $xunitlogchecker_file_name"
xunitlogchecker_exit_code=2
elif [[ ! -d $dump_folder ]]; then
echo "The dump directory '$dump_folder' does not exist."
else
echo "Executing XUnitLogChecker in $dump_folder..."
cmd="$xunitlogchecker_file_name --dumps-path $dump_folder"
echo "$cmd"
$cmd
xunitlogchecker_exit_code=$?
fi
else
echo "No dumps found in $dump_folder."
fi
}
# ========================= BEGIN Core File Setup ============================
system_name="$(uname -s)"
if [[ $system_name == "Darwin" ]]; then
# On OS X, we will enable core dump generation only if there are no core
# files already in /cores/ at this point. This is being done to prevent
# inadvertently flooding the CI machines with dumps.
if [[ ! -d "/cores" || ! "$(ls -A /cores)" ]]; then
# Disabling core dumps on macOS. System dumps are large (even for very small
# programs) and not configurable. As a result, if a single PR build causes a
# lot of tests to crash, we can take out the entire queue.
# See discussions in:
# https://github.com/dotnet/core-eng/issues/15333
# https://github.com/dotnet/core-eng/issues/15597
ulimit -c 0
fi
fi
export DOTNET_DbgEnableMiniDump=1
export DOTNET_EnableCrashReport=1
export DOTNET_DbgMiniDumpName=$HELIX_DUMP_FOLDER/coredump.%d.dmp
# ========================= END Core File Setup ==============================
# ========================= BEGIN support for SuperPMI collection ==============================
if [ ! -z $spmi_enable_collection ]; then
echo "SuperPMI collection enabled"
# spmi_collect_dir and spmi_core_root need to be set before this script is run, if SuperPMI collection is enabled.
if [ -z $spmi_collect_dir ]; then
echo "ERROR - spmi_collect_dir not defined"
exit 1
fi
if [ -z $spmi_core_root ]; then
echo "ERROR - spmi_core_root not defined"
exit 1
fi
mkdir -p $spmi_collect_dir
export spmi_file_extension=so
if [[ $system_name == "Darwin" ]]; then
export spmi_file_extension=dylib
fi
export SuperPMIShimLogPath=$spmi_collect_dir
export SuperPMIShimPath=$spmi_core_root/libclrjit.$spmi_file_extension
export DOTNET_EnableExtraSuperPmiQueries=1
export DOTNET_JitPath=$spmi_core_root/libsuperpmi-shim-collector.$spmi_file_extension
if [ ! -e $SuperPMIShimPath ]; then
echo "ERROR - $SuperPMIShimPath not found"
exit 1
fi
if [ ! -e $DOTNET_JitPath ]; then
echo "ERROR - $DOTNET_JitPath not found"
exit 1
fi
echo "SuperPMIShimLogPath=$SuperPMIShimLogPath"
echo "SuperPMIShimPath=$SuperPMIShimPath"
echo "DOTNET_EnableExtraSuperPmiQueries=$DOTNET_EnableExtraSuperPmiQueries"
echo "DOTNET_JitPath=$DOTNET_JitPath"
fi
# ========================= END support for SuperPMI collection ==============================
echo ========================= Begin custom configuration settings ==============================
[[SetCommandsEcho]]
[[SetCommands]]
echo ========================== End custom configuration settings ===============================
# ========================= BEGIN Test Execution =============================
echo ----- start $(date) =============== To repro directly: =====================================================
echo pushd $EXECUTION_DIR
[[RunCommandsEcho]]
echo popd
echo ===========================================================================================================
pushd $EXECUTION_DIR
[[RunCommands]]
test_exitcode=$?
if [[ -s testResults.xml ]]; then
has_test_results=1;
fi;
popd
echo ----- end $(date) ----- exit code $test_exitcode ----------------------------------------------------------
if [[ -n "${exitcode_list[$test_exitcode]}" ]]; then
echo exit code $test_exitcode means ${exitcode_list[$test_exitcode]}
fi
# ========================= END Test Execution ===============================
# ======================= BEGIN Core File Inspection =========================
pushd $EXECUTION_DIR >/dev/null
if [[ $test_exitcode -ne 0 ]]; then
echo ulimit -c value: $(ulimit -c)
fi
if [[ $system_name == "Linux" && $test_exitcode -ne 0 ]]; then
echo cat /proc/sys/kernel/core_pattern: $(cat /proc/sys/kernel/core_pattern)
echo cat /proc/sys/kernel/core_uses_pid: $(cat /proc/sys/kernel/core_uses_pid)
echo cat /proc/sys/kernel/coredump_filter: $(cat /proc/sys/kernel/coredump_filter)
# Depending on distro/configuration, the core files may either be named "core"
# or "core.<PID>" by default. We read /proc/sys/kernel/core_uses_pid to
# determine which it is.
core_name_uses_pid=0
if [[ -e /proc/sys/kernel/core_uses_pid && "1" == $(cat /proc/sys/kernel/core_uses_pid) ]]; then
core_name_uses_pid=1
fi
# The osx dumps are too large to egress the machine
echo Looking around for any Linux dumps...
if [[ "$core_name_uses_pid" == "1" ]]; then
# We don't know what the PID of the process was, so let's look at all core
# files whose name matches core.NUMBER
echo "Looking for files matching core.* ..."
for f in $(find . -name "core.*"); do
[[ $f =~ core.[0-9]+ ]] && move_core_file_to_temp_location "$f"
done
fi
if [ -f core ]; then
move_core_file_to_temp_location "core"
fi
fi
if [ -n "$HELIX_WORKITEM_PAYLOAD" ]; then
# For abrupt failures, in Helix, dump some of the kernel log, in case there is a hint
if [[ $test_exitcode -ne 1 ]]; then
dmesg | tail -50
fi
fi
if [[ -z "$HELIX_CORRELATION_PAYLOAD" ]]; then
: # Skip XUnitLogChecker execution
elif [[ -z "$__IsXUnitLogCheckerSupported" ]]; then
echo "The '__IsXUnitLogCheckerSupported' env var is not set."
elif [[ "$__IsXUnitLogCheckerSupported" != "1" ]]; then
echo "XUnitLogChecker not supported for this test case. Skipping."
else
echo "XUnitLogChecker status: $__IsXUnitLogCheckerSupported"
echo ----- start =============== XUnitLogChecker Output =====================================================
invoke_xunitlogchecker "$HELIX_DUMP_FOLDER"
if [[ $xunitlogchecker_exit_code -ne 0 ]]; then
test_exitcode=$xunitlogchecker_exit_code
fi
echo ----- end =============== XUnitLogChecker Output - exit code $xunitlogchecker_exit_code ===========================
fi
popd >/dev/null
# ======================== END Core File Inspection ==========================
# The helix work item should not exit with non-zero if tests ran and produced results
# The special console runner for runtime returns 1 when tests fail
if [[ "$test_exitcode" == "1" && "$has_test_results" == "1" ]]; then
if [ -n "$HELIX_WORKITEM_PAYLOAD" ]; then
exit 0
fi
fi
exit $test_exitcode
fi