Skip to content
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 29 additions & 16 deletions providers/base/bin/gl_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,26 @@
import platform
import argparse
from pathlib import Path


# Checkbox could run in a snap container, so we need to prepend this root path
try:
CHECKBOX_RUNTIME = Path(os.environ["CHECKBOX_RUNTIME"])
except KeyError: # from indexing os.environ
CHECKBOX_RUNTIME = None
GLMARK2_DATA_PATH = Path("/usr/share/glmark2")
from checkbox_support.snap_utils.system import in_classic_snap


class GLSupportTester:

GLMARK2_DATA_ABS_PATH = Path("/usr/share/glmark2")

def __init__(self) -> None:
if "SNAP" in os.environ:
# don't use $CHECKBOX_RUNTIME in Path() unless in classic
if in_classic_snap():
self.CHECKBOX_RUNTIME = Path(os.environ["CHECKBOX_RUNTIME"])
else:
# in strict frontend, CHECKBOX_RUNTIME has multiple lines
self.CHECKBOX_RUNTIME = (
Path(os.environ["SNAP"]) / "checkbox-runtime"
)
else:
self.CHECKBOX_RUNTIME = None

def pick_glmark2_executable(
self, xdg_session_type: str, cpu_arch: str
) -> str:
Expand Down Expand Up @@ -145,23 +153,26 @@ def call_glmark2_validate(
)

try:
if CHECKBOX_RUNTIME and not os.path.exists(GLMARK2_DATA_PATH):
if self.CHECKBOX_RUNTIME and not os.path.exists(
self.GLMARK2_DATA_ABS_PATH
):
# the official way to specify the location of the data files
# is "--data-path path/to/data/files"
# but 16, 18, 20 doesn't have this option
# and the /usr/share/glmark2 path is hard-coded inside glmark2
# by the GLMARK_DATA_PATH build macro
src = CHECKBOX_RUNTIME / GLMARK2_DATA_PATH
dst = GLMARK2_DATA_PATH

# do not directly truediv against GLMARK2_DATA_PATH
# absolute path on the right will overwrite the left hand side
src = self.CHECKBOX_RUNTIME / "usr" / "share" / "glmark2"
dst = self.GLMARK2_DATA_ABS_PATH
print(
"[ DEBUG ] Symlinking glmark2 data dir ({} -> {})".format(
src, dst
)
)
os.symlink(src, dst, target_is_directory=True)
# override is needed for snaps on classic ubuntu
# to allow the glmark2 command itself to be discovered
# in debian version of checkbox this line does nothing

