Skip to content

Commit

Permalink
Merge patch series "labgrid: Provide an integration with Labgrid"
Browse files Browse the repository at this point in the history
Simon Glass <[email protected]> says:

Labgrid provides access to a hardware lab in an automated way. It is
possible to boot U-Boot on boards in the lab without physically touching
them. It relies on relays, USB UARTs and SD muxes, among other things.

By way of background, about 4 years ago I wrong a thing called Labman[1]
which allowed my lab of about 30 devices to be operated remotely, using
tbot for the console and build integration. While it worked OK and I
used it for many bisects, I didn't take it any further.

It turns out that there was already an existing program, called Labgrid,
which I did not know about at time (thank you Tom for telling me). It is
more rounded than Labman and has a number of advantages:

- does not need udev rules, mostly
- has several existing users who rely on it
- supports multiple machines exporting their devices

It lacks a 'lab check' feature and a few other things, but these can be
remedied.

On and off over the past several weeks I have been experimenting with
Labgrid. I have managed to create an initial U-Boot integration (this
series) by adding various features to Labgrid[2] and the U-Boot test
hooks.

I hope that this might inspire others to set up boards and run tests
automatically, rather than relying on infrequent, manual test. Perhaps
it may even be possible to have a number of labs available.

Included in the integration are a number of simple scripts which make it
easy to connect to boards and run tests:

ub-int <target>
    Build and boot on a target, starting an interactive session

ub-cli <target>
    Build and boot on a target, ensure U-Boot starts and provide an interactive
    session from there

ub-smoke <target>
    Smoke test U-Boot to check that it boots to a prompt on a target

ub-bisect <target>
    Bisect a git tree to locate a failure on a particular target

ub-pyt <target> <testspec>
    Run U-Boot pytests on a target

Some of these help to provide the same tbot[4] workflow which I have
relied on for several years, albeit much simpler versions.

The goal here is to create some sort of script which can collect
patches from the mailing list, apply them and test them on a selection
of boards. I suspect that script already exists, so please let me know
what you suggest.

I hope you find this interesting and take a look!

[1] https://github.com/sjg20/u-boot/tree/lab6a
[2] labgrid-project/labgrid#1411
[3] https://github.com/sjg20/uboot-test-hooks/tree/labgrid
[4] https://tbot.tools/index.html

Link: https://lore.kernel.org/r/[email protected]
[trini: Move the sjg-lab job to prior to world build, to fix pipeline
        status]
Signed-off-by: Tom Rini <[email protected]>
  • Loading branch information
trini committed Nov 13, 2024
2 parents aa48299 + 1888b09 commit 3ad199a
Show file tree
Hide file tree
Showing 6 changed files with 374 additions and 54 deletions.
155 changes: 155 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
variables:
DEFAULT_TAG: ""
MIRROR_DOCKER: docker.io
SJG_LAB: ""

default:
tags:
Expand All @@ -16,6 +17,7 @@ image: ${MIRROR_DOCKER}/trini/u-boot-gitlab-ci-runner:jammy-20240808-21Aug2024
stages:
- testsuites
- test.py
- sjg-lab
- world build

.buildman_and_testpy_template: &buildman_and_testpy_dfn
Expand Down Expand Up @@ -521,3 +523,156 @@ coreboot test.py:
TEST_PY_TEST_SPEC: "not sleep"
TEST_PY_ID: "--id qemu"
<<: *buildman_and_testpy_dfn

.lab_template: &lab_dfn
stage: sjg-lab
rules:
- if: $SJG_LAB == "1"
when: always
- when: manual
tags: [ 'lab' ]
script:
- if [[ -z "${SJG_LAB}" ]]; then
exit 0;
fi
# Environment:
# SRC - source tree
# OUT - output directory for builds
- export SRC="$(pwd)"
- export OUT="${SRC}/build/${BOARD}"
- export PATH=$PATH:~/bin
- export PATH=$PATH:/vid/software/devel/ubtest/u-boot-test-hooks/bin

