From 48e671011c114f013dc88f0089ebcf65afcc7d94 Mon Sep 17 00:00:00 2001 From: Muminul Islam Date: Mon, 27 Apr 2026 13:06:59 -0700 Subject: [PATCH] scripts: Add kernel option validation in prepare_linux Add validation checks to prepare_linux() to catch invalid kernel option combinations early: - Error if --build-guest-kernel and CH_CUSTOM_KERNEL are both provided, as they are mutually exclusive. - On x86_64, error if only one of CH_CUSTOM_KERNEL or CH_CUSTOM_BZIMAGE is set; both must be provided together. - Fix kernel-already-present check: use per-architecture branches with correct bash syntax (elif instead of else-if, [[ ]] instead of [ && ]) so aarch64 and x86_64 are each handled properly. Signed-off-by: Muminul Islam --- scripts/test-util.sh | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/scripts/test-util.sh b/scripts/test-util.sh index 3b17ee4c9..ca89159e2 100644 --- a/scripts/test-util.sh +++ b/scripts/test-util.sh @@ -187,15 +187,32 @@ download_linux() { } prepare_linux() { + if [ "$build_kernel" = true ] && [ -n "$CH_CUSTOM_KERNEL" ]; then + echo "ERROR: --build-guest-kernel and CH_CUSTOM_KERNEL are mutually exclusive" + exit 1 + fi + + if [ "$(uname -m)" = "x86_64" ]; then + if { [ -n "$CH_CUSTOM_KERNEL" ] && [ -z "$CH_CUSTOM_BZIMAGE" ]; } || + { [ -z "$CH_CUSTOM_KERNEL" ] && [ -n "$CH_CUSTOM_BZIMAGE" ]; }; then + echo "ERROR: On x86_64, both CH_CUSTOM_KERNEL and CH_CUSTOM_BZIMAGE must be provided" + exit 1 + fi + fi + if [ "$(uname -m)" = "aarch64" ]; then KERNEL_FILE="$WORKLOADS_DIR/Image-arm64" - else + if [[ -f "$KERNEL_FILE" ]]; then + echo "Kernel already present at $KERNEL_FILE, skipping" + return + fi + elif [ "$(uname -m)" = "x86_64" ]; then KERNEL_FILE="$WORKLOADS_DIR/vmlinux-x86_64" BZIMAGE_FILE="$WORKLOADS_DIR/bzImage-x86_64" - fi - if [[ -f "$KERNEL_FILE" && -f "$BZIMAGE_FILE" ]]; then - echo "Kernel already present at $KERNEL_FILE, skipping" - return + if [[ -f "$KERNEL_FILE" ]] && [[ -f "$BZIMAGE_FILE" ]]; then + echo "Kernel already present at $KERNEL_FILE and bzImage at $BZIMAGE_FILE, skipping" + return + fi fi if [ "$build_kernel" = true ]; then