Skip to content

Commit a11597d

Browse files
committed
fixed up posix compliance & attempted to clean up variables
- converted `test_cmdline` to a NoDupFlatList to allow modules to append parameters more easily - made script in `test_resume` posix compliant, removed use of "local", "source" and (technically compliant, but not universally supported) redirects - attempted to clean up test-specific variables that are appended to by the resume module.
1 parent 9c5637f commit a11597d

File tree

7 files changed

+32
-28
lines changed

7 files changed

+32
-28
lines changed

src/ugrd/base/test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def _get_qemu_cmd_args(self, test_image):
5555
"-cpu": self["test_cpu"],
5656
"-kernel": self["test_kernel"],
5757
"-initrd": test_initrd,
58-
"-append": self["test_cmdline"],
58+
"-append": " ".join(self["test_cmdline"]),
5959
"-drive": "file=%s,format=raw" % test_rootfs,
6060
}
6161

@@ -86,7 +86,7 @@ def make_test_image(self):
8686
"validate": False,
8787
"NO_BASE": True,
8888
"config": None,
89-
"modules": ','.join(self["test_modules"]), # By default is only "ugrd.fs.test_image"
89+
"modules": ",".join(self["test_modules"]), # By default is only "ugrd.fs.test_image"
9090
"out_file": self["test_rootfs_name"],
9191
"build_dir": self["test_rootfs_build_dir"],
9292
"custom_parameters": get_copy_config_types(self),

src/ugrd/base/test.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ test_memory = '256M'
99
test_cpu = 'host'
1010
test_arch = 'x86_64'
1111
test_timeout = 30
12-
test_cmdline = 'console=ttyS0,115200 panic=0'
12+
test_cmdline = ['console=ttyS0,115200', 'panic=0']
1313
test_modules = [ "ugrd.fs.test_image" ]
1414
qemu_bool_args = ['nographic', 'enable-kvm' ]
1515

@@ -24,7 +24,7 @@ test_kernel = "Path" # Define the kernel to use for the test
2424
test_memory = "str" # Define the amount of memory to use for the test image (passed to qemu)
2525
test_cpu = "str" # Define the CPU to use for the test image (passed to qemu)
2626
test_arch = "str" # Define the qemu arch (added to the qemu-system- command)
27-
test_cmdline = "str" # Define the kernel command line for the test image
27+
test_cmdline = "NoDupFlatList" # Define the kernel command line for the test image
2828
test_timeout = "int" # Define the timeout for the test
2929
test_image_size = "int" # Define the size of the test image, in MB
3030
test_flag = "str" # Define the success flag for the test

src/ugrd/fs/resume.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33
from zenlib.util import contains
44

55

6+
@contains("test_resume")
7+
def setup_resume_tests(self) -> None:
8+
if "ugrd.base.test" in self["modules"]:
9+
from uuid import uuid4
10+
11+
# Create a uuid for the swap partition in the test image
12+
if not self["test_swap_uuid"]:
13+
self["test_swap_uuid"] = uuid4()
14+
15+
# pull in the hibernation/resume testing module
16+
self["test_modules"] = "ugrd.fs.test_resume"
17+
18+
# append resume partition to QEMU kernel cmdline
19+
self["test_cmdline"] = f"resume=UUID={self['test_swap_uuid']}"
20+
21+
622
def resume(self) -> str:
723
"""Returns a shell script handling resume from hibernation.
824
Checks that /sys/power/resume is writable, resume= is set, and noresume is not set, if so,
@@ -30,8 +46,7 @@ def resume(self) -> str:
3046
3147
[ -b "$1" ] || (ewarn "\'$1\' is not a valid block device!" ; return 1)
3248
einfo "Attempting resume from: $1"
33-
# TODO: This could maybe be printf?
34-
echo -n "$1" > /sys/power/resume
49+
printf "%s" "$1" > /sys/power/resume
3550
einfo "No image on: $resume"
3651
return 0
3752
"""
@@ -70,17 +85,3 @@ def handle_late_resume(self) -> None:
7085

7186
# At the moment it's the same code but delayed, will change when more features are added
7287
return handle_early_resume(self)
73-
74-
@contains("test_resume")
75-
def test_resume_setup(self) -> None:
76-
if "ugrd.base.test" in self["modules"]:
77-
# Add resume to the list of test modules
78-
self["test_modules"] = "ugrd.fs.test_resume"
79-
80-
# Create a uuid for the swap partition in the test image
81-
from uuid import uuid4
82-
if not self["test_swap_uuid"]:
83-
self["test_swap_uuid"] = swap_uuid = uuid4()
84-
85-
# append to QEMU kernel cmdline
86-
self["test_cmdline"] = f"{self.get('test_cmdline')} resume=UUID={swap_uuid}"

src/ugrd/fs/resume.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ binaries = [ 'lsblk' ]
33
test_copy_config = [ "test_resume", "test_swap_uuid" ]
44

55
[imports.build_pre]
6-
"ugrd.fs.resume" = [ "test_resume_setup" ]
6+
"ugrd.fs.resume" = [ "setup_resume_tests" ]
77

88
[imports.init_main]
99
"ugrd.fs.resume" = [ "handle_early_resume", "handle_late_resume"]
@@ -15,9 +15,9 @@ handle_early_resume = "mount_fstab"
1515
handle_late_resume = ["crypt_init", "init_lvm"]
1616

1717
[imports.functions]
18-
"ugrd.fs.resume" = ["resume"]
18+
"ugrd.fs.resume" = [ "resume" ]
1919

2020
[custom_parameters]
21-
late_resume = "bool"
21+
late_resume = "bool" # Include code for late resume
2222
test_resume = "bool" # Test hibernation/resume pathways when test is enabled
23-
test_swap_uuid = "str" # Define the uuid of the swap partition on the test image
23+
test_swap_uuid = "str" # Define the uuid of the swap partition on the test image

src/ugrd/fs/test_image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def make_test_image(self):
144144

145145
image_path = f"{loopback}p2"
146146
except RuntimeError as e:
147-
self._run(["losetup", "-d", loopback]) # Free loopback device on fail
147+
self._run(["losetup", "-d", loopback]) # Free loopback device on fail
148148
raise RuntimeError("Failed to allocate loopback device for disk creation: %s", e)
149149

150150
# sleep for 100ms, to give the loopback device time to scan for partitions

src/ugrd/fs/test_resume.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from zenlib.util import contains
44

5+
56
@contains("test_resume")
67
def resume_tests(self):
78
return """
@@ -10,9 +11,8 @@ def resume_tests(self):
1011
echo reboot > /sys/power/disk
1112
echo 1 > /sys/power/pm_debug_messages
1213
13-
local SWAPDEV=/dev/$(source "/sys/dev/block/$(</sys/power/resume)/uevent" && echo $DEVNAME)
14-
echo "Activating swap device ${SWAPDEV}..."
15-
swapon ${SWAPDEV}
14+
echo "Activating hibernation swap device..."
15+
swapon /dev/$(. "/sys/dev/block/$(read blk </sys/power/resume && echo $blk)/uevent" && echo $DEVNAME)
1616
1717
echo "Triggering test hibernation..."
1818
echo disk > /sys/power/state || (echo "Suspend to disk failed!" ; echo c > /proc/sysrq-trigger)

src/ugrd/fs/test_resume.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
[imports.init_main]
22
"ugrd.fs.test_resume" = ["resume_tests"]
3+
4+
[custom_parameters]
5+
test_resume = "bool"

0 commit comments

Comments
 (0)