Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add glmark2 test for hardware rendering in addition to unity_support_test for devices running wayland (BugFix) #1677

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
118 changes: 100 additions & 18 deletions providers/base/bin/reboot_check_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import typing as T
from checkbox_support.scripts.image_checker import has_desktop_environment
from datetime import datetime
import time


# Checkbox could run in a snap container, so we need to prepend this root path
Expand Down Expand Up @@ -50,11 +51,17 @@ class Device:
# to modify, add more values in the enum
# and reference them in required/optional respectively

COMMAND_TIMEOUT_SECONDS = 30

def get_drm_info(self) -> str:
return str(os.listdir("/sys/class/drm"))

def get_wireless_info(self) -> str:
iw_out = sp.check_output(["iw", "dev"], universal_newlines=True)
iw_out = sp.check_output(
["iw", "dev"],
timeout=self.COMMAND_TIMEOUT_SECONDS,
universal_newlines=True,
)
lines = iw_out.splitlines()
lines_to_write = list(
filter(
Expand All @@ -75,13 +82,15 @@ def get_usb_info(self) -> str:
"-s",
],
universal_newlines=True,
timeout=self.COMMAND_TIMEOUT_SECONDS,
).splitlines()
out.sort()
return "\n".join(out)

def get_pci_info(self) -> str:
return sp.check_output(
["lspci", "-i", "{}/usr/share/misc/pci.ids".format(SNAP)],
timeout=self.COMMAND_TIMEOUT_SECONDS,
universal_newlines=True,
)

Expand Down Expand Up @@ -270,38 +279,91 @@ def is_hardware_renderer_available(self) -> bool:
DISPLAY = os.getenv("DISPLAY", "")

if DISPLAY == "":
print("$DISPLAY is not set, we will let unity_support infer this")
print("$DISPLAY is not set, we will let glmark2 infer this")
else:
print("Checking $DISPLAY={}".format(DISPLAY))

unity_support_output = sp.run(
["{}/usr/lib/nux/unity_support_test".format(RUNTIME_ROOT), "-p"],
stdout=sp.PIPE,
universal_newlines=True,
)
if unity_support_output.returncode != 0:
try:
glmark2_output = sp.run(
["glmark2-es2", "--off-screen", "--validate"],
stdout=sp.PIPE,
stderr=sp.STDOUT,
universal_newlines=True,
timeout=60,
)
except sp.TimeoutExpired:
print("[ ERR ] glmark2 timed out. Marking this test as failed.")
return False

if glmark2_output.returncode != 0:
print(
"[ ERR ] unity support test returned {}. Error is: {}".format(
unity_support_output.returncode,
unity_support_output.stdout,
"[ ERR ] glmark2 returned {}. Error is: {}".format(
glmark2_output.returncode,
glmark2_output.stdout,
),
file=sys.stderr,
)
return False

is_hardware_rendered = (
self.parse_unity_support_output(unity_support_output.stdout).get(
"Not software rendered"
)
== "yes"
)
gl_renderer_line = None # type: str | None
for line in glmark2_output.stdout.splitlines():
if "GL_RENDERER" in line:
gl_renderer_line = line
break

# See the discussion on checkbox issue 1630
# the same logic as unity_support_test
is_hardware_rendered = True
if gl_renderer_line is not None:
gl_renderer = gl_renderer_line.split(":")[-1].strip()
print("Found GL_RENDERER: {}".format(gl_renderer))
if gl_renderer in ("Software Rasterizer", "Mesa X11"):
is_hardware_rendered = False
if "llvmpipe" in gl_renderer or "on softpipe" in gl_renderer:
is_hardware_rendered = False
else:
print("[ ERR ] glmark2 did not return a renderer string")
return False

if is_hardware_rendered:
print("[ OK ] This machine is using a hardware renderer!")
return True

print("[ ERR ] Software rendering detected", file=sys.stderr)
return False

def wait_for_graphical_target(self, max_wait_seconds: int) -> bool:
"""Wait for the DUT to reach graphical.target in systemd critical chain

:param max_wait_seconds: num seconds to wait at most
:return: whether graphical.target was reached within max_wait_seconds
"""

start = time.time()
print("Checking if DUT has reached systemd's graphical.target...")
while time.time() - start < max_wait_seconds:
try:
out = sp.run(
[
"systemd-analyze",
"critical-chain",
"graphical.target",
"--no-pager",
],
stdout=sp.DEVNULL,
stderr=sp.DEVNULL,
timeout=min(5, max_wait_seconds),
)
if out.returncode == 0:
print("Graphical target reached!")
return True
else:
time.sleep(1)
except sp.TimeoutExpired:
return False

return False

def parse_unity_support_output(
self, unity_output_string: str
) -> T.Dict[str, str]:
Expand Down Expand Up @@ -390,6 +452,16 @@ def create_parser():
action="store_true",
help="If specified, check if hardware rendering is being used",
)
parser.add_argument(
"--graphical-target-timeout",
default=120,
type=int,
dest="graphical_target_timeout",
help="How many seconds should we wait for systemd to report "
"that it has reached graphical.target in its critical chain "
"before the renderer check starts. "
"Default is 120 seconds. Ignored if -g/--graphics is not specified.",
)

return parser

Expand Down Expand Up @@ -469,7 +541,17 @@ def main() -> int:

if args.do_renderer_check:
tester = HardwareRendererTester()
if has_desktop_environment() and tester.has_display_connection():
graphical_target_reached = tester.wait_for_graphical_target(
args.graphical_target_timeout
)
if not graphical_target_reached:
print(
"[ ERR ] systemd's graphical.target was not reached",
"in {} seconds.".format(args.graphical_target_timeout),
"Marking the renderer test as failed.",
)
renderer_test_passed = False
elif has_desktop_environment() and tester.has_display_connection():
# skip renderer test if there's no display
renderer_test_passed = tester.is_hardware_renderer_available()

Expand Down
45 changes: 45 additions & 0 deletions providers/base/tests/test_reboot_check_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,51 @@ def test_is_hardware_renderer_available_fail(
tester = RCT.HardwareRendererTester()
self.assertFalse(tester.is_hardware_renderer_available())

def test_slow_boot_scenario(self):

def fake_time(delta: int, ticks=2):
# fake a time.time() delta using closure
call_idx = [0]

def wrapped():
if call_idx[0] != ticks:
call_idx[0] += 1
return 0 # when time.time is initially called
else:
return delta # the "last" time when time.time is called

return wrapped

with patch("subprocess.run") as mock_run, patch(
"time.sleep"
) as mock_sleep, patch("time.time") as mock_time, patch(
"sys.argv",
sh_split("reboot_check_test.py -g --graphical-target-timeout 2"),
):
mock_run.side_effect = lambda *args, **kwargs: sp.CompletedProcess(
[],
1,
"systemd says it's not ready",
"graphical target not reached blah",
)
mock_sleep.side_effect = do_nothing
mock_time.side_effect = fake_time(3)
tester = RCT.HardwareRendererTester()

self.assertFalse(tester.wait_for_graphical_target(2))

mock_sleep.reset_mock()
mock_time.side_effect = fake_time(3)
tester = RCT.HardwareRendererTester()
self.assertEqual(RCT.main(), 1)
self.assertTrue(mock_time.called)
self.assertTrue(mock_sleep.called)

mock_time.side_effect = fake_time(3)
mock_run.side_effect = sp.TimeoutExpired([], 1)
tester = RCT.HardwareRendererTester()
self.assertFalse(tester.wait_for_graphical_target(2))


class InfoDumpTests(unittest.TestCase):
@classmethod
Expand Down
Loading