Skip to content

Commit

Permalink
ch_tests_tool: support using pmem for ch block tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pupacha committed Mar 4, 2025
1 parent 2d5d85f commit 4e6e881
Showing 2 changed files with 72 additions and 13 deletions.
9 changes: 6 additions & 3 deletions microsoft/testsuites/cloud_hypervisor/ch_tests.py
Original file line number Diff line number Diff line change
@@ -206,7 +206,8 @@ def _set_ms_clh_param(self, variables: Dict[str, Any]) -> None:
# will not run it with data-disk and it would not add direct=on
# if run_without_cache is not set to YES
use_datadisk = variables.get("use_datadisk", "")
disable_datadisk_cache = variables.get("disable_datadisk_cache", "")
use_pmem = variables.get("ch_tests_use_pmem", "")
disable_disk_cache = variables.get("disable_disk_cache", "")
block_size_kb = variables.get("block_size_kb", "")

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

if block_size_kb:
CloudHypervisorTests.block_size_kb = block_size_kb
if use_pmem:
CloudHypervisorTests.use_pmem = use_pmem
if use_datadisk:
CloudHypervisorTests.use_datadisk = use_datadisk
if disable_datadisk_cache:
CloudHypervisorTests.disable_datadisk_cache = disable_datadisk_cache
if disable_disk_cache:
CloudHypervisorTests.disable_disk_cache = disable_disk_cache


def get_test_list(variables: Dict[str, Any], var1: str, var2: str) -> Any:
76 changes: 66 additions & 10 deletions microsoft/testsuites/cloud_hypervisor/ch_tests_tool.py
Original file line number Diff line number Diff line change
@@ -12,9 +12,10 @@
from lisa.executable import Tool
from lisa.features import SerialConsole
from lisa.messages import TestStatus, send_sub_test_result_message
from lisa.operating_system import CBLMariner
from lisa.operating_system import CBLMariner, Ubuntu
from lisa.testsuite import TestResult
from lisa.tools import (
Cat,
Chmod,
Chown,
Dmesg,
@@ -25,9 +26,10 @@
Lsblk,
Mkdir,
Modprobe,
Sed,
Whoami,
)
from lisa.util import LisaException, find_groups_in_lines
from lisa.util import LisaException, UnsupportedDistroException, find_groups_in_lines


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

# Block perf related env var
use_datadisk = ""
disable_datadisk_cache = ""
use_pmem = ""
disable_disk_cache = ""
block_size_kb = ""

cmd_path: PurePath
@@ -164,8 +167,16 @@ def run_metrics_tests(
skip: Optional[List[str]] = None,
subtest_timeout: Optional[int] = None,
) -> None:
if self.use_datadisk:
self._set_data_disk()
disk_name = ""
if self.use_pmem:
disk_name = self._get_pmem_for_block_tests()
elif self.use_datadisk:
disk_name = self._get_data_disk_for_block_tests()

if disk_name:
self._log.debug(f"Using disk: {disk_name}, for block tests")
self.env_vars["DATADISK_NAME"] = disk_name
self._save_kernel_logs(log_path)

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

if self.use_datadisk:
self.env_vars["USE_DATADISK"] = self.use_datadisk
if self.disable_datadisk_cache:
self.env_vars["DISABLE_DATADISK_CACHING"] = self.disable_datadisk_cache
if self.disable_disk_cache:
self.env_vars["DISABLE_DATADISK_CACHING"] = self.disable_disk_cache
if self.block_size_kb:
self.env_vars["PERF_BLOCK_SIZE_KB"] = self.block_size_kb
else:
@@ -497,7 +508,53 @@ def _configure_vdpa_devices(self, node: Node) -> None:
node.tools[Chown].change_owner(file=PurePath(device_path), user=user)
node.tools[Chmod].chmod(path=device_path, permission=permission, sudo=True)

def _set_data_disk(self) -> None:
def _get_pmem_for_block_tests(self) -> str:
"""
Following is the last usable entry in e829 table and is safest to use for
pmem since its most likely to be free. 0x0000001000000000 is 64G.
[ 0.000000] BIOS-e820: [mem 0x0000001000000000-0x00000040ffffffff] usable
"""
memmap_str = "memmap=16G!64G"

lsblk = self.node.tools[Lsblk]
sed = self.node.tools[Sed]
cat = self.node.tools[Cat]

grub_file = "/etc/default/grub"
grub_cmdline = cat.read_with_filter(
file=grub_file,
grep_string="GRUB_CMDLINE_LINUX=",
sudo=True,
)
if memmap_str not in grub_cmdline:
sed.substitute(
file=grub_file,
match_lines="^GRUB_CMDLINE_LINUX=",
regexp='"$',
replacement=' memmap=16G!64G "',
sudo=True,
)
if isinstance(self.node.os, CBLMariner):
self.node.execute(
"grub2-mkconfig -o /boot/grub2/grub.cfg", sudo=True, shell=True
)
elif isinstance(self.node.os, Ubuntu):
self.node.execute("update-grub", sudo=True, shell=True)
else:
raise UnsupportedDistroException(
self.node.os,
"pmem for CH tests is supported only on Ubuntu and CBLMariner",
)

lsblk.run()
self.node.reboot(time_out=900)
lsblk.run()

return "/dev/pmem0"

def _get_data_disk_for_block_tests(self) -> str:
datadisk_name = ""
lsblk = self.node.tools[Lsblk]
disks = lsblk.get_disks()
@@ -512,8 +569,7 @@ def _set_data_disk(self) -> None:
lsblk.run()
if not datadisk_name:
raise LisaException("No unmounted data disk (/dev/sdX) found")
self._log.debug(f"Using data disk: {datadisk_name}")
self.env_vars["DATADISK_NAME"] = datadisk_name
return datadisk_name


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

0 comments on commit 4e6e881

Please sign in to comment.