:: limine / contrib / test_gzip_qemu.sh 1.9 KB raw

1
#!/bin/bash
2
# Mechanically test gzip decompression end-to-end in QEMU.
3
# Boots the Limine test kernel via UEFI with both a plain file and
4
# its .gz counterpart as internal modules.  The test kernel loads
5
# the compressed module (decompressed by the bootloader) and compares
6
# it byte-for-byte against the plain copy.
7
# Usage:    bash contrib/test_gzip_qemu.sh
8
# Requires: qemu-system-x86_64, mtools, gzip
9
set -euo pipefail
10
cd "$(dirname "$0")/.."
11
TIMEOUT="${QEMU_TIMEOUT:-20}"
12
if ! command -v gzip >/dev/null 2>&1; then
13
  echo "where's your gzip?"
14
  exit 1
15
fi
16
TEST_CFLAGS="-DENABLE_QEMU_SHUTDOWN -DENABLE_GZIP_TEST"
17
make limine-bios limine-uefi-x86-64 2>&1 | tail -1
18
make edk2-ovmf 2>&1 | tail -1
19
make -C test -f test.mk ARCH=x86 EXTRA_CFLAGS="$TEST_CFLAGS" test.elf 2>&1 | tail -1
20
IMG=test_uefi.img
21
rm -f "$IMG"
22
mformat -i "$IMG" -C -F -T 131072 :: 2>/dev/null
23
mmd -i "$IMG" ::/boot ::/EFI ::/EFI/BOOT 2>/dev/null
24
mcopy -i "$IMG" bin/BOOTX64.EFI ::/EFI/BOOT/
25
mcopy -i "$IMG" bin/limine-bios.sys ::/boot/
26
mcopy -i "$IMG" test/test.elf ::/boot/
27
mcopy -i "$IMG" test/bg.jpg ::/boot/
28
mcopy -i "$IMG" test/limine.conf ::/boot/
29
GZ_TMP=$(mktemp)
30
gzip -c test/limine.conf > "$GZ_TMP"
31
mcopy -i "$IMG" "$GZ_TMP" ::/boot/limine.conf.gz
32
rm -f "$GZ_TMP"
33
QEMU_LOG=$(mktemp)
34
trap 'rm -f "$QEMU_LOG" "$IMG"' EXIT
35
timeout "$TIMEOUT" \
36
  qemu-system-x86_64 \
37
    -display none \
38
    -m 512M -M q35 \
39
    -drive if=pflash,unit=0,format=raw,file=edk2-ovmf/ovmf-code-x86_64.fd,readonly=on \
40
    -net none -smp 4 \
41
    -drive format=raw,file="$IMG" \
42
    -debugcon file:"$QEMU_LOG" \
43
  || true  # timeout exits 124
44
if grep -q 'gzip: pass' "$QEMU_LOG"; then
45
  grep 'gzip:' "$QEMU_LOG"
46
  echo "pass: gzip decompression verified in QEMU"
47
  exit 0
48
elif grep -q 'gzip: FAIL' "$QEMU_LOG"; then
49
  grep 'gzip:' "$QEMU_LOG"
50
  echo "fail"
51
  exit 1
52
else
53
  echo "fail: gzip test marker not found in QEMU output"
54
  echo "last 20 lines of log:"
55
  tail -20 "$QEMU_LOG"
56
  exit 1
57
fi
tab: 248 wrap: offon