Skip to content

Commit

Permalink
test/test_layout_std.py: add tests for efistub
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Ammerlaan <[email protected]>
  • Loading branch information
Nowa-Ammerlaan committed Apr 22, 2024
1 parent 71d410e commit a807587
Showing 1 changed file with 75 additions and 5 deletions.
80 changes: 75 additions & 5 deletions test/test_layout_std.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,21 @@ def create_layout(self) -> tempfile.TemporaryDirectory:
'boot/initrd-1.2.3.img',
]
test_spec += [f'{x}.old' for x in test_spec]

"""EFI Stub"""
test_spec += [
'efi/EFI/Gentoo/vmlinuz-1.2.1.efi',
'efi/EFI/Gentoo/System.map-1.2.1',
'efi/EFI/Gentoo/config-1.2.1',
'efi/EFI/Gentoo/initramfs-1.2.1.img',
]

test_spec += [
'boot/config-1.2.4',
'boot/vmlinuz-1.2.2',
'boot/vmlinuz-1.2.2.sig',
'boot/System.map-1.2.2',
'lib/modules/1.2.1/test.ko',
'lib/modules/1.2.2/test.ko',
'lib/modules/1.2.3/test.ko',
'lib/modules/1.2.4/test.ko',
Expand All @@ -82,11 +92,14 @@ def create_layout(self) -> tempfile.TemporaryDirectory:
td = make_test_files(test_spec)
path = Path(td.name)
boot = path / 'boot'
efistub = path / 'efi/EFI/Gentoo/'
modules = path / 'lib/modules'

write_bzImage(efistub / 'vmlinuz-1.2.1.efi', b'1.2.1 test')
write_bzImage(boot / 'vmlinuz-1.2.2', b'1.2.2 test')
write_bzImage(boot / 'vmlinuz-1.2.3', b'1.2.3 test')
write_bzImage(boot / 'vmlinuz-1.2.3.old', b'1.2.3 test')
os.symlink('../../../usr/src/linux', modules / '1.2.1/build')
os.symlink('../../../usr/src/linux', modules / '1.2.2/build')
os.symlink('../../../usr/src/linux', modules / '1.2.3/build')

Expand All @@ -98,6 +111,7 @@ def assert_kernels(self,
k123: bool = True,
k123old: bool = True,
k122: bool = True,
k121: bool = True,
stray: bool = True
) -> None:
"""Assert whether specified kernels were removed or kept"""
Expand All @@ -112,7 +126,12 @@ def assert_kernels(self,
'boot/initrd-1.2.3.img.old': k123old,
'boot/vmlinuz-1.2.2': k122,
'boot/System.map-1.2.2': k122,
'efi/EFI/Gentoo/vmlinuz-1.2.1.efi': k121,
'efi/EFI/Gentoo/System.map-1.2.1': k121,
'efi/EFI/Gentoo/config-1.2.1': k121,
'efi/EFI/Gentoo/initramfs-1.2.1.img': k121,
'boot/config-1.2.4': k124,
'lib/modules/1.2.1/test.ko': k121,
'lib/modules/1.2.2/test.ko': k122,
'lib/modules/1.2.2': k122,
'lib/modules/1.2.3/test.ko': k123 or k123old,
Expand All @@ -135,12 +154,23 @@ def test_find_modules(self) -> None:
with self.create_layout() as td:
path = Path(td)
boot = path / 'boot'
efistub = path / 'efi/EFI/Gentoo/'
modules = path / 'lib/modules'

self.assertEqual(
sorted(kernel_paths(
StdLayout(root=path).find_kernels())),
[('1.2.2',
[('1.2.1',
[GenericFile(efistub / 'System.map-1.2.1', KFT.SYSTEM_MAP),
GenericFile(efistub / 'config-1.2.1', KFT.CONFIG),
GenericFile(efistub / 'initramfs-1.2.1.img', KFT.INITRAMFS),
KernelImage(efistub / 'vmlinuz-1.2.1.efi'),
ModuleDirectory(modules / '1.2.1'),
GenericFile(modules / '1.2.1/../../../usr/src/linux',
KFT.BUILD),
],
'1.2.1'),
('1.2.2',
[GenericFile(boot / 'System.map-1.2.2', KFT.SYSTEM_MAP),
KernelImage(boot / 'vmlinuz-1.2.2'),
ModuleDirectory(modules / '1.2.2'),
Expand Down Expand Up @@ -178,13 +208,23 @@ def test_exclude_config(self) -> None:
with self.create_layout() as td:
path = Path(td)
boot = path / 'boot'
efistub = path / 'efi/EFI/Gentoo/'
modules = path / 'lib/modules'

self.assertEqual(
sorted(kernel_paths(
StdLayout(root=path).find_kernels(
exclusions=[KFT.CONFIG]))),
[('1.2.2',
[('1.2.1',
[GenericFile(efistub / 'System.map-1.2.1', KFT.SYSTEM_MAP),
GenericFile(efistub / 'initramfs-1.2.1.img', KFT.INITRAMFS),
KernelImage(efistub / 'vmlinuz-1.2.1.efi'),
ModuleDirectory(modules / '1.2.1'),
GenericFile(modules / '1.2.1/../../../usr/src/linux',
KFT.BUILD),
],
'1.2.1'),
('1.2.2',
[GenericFile(boot / 'System.map-1.2.2', KFT.SYSTEM_MAP),
KernelImage(boot / 'vmlinuz-1.2.2'),
ModuleDirectory(modules / '1.2.2'),
Expand Down Expand Up @@ -219,13 +259,23 @@ def test_exclude_modules(self) -> None:
with self.create_layout() as td:
path = Path(td)
boot = path / 'boot'
efistub = path / 'efi/EFI/Gentoo/'
modules = path / 'lib/modules'

self.assertEqual(
sorted(kernel_paths(
StdLayout(root=path).find_kernels(
exclusions=[KFT.MODULES]))),
[('1.2.2',
[('1.2.1',
[GenericFile(efistub / 'System.map-1.2.1', KFT.SYSTEM_MAP),
GenericFile(efistub / 'config-1.2.1', KFT.CONFIG),
GenericFile(efistub / 'initramfs-1.2.1.img', KFT.INITRAMFS),
KernelImage(efistub / 'vmlinuz-1.2.1.efi'),
GenericFile(modules / '1.2.1/../../../usr/src/linux',
KFT.BUILD),
],
'1.2.1'),
('1.2.2',
[GenericFile(boot / 'System.map-1.2.2', KFT.SYSTEM_MAP),
KernelImage(boot / 'vmlinuz-1.2.2'),
GenericFile(modules / '1.2.2/../../../usr/src/linux',
Expand Down Expand Up @@ -259,13 +309,22 @@ def test_exclude_build(self) -> None:
with self.create_layout() as td:
path = Path(td)
boot = path / 'boot'
efistub = path / 'efi/EFI/Gentoo/'
modules = path / 'lib/modules'

self.assertEqual(
sorted(kernel_paths(
StdLayout(root=path).find_kernels(
exclusions=[KFT.BUILD]))),
[('1.2.2',
[('1.2.1',
[GenericFile(efistub / 'System.map-1.2.1', KFT.SYSTEM_MAP),
GenericFile(efistub / 'config-1.2.1', KFT.CONFIG),
GenericFile(efistub / 'initramfs-1.2.1.img', KFT.INITRAMFS),
KernelImage(efistub / 'vmlinuz-1.2.1.efi'),
ModuleDirectory(modules / '1.2.1'),
],
'1.2.1'),
('1.2.2',
[GenericFile(boot / 'System.map-1.2.2', KFT.SYSTEM_MAP),
KernelImage(boot / 'vmlinuz-1.2.2'),
ModuleDirectory(modules / '1.2.2'),
Expand Down Expand Up @@ -351,7 +410,14 @@ def test_main_list_kernels(self,
- systemmap: {td}/boot/System.map-1.2.2
- vmlinuz: {td}/boot/vmlinuz-1.2.2
- modules: {td}/lib/modules/1.2.2
- build: {td}/lib/modules/1.2.2/../../../usr/src/linux'''.lstrip())
- build: {td}/lib/modules/1.2.2/../../../usr/src/linux
other 1.2.1 [1.2.1]
- systemmap: {td}/efi/EFI/Gentoo/System.map-1.2.1
- config: {td}/efi/EFI/Gentoo/config-1.2.1
- initramfs: {td}/efi/EFI/Gentoo/initramfs-1.2.1.img
- vmlinuz: {td}/efi/EFI/Gentoo/vmlinuz-1.2.1.efi
- modules: {td}/lib/modules/1.2.1
- build: {td}/lib/modules/1.2.1/../../../usr/src/linux'''.lstrip())
self.assert_kernels(Path(td))

def test_main_remove(self) -> None:
Expand All @@ -378,6 +444,7 @@ def test_main_remove_all(self) -> None:
'--root', td, '--debug', '--no-mount']),
0)
self.assert_kernels(Path(td),
k121=False,
k122=False,
k123=False,
k123old=False,
Expand All @@ -398,6 +465,7 @@ def test_main_remove_n2(self) -> None:
'--root', td, '--debug', '--no-mount']),
0)
self.assert_kernels(Path(td),
k121=False,
k122=False,
k124=False)

Expand Down Expand Up @@ -428,6 +496,7 @@ def test_config_file_system(self) -> None:
'--root', td, '--debug', '--no-mount']),
0)
self.assert_kernels(Path(td),
k121=False,
k122=False,
k124=False)

Expand All @@ -447,5 +516,6 @@ def test_config_file_user(self) -> None:
'--root', td, '--debug', '--no-mount']),
0)
self.assert_kernels(Path(td),
k121=False,
k122=False,
k124=False)

0 comments on commit a807587

Please sign in to comment.