diff options
author | Georgy Yakovlev <gyakovlev@gentoo.org> | 2020-08-28 15:07:49 -0700 |
---|---|---|
committer | Georgy Yakovlev <gyakovlev@gentoo.org> | 2020-08-29 17:24:38 -0700 |
commit | 57d291e49e5502dae4161d0d48e34bf223cfdce8 (patch) | |
tree | 4015f8212029ee3b642ee1a5551c1ba8926a3a1f /eclass | |
parent | app-emulation/conmon: Remove old versions (diff) | |
download | gentoo-57d291e49e5502dae4161d0d48e34bf223cfdce8.tar.gz gentoo-57d291e49e5502dae4161d0d48e34bf223cfdce8.tar.bz2 gentoo-57d291e49e5502dae4161d0d48e34bf223cfdce8.zip |
eclass/kernel-install.eclass: rework tests
instead of using linux image we compile tiny static binary and use
it as /sbin/init
image is simply created using mkfs.ext4 -d option
arm tests need qemu keyworded, so disabled for now
Closes: https://github.com/gentoo/gentoo/pull/17305
Signed-off-by: Georgy Yakovlev <gyakovlev@gentoo.org>
Diffstat (limited to 'eclass')
-rw-r--r-- | eclass/kernel-install.eclass | 119 |
1 files changed, 96 insertions, 23 deletions
diff --git a/eclass/kernel-install.eclass b/eclass/kernel-install.eclass index f834670d4574..e826626e13f2 100644 --- a/eclass/kernel-install.eclass +++ b/eclass/kernel-install.eclass @@ -40,18 +40,7 @@ case "${EAPI:-0}" in ;; esac -inherit mount-boot - -TCL_VER=10.1 -SRC_URI+=" - test? ( - amd64? ( - https://dev.gentoo.org/~mgorny/dist/tinycorelinux-${TCL_VER}-amd64.qcow2 - ) - x86? ( - https://dev.gentoo.org/~mgorny/dist/tinycorelinux-${TCL_VER}-x86.qcow2 - ) - )" +inherit mount-boot toolchain-funcs SLOT="${PV}" IUSE="+initramfs test" @@ -59,8 +48,6 @@ RESTRICT+=" !test? ( test ) test? ( userpriv ) arm? ( test ) - arm64? ( test ) - ppc64? ( test ) " # install-DEPEND actually @@ -74,8 +61,12 @@ RDEPEND=" BDEPEND=" test? ( dev-tcltk/expect + sys-apps/coreutils sys-kernel/dracut + sys-fs/e2fsprogs amd64? ( app-emulation/qemu[qemu_softmmu_targets_x86_64] ) + arm64? ( app-emulation/qemu[qemu_softmmu_targets_aarch64] ) + ppc64? ( app-emulation/qemu[qemu_softmmu_targets_ppc64] ) x86? ( app-emulation/qemu[qemu_softmmu_targets_i386] ) )" @@ -206,12 +197,68 @@ kernel-install_get_qemu_arch() { arm64) echo aarch64 ;; + ppc64) + echo ppc64 + ;; *) die "${FUNCNAME}: unsupported ARCH=${ARCH}" ;; esac } +# @FUNCTION: kernel-install_create_init +# @USAGE: <filename> +# @DESCRIPTION: +# Create minimal /sbin/init +kernel-install_create_init() { + debug-print-function ${FUNCNAME} "${@}" + + [[ ${#} -eq 1 ]] || die "${FUNCNAME}: invalid arguments" + [[ -z ${1} ]] && die "${FUNCNAME}: empty argument specified" + + local output="${1}" + [[ -f ${output} ]] && die "${FUNCNAME}: ${output} already exists" + + cat <<-_EOF_ >"${T}/init.c" || die + #include <stdio.h> + int main() { + printf("Hello, World!\n"); + return 0; + } + _EOF_ + + $(tc-getBUILD_CC) -Os -static "${T}/init.c" -o "${output}" || die + $(tc-getBUILD_STRIP) "${output}" || die +} + +# @FUNCTION: kernel-install_create_qemu_image +# @USAGE: <filename> +# @DESCRIPTION: +# Create minimal qemu raw image +kernel-install_create_qemu_image() { + debug-print-function ${FUNCNAME} "${@}" + + [[ ${#} -eq 1 ]] || die "${FUNCNAME}: invalid arguments" + [[ -z ${1} ]] && die "${FUNCNAME}: empty argument specified" + + local image="${1}" + [[ -f ${image} ]] && die "${FUNCNAME}: ${image} already exists" + + local imageroot="${T}/imageroot" + [[ -d ${imageroot} ]] && die "${FUNCNAME}: ${imageroot} already exists" + mkdir "${imageroot}" || die + + # some layout needed to pass dracut's usable_root() validation + mkdir -p "${imageroot}"/{bin,dev,etc,lib,proc,root,sbin,sys} || die + touch "${imageroot}/lib/ld-fake.so" || die + + kernel-install_create_init "${imageroot}/sbin/init" + + # image may be smaller if needed + truncate -s 4M "${image}" || die + mkfs.ext4 -v -d "${imageroot}" -L groot "${image}" || die +} + # @FUNCTION: kernel-install_test # @USAGE: <version> <image> <modules> # @DESCRIPTION: @@ -234,25 +281,43 @@ kernel-install_test() { --no-hostonly \ --kmoddir "${modules}" \ "${T}/initrd" "${version}" || die - # get a read-write copy of the disk image - cp "${DISTDIR}/tinycorelinux-${TCL_VER}-${ARCH}.qcow2" \ - "${T}/fs.qcow2" || die + + kernel-install_create_qemu_image "${T}/fs.img" cd "${T}" || die + local qemu_extra_args= - [[ ${qemu_arch} == x86_64 ]] && qemu_extra_args='-cpu max' + local qemu_extra_append= + + case ${qemu_arch} in + aarch64) + qemu_extra_args="-M virt -cpu cortex-a57 -smp 1" + qemu_extra_append="console=ttyAMA0" + ;; + i386|x86_64) + qemu_extra_args="-cpu max" + qemu_extra_append="console=ttyS0,115200n8" + ;; + ppc64) + qemu_extra_args="-nodefaults" + ;; + *) + : + ;; + esac + cat > run.sh <<-EOF || die #!/bin/sh exec qemu-system-${qemu_arch} \ ${qemu_extra_args} \ - -m 256M \ - -display none \ + -m 512M \ + -nographic \ -no-reboot \ -kernel '${image}' \ -initrd '${T}/initrd' \ -serial mon:stdio \ - -hda '${T}/fs.qcow2' \ - -append 'root=/dev/sda console=ttyS0,115200n8' + -drive file=fs.img,format=raw,index=0,media=disk \ + -append 'root=LABEL=groot ${qemu_extra_append}' EOF chmod +x run.sh || die # TODO: initramfs does not let core finish starting on some systems, @@ -261,6 +326,14 @@ kernel-install_test() { set timeout 900 spawn ./run.sh expect { + "terminating on signal" { + send_error "\n* Qemu killed" + exit 1 + } + "OS terminated" { + send_error "\n* Qemu terminated OS" + exit 1 + } "Kernel panic" { send_error "\n* Kernel panic" exit 1 @@ -269,7 +342,7 @@ kernel-install_test() { send_error "\n* Initramfs failed to start the system" exit 1 } - "Core 10.1" { + "Hello, World!" { send_error "\n* Booted successfully" exit 0 } |