Skip to content

Commit

Permalink
Blacklist hyper_fb in grub cmdline
Browse files Browse the repository at this point in the history
  • Loading branch information
kanchansenlaskar authored and LiliDeng committed Aug 5, 2024
1 parent 4783f79 commit 00b09b3
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions microsoft/testsuites/display/drm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import re
from typing import Any

from assertpy import assert_that
Expand All @@ -14,12 +15,16 @@
)
from lisa.base_tools import Cat
from lisa.features.security_profile import CvmDisabled
from lisa.operating_system import BSD, Windows
from lisa.operating_system import BSD, Fedora, Suse, Ubuntu, Windows
from lisa.sut_orchestrator import AZURE, READY
from lisa.tools import Dmesg, Echo, KernelConfig, Lsmod, Reboot
from lisa.util import SkippedException
from lisa.tools import Dmesg, Echo, KernelConfig, Lsmod, Reboot, Sed
from lisa.util import SkippedException, get_matched_str
from microsoft.testsuites.display.modetest import Modetest

GRUB_CMDLINE_LINUX_DEFAULT_PATTERN = re.compile(
r'GRUB_CMDLINE_LINUX_DEFAULT="(?P<grub_cmdline>.*)"', re.M
)


@TestSuiteMetadata(
area="drm",
Expand Down Expand Up @@ -74,7 +79,7 @@ def verify_drm_driver(self, node: Node, log: Logger) -> None:
)
def verify_dri_node(self, node: Node, log: Logger) -> None:
cat = node.tools[Cat]
dri_path = "/sys/kernel/debug/dri/0/name"
dri_path = "/sys/kernel/debug/dri/*/name"
dri_name = cat.read(dri_path, sudo=True, force_run=True)
assert_that(dri_name).described_as(
"dri node not populated for hyperv_drm"
Expand Down Expand Up @@ -139,6 +144,37 @@ def before_case(self, log: Logger, **kwargs: Any) -> None:
sudo=True,
)
node.tools[Reboot].reboot()

# if the hyperv_fb is built-in, then we need to blacklist it in grub
if lsmod.module_exists("hyperv_fb"):
cat = node.tools[Cat]
grub_content = "\n".join(
cat.run("/etc/default/grub").stdout.splitlines()
)
result = get_matched_str(
grub_content,
GRUB_CMDLINE_LINUX_DEFAULT_PATTERN,
first_match=False,
).replace("/", r"\/")

sed = node.tools[Sed]

sed.substitute(
regexp="GRUB_CMDLINE_LINUX_DEFAULT=.*",
replacement=f'GRUB_CMDLINE_LINUX_DEFAULT="{result} '
'module_blacklist=hyperv_fb"',
file="/etc/default/grub",
sudo=True,
)

if isinstance(node.os, Ubuntu):
node.execute("update-grub", sudo=True)
elif isinstance(node.os, Fedora) or isinstance(node.os, Suse):
node.execute("grub2-mkconfig -o /boot/grub2/grub.cfg", sudo=True)
# doesn't apply in debian as CONFIG_DRM_HYPERV isn't enabled in debian

node.reboot(time_out=600)

else:
raise SkippedException(
"DRM hyperv driver is not enabled in current distro"
Expand Down

0 comments on commit 00b09b3

Please sign in to comment.