Skip to content

Commit 4e6e881

Browse files
committed
ch_tests_tool: support using pmem for ch block tests
1 parent 2d5d85f commit 4e6e881

File tree

2 files changed

+72
-13
lines changed

2 files changed

+72
-13
lines changed

microsoft/testsuites/cloud_hypervisor/ch_tests.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ def _set_ms_clh_param(self, variables: Dict[str, Any]) -> None:
206206
# will not run it with data-disk and it would not add direct=on
207207
# if run_without_cache is not set to YES
208208
use_datadisk = variables.get("use_datadisk", "")
209-
disable_datadisk_cache = variables.get("disable_datadisk_cache", "")
209+
use_pmem = variables.get("ch_tests_use_pmem", "")
210+
disable_disk_cache = variables.get("disable_disk_cache", "")
210211
block_size_kb = variables.get("block_size_kb", "")
211212

212213
if not ms_access_token:
@@ -229,10 +230,12 @@ def _set_ms_clh_param(self, variables: Dict[str, Any]) -> None:
229230

230231
if block_size_kb:
231232
CloudHypervisorTests.block_size_kb = block_size_kb
233+
if use_pmem:
234+
CloudHypervisorTests.use_pmem = use_pmem
232235
if use_datadisk:
233236
CloudHypervisorTests.use_datadisk = use_datadisk
234-
if disable_datadisk_cache:
235-
CloudHypervisorTests.disable_datadisk_cache = disable_datadisk_cache
237+
if disable_disk_cache:
238+
CloudHypervisorTests.disable_disk_cache = disable_disk_cache
236239

237240

238241
def get_test_list(variables: Dict[str, Any], var1: str, var2: str) -> Any:

microsoft/testsuites/cloud_hypervisor/ch_tests_tool.py

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
from lisa.executable import Tool
1313
from lisa.features import SerialConsole
1414
from lisa.messages import TestStatus, send_sub_test_result_message
15-
from lisa.operating_system import CBLMariner
15+
from lisa.operating_system import CBLMariner, Ubuntu
1616
from lisa.testsuite import TestResult
1717
from lisa.tools import (
18+
Cat,
1819
Chmod,
1920
Chown,
2021
Dmesg,
@@ -25,9 +26,10 @@
2526
Lsblk,
2627
Mkdir,
2728
Modprobe,
29+
Sed,
2830
Whoami,
2931
)
30-
from lisa.util import LisaException, find_groups_in_lines
32+
from lisa.util import LisaException, UnsupportedDistroException, find_groups_in_lines
3133

3234

3335
@dataclass
@@ -63,7 +65,8 @@ class CloudHypervisorTests(Tool):
6365

6466
# Block perf related env var
6567
use_datadisk = ""
66-
disable_datadisk_cache = ""
68+
use_pmem = ""
69+
disable_disk_cache = ""
6770
block_size_kb = ""
6871

6972
cmd_path: PurePath
@@ -164,8 +167,16 @@ def run_metrics_tests(
164167
skip: Optional[List[str]] = None,
165168
subtest_timeout: Optional[int] = None,
166169
) -> None:
167-
if self.use_datadisk:
168-
self._set_data_disk()
170+
disk_name = ""
171+
if self.use_pmem:
172+
disk_name = self._get_pmem_for_block_tests()
173+
elif self.use_datadisk:
174+
disk_name = self._get_data_disk_for_block_tests()
175+
176+
if disk_name:
177+
self._log.debug(f"Using disk: {disk_name}, for block tests")
178+
self.env_vars["DATADISK_NAME"] = disk_name
179+
self._save_kernel_logs(log_path)
169180

170181
if ref:
171182
self.node.tools[Git].checkout(ref, self.repo_root)
@@ -267,8 +278,8 @@ def _install(self) -> bool:
267278

268279
if self.use_datadisk:
269280
self.env_vars["USE_DATADISK"] = self.use_datadisk
270-
if self.disable_datadisk_cache:
271-
self.env_vars["DISABLE_DATADISK_CACHING"] = self.disable_datadisk_cache
281+
if self.disable_disk_cache:
282+
self.env_vars["DISABLE_DATADISK_CACHING"] = self.disable_disk_cache
272283
if self.block_size_kb:
273284
self.env_vars["PERF_BLOCK_SIZE_KB"] = self.block_size_kb
274285
else:
@@ -497,7 +508,53 @@ def _configure_vdpa_devices(self, node: Node) -> None:
497508
node.tools[Chown].change_owner(file=PurePath(device_path), user=user)
498509
node.tools[Chmod].chmod(path=device_path, permission=permission, sudo=True)
499510

500-
def _set_data_disk(self) -> None:
511+
def _get_pmem_for_block_tests(self) -> str:
512+
"""
513+
Following is the last usable entry in e829 table and is safest to use for
514+
pmem since its most likely to be free. 0x0000001000000000 is 64G.
515+
516+
[ 0.000000] BIOS-e820: [mem 0x0000001000000000-0x00000040ffffffff] usable
517+
518+
"""
519+
memmap_str = "memmap=16G!64G"
520+
521+
lsblk = self.node.tools[Lsblk]
522+
sed = self.node.tools[Sed]
523+
cat = self.node.tools[Cat]
524+
525+
grub_file = "/etc/default/grub"
526+
grub_cmdline = cat.read_with_filter(
527+
file=grub_file,
528+
grep_string="GRUB_CMDLINE_LINUX=",
529+
sudo=True,
530+
)
531+
if memmap_str not in grub_cmdline:
532+
sed.substitute(
533+
file=grub_file,
534+
match_lines="^GRUB_CMDLINE_LINUX=",
535+
regexp='"$',
536+
replacement=' memmap=16G!64G "',
537+
sudo=True,
538+
)
539+
if isinstance(self.node.os, CBLMariner):
540+
self.node.execute(
541+
"grub2-mkconfig -o /boot/grub2/grub.cfg", sudo=True, shell=True
542+
)
543+
elif isinstance(self.node.os, Ubuntu):
544+
self.node.execute("update-grub", sudo=True, shell=True)
545+
else:
546+
raise UnsupportedDistroException(
547+
self.node.os,
548+
"pmem for CH tests is supported only on Ubuntu and CBLMariner",
549+
)
550+
551+
lsblk.run()
552+
self.node.reboot(time_out=900)
553+
lsblk.run()
554+
555+
return "/dev/pmem0"
556+
557+
def _get_data_disk_for_block_tests(self) -> str:
501558
datadisk_name = ""
502559
lsblk = self.node.tools[Lsblk]
503560
disks = lsblk.get_disks()
@@ -512,8 +569,7 @@ def _set_data_disk(self) -> None:
512569
lsblk.run()
513570
if not datadisk_name:
514571
raise LisaException("No unmounted data disk (/dev/sdX) found")
515-
self._log.debug(f"Using data disk: {datadisk_name}")
516-
self.env_vars["DATADISK_NAME"] = datadisk_name
572+
return datadisk_name
517573

518574

519575
def extract_jsons(input_string: str) -> List[Any]:

0 commit comments

Comments
 (0)