-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkerneldumptest
executable file
·460 lines (400 loc) · 14.1 KB
/
kerneldumptest
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
#!/bin/sh
warn()
{
echo "$(basename $0): $1" >&2
}
err()
{
warn "$1"
exit 1
}
usage()
{
local progname
# XXX add descriptions
progname=$(basename $0)
cat >&2 <<__EOF__
usage: $progname provision [-d <datastore>] <vm image>
$progname deprovision
$progname runtests
__EOF__
exit 1
}
#
# (De-)Provisioning routines.
#
# Arguments:
# 1. VM image path
# 2. main filesystem partition number in image
# XXX want some way of auto-discovering the right partition.
provision::main()
{
local bridge ds image md mntdir partnum
image=$1
partnum=$2
ds=$(vm datastore list | awk '$1 == "kerneldumptest"{print}')
[ -z "$ds" ] || err "datastore already exists. Run deprovision first."
ds=$(mktemp -d)
vm datastore add kerneldumptest $ds || : # XXX always exits status 1
# XXX needs to be specified in the template.
vm switch create test
bridge=$(vm switch list | awk '$1 == "test"{print $3}')
ifconfig $bridge inet 192.168.${bridge#bridge}.1
md=$(mdconfig -a -t vnode -f $image)
mntdir=$(mktemp -d)
mount /dev/${md}p${partnum} $mntdir
# XXX shouldn't really live in the root of the datastore.
ssh-keygen -t rsa -N "" -f ${ds}/id_rsa
echo "PermitRootLogin yes" >> ${mntdir}/etc/ssh/sshd_config
echo "UseDNS no" >> ${mntdir}/etc/ssh/sshd_config
mkdir -p ${mntdir}/root/.ssh
cat ${ds}/id_rsa.pub > ${mntdir}/root/.ssh/authorized_keys
# XXX need a better way to do this...
echo "ifconfig_vtnet0=\"inet 192.168.${bridge#bridge}.2\"" >> ${mntdir}/etc/rc.conf
echo "defaultrouter=192.168.${bridge#bridge}.1" >> ${mntdir}/etc/rc.conf
umount $mntdir
mdconfig -d -u ${md#md}
# XXX need to add our own template to the dir.
vm create -d kerneldumptest -t default kerneldumptest || : # XXX always exits status 1
}
deprovision::main()
{
local dspath
vm stop kerneldumptest || :
dspath=$(vm datastore list | awk '$1 == "kerneldumptest"{print $3}')
if [ -n "$dspath" ]; then
vm datastore remove kerneldumptest || : # XXX always exits status 1
rm -rf $dspath
fi
vm switch destroy test || :
}
#
# Test code
#
test::runcmd()
{
local cmd
cmd=$1
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
-i ${DSDIR}/id_rsa root@${IPADDR} "$cmd"
}
test::setvars()
{
local bridge dsdir ipaddr
dsdir=$(vm datastore list | awk '$1 == "kerneldumptest"{print $3}')
bridge=$(vm switch list | awk '$1 == "test"{print $3}')
ipaddr=$(ifconfig $bridge | awk '/^[[:space:]]+inet /{print $2}')
ipaddr=${ipaddr%[0-9]*}2
DSDIR=$dsdir
IPADDR=$ipaddr
}
test::setup()
{
test::setvars
vm start kerneldumptest || :
test::waitforonline
test::runcmd "sync; sync; sync"
}
test::waitforonline()
{
local count
count=120
while [ $count -gt 0 ]; do
nc -w 1 -z $IPADDR 22 >/dev/null 2>&1 && return 0
sleep 1
count=$(($count - 1))
done
warn "timed out waiting for ssh to come up"
return 1
}
runtests::main()
{
local status
test::setup
echo "1..10"
set +e
# Test case 1: basic minidump.
(
set -e
test::runcmd "rm -rf /var/crash/*"
test::runcmd "dumpon /dev/null"
test::runcmd "dumpon /dev/vtbd0p2" # XXX hardcoded partition number
test::runcmd "sysctl debug.kdb.panic=1" || : &
sleep 1 # Give the system a second to panic.
test::waitforonline
test::runcmd "test -f /var/crash/vmcore.0"
test::runcmd "test -f /var/crash/info.0"
test::runcmd "grep -q '^[[:space:]]*Dump Status: good' /var/crash/info.0"
test::runcmd "echo 'thread apply all bt' |
kgdb /boot/kernel/kernel /var/crash/vmcore.last"
test::runcmd "crashinfo -d /var/crash -n 0"
) > /dev/null 2>&1
status=$?
if [ $status -eq 0 ]; then
echo 1 ok
else
echo 1 not ok
fi
# Test case 2: basic full dump.
(
set -e
test::runcmd "rm -rf /var/crash/*"
test::runcmd "dumpon /dev/null"
test::runcmd "dumpon /dev/vtbd0p2" # XXX hardcoded partition number
test::runcmd "sysctl debug.minidump=0"
test::runcmd "sysctl debug.kdb.panic=1" || : &
sleep 1 # Give the system a second to panic.
test::waitforonline
test::runcmd "test -f /var/crash/vmcore.0"
test::runcmd "test -f /var/crash/info.0"
test::runcmd "grep -q '^[[:space:]]*Dump Status: good' /var/crash/info.0"
test::runcmd "echo 'thread apply all bt' |
kgdb /boot/kernel/kernel /var/crash/vmcore.last"
test::runcmd "crashinfo -d /var/crash -n 0"
) > /dev/null 2>&1
status=$?
if [ $status -eq 0 ]; then
echo 2 ok
else
echo 2 not ok
fi
# Test case 3: compressed minidump.
(
set -e
test::runcmd "rm -rf /var/crash/*"
test::runcmd "dumpon /dev/null"
test::runcmd "dumpon -c /dev/vtbd0p2" # XXX hardcoded partition number
test::runcmd "sysctl debug.kdb.panic=1" || : &
sleep 1 # Give the system a second to panic.
test::waitforonline
test::runcmd "test -f /var/crash/vmcore.0.gz"
test::runcmd "test -f /var/crash/info.0"
test::runcmd "grep -q '^[[:space:]]*Dump Status: good' /var/crash/info.0"
test::runcmd "gunzip /var/crash/vmcore.0.gz"
test::runcmd "echo 'thread apply all bt' |
kgdb /boot/kernel/kernel /var/crash/vmcore.0"
test::runcmd "crashinfo -d /var/crash -n 0"
) >/dev/null 2>&1
status=$?
if [ $status -eq 0 ]; then
echo 3 ok
else
echo 3 not ok
fi
# Test case 4: encrypted minidump.
(
set -e
test::runcmd "rm -rf /var/crash/*"
test::runcmd "dumpon /dev/null"
test::runcmd "openssl genrsa -out /var/crash/private.pem 4096"
test::runcmd "openssl rsa -in /var/crash/private.pem \
-out /var/crash/public.pem -pubout"
test::runcmd "dumpon -k /var/crash/public.pem /dev/vtbd0p2" # XXX hardcoded partition number
test::runcmd "fsync /var/crash/*"
test::runcmd "sysctl debug.kdb.panic=1" || : &
sleep 1 # Give the system a second to panic.
test::waitforonline
test::runcmd "test -f /var/crash/vmcore_encrypted.0"
test::runcmd "test -f /var/crash/key.0"
test::runcmd "test -f /var/crash/info.0"
test::runcmd "grep -q '^[[:space:]]*Dump Status: good' /var/crash/info.0"
test::runcmd "decryptcore -p /var/crash/private.pem -k /var/crash/key.0 \
-e /var/crash/vmcore_encrypted.0 -c /var/crash/vmcore.0"
test::runcmd "echo 'thread apply all bt' |
kgdb /boot/kernel/kernel /var/crash/vmcore.0"
test::runcmd "crashinfo -d /var/crash -n 0"
) >/dev/null 2>&1
status=$?
if [ $status -eq 0 ]; then
echo 4 ok
else
echo 4 not ok
fi
# Test case 5: compressed, encrypted minidump.
(
set -e
test::runcmd "rm -rf /var/crash/*"
test::runcmd "dumpon /dev/null"
test::runcmd "openssl genrsa -out /var/crash/private.pem 4096"
test::runcmd "openssl rsa -in /var/crash/private.pem \
-out /var/crash/public.pem -pubout"
test::runcmd "dumpon -c -k /var/crash/public.pem /dev/vtbd0p2" # XXX hardcoded partition number
test::runcmd "fsync /var/crash/*"
test::runcmd "sysctl debug.kdb.panic=1" || : &
sleep 1 # Give the system a second to panic.
test::waitforonline
test::runcmd "test -f /var/crash/vmcore_encrypted.0"
test::runcmd "test -f /var/crash/key.0"
test::runcmd "test -f /var/crash/info.0"
test::runcmd "grep -q '^[[:space:]]*Dump Status: good' /var/crash/info.0"
test::runcmd "decryptcore -p /var/crash/private.pem -k /var/crash/key.0 \
-e /var/crash/vmcore_encrypted.0 -c /var/crash/vmcore.0.gz"
test::runcmd "gunzip /var/crash/vmcore.0.gz"
test::runcmd "echo 'thread apply all bt' |
kgdb /boot/kernel/kernel /var/crash/vmcore.0"
test::runcmd "crashinfo -d /var/crash -n 0"
) >/dev/null 2>&1
status=$?
if [ $status -eq 0 ]; then
echo 5 ok
else
echo 5 not ok
fi
# Test case 6: minidump on 4Kn drive.
(
set -e
test::runcmd "rm -rf /var/crash/*"
test::runcmd "dumpon /dev/null"
test::runcmd "dumpon /dev/vtbd1" # XXX hardcoded device
test::runcmd "sysctl debug.kdb.panic=1" || : &
sleep 1 # Give the system a second to panic.
test::waitforonline
test::runcmd "savecore /var/crash /dev/vtbd1"
test::runcmd "test -f /var/crash/vmcore.0"
test::runcmd "test -f /var/crash/info.0"
test::runcmd "grep -q '^[[:space:]]*Dump Status: good' /var/crash/info.0"
test::runcmd "echo 'thread apply all bt' |
kgdb /boot/kernel/kernel /var/crash/vmcore.last"
test::runcmd "crashinfo -d /var/crash -n 0"
) > /dev/null 2>&1
status=$?
if [ $status -eq 0 ]; then
echo 6 ok
else
echo 6 not ok
fi
# Test case 7: full dump on 4Kn drive.
(
set -e
test::runcmd "rm -rf /var/crash/*"
test::runcmd "dumpon /dev/null"
test::runcmd "dumpon /dev/vtbd1" # XXX hardcoded device
test::runcmd "sysctl debug.minidump=0"
test::runcmd "sysctl debug.kdb.panic=1" || : &
sleep 1 # Give the system a second to panic.
test::waitforonline
test::runcmd "savecore /var/crash /dev/vtbd1"
test::runcmd "test -f /var/crash/vmcore.0"
test::runcmd "test -f /var/crash/info.0"
test::runcmd "grep -q '^[[:space:]]*Dump Status: good' /var/crash/info.0"
test::runcmd "echo 'thread apply all bt' |
kgdb /boot/kernel/kernel /var/crash/vmcore.last"
test::runcmd "crashinfo -d /var/crash -n 0"
) > /dev/null 2>&1
status=$?
if [ $status -eq 0 ]; then
echo 7 ok
else
echo 7 not ok
fi
# Test case 8: compressed minidump on 4Kn drive.
(
set -e
test::runcmd "rm -rf /var/crash/*"
test::runcmd "dumpon /dev/null"
test::runcmd "dumpon -c /dev/vtbd1" # XXX hardcoded device number
test::runcmd "sysctl debug.kdb.panic=1" || : &
sleep 1 # Give the system a second to panic.
test::waitforonline
test::runcmd "savecore /var/crash /dev/vtbd1"
test::runcmd "test -f /var/crash/vmcore.0.gz"
test::runcmd "test -f /var/crash/info.0"
test::runcmd "grep -q '^[[:space:]]*Dump Status: good' /var/crash/info.0"
test::runcmd "gunzip /var/crash/vmcore.0.gz"
test::runcmd "echo 'thread apply all bt' |
kgdb /boot/kernel/kernel /var/crash/vmcore.0"
test::runcmd "crashinfo -d /var/crash -n 0"
) >/dev/null 2>&1
status=$?
if [ $status -eq 0 ]; then
echo 8 ok
else
echo 8 not ok
fi
# Test case 9: encrypted minidump on 4Kn drive.
(
set -e
test::runcmd "rm -rf /var/crash/*"
test::runcmd "dumpon /dev/null"
test::runcmd "openssl genrsa -out /var/crash/private.pem 4096"
test::runcmd "openssl rsa -in /var/crash/private.pem \
-out /var/crash/public.pem -pubout"
test::runcmd "dumpon -k /var/crash/public.pem /dev/vtbd1" # XXX hardcoded device number
test::runcmd "fsync /var/crash/*"
test::runcmd "sysctl debug.kdb.panic=1" || : &
sleep 1 # Give the system a second to panic.
test::waitforonline
test::runcmd "savecore /var/crash /dev/vtbd1"
test::runcmd "test -f /var/crash/vmcore_encrypted.0"
test::runcmd "test -f /var/crash/key.0"
test::runcmd "test -f /var/crash/info.0"
test::runcmd "grep -q '^[[:space:]]*Dump Status: good' /var/crash/info.0"
test::runcmd "decryptcore -p /var/crash/private.pem -k /var/crash/key.0 \
-e /var/crash/vmcore_encrypted.0 -c /var/crash/vmcore.0"
test::runcmd "echo 'thread apply all bt' |
kgdb /boot/kernel/kernel /var/crash/vmcore.0"
test::runcmd "crashinfo -d /var/crash -n 0"
) >/dev/null 2>&1
status=$?
if [ $status -eq 0 ]; then
echo 9 ok
else
echo 9 not ok
fi
# Test case 10: compressed, encrypted minidump on 4Kn drive.
(
set -e
test::runcmd "rm -rf /var/crash/*"
test::runcmd "dumpon /dev/null"
test::runcmd "openssl genrsa -out /var/crash/private.pem 4096"
test::runcmd "openssl rsa -in /var/crash/private.pem \
-out /var/crash/public.pem -pubout"
test::runcmd "dumpon -c -k /var/crash/public.pem /dev/vtbd1" # XXX hardcoded device number
test::runcmd "fsync /var/crash/*"
test::runcmd "sysctl debug.kdb.panic=1" || : &
sleep 1 # Give the system a second to panic.
test::waitforonline
test::runcmd "savecore /var/crash /dev/vtbd1"
test::runcmd "test -f /var/crash/vmcore_encrypted.0"
test::runcmd "test -f /var/crash/key.0"
test::runcmd "test -f /var/crash/info.0"
test::runcmd "grep -q '^[[:space:]]*Dump Status: good' /var/crash/info.0"
test::runcmd "decryptcore -p /var/crash/private.pem -k /var/crash/key.0 \
-e /var/crash/vmcore_encrypted.0 -c /var/crash/vmcore.0.gz"
test::runcmd "gunzip /var/crash/vmcore.0.gz"
test::runcmd "echo 'thread apply all bt' |
kgdb /boot/kernel/kernel /var/crash/vmcore.0"
test::runcmd "crashinfo -d /var/crash -n 0"
) >/dev/null 2>&1
status=$?
if [ $status -eq 0 ]; then
echo 10 ok
else
echo 10 not ok
fi
set -e
}
#
# Execution starts here.
#
set -e
[ $# -ge 1 ] || usage
args=
verb=$1
case "$verb" in
provision)
[ $# -eq 2 ] || usage
args="$2 3"
;;
deprovision)
;;
runtests)
;;
*)
usage
esac
# Check some preconditions.
[ $(id -u) -eq 0 ] || err "must be run as root"
pkg info -q vm-bhyve || err "vm-bhyve is not installed"
kldstat -q -m vmm || kldload vmm || err "failed to load vmm.ko"
${verb}::main $args