#!/bin/bash
# With both generators installed, the kernel hook must pick dracut. Every other
# test pins KDUMP_INITRD_GENERATOR, so this is the only coverage of the
# auto-detection path.

TEST_NAME="generator-autodetect"
# shellcheck source=debian/tests/kdump-test-lib.sh
. "$(dirname "$0")/kdump-test-lib.sh"

command -v dracut > /dev/null 2>&1 || error "dracut not installed"
[ -x /usr/sbin/mkinitramfs ] || error "mkinitramfs not installed"
report "both generators available"

# The shipped default must leave the generator unset, otherwise there is nothing
# to auto-detect.
if grep -q '^KDUMP_INITRD_GENERATOR=' "$KDUMP_DEFAULTS"; then
	error "KDUMP_INITRD_GENERATOR is set in $KDUMP_DEFAULTS; auto-detection is not being exercised"
fi

rebuild_capture_initrd
assert_dracut_capture_initrd
report "auto-detection chose dracut over initramfs-tools"