# Load it on the device
- ret=0
- echo "role ${ROLE}"
- export strategy="-s uboot -e off"
- export USE_LABGRID_SJG=1
# export verbose="-v"
- ${SRC}/test/py/test.py --role ${ROLE} --build-dir "${OUT}"
--capture=tee-sys -k "not bootstd" || ret=$?
- U_BOOT_BOARD_IDENTITY="${ROLE}" u-boot-test-release || true
- if [[ $ret -ne 0 ]]; then
exit $ret;
fi
artifacts:
when: always
paths:
- "build/${BOARD}/test-log.html"
- "build/${BOARD}/multiplexed_log.css"
expire_in: 1 week

rpi3:
variables:
ROLE: rpi3
<<: *lab_dfn

opi_pc:
variables:
ROLE: opi_pc
<<: *lab_dfn

pcduino3_nano:
variables:
ROLE: pcduino3_nano
<<: *lab_dfn

samus:
variables:
ROLE: samus
<<: *lab_dfn

link:
variables:
ROLE: link
<<: *lab_dfn

jerry:
variables:
ROLE: jerry
<<: *lab_dfn

minnowmax:
variables:
ROLE: minnowmax
<<: *lab_dfn

opi_pc2:
variables:
ROLE: opi_pc2
<<: *lab_dfn

bpi:
variables:
ROLE: bpi
<<: *lab_dfn

rpi2:
variables:
ROLE: rpi2
<<: *lab_dfn

bob:
variables:
ROLE: bob
<<: *lab_dfn

ff3399:
variables:
ROLE: ff3399
<<: *lab_dfn

coral:
variables:
ROLE: coral
<<: *lab_dfn

rpi3z:
variables:
ROLE: rpi3z
<<: *lab_dfn

bbb:
variables:
ROLE: bbb
<<: *lab_dfn

kevin:
variables:
ROLE: kevin
<<: *lab_dfn

pine64:
variables:
ROLE: pine64
<<: *lab_dfn

c4:
variables:
ROLE: c4
<<: *lab_dfn

rpi4:
variables:
ROLE: rpi4
<<: *lab_dfn

rpi0:
variables:
ROLE: rpi0
<<: *lab_dfn

snow:
variables:
ROLE: snow
<<: *lab_dfn

pcduino3:
variables:
ROLE: pcduino3
<<: *lab_dfn

nyan-big:
variables:
ROLE: nyan-big
<<: *lab_dfn
73 changes: 66 additions & 7 deletions test/py/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import pytest
import re
from _pytest.runner import runtestprotocol
import subprocess
import sys
from u_boot_spawn import BootFail, Timeout, Unexpected, handle_exception

Expand Down Expand Up @@ -65,12 +66,16 @@ def pytest_addoption(parser):

