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
|
#!/bin/bash
set -e -o pipefail
testimg=$1
arch=$(echo "$(basename -- "$(dirname -- "$testimg")")" | cut -d- -f2)
. debian/tests/qemu-cmd
qemu_exec=("${QEMU_CMD[@]}")
if ! command -v "$qemu_exec" >/dev/null 2>&1; then
echo "WARNING: QEMU executable not found: $qemu_exec" >&2
if [ "$arch" = "i386" ] || [ "$arch" = "x86_64" ]; then
echo "SKIPPING test" >&2
exit 0
else
exit 1
fi
fi
workdir=$(mktemp -d)
trap "rm -rf $workdir" EXIT
QEMU_CMD+=(-netdev user,id=net0,tftp="$workdir",bootfile=__nonexistent__)
QEMU_CMD+=(-device vmxnet3,netdev=net0,id=net0,romfile=)
case "$testimg" in
*.efi)
mkfs.vfat -C --mbr=y "$workdir/test.img" 16384
mcopy -i "$workdir/test.img" "$testimg" "::tests.efi"
cat > "$workdir/startup.nsh" <<EOF
@echo -off
tests.efi
echo "IPXE_TEST_DONE"
reset -s
EOF
mcopy -i "$workdir/test.img" "$workdir/startup.nsh" "::startup.nsh"
;;
*.lkrn)
# ljmp $0xf000,$0xfff0
echo "ea f0 ff 00 f0" | xxd -r -p > "$workdir/test.img"
echo "55 aa" | xxd -r -p | dd of="$workdir/test.img" bs=1 seek=510 conv=notrunc
truncate -s 1M "$workdir/test.img"
QEMU_CMD+=(-kernel "$testimg" -no-reboot)
;;
*)
echo "Unsupported image type: $testimg" >&2
exit 1
;;
esac
QEMU_CMD+=(-blockdev driver=raw,node-name=img,file.driver=file,file.filename="$workdir/test.img")
QEMU_CMD+=(-device virtio-scsi-pci,id=scsi -device scsi-hd,id=medium,bus=scsi.0,drive=img,bootindex=1)
expect -- - "${QEMU_CMD[@]}"<< 'EOF'
set timeout 120
proc abort {msg} {
set ferr [open "/dev/fd/2" "w"]
puts $ferr $msg
close $ferr
exit 1
}
source debian/tests/select_menu.tcl
spawn {*}$argv
expect {
"Press any key to enter the Boot Manager Menu" {
send "\r"
expect {
"Please select boot device" {
selectMenu "EFI Internal Shell"
}
-re {Standard PC|QEMU Virtual Machine| GHz} {
selectMenu "Boot Manager"
selectMenu "EFI Internal Shell"
}
timeout {
abort "Timeout"
}
eof {
abort "VM terminates unexpectedly"
}
}
}
"UEFI Interactive Shell" {}
"SeaBIOS" {}
"iPXE initialising devices" {}
eof {
abort "VM terminates unexpectedly"
}
timeout {
abort "Timeout"
}
}
expect {
"*No bootable device" {abort "Cannot Boot iPXE"}
"*Shell>" {abort "Cannot Boot iPXE"}
eof {abort "VM terminates unexpectedly"}
timeout {abort "Timeout"}
-re {OK: all \d+ tests passed} {}
}
set timeout 10
expect {
eof {}
timeout {}
}
puts "\x1b\[!p\x1b\[?7h"
exit 0
EOF
|