]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/boot/ci-qemu-test.sh
stand/powerpc: Only build loader.kboot for powerpc64
[FreeBSD/FreeBSD.git] / tools / boot / ci-qemu-test.sh
1 #!/bin/sh
2
3 # Install loader, kernel, and enough of userland to boot in QEMU and echo
4 # "Hello world." from init, as a very quick smoke test for CI.  Uses QEMU's
5 # virtual FAT filesystem to avoid the need to create a disk image.  While
6 # designed for CI automated testing, this script can also be run by hand as
7 # a quick smoke-test.  The rootgen.sh and related scripts generate much more
8 # extensive tests for many combinations of boot env (ufs, zfs, geli, etc).
9 #
10 # $FreeBSD$
11
12 set -e
13
14 die()
15 {
16         echo "$*" 1>&2
17         exit 1
18 }
19
20 tempdir_cleanup()
21 {
22         trap - EXIT SIGINT SIGHUP SIGTERM SIGQUIT
23         rm -rf ${ROOTDIR}
24 }
25
26 tempdir_setup()
27 {
28         # Create minimal directory structure and populate it.
29         # Caller must cd ${SRCTOP} before calling this function.
30
31         for dir in dev bin efi/boot etc lib libexec sbin usr/lib usr/libexec; do
32                 mkdir -p ${ROOTDIR}/${dir}
33         done
34
35         # Install kernel, loader and minimal userland.
36
37         make -DNO_ROOT DESTDIR=${ROOTDIR} \
38             MODULES_OVERRIDE= \
39             WITHOUT_DEBUG_FILES=yes \
40             WITHOUT_KERNEL_SYMBOLS=yes \
41             installkernel
42         for dir in stand \
43             lib/libc lib/libedit lib/ncurses \
44             libexec/rtld-elf \
45             bin/sh sbin/init sbin/shutdown; do
46                 make -DNO_ROOT DESTDIR=${ROOTDIR} INSTALL="install -U" \
47                     WITHOUT_DEBUG_FILES= \
48                     WITHOUT_MAN= \
49                     WITHOUT_PROFILE= \
50                     WITHOUT_TESTS= \
51                     WITHOUT_TOOLCHAIN= \
52                     -C ${dir} install
53         done
54
55         # Put loader in standard EFI location.
56         mv ${ROOTDIR}/boot/loader.efi ${ROOTDIR}/efi/boot/BOOTx64.EFI
57
58         # Configuration files.
59         cat > ${ROOTDIR}/boot/loader.conf <<EOF
60 vfs.root.mountfrom="msdosfs:/dev/ada0s1"
61 autoboot_delay=-1
62 boot_verbose=YES
63 EOF
64         cat > ${ROOTDIR}/etc/rc <<EOF
65 #!/bin/sh
66
67 echo "Hello world."
68 /sbin/shutdown -p now
69 EOF
70
71         # Entropy needed to boot, see r346250 and followup commits/discussion.
72         dd if=/dev/random of=${ROOTDIR}/boot/entropy bs=4k count=1
73
74         # Remove unnecessary files to keep FAT filesystem size down.
75         rm -rf ${ROOTDIR}/METALOG ${ROOTDIR}/usr/lib
76 }
77
78 # Locate the top of the source tree, to run make install from.
79 : ${SRCTOP:=$(make -V SRCTOP)}
80 if [ -z "${SRCTOP}" ]; then
81         die "Cannot locate top of source tree"
82 fi
83
84 # Locate the uefi firmware file used by qemu.
85 : ${OVMF:=/usr/local/share/uefi-edk2-qemu/QEMU_UEFI_CODE-x86_64.fd}
86 if [ ! -r "${OVMF}" ]; then
87         die "Cannot read UEFI firmware file ${OVMF}"
88 fi
89
90 # Create a temp dir to hold the boot image.
91 ROOTDIR=$(mktemp -d -t ci-qemu-test-fat-root)
92 trap tempdir_cleanup EXIT SIGINT SIGHUP SIGTERM SIGQUIT
93
94 # Populate the boot image in a temp dir.
95 ( cd ${SRCTOP} && tempdir_setup )
96
97 # And, boot in QEMU.
98 : ${BOOTLOG:=${TMPDIR:-/tmp}/ci-qemu-test-boot.log}
99 timeout 300 \
100     qemu-system-x86_64 -m 256M -nodefaults \
101         -drive if=pflash,format=raw,readonly,file=${OVMF} \
102         -serial stdio -vga none -nographic -monitor none \
103         -snapshot -hda fat:${ROOTDIR} 2>&1 | tee ${BOOTLOG}
104
105 # Check whether we succesfully booted...
106 if grep -q 'Hello world.' ${BOOTLOG}; then
107         echo "OK"
108 else
109         die "Did not boot successfully, see ${BOOTLOG}"
110 fi