glmark2_output = sp.check_output(
# all glmark2 programs share the same args
[glmark2_executable, "--off-screen", "--validate"],
Expand All @@ -173,9 +184,11 @@ def call_glmark2_validate(
return glmark2_output
finally:
# immediately cleanup
if CHECKBOX_RUNTIME and os.path.islink(GLMARK2_DATA_PATH):
if self.CHECKBOX_RUNTIME and os.path.islink(
self.GLMARK2_DATA_ABS_PATH
):
print("[ DEBUG ] Un-symlinking glmark2 data")
os.unlink(GLMARK2_DATA_PATH)
os.unlink(self.GLMARK2_DATA_ABS_PATH)


def remove_prefix(s: str, prefix: str) -> str:
Expand Down
44 changes: 30 additions & 14 deletions providers/base/bin/reboot_check_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,27 @@
import time
import platform

# Checkbox could run in a snap container, so we need to prepend this root path
RUNTIME_ROOT = os.getenv("CHECKBOX_RUNTIME", default="").rstrip("/")
# Snap mount point, see
# https://snapcraft.io/docs/environment-variables#heading--snap
SNAP = os.getenv("SNAP", default="").rstrip("/")
from checkbox_support.snap_utils.system import in_classic_snap

# global const for subprocess calls that should timeout
COMMAND_TIMEOUT_SECONDS = 30


def get_snap_and_checkbox_runtime():
SNAP = os.getenv("SNAP", default="").rstrip("/")
if SNAP:
if in_classic_snap():
CHECKBOX_RUNTIME = os.environ["CHECKBOX_RUNTIME"].rstrip("/")
else:
# in strict frontend, CHECKBOX_RUNTIME has multiple lines
# explicitly build this path
CHECKBOX_RUNTIME = "{}/checkbox-runtime".format(SNAP)
else:
CHECKBOX_RUNTIME = ""

return SNAP, CHECKBOX_RUNTIME


def get_timestamp_str() -> str:
with open("/proc/uptime", "r") as f:
# uptime file always have 2 numbers
Expand Down Expand Up @@ -84,7 +96,7 @@ def get_usb_info(self) -> str:
[
"checkbox-support-lsusb",
"-f",
'"{}"/var/lib/usbutils/usb.ids'.format(RUNTIME_ROOT),
'"{}"/var/lib/usbutils/usb.ids'.format(self.CHECKBOX_RUNTIME),
"-s",
],
universal_newlines=True,
Expand All @@ -95,7 +107,7 @@ def get_usb_info(self) -> str:

def get_pci_info(self) -> str:
return sp.check_output(
["lspci", "-i", "{}/usr/share/misc/pci.ids".format(SNAP)],
["lspci", "-i", "{}/usr/share/misc/pci.ids".format(self.SNAP)],
timeout=COMMAND_TIMEOUT_SECONDS,
universal_newlines=True,
)
Expand Down Expand Up @@ -174,6 +186,7 @@ def print_diff(self, name: str, expected_path: str, actual_path: str):
print("End of {} diff".format(name), file=sys.stderr)

def __init__(self) -> None:
self.SNAP, self.CHECKBOX_RUNTIME = get_snap_and_checkbox_runtime()
self.dump_function = {
self.Device.PCI: self.get_pci_info,
self.Device.DRM: self.get_drm_info,
Expand Down Expand Up @@ -220,6 +233,9 @@ def fwts_log_check_passed(

class HardwareRendererTester:

def __init__(self) -> None:
self.SNAP, self.CHECKBOX_RUNTIME = get_snap_and_checkbox_runtime()

def get_desktop_environment_variables(
self,
) -> T.Optional[T.Dict[str, str]]:
Expand Down Expand Up @@ -287,7 +303,7 @@ def has_display_connection(self) -> bool:
# kernel doesn't see any GPU nodes
print(
"There's nothing under {}".format(DRM_PATH),
"if an external GPU is connected,"
"if an external GPU is connected,",
"check if the connection is loose.",
)
return False
Expand Down Expand Up @@ -317,7 +333,7 @@ def has_display_connection(self) -> bool:
print(
"No display is connected. This case will be skipped.",
"Maybe the display cable is not connected?",
"If the device is not supposed to have a display,"
"If the device is not supposed to have a display,",
"then skipping is expected.",
)

Expand Down Expand Up @@ -401,8 +417,8 @@ def is_hardware_renderer_available(self) -> bool:
desktop_env_vars = self.get_desktop_environment_variables()
if desktop_env_vars is None:
print(
"[ ERR ] Unable to get the environment variables "
"used by the current desktop. Is the desktop process running?"
"[ ERR ] Unable to get the environment variables",
"used by the current desktop. Is the desktop process running?",
)
return False

Expand All @@ -426,13 +442,13 @@ def is_hardware_renderer_available(self) -> bool:
glmark2_data_path = "/usr/share/glmark2"

try:
if RUNTIME_ROOT and not os.path.exists(glmark2_data_path):
if self.CHECKBOX_RUNTIME and not os.path.exists(glmark2_data_path):
# the official way to specify the location of the data files
# is "--data-path path/to/data/files"
# but 16, 18, 20 doesn't have this option
# and the /usr/share/glmark2 is hard-coded inside glmark2
# by the GLMARK_DATA_PATH build macro
src = "{}/usr/share/glmark2".format(RUNTIME_ROOT)
src = "{}/usr/share/glmark2".format(self.CHECKBOX_RUNTIME)
dst = glmark2_data_path
print(
"[ DEBUG ] Symlinking glmark2 data dir ({} -> {})".format(
Expand Down Expand Up @@ -464,7 +480,7 @@ def is_hardware_renderer_available(self) -> bool:
return False
finally:
# immediately cleanup
if RUNTIME_ROOT and os.path.islink(glmark2_data_path):
if self.CHECKBOX_RUNTIME and os.path.islink(glmark2_data_path):
print("[ DEBUG ] Un-symlinking glmark2 data")
os.unlink(glmark2_data_path)

Expand Down
Loading
Loading