parser.addoption('--build-dir', default=None,
help='U-Boot build directory (O=)')
parser.addoption('--build-dir-extra', default=None,
help='U-Boot build directory for extra build (O=)')
parser.addoption('--result-dir', default=None,
help='U-Boot test result/tmp directory')
parser.addoption('--persistent-data-dir', default=None,
help='U-Boot test persistent generated data directory')
parser.addoption('--board-type', '--bd', '-B', default='sandbox',
help='U-Boot board type')
parser.addoption('--board-type-extra', '--bde', default='sandbox',
help='U-Boot extra board type')
parser.addoption('--board-identity', '--id', default='na',
help='U-Boot board identity/instance')
parser.addoption('--build', default=False, action='store_true',
Expand All @@ -80,6 +85,9 @@ def pytest_addoption(parser):
parser.addoption('--gdbserver', default=None,
help='Run sandbox under gdbserver. The argument is the channel '+
'over which gdbserver should communicate, e.g. localhost:1234')
parser.addoption('--role', help='U-Boot board role (for Labgrid-sjg)')
parser.addoption('--use-running-system', default=False, action='store_true',
help="Assume that U-Boot is ready and don't wait for a prompt")

def run_build(config, source_dir, build_dir, board_type, log):
"""run_build: Build U-Boot
Expand Down Expand Up @@ -125,26 +133,71 @@ def get_details(config):
Returns:
tuple:
str: Board type (U-Boot build name)
str: Extra board type (where two U-Boot builds are needed)
str: Identity for the lab board
str: Build directory
str: Extra build directory (where two U-Boot builds are needed)
str: Source directory
"""
board_type = config.getoption('board_type')
board_identity = config.getoption('board_identity')
role = config.getoption('role')

# Get a few provided parameters
build_dir = config.getoption('build_dir')
build_dir_extra = config.getoption('build_dir_extra')
if role:
# When using a role, build_dir and build_dir_extra are normally not set,
# since they are picked up from Labgrid-sjg via the u-boot-test-getrole
# script
board_identity = role
cmd = ['u-boot-test-getrole', role, '--configure']
env = os.environ.copy()
if build_dir:
env['U_BOOT_BUILD_DIR'] = build_dir
if build_dir_extra:
env['U_BOOT_BUILD_DIR_EXTRA'] = build_dir_extra
proc = subprocess.run(cmd, capture_output=True, encoding='utf-8',
env=env)
if proc.returncode:
raise ValueError(proc.stderr)
# For debugging
# print('conftest: lab:', proc.stdout)
vals = {}
for line in proc.stdout.splitlines():
item, value = line.split(' ', maxsplit=1)
k = item.split(':')[-1]
vals[k] = value
# For debugging
# print('conftest: lab info:', vals)

# Read the build directories here, in case none were provided in the
# command-line arguments
(board_type, board_type_extra, default_build_dir,
default_build_dir_extra, source_dir) = (vals['board'],
vals['board_extra'], vals['build_dir'], vals['build_dir_extra'],
vals['source_dir'])
else:
board_type = config.getoption('board_type')
board_type_extra = config.getoption('board_type_extra')
board_identity = config.getoption('board_identity')

source_dir = os.path.dirname(os.path.dirname(TEST_PY_DIR))
default_build_dir = source_dir + '/build-' + board_type
default_build_dir_extra = source_dir + '/build-' + board_type_extra

source_dir = os.path.dirname(os.path.dirname(TEST_PY_DIR))
default_build_dir = source_dir + '/build-' + board_type
# Use the provided command-line arguments if present, else fall back to
if not build_dir:
build_dir = default_build_dir
if not build_dir_extra:
build_dir_extra = default_build_dir_extra

return board_type, board_identity, build_dir, source_dir
return (board_type, board_type_extra, board_identity, build_dir,
build_dir_extra, source_dir)

def pytest_xdist_setupnodes(config, specs):
"""Clear out any 'done' file from a previous build"""
global build_done_file

build_dir = get_details(config)[2]
build_dir = get_details(config)[3]

build_done_file = Path(build_dir) / 'build.done'
if build_done_file.exists():
Expand Down Expand Up @@ -184,7 +237,8 @@ def parse_config(conf_file):
global console
global ubconfig

board_type, board_identity, build_dir, source_dir = get_details(config)
(board_type, board_type_extra, board_identity, build_dir, build_dir_extra,
source_dir) = get_details(config)

board_type_filename = board_type.replace('-', '_')
board_identity_filename = board_identity.replace('-', '_')
Expand Down Expand Up @@ -249,20 +303,25 @@ class ArbitraryAttributeContainer(object):
ubconfig.test_py_dir = TEST_PY_DIR
ubconfig.source_dir = source_dir
ubconfig.build_dir = build_dir
ubconfig.build_dir_extra = build_dir_extra
ubconfig.result_dir = result_dir
ubconfig.persistent_data_dir = persistent_data_dir
ubconfig.board_type = board_type
ubconfig.board_type_extra = board_type_extra
ubconfig.board_identity = board_identity
ubconfig.gdbserver = gdbserver
ubconfig.use_running_system = config.getoption('use_running_system')
ubconfig.dtb = build_dir + '/arch/sandbox/dts/test.dtb'
ubconfig.connection_ok = True

env_vars = (
'board_type',
'board_type_extra',
'board_identity',
'source_dir',
'test_py_dir',
'build_dir',
'build_dir_extra',
'result_dir',
'persistent_data_dir',
)
Expand Down
2 changes: 1 addition & 1 deletion test/py/tests/test_spi.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ def test_spi_negative(u_boot_console):

# Read to relocation address
output = u_boot_console.run_command('bdinfo')
m = re.search('relocaddr\s*= (.+)', output)
m = re.search(r'relocaddr\s*= (.+)', output)
res_area = int(m.group(1), 16)

start = 0
Expand Down
Loading

0 comments on commit 3ad199a

Please sign in to comment.