Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 17 additions & 8 deletions tests/test_labgrid_resources.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import time

import pytest
Expand All @@ -9,15 +10,15 @@
# resources on the fly.


@pytest.mark.slow
def test_labgrid_resources_simple(strategy, shell, check):
"""Test non-managed resources."""

def retry_loop():
def retry_loop(logger):
rpm = RemotePlaceManager.get()
exporter = strategy.target_hostname

for _ in range(300):
time.sleep(1)
for _ in range(300 // 15):
rpm.poll()

try:
Expand All @@ -44,26 +45,30 @@ def retry_loop():
except Exception:
pass

logger.info("(Still) waiting for labgrid resources to appear...")
time.sleep(15)

pytest.fail("Failed to get resources, even after trying for 5 minutes")

serial_port_params, power_port_params, _out_0, _out_1 = retry_loop()
logger = logging.getLogger("test_labgrid_resources_simple")
serial_port_params, power_port_params, _out_0, _out_1 = retry_loop(logger)

with check:
assert serial_port_params["extra"]["path"].startswith("/dev/ttySTM")
with check:
assert power_port_params["model"] == "rest"


@pytest.mark.slow
def test_labgrid_resources_usb(strategy, shell, eet):
"""Test ManagedResources (udev)."""

def retry_loop():
def retry_loop(logger):
rpm = RemotePlaceManager.get()
exporter = strategy.target_hostname
match = ResourceMatch.fromstr(f"{exporter}/lxatac-usb-ports-p*/*")

for _ in range(300):
time.sleep(1)
for _ in range(300 // 15):
rpm.poll()

try:
Expand All @@ -81,11 +86,15 @@ def retry_loop():
except Exception:
pass

logger.info("(Still) waiting for labgrid resources to appear...")
time.sleep(15)

pytest.fail("Failed to get resources, even after trying for 5 minutes")

if eet:
eet.link("USB1_IN -> USB1_OUT, USB2_IN -> USB2_OUT, USB3_IN -> USB3_OUT")
usb_resources = retry_loop()
logger = logging.getLogger("test_labgrid_resources_usb")
usb_resources = retry_loop(logger)

# make sure at least one USB resource is available
assert usb_resources != []
29 changes: 29 additions & 0 deletions tests/test_linux_pstore.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
import re


def test_pstore_fs(shell):
"""
Test if the pstore filesystem exists.
"""

shell.run_check("test -d /sys/fs/pstore")


def test_kernel_messages(shell, check):
"""
Test if the kernel only logs messages that we expect.

This test will ignore some harmless messages that can happen during normal operation.
"""

expected = {
"spi_stm32 44009000.spi: failed to request tx dma channel",
"spi_stm32 44009000.spi: failed to request rx dma channel",
"clk: failed to reparent ethck_k to pll4_p: -22",
"stm32-dwmac 5800a000.ethernet switch: Adding VLAN ID 0 is not supported",
}

allowed = {
# The following messages can happen during other tests and are harmless
"sd 0:0:0:0: [sda] No Caching mode page found",
"sd 0:0:0:0: [sda] Assuming drive cache: write through",
}

messages = shell.run_check("dmesg -l warn -l err -l crit -l alert -l emerg -k")
messages = set(re.sub(r"^\[\s*\d+\.\d+\] ", "", m) for m in messages)

assert messages - allowed == expected
91 changes: 89 additions & 2 deletions tests/test_userspace.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import csv
import json
import re
from dataclasses import dataclass

import pytest


def test_chrony(shell):
Expand Down Expand Up @@ -66,7 +70,7 @@ def test_switch_configuration(shell, check):
assert global_v6.endswith(v6_tail)


def test_hostname(shell):
def test_hostname(shell, check):
"""Test whether the serial number is contained in the hostname"""

[serial_number] = shell.run_check("cat /sys/firmware/devicetree/base/chosen/baseboard-factory-data/serial-number")
Expand All @@ -75,4 +79,87 @@ def test_hostname(shell):

[hostname] = shell.run_check("hostname")

assert serial_number in hostname
with check:
assert serial_number in hostname

[etc_hostname] = shell.run_check("cat /etc/hostname")

with check:
assert etc_hostname != "localhost"

with check:
assert serial_number in etc_hostname


def test_system_running(shell):
"""
Test if the system state is running.
"""

# This will exit non-zero if we have any other state than "running", but we are interested in the string output.
# So let's ignore the returncode.
[state], _, _ = shell.run("systemctl is-system-running")

assert state == "running"


@pytest.fixture
def clocktree(shell):
"""
Read the clock tree from the DUT and parse it into a data structure.
"""
re_entry = re.compile(r"^\s*(\S+)\s+\d+\s+\d+\s+\d+\s+(\d+)\s+\d+\s+\d+\s+(\d+)\s+\S\s+(\S+)\s+")
re_2nd = re.compile(r"^\s+(\S+)\s+\S+\s+$")

@dataclass
class Clk:
clk_name: str
rate: int
duty: int
consumer: list

clks = {}
clk = None
for line in shell.run_check("cat /sys/kernel/debug/clk/clk_summary"):
if match := re_entry.match(line):
if clk:
clks[clk.clk_name] = clk
clk = Clk(clk_name=match.group(1), rate=int(match.group(2)), duty=int(match.group(3)), consumer=[])
if match.group(4) != "deviceless":
clk.consumer.append(match.group(4))
continue

match = re_2nd.match(line)
if match and match.group(1) != "deviceless":
clk.consumer.append(match.group(1))

return clks


@pytest.mark.parametrize(
"clock_name, rate, consumer",
(
# Ethernet Clocks: Needed for the communication with the phy to work
("ethptp_k", 125000000, ("5800a000.ethernet",)),
("ethck_k", 125000000, ("5800a000.ethernet",)),
("ethrx", 125000000, ("5800a000.ethernet",)),
# CAN Clock: Chosen to be 48MHz for minimum baudrate error across all rates
("fdcan_k", 48000000, ("4400f000.can", "4400e000.can")),
),
)
def test_clocktree(clocktree, check, clock_name, rate, consumer):
"""
Make sure a few selected devices have their fixed clock rates applied.
In this test we check the association of the clock signal with the actual
device and the clocks rate.
"""
assert clock_name in clocktree

clk = clocktree[clock_name]

with check:
assert clk.rate == rate

for c in consumer:
with check:
assert c in clk.consumer