Skip to content

Commit 2713866

Browse files
authored
Merge pull request #333 from desultory/dev
improve tests, add tests for the mask system, improve organization/comments
2 parents 2f8ad43 + 618df02 commit 2713866

File tree

4 files changed

+59
-11
lines changed

4 files changed

+59
-11
lines changed

tests/test_compression.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from unittest import TestCase, main
2+
3+
from pycpio.errors import UnavailableCompression
4+
from ugrd.initramfs_generator import InitramfsGenerator
5+
from zenlib.logging import loggify
6+
7+
8+
@loggify
9+
class TestCompression(TestCase):
10+
def test_xz(self):
11+
"""Text XZ compression for initramfs."""
12+
generator = InitramfsGenerator(logger=self.logger, config="tests/fullauto.toml", cpio_compression="xz")
13+
generator.build()
14+
15+
def test_zstd(self):
16+
"""Test ZSTD compression for initramfs."""
17+
generator = InitramfsGenerator(logger=self.logger, config="tests/fullauto.toml", cpio_compression="zstd")
18+
try:
19+
generator.build()
20+
except UnavailableCompression as e:
21+
self.skipTest(f"ZSTD compression is not available: {e}")
22+
23+
24+
if __name__ == "__main__":
25+
main()

tests/test_cryptsetup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def tearDown(self):
2727
keyfile.unlink()
2828

2929
def test_cryptsetup_included_key(self):
30+
"""Tests LUKS based roots using a keyfile included in the initramfs"""
3031
generator = InitramfsGenerator(logger=self.logger, config="tests/cryptsetup_included_key.toml")
3132
generator.build()
3233

tests/test_filesystems.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,46 @@
11
from unittest import TestCase, main
22

3+
from ugrd.exceptions import AutodetectError
34
from ugrd.initramfs_generator import InitramfsGenerator
45
from ugrd.kmod import MissingModuleError
56
from zenlib.logging import loggify
67

78

89
@loggify
9-
class TestCpio(TestCase):
10+
class TestFilesystems(TestCase):
1011
def test_ext4(self):
12+
"""Test ext4 root filesystem functionality."""
1113
generator = InitramfsGenerator(logger=self.logger, config="tests/fs/ext4.toml")
1214
generator.build()
1315

1416
def test_btrfs(self):
17+
"""Test btrfs root filesystem functionality."""
1518
generator = InitramfsGenerator(logger=self.logger, config="tests/fs/btrfs.toml")
1619
generator.build()
1720

1821
def test_xfs(self):
22+
"""Test xfs root filesystem functionality."""
1923
generator = InitramfsGenerator(logger=self.logger, config="tests/fs/xfs.toml")
2024
generator.build()
2125

2226
def test_f2fs(self):
27+
"""Test f2fs root filesystem functionality."""
2328
generator = InitramfsGenerator(logger=self.logger, config="tests/fs/f2fs.toml")
2429
try:
2530
generator.build()
26-
except MissingModuleError:
27-
generator.logger.critical("F2FS is not supported on this system, skipping test.")
31+
except (MissingModuleError, AutodetectError) as e:
32+
self.skipTest(f"F2FS is not supported on this system: {e}")
2833

2934
def test_overlayfs(self):
35+
"""Test overlayfs/tmpfs overlay over root creation."""
3036
generator = InitramfsGenerator(logger=self.logger, config="tests/fs/overlayfs.toml")
3137
generator.build()
3238

3339
def test_squashfs(self):
40+
"""Test squashfs/overlayfs/tmpfs for live cd systems."""
3441
generator = InitramfsGenerator(logger=self.logger, config="tests/fs/squashfs.toml")
3542
generator.build()
3643

44+
3745
if __name__ == "__main__":
3846
main()

tests/test_ugrd.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,39 @@
44
from zenlib.logging import loggify
55

66

7+
def bad_function(self):
8+
"""A function that should not be called."""
9+
return "exit 1"
10+
11+
712
@loggify
813
class TestUGRD(TestCase):
914
def test_fullauto(self):
15+
"""Test a basic initramfs image using config determined from the build environment, with no compression."""
1016
generator = InitramfsGenerator(logger=self.logger, config="tests/fullauto.toml")
1117
generator.build()
1218

13-
def test_xz(self):
14-
generator = InitramfsGenerator(logger=self.logger, config="tests/fullauto.toml", cpio_compression="xz")
15-
generator.build()
16-
17-
def test_zstd(self):
18-
generator = InitramfsGenerator(logger=self.logger, config="tests/fullauto.toml", cpio_compression="zstd")
19-
generator.build()
20-
2119
def test_bad_config(self):
20+
"""Test that a bad config file which should raise an error."""
2221
with self.assertRaises(ValueError):
2322
InitramfsGenerator(logger=self.logger, config="tests/bad_config.toml")
2423

24+
def test_bad_mask(self):
25+
"""Test that masking a critical function raises an error."""
26+
generator = InitramfsGenerator(logger=self.logger, config="tests/fullauto.toml")
27+
generator["masks"] = {"init_final": "do_switch_root"}
28+
with self.assertRaises(RuntimeError):
29+
generator.build()
30+
31+
def test_good_mask(self):
32+
""" Tests that masking a broken function resolves a boot issue. """
33+
generator = InitramfsGenerator(logger=self.logger, config="tests/fullauto.toml")
34+
generator["imports"]["init_main"] += bad_function
35+
generator["masks"] = {"init_main": "bad_function"}
36+
generator.build()
37+
2538
def test_no_root(self):
39+
"""Test without a rootfs which can be found, should cause the initramfs to restart."""
2640
generator = InitramfsGenerator(
2741
logger=self.logger, config="tests/fullauto.toml", test_no_rootfs=True, test_flag="Restarting init"
2842
)

0 commit comments

Comments
 (0)