Skip to content

Commit

Permalink
test: Add a test for EFI zboot images
Browse files Browse the repository at this point in the history
Closes: #53
  • Loading branch information
hexchain authored and mgorny committed Oct 27, 2024
1 parent 39cba6e commit 14b395e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import gzip
import hashlib
import os
import struct
import tempfile
import unittest

Expand Down Expand Up @@ -98,6 +99,22 @@ def write_efistub(path: Path,
f.write(version_line)


def write_efi_zboot(path: Path,
version_line: bytes,
) -> None:
"""Write an EFI zboot kernel image at `path`, with `version_line`"""
# generate a compressed image as our payload
write_compress(path, version_line)
b = path.read_bytes()

with open(path, "wb") as f:
f.write(b"MZ\0\0zimg")
f.write(struct.pack("<LL", 0x40, len(b)))
f.write(8 * b"\0" + b"gzip" + 4 * b"\0")
f.write(0x20 * b"\0")
f.write(b)


class KernelImageTests(unittest.TestCase):
def setUp(self) -> None:
self.td = tempfile.TemporaryDirectory()
Expand Down Expand Up @@ -147,6 +164,13 @@ def test_read_internal_version_efistub_uname_nowhitespace(self) -> None:
KernelImage(path).read_internal_version(),
"1.2.3")

def test_read_internal_version_efi_zboot(self) -> None:
path = Path(self.td.name) / "vmlinuz"
write_efi_zboot(path, b"Linux version 1.2.3 built on test")
self.assertEqual(
KernelImage(path).read_internal_version(),
"1.2.3")

def test_very_short(self) -> None:
path = Path(self.td.name) / 'vmlinuz'
with open(path, 'wb') as f:
Expand Down

0 comments on commit 14b395e

Please sign in to comment.