### Setup Virtual Environment for Labgrid Source: https://github.com/labgrid-project/labgrid/blob/master/doc/development.rst Create and activate a Python virtual environment and install dependencies. ```bash virtualenv -p python3 venv source venv/bin/activate pip install --upgrade pip ``` -------------------------------- ### Setup and Build Labgrid Documentation Source: https://github.com/labgrid-project/labgrid/blob/master/doc/development.rst Follow these steps to set up a virtual environment, install dependencies, clone the repository, and build the HTML documentation locally. This is useful for contributing to the documentation. ```bash virtualenv -p python3 labgrid-venv source labgrid-venv/bin/activate pip install --upgrade pip git clone https://github.com/labgrid-project/labgrid.git cd labgrid pip install -e ".[dev]" cd doc make html ``` ```bash make SPHINXOPTS="-a -E" html ``` -------------------------------- ### Barebox Strategy Environment Configuration Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst Example environment configuration for using BareboxStrategy. This setup includes resources for a serial port and drivers for manual power, serial, shell, and Barebox, along with the BareboxStrategy itself. ```yaml targets: main: resources: RawSerialPort: port: '/dev/ttyUSB0' drivers: ManualPowerDriver: {} SerialDriver: {} BareboxDriver: {} ShellDriver: prompt: 'root@["w-]+:[^ ]+ ' login_prompt: ' login: ' username: 'root' BareboxStrategy: {} ``` -------------------------------- ### Test Labgrid Installation Source: https://github.com/labgrid-project/labgrid/blob/master/doc/getting_started.rst Verifies the labgrid installation by running the client help command. ```bash labgrid-venv $ labgrid-client --help usage: labgrid-client [-h] [-x ADDRESS] [-c CONFIG] [-p PLACE] [-d] COMMAND ... ``` -------------------------------- ### Proxy Manager Example Source: https://github.com/labgrid-project/labgrid/blob/master/doc/development.rst Demonstrates how to use the proxymanager to get the host and port for a given resource. This is typically used for setting up SSH gateway connections. ```python from labgrid.resource import Resource from labgrid import Target your_resource = Resource(Target("main"), "example") your_resource.host = "localhost" from labgrid.util.proxy import proxymanager host, port = proxymanager.get_host_and_port(your_resource) ``` -------------------------------- ### Start Labgrid Coordinator Source: https://github.com/labgrid-project/labgrid/blob/master/doc/getting_started.rst Run the labgrid-coordinator command to start the coordinator service. Ensure you are in the virtual environment. ```bash labgrid-venv $ labgrid-coordinator ``` -------------------------------- ### Initialize and Start StepLogger Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst Initializes logging configuration and starts the StepLogger. Ensure logging level is set appropriately. ```python import logging from labgrid.logging import basicConfig, StepLogger basicConfig(level=logging.INFO) StepLogger.start() ``` -------------------------------- ### Docker Strategy Environment Configuration Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst Example YAML configuration for setting up a target with DockerDriver and DockerStrategy. This configuration is used to create and start a Docker container. ```yaml targets: main: resources: DockerDaemon: docker_daemon_url: 'unix://var/run/docker.sock' drivers: DockerDriver: image_uri: 'rastasheep/ubuntu-sshd:16.04' container_name: 'ubuntu-lg-example' host_config: {'network_mode': 'bridge'} network_services: [{'port': 22, 'username': 'root', 'password': 'root'}] DockerStrategy: {} ``` -------------------------------- ### Run Docker Example with Pytest Source: https://github.com/labgrid-project/labgrid/blob/master/examples/docker/README.md Execute the Docker example using pytest. Ensure Docker is installed and accessible via the default socket. The default Docker bridge network must also be accessible for SSH connections to containers. ```bash pytest -s --lg-env env.yaml test_shell.py ``` -------------------------------- ### Copy and Prepare Test Files Source: https://github.com/labgrid-project/labgrid/blob/master/doc/getting_started.rst Copies example test files to a new directory and navigates into it. ```bash $ mkdir ../first_test/ $ cp examples/shell/* ../first_test/ $ cd ../first_test/ ``` -------------------------------- ### Install Labgrid Development Version Source: https://github.com/labgrid-project/labgrid/blob/master/README.rst Installs labgrid from its git repository for development purposes. This involves cloning the repository, setting up a virtual environment, and installing the package locally. ```bash $ git clone https://github.com/labgrid-project/labgrid $ virtualenv -p python3 venv $ source venv/bin/activate venv $ pip install --upgrade pip venv $ pip install . ``` -------------------------------- ### Install and Run Labgrid Webapp Source: https://github.com/labgrid-project/labgrid/blob/master/contrib/README.rst Install dependencies and run the labgrid-webapp. Ensure graphviz is installed for graph features. The app defaults to port 8800. ```bash $ cd labgrid/ $ source venv/bin/activate venv $ pip install -r contrib/requirements-webapp.txt venv $ ./contrib/labgrid-webapp --help ``` ```bash usage: labgrid-webapp [-h] [--coordinator ADDRESS] [--port PORT] [--proxy PROXY] Labgrid webapp options: -h, --help show this help message and exit --coordinator ADDRESS, -x ADDRESS Coordinator address as HOST[:PORT] (default: 127.0.0.1:20408) --port PORT Port to serve on --proxy PROXY, -P PROXY ``` ```bash venv $ ./contrib/labgrid-webapp INFO: Available routes: INFO: - /labgrid/graph INFO: Started server process [2378028] INFO: Waiting for application startup. INFO: Application startup complete. INFO: Uvicorn running on http://0.0.0.0:8800 (Press CTRL+C to quit) ... ``` -------------------------------- ### Start Exporter with Configuration Source: https://github.com/labgrid-project/labgrid/blob/master/doc/man/exporter.rst Use this command to start the exporter with a specified YAML configuration file. Ensure the configuration file path is correct. ```bash $ labgrid-exporter my-config.yaml ``` -------------------------------- ### Start Labgrid Coordinator Source: https://github.com/labgrid-project/labgrid/blob/master/examples/usbpower/README.rst Command to start the Labgrid coordinator, which is necessary for remote resource access. ```bash labgrid-coordinator ``` -------------------------------- ### Start Labgrid Exporter with Configuration Source: https://github.com/labgrid-project/labgrid/blob/master/doc/getting_started.rst Start the labgrid-exporter, providing the path to its YAML configuration file. The configuration file defines the resources to be exported. ```bash labgrid-venv $ labgrid-exporter configuration.yaml ``` -------------------------------- ### Install System Dependencies Source: https://github.com/labgrid-project/labgrid/blob/master/doc/development.rst Install necessary system packages for Python development. ```bash sudo apt install python3-dev libow-dev ``` -------------------------------- ### Start Exporter with Configuration and Name Source: https://github.com/labgrid-project/labgrid/blob/master/doc/man/exporter.rst This command starts the exporter with a configuration file and assigns a specific name to it. This is useful when running multiple exporters on the same host. ```bash $ labgrid-exporter -n myname my-config.yaml ``` -------------------------------- ### Define Example Driver with Post-Initialization Logic Source: https://github.com/labgrid-project/labgrid/blob/master/doc/development.rst Implement a driver that requires custom logic during instantiation using `__attrs_post_init__`. ```python import attr from labgrid.factory import target_factory from labgrid.driver import Driver from labgrid.driver.consoleexpectmixin import ConsoleExpectMixin from labgrid.protocol import ConsoleProtocol @target_factory.reg_driver @attr.s(eq=False) class ExampleDriver(ConsoleExpectMixin, Driver, ConsoleProtocol): bindings = { "port": "SerialPort" } def __attrs_post_init__(self): super().__attrs_post_init__() ``` -------------------------------- ### Create and Activate Virtual Environment Source: https://github.com/labgrid-project/labgrid/blob/master/doc/getting_started.rst Sets up a Python virtual environment for labgrid and installs pip. ```bash $ virtualenv -p python3 labgrid-venv $ source labgrid-venv/bin/activate labgrid-venv $ pip install --upgrade pip ``` -------------------------------- ### BareboxStrategy Status Transitions Source: https://github.com/labgrid-project/labgrid/blob/master/doc/development.rst Example transitions for the BareboxStrategy, demonstrating how to manage power, bootloader, and shell states. Use await_resources() to wait for specific conditions. ```python elif status == Status.off: self.target.deactivate(self.barebox) self.target.deactivate(self.shell) self.target.activate(self.power) self.power.off() elif status == Status.barebox: self.transition(Status.off) # cycle power self.power.cycle() # interrupt barebox self.target.activate(self.barebox) elif status == Status.shell: # transition to barebox self.transition(Status.barebox) self.barebox.boot("") self.barebox.await_boot() self.target.activate(self.shell) ``` -------------------------------- ### Install Labgrid in Editable Mode Source: https://github.com/labgrid-project/labgrid/blob/master/doc/development.rst Install Labgrid with development dependencies in editable mode for active development. ```bash pip install -e ".[dev]" ``` -------------------------------- ### Start Labgrid Staging Environment Source: https://github.com/labgrid-project/labgrid/blob/master/dockerfiles/README.rst Starts the Labgrid staging environment using Docker Compose, including coordinator, statsd, exporter, and dut services. This command should be run from the `dockerfiles/staging` directory. ```bash cd dockerfiles/staging CURRENT_UID=$(id -u):$(id -g) docker compose up -d coordinator coordinator-statsd exporter dut ``` -------------------------------- ### Clone Labgrid Repository and Install Source: https://github.com/labgrid-project/labgrid/blob/master/doc/getting_started.rst Clones the labgrid repository from GitHub and installs it in development mode. ```bash labgrid-venv $ git clone https://github.com/labgrid-project/labgrid labgrid-venv $ cd labgrid && pip install . ``` -------------------------------- ### Install Documentation Dependencies Source: https://github.com/labgrid-project/labgrid/blob/master/README.rst Installs Sphinx and other dependencies required for generating man pages and documentation for labgrid. This is useful for developers contributing to the documentation. ```bash venv $ pip install '.[doc]' ``` -------------------------------- ### labgrid-suggest YAML output example Source: https://github.com/labgrid-project/labgrid/blob/master/doc/man/suggest.rst Example output from labgrid-suggest showing suggested YAML matches for a USB serial device. This output can be added to environment configurations. ```yaml === added device === USBSerialPort for /devices/pci0000:00/0000:00:01.3/0000:02:00.0/usb1/1-3/1-3.1/1-3.1:1.0/ttyUSB0/tty/ttyUSB0 === device properties === device node: /dev/ttyUSB0 udev tags: , systemd vendor: Silicon_Labs vendor (DB): Advanced Micro Devices, Inc. [AMD] model: CP2102_USB_to_UART_Bridge_Controller revision: 0100 === suggested matches === USBSerialPort: match: ID_PATH: pci-0000:02:00.0-usb-0:3.1:1.0 --- USBSerialPort: match: ID_SERIAL_SHORT: P-00-03564 --- ``` -------------------------------- ### Start Labgrid Exporter Source: https://github.com/labgrid-project/labgrid/blob/master/examples/usbpower/README.rst Command to start the Labgrid exporter, which exports resources over the network. Requires an exports.yaml configuration file. ```bash labgrid-exporter exports.yaml ``` -------------------------------- ### Install Debian Dependencies Source: https://github.com/labgrid-project/labgrid/blob/master/doc/getting_started.rst Installs necessary dependencies on Debian-based systems for labgrid. ```bash $ sudo apt install python3 python3-virtualenv python3-pip python3-setuptools virtualenv microcom ``` -------------------------------- ### Install Latest Labgrid Release Source: https://github.com/labgrid-project/labgrid/blob/master/doc/getting_started.rst Installs the latest stable release of labgrid using pip. ```bash labgrid-venv $ pip install labgrid ``` -------------------------------- ### Install junit2html Tool Source: https://github.com/labgrid-project/labgrid/blob/master/doc/usage.rst Command to install the junit2html tool, used for converting JUnit XML reports to HTML format. ```bash $ pip install junit2html ``` -------------------------------- ### Start Labgrid Coordinator Service Source: https://github.com/labgrid-project/labgrid/blob/master/doc/getting_started.rst Command to start the labgrid coordinator systemd service. This should be done if the coordinator is being used. ```console # systemctl start labgrid-coordinator ``` -------------------------------- ### Start StepReporter Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst Starts the StepReporter, which outputs individual labgrid steps to STDOUT. Ensure this is called before any steps you wish to report. ```python from labgrid import StepReporter StepReporter.start() ``` -------------------------------- ### Install `devscripts` for `annotate-output` Source: https://github.com/labgrid-project/labgrid/blob/master/doc/development.rst Install the `devscripts` package on Debian-based systems to gain access to the `annotate-output` command, which helps in analyzing output timing. ```bash $ sudo apt install devscripts ``` -------------------------------- ### Install Labgrid with SNMP Support Source: https://github.com/labgrid-project/labgrid/blob/master/doc/getting_started.rst Installs labgrid with optional SNMP support using pip extras. ```bash labgrid-venv $ pip install "'.[snmp]'" ``` -------------------------------- ### Start ConsoleLoggingReporter Source: https://github.com/labgrid-project/labgrid/blob/master/CHANGES.rst This snippet shows how to start the ConsoleLoggingReporter when using the Labgrid library. Specify the output directory as an argument. ```python from labgrid.consoleloggingreporter import ConsoleLoggingReporter ConsoleLoggingReporter.start(".") ``` -------------------------------- ### UBoot Strategy Environment Configuration Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst Example YAML configuration for setting up a target with UBootDriver, ShellDriver, and UBootStrategy. This configuration is used to transition to a Linux shell from U-Boot. ```yaml targets: main: resources: RawSerialPort: port: '/dev/ttyUSB0' drivers: ManualPowerDriver: {} SerialDriver: {} UBootDriver: {} ShellDriver: prompt: 'root@[\w-]+:[^ ]+ ' login_prompt: ' login: ' username: 'root' UBootStrategy: {} ``` -------------------------------- ### Transitioning States and Rendering Graph with GraphStrategy Source: https://github.com/labgrid-project/labgrid/blob/master/doc/development.rst Demonstrates transitioning a `GraphStrategy` to a specific state using `transition()` and rendering the strategy graph to a PNG file using `render()`. Requires GraphViz to be installed. ```python >>> from labgrid.environment import Environment >>> env = Environment('test.yaml') >>> strategy = env.get_target().get_driver('Strategy') >>> strategy.transition('barebox', via=['boot_via_nfs']) ['unknown', 'boot_via_nfs', 'barebox'] >>> strategy.graph.render("teststrategy-via-nfs") 'teststrategy-via-nfs.png' >>> strategy.transition('barebox', via=['boot_via_nand']) ['unknown', 'boot_via_nand', 'barebox'] >>> strategy.graph.render("teststrategy-via-nand") 'teststrategy-via-nand.png' ``` -------------------------------- ### Cleanup Target Example Source: https://github.com/labgrid-project/labgrid/blob/master/doc/usage.rst Demonstrates how to manually call the cleanup method on a target, allowing for custom exception handling. ```python from labgrid import Target target = Target('main') ``` ```python >>> try: ... target.cleanup() ... except Exception as e: ... pass # your code here ``` -------------------------------- ### Define Example Driver with ConsoleExpectMixin Source: https://github.com/labgrid-project/labgrid/blob/master/doc/development.rst Implement a driver using ConsoleExpectMixin for added 'expect' functionality, ensuring it's the first in the subclass list. ```python import attr from labgrid.driver import Driver from labgrid.driver.consoleexpectmixin import ConsoleExpectMixin from labgrid.protocol import ConsoleProtocol @attr.s(eq=False) class ExampleDriver(ConsoleExpectMixin, Driver, ConsoleProtocol): pass ``` -------------------------------- ### Install Exporter Dependencies Source: https://github.com/labgrid-project/labgrid/blob/master/doc/getting_started.rst Install the 'ser2net' package, which is required by the labgrid exporter. This command requires superuser privileges. ```bash $ sudo apt install ser2net ``` -------------------------------- ### Configure Images for Flashing Source: https://github.com/labgrid-project/labgrid/blob/master/doc/man/device-config.rst Define paths to preconfigured images for flashing onto a board. Paths can be relative to the YAML file or absolute. This example shows configurations for the root filesystem and bootloader images. ```yaml images: root: "platform-v7a/images/root.img" boot: "platform-v7a/images/barebox.img" ``` -------------------------------- ### Define a Basic Example Driver Source: https://github.com/labgrid-project/labgrid/blob/master/doc/development.rst Define a new driver class inheriting from Driver and ConsoleProtocol using attrs. ```python import attr from labgrid.driver import Driver from labgrid.protocol import ConsoleProtocol @attr.s(eq=False) class ExampleDriver(Driver, ConsoleProtocol): pass ``` -------------------------------- ### Start Labgrid Exporter Service Source: https://github.com/labgrid-project/labgrid/blob/master/doc/getting_started.rst Command to start the labgrid exporter systemd service. Ensure the exporter configuration file is correctly set up before running this command. ```console # systemctl start labgrid-exporter ``` -------------------------------- ### Configure PDUDaemonPort Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst Example configuration for a PDUDaemonPort, specifying the host, PDU name, and port index. ```yaml PDUDaemonPort: host: 'pduserver' pdu: 'apc-snmpv3-noauth' index: 1 ``` -------------------------------- ### Start ConsoleLoggingReporter Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst Starts the ConsoleLoggingReporter, which outputs read calls from console transports into files. Provide the directory path where logs should be stored. ```python from labgrid import ConsoleLoggingReporter ConsoleLoggingReporter.start(".") ``` -------------------------------- ### Configure Labgrid Environment Source: https://github.com/labgrid-project/labgrid/blob/master/doc/getting_started.rst Example YAML configuration for labgrid, specifying serial port and driver settings. ```yaml targets: main: resources: RawSerialPort: port: "/dev/ttyUSB0" drivers: ManualPowerDriver: name: "example" SerialDriver: {} ShellDriver: prompt: 'root@[\w-]+:[^ ]+ ' login_prompt: ' login: ' username: 'root' ``` -------------------------------- ### Start Pytest with Labgrid Environment Source: https://github.com/labgrid-project/labgrid/blob/master/doc/man/pytest.rst Use this command to start pytest tests with a specified labgrid environment configuration file and test directory. Ensure the --lg-env flag is followed by your YAML configuration file. ```bash $ pytest --lg-env myconfig.yaml tests ``` -------------------------------- ### List Available Resources with Labgrid Client Source: https://github.com/labgrid-project/labgrid/blob/master/doc/getting_started.rst Use the labgrid-client to list all resources currently exported and managed by the coordinator. This command helps verify the exporter setup. ```bash labgrid-venv $ labgrid-client resources ``` -------------------------------- ### Shell Strategy Environment Configuration Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst Example YAML configuration for setting up a target with ShellDriver and ShellStrategy. Ensure the 'prompt', 'login_prompt', and 'username' are correctly set for your environment. ```yaml targets: main: resources: RawSerialPort: port: '/dev/ttyUSB0' drivers: ManualPowerDriver: {} SerialDriver: {} ShellDriver: prompt: 'root@[\w-]+:[^ ]+ ' login_prompt: ' login: ' username: 'root' ShellStrategy: {} ``` -------------------------------- ### Clone Labgrid Repository Source: https://github.com/labgrid-project/labgrid/blob/master/doc/development.rst Clone the Labgrid git repository to start development. ```bash git clone https://github.com/labgrid-project/labgrid && cd labgrid ``` -------------------------------- ### Create a Target Instance Source: https://github.com/labgrid-project/labgrid/blob/master/doc/usage.rst Instantiate a Target object directly. This is a lower-level approach; consider using environments for simpler setups. ```python from labgrid import Target t = Target('example') ``` -------------------------------- ### List Remote Resources with Labgrid Client Source: https://github.com/labgrid-project/labgrid/blob/master/examples/usbpower/README.rst Command to list available resources when connected to a remote setup via the coordinator and exporter. ```bash labgrid-client resources ``` -------------------------------- ### Run Pytest Source: https://github.com/labgrid-project/labgrid/blob/master/doc/development.rst Execute tests using pytest after installation. ```bash python -m pytest ``` -------------------------------- ### Environment Configuration with Target-Scoped Feature Flag Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst Example YAML for an environment configuration defining a target-scoped feature flag named 'camera'. ```yaml targets: main: features: - camera resources: {} drivers: {} ``` -------------------------------- ### YAML Environment Configuration Source: https://github.com/labgrid-project/labgrid/blob/master/doc/usage.rst An example YAML file defining a Labgrid environment with a serial port resource and a SerialDriver. ```yaml targets: example: resources: RawSerialPort: port: '/dev/ttyUSB0' drivers: SerialDriver: {} ``` -------------------------------- ### Environment Configuration with Global Feature Flag Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst Example YAML for an environment configuration defining a global feature flag named 'camera', alongside a target-specific 'console' feature. ```yaml features: - camera targets: main: features: - console resources: {} drivers: {} ``` -------------------------------- ### Build Labgrid Docker Images with Podman Source: https://github.com/labgrid-project/labgrid/blob/master/dockerfiles/README.rst Builds all Labgrid Docker images using the provided script, explicitly setting `DOCKER` to `podman`. Ensure `pip install --upgrade setuptools_scm` is run first. ```bash export DOCKER=podman ./dockerfiles/build.sh ``` -------------------------------- ### Enable Labgrid Logging to File Source: https://github.com/labgrid-project/labgrid/blob/master/doc/development.rst Use the `--lg-log` option when starting Labgrid to dump serial driver input to a specified directory. This aids in post-mortem analysis of test failures. ```bash $ pytest [OPTIONS] --lg-log=logdir test-dir/ ``` -------------------------------- ### Establish Serial Console Connection Source: https://github.com/labgrid-project/labgrid/blob/master/examples/usbpower/README.rst Connect to the serial console of a device managed by labgrid. This example shows the connection process and the initial output from a barebox bootloader. ```bash $ labgrid-client -p demo1 console connecting to NetworkSerialPort(target=Target(name='demo1', env=None), name='USBSerialPort', state=, avail=True, host='polaris', port=52363, speed=115200, protocol='rfc2217') calling microcom -s 115200 -t polaris:52363 connected to 127.0.1.1 (port 52363) Escape character: Ctrl-\' Type the escape character followed by c to get to the menu or q to quit barebox 2018.03.0-20180308-1 #1 Thu Mar 8 17:11:54 CET 2018 Board: RaspberryPi 3 Model B bcm2835_mci 3f300000.sdhci: registered as 3f300000.sdhci bcm2835-gpio 3f200000.gpio: probed gpiochip-1 with base 0 pitft@0-2: setting up native-CS0 as GPIO 8 fbtft_of_value: buswidth = 8 fbtft_of_value: debug = 4294967295 fbtft_of_value: rotate = 0 fbtft_of_value: fps = 25 mci0: detected SD card version 2.0 mci0: registered disk0 state: New state registered 'state' state: Using bucket 0@0x00000000 malloc space: 0x0fefe3c0 -> 0x1fdfc77f (size 255 MiB) bcm2835_fb bcm2835_fb0: registered Hit any key to stop autoboot: barebox@RaspberryPi 3 Model B:/ ``` -------------------------------- ### Transition to Shell using BareboxStrategy Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst Use this snippet to transition from the bootloader into a Linux shell and activate the ShellDriver. Requires a 'barebox-env.yaml' configuration file. ```python from labgrid import Environment e = Environment("barebox-env.yaml") t = e.get_target("main") s = t.get_driver("BareboxStrategy") s.transition("shell") ``` -------------------------------- ### Get udevadm info for a specific UART Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst Example output of 'udevadm info' for a specific device, showing various properties like P, N, S, E, and ID_* values. This is used to determine the correct matching criteria. ```bash $ udevadm info /dev/ttyUSB9 P: /devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10.2/3-10.2.2/3-10.2.2.2/3-10.2.2.2:1.1/ttyUSB9/tty/ttyUSB9 N: ttyUSB9 S: serial/by-id/usb-FTDI_Dual_RS232-HS-if01-port0 S: serial/by-path/pci-0000:00:14.0-usb-0:10.2.2.2:1.1-port0 E: DEVLINKS=/dev/serial/by-id/usb-FTDI_Dual_RS232-HS-if01-port0 /dev/serial/by-path/pci-0000:00:14.0-usb-0:10.2.2.2:1.1-port0 E: DEVNAME=/dev/ttyUSB9 E: DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10.2/3-10.2.2/3-10.2.2.2/3-10.2.2.2:1.1/ttyUSB9/tty/ttyUSB9 E: ID_BUS=usb E: ID_MODEL=Dual_RS232-HS E: ID_MODEL_ENC=Dual\x20RS232-HS E: ID_MODEL_FROM_DATABASE=FT2232C Dual USB-UART/FIFO IC E: ID_MODEL_ID=6010 E: ID_PATH=pci-0000:00:14.0-usb-0:10.2.2.2:1.1 E: ID_PATH_TAG=pci-0000_00_14_0-usb-0_10_2_2_2_1_1 E: ID_REVISION=0700 E: ID_SERIAL=FTDI_Dual_RS232-HS E: ID_TYPE=generic E: ID_USB_DRIVER=ftdi_sio E: ID_USB_INTERFACES=:ffffff: E: ID_USB_INTERFACE_NUM=01 E: ID_VENDOR=FTDI E: ID_VENDOR_ENC=FTDI E: ID_VENDOR_FROM_DATABASE=Future Technology Devices International, Ltd E: ID_VENDOR_ID=0403 E: MAJOR=188 E: MINOR=9 E: SUBSYSTEM=tty E: TAGS=:systemd: E: USEC_INITIALIZED=9129609697 ``` -------------------------------- ### Install Latest Labgrid Release Source: https://github.com/labgrid-project/labgrid/blob/master/README.rst Installs the latest stable release of labgrid using pip within a virtual environment. Ensure you have python3 and virtualenv installed. ```bash $ virtualenv -p python3 venv $ source venv/bin/activate venv $ pip install --upgrade pip venv $ pip install labgrid ``` -------------------------------- ### Run Labgrid Tests Source: https://github.com/labgrid-project/labgrid/blob/master/README.rst Executes labgrid tests using pytest after installation from the development state. Requires a configuration file specified by --lg-env. ```bash venv $ python -m pytest --lg-env ``` -------------------------------- ### Transition to Accessible state using DockerStrategy Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst Use this snippet to transition the DockerStrategy to the 'accessible' state, which creates and starts a Docker container. This makes NetworkService instances available for access. ```python from labgrid import Environment e = Environment("docker-env.yaml") t = e.get_target("main") s = t.get_driver("DockerStrategy") s.transition("accessible") ``` -------------------------------- ### Build Labgrid Docker Images for Foreign Platform Source: https://github.com/labgrid-project/labgrid/blob/master/dockerfiles/README.rst Builds Labgrid Docker images for a specified foreign platform, such as `linux/arm64`, using the build script. Ensure `pip install --upgrade setuptools_scm` is run first. ```bash pip install --upgrade setuptools_scm ./dockerfiles/build.sh --platform linux/arm64 ``` -------------------------------- ### Configure USBSDWire3Device Match Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst This YAML snippet defines the matching parameters for a USBSDWire3Device, utilizing the udev ID path. Ensure the ID_PATH is correct for your setup. ```yaml USBSDWire3Device: match: '@ID_PATH': 'pci-0000:00:14.0-usb-0:1.2' ``` -------------------------------- ### Configure Target with RemotePlace, IMXUSBDriver, and Custom Strategy Source: https://github.com/labgrid-project/labgrid/blob/master/doc/man/device-config.rst Sets up a 'main' target using RemotePlace, SerialDriver, ShellDriver, IMXUSBDriver, and a custom strategy defined in an imported Python file. Includes tool configuration for imx-usb-loader. ```yaml targets: main: resources: RemotePlace: name: test-place drivers: SerialDriver: {} ShellDriver: prompt: 'root@[\w-]+:[^ ]+ ' login_prompt: ' login: ' username: 'root' IMXUSBDriver: {} MyStrategy: {} tools: imx-usb-loader: "/opt/lg-tools/imx-usb-loader" imports: - mystrategy.py ``` -------------------------------- ### Configure USBTMC udev Rule Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst This is a udev rule example to grant non-root users access to USB TMC devices. It sets read/write permissions for the 'plugdev' group. ```none DRIVERS=="usbtmc", MODE="0660", GROUP="plugdev" ``` -------------------------------- ### Exporting a Single USBSerialPort Resource Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst Example of configuring a single USBSerialPort resource within a group, using udev matching for identification. This resource will be exported with a specific name. ```yaml usb-hub-in-rack12: USBSerialPort: match: '@ID_PATH': 'pci-0000:05:00.0-usb-3-1.3' ``` -------------------------------- ### Install pytest-html Plugin Source: https://github.com/labgrid-project/labgrid/blob/master/doc/usage.rst Command to install the pytest-html plugin, which enables the generation of HTML test reports. ```bash $ pip install pytest-html ``` -------------------------------- ### Transition to Shell using UBootStrategy Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst Use this snippet to transition from the U-Boot bootloader into a Linux shell and activate the ShellDriver. Requires a 'uboot-env.yaml' configuration file. ```python from labgrid import Environment e = Environment("uboot-env.yaml") t = e.get_target("main") s = t.get_driver("UBootStrategy") s.transition("shell") ``` -------------------------------- ### labgrid-suggest command line help Source: https://github.com/labgrid-project/labgrid/blob/master/doc/man/suggest.rst Displays command line help for the labgrid-suggest tool. Use this to understand available options. ```bash labgrid-suggest --help ``` -------------------------------- ### Run Labgrid Coordinator Instance Source: https://github.com/labgrid-project/labgrid/blob/master/dockerfiles/README.rst Runs a Labgrid coordinator instance, publishing port 20408 and binding a volume for state persistence. The state is written to `/opt/coordinator`. ```bash $ docker run -t -p 20408:20408 -v $HOME/coordinator:/opt/coordinator \ docker.io/labgrid/coordinator ``` -------------------------------- ### Configure Remote Place with Labgrid Client Source: https://github.com/labgrid-project/labgrid/blob/master/examples/usbpower/README.rst Commands to create a remote place named 'demo1' and add a specific network USB power port resource to it. ```bash labgrid-client -p demo1 create ``` ```bash labgrid-client -p demo1 add-match polaris/hub-p1/NetworkUSBPowerPort ``` -------------------------------- ### Create a Place with Labgrid Client Source: https://github.com/labgrid-project/labgrid/blob/master/doc/getting_started.rst Create a new 'place' in the coordinator using the labgrid-client. A place is a logical grouping of resources for interaction. ```bash labgrid-venv $ labgrid-client --place example-place create ``` -------------------------------- ### Transition to Shell State using BareboxStrategy Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst Python code to transition to the 'shell' state using the BareboxStrategy library. This requires importing the BareboxStrategy class. ```python from labgrid.strategy import BareboxStrategy ``` -------------------------------- ### Get Target from Environment Source: https://github.com/labgrid-project/labgrid/blob/master/doc/usage.rst Retrieves a configured target by its name from a Labgrid Environment object. ```python t = env.get_target('example') ``` -------------------------------- ### Transition to Shell using ShellStrategy Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst Use this snippet to transition directly into a Linux shell and activate the ShellDriver. Requires a 'shell-env.yaml' configuration file. ```python from labgrid import Environment e = Environment("shell-env.yaml") t = e.get_target("main") s = t.get_driver("ShellStrategy") ``` -------------------------------- ### Update PyYAML Version Source: https://github.com/labgrid-project/labgrid/blob/master/CHANGES.rst Updates PyYAML to version 6.0.1 to prevent installation errors with Cython>=3.0. ```python Update to PyYAML 6.0.1 to prevent install errors with Cython>=3.0, see: https://github.com/yaml/pyyaml/issues/601 https://github.com/yaml/pyyaml/pull/726#issuecomment-1640397938 ``` -------------------------------- ### Configure QEMUDriver with Basic Settings Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst Configures the QEMUDriver with essential parameters for running a QEMU instance as a target. ```yaml QEMUDriver: qemu_bin: 'qemu_arm' machine: 'vexpress-a9' cpu: 'cortex-a9' memory: '512M' boot_args: 'root=/dev/root console=ttyAMA0,115200' extra_args: '' kernel: 'kernel' rootfs: 'rootfs' dtb: 'dtb' nic: 'user' ``` -------------------------------- ### Configure YKUSHPowerPort Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst Example configuration for a YKUSHPowerPort, specifying the serial number of the YKUSH hub and the port index. ```yaml YKUSHPowerPort: serial: 'Y3N12345' index: '1' ``` -------------------------------- ### Configure ModbusCoilDriver Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst An empty configuration for ModbusCoilDriver, used to control a ModbusTCPCoil resource for setting and getting its state. ```yaml ModbusCoilDriver: {} ``` -------------------------------- ### List Places with Labgrid Client Source: https://github.com/labgrid-project/labgrid/blob/master/dockerfiles/README.rst Uses the labgrid-client Docker image to list available places registered at a specified coordinator. The `LG_COORDINATOR` environment variable must be set. ```bash $ docker run -e LG_COORDINATOR=192.168.1.42:20408 docker.io/labgrid/client \ labgrid-client places ``` -------------------------------- ### Build labgrid-client Docker Image Source: https://github.com/labgrid-project/labgrid/blob/master/dockerfiles/README.rst Builds the labgrid-client Docker image using a specific Dockerfile and tags it for distribution. Ensure you are in the root of the repository. ```bash $ docker build --target labgrid-client -t docker.io/labgrid/client -f dockerfiles/Dockerfile . ``` -------------------------------- ### Get ID_SERIAL_SHORT using udevadm Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst Command to retrieve the 'ID_SERIAL_SHORT' property for a USB serial device, which can then be used for matching. ```bash $ udevadm info /dev/ttyUSB5 | grep SERIAL_SHORT E: ID_SERIAL_SHORT=P-00-03564 ``` -------------------------------- ### Build All Labgrid Docker Images Source: https://github.com/labgrid-project/labgrid/blob/master/dockerfiles/README.rst Builds all Labgrid Docker images using the provided script. It supports `docker buildx` and `podman`. ```bash pip install --upgrade setuptools_scm ./dockerfiles/build.sh ``` -------------------------------- ### Configure dpcmd Path for DediprogFlasher Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst Specify the path to the dpcmd executable for the DediprogFlasher resource. Ensure dpcmd is installed and accessible. ```yaml tools: dpcmd: '/usr/sbin/dpcmd' ``` -------------------------------- ### Configure RawNetworkInterfaceDriver Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst This configuration snippet for RawNetworkInterfaceDriver specifies denied network interfaces. The RawNetworkInterfaceDriver requires the 'labgrid-raw-interface' helper to be installed and configured. ```yaml raw-interface: denied-interfaces: - 'eth1' ``` -------------------------------- ### DeditecRelaisDriver Configuration Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst Configure the DeditecRelaisDriver to control a Deditec relay resource, allowing for setting and getting its current state. Implements DigitalOutputProtocol. ```yaml DeditecRelaisDriver: {} ``` -------------------------------- ### Get and Activate SerialDriver Source: https://github.com/labgrid-project/labgrid/blob/master/doc/usage.rst Retrieves a driver by its name from a target. The driver is automatically activated, and the method waits for unavailable resources if necessary. ```python from labgrid import Environment env = Environment('example-env.yaml') t = env.get_target('example') s = t.get_driver('SerialDriver', activate=False) s.serial.open = Mock() s.serial.write = Mock(return_value=4) ``` ```python >>> cp = t.get_driver('ConsoleProtocol') >>> cp SerialDriver(target=Target(name='example', env=Environment(config_file='example-env.yaml')), name=None, state=, txdelay=0.0, txchunk=1, timeout=3.0) >>> cp.write(b'test') 4 ``` -------------------------------- ### Connect to Serial Console Source: https://github.com/labgrid-project/labgrid/blob/master/doc/getting_started.rst Connect to the serial console of a resource within an acquired place using the labgrid-client. Requires 'microcom' or 'telnet' to be installed. ```bash labgrid-venv $ labgrid-client -p example-place console ``` -------------------------------- ### Test usb_id udev helper Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst Example output from 'udevadm test-builtin usb_id' showing properties extracted by the usb_id helper, including ID_SERIAL_SHORT. ```bash $ udevadm test-builtin usb_id /sys/class/tty/ttyUSB0 Load module index Parsed configuration file /lib/systemd/network/99-default.link Parsed configuration file /lib/systemd/network/73-usb-net-by-mac.link Created link configuration context. ID_VENDOR=Silicon_Labs ID_VENDOR_ENC=Silicon\x20Labs ID_VENDOR_ID=10c4 ID_MODEL=CP2102_USB_to_UART_Bridge_Controller ID_MODEL_ENC=CP2102\x20USB\x20to\x20UART\x20Bridge\x20Controller ID_MODEL_ID=ea60 ID_REVISION=0100 ID_SERIAL=Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_P-00-03564 ID_SERIAL_SHORT=P-00-03564 ID_TYPE=generic ID_BUS=usb ID_USB_INTERFACES=:ff0000: ID_USB_INTERFACE_NUM=00 ID_USB_DRIVER=cp210x Unload module index Unloaded link configuration context. ``` -------------------------------- ### Configure Logging Level Source: https://github.com/labgrid-project/labgrid/blob/master/CHANGES.rst Sets up basic logging configuration to display INFO level messages and above to stderr. ```python logging.basicConfig( level=logging.INFO, format='%(levelname)8s: %(message)s', stream=sys.stderr, ) ``` -------------------------------- ### Request and Remove SSH Port Forwarding Source: https://github.com/labgrid-project/labgrid/blob/master/doc/development.rst Use SSHManager to request and remove port forwardings. Ensure the SSHManager is available in the test setup. ```python from labgrid.util import sshmanager sshmanager.get = Mock() from labgrid.util import sshmanager localport = sshmanager.request_forward('localhost', 'somehost', 3000) sshmanager.remove_forward('localhost', 'somehost', 3000) ``` -------------------------------- ### SSHDriver Redirect /dev/null to stdin Source: https://github.com/labgrid-project/labgrid/blob/master/CHANGES.rst Ensures that the SSHDriver redirects /dev/null to stdin during run() to prevent unexpected consumption of stdin by remotely started processes. ```python Let the `SSHDriver` redirect ``/dev/null`` to stdin on ``run()`` to prevent unexpected consumption of stdin of the remotely started process. ``` -------------------------------- ### Create Signed Git Tag Source: https://github.com/labgrid-project/labgrid/blob/master/doc/RELEASE.rst Create a signed Git tag for the new release. Ensure your PGP key is available and the tag starts with 'v'. ```bash git tag -s $VERSION ``` -------------------------------- ### Run Labgrid Exporter with Devices and Udev Source: https://github.com/labgrid-project/labgrid/blob/master/dockerfiles/README.rst Runs the labgrid-exporter Docker image, including necessary device mappings and udev mounts for serial device exporting. Configuration files must be bind-mounted to `/opt/conf/`. ```bash $ docker run -e LG_COORDINATOR=192.168.1.42:20408 \ -v $HOME/exporter-conf:/opt/conf \ --device /dev/ttyUSB0:/dev/ttyUSB0 \ -v run/udev:/run/udev:ro \ docker.io/labgrid/exporter ``` -------------------------------- ### Define QEMU Environment Paths and Images Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst Specifies the paths to QEMU binaries, root filesystem, and kernel/DTB images required by the QEMUDriver. ```yaml tools: qemu_arm: '/bin/qemu-system-arm' paths: rootfs: '../images/root' images: dtb: '../images/mydtb.dtb' kernel: '../images/vmlinuz' ``` -------------------------------- ### Interact with Labgrid Client Source: https://github.com/labgrid-project/labgrid/blob/master/doc/getting_started.rst Commands to acquire resources, enter a console, and release resources using the labgrid client with a specified environment file. ```bash labgrid-venv $ labgrid-client -c remote.yaml acquire labgrid-venv $ labgrid-client -c remote.yaml console labgrid-venv $ labgrid-client -c remote.yaml release ``` -------------------------------- ### Initialize and Sync ManagedFile Source: https://github.com/labgrid-project/labgrid/blob/master/doc/development.rst Instantiate ManagedFile with a local file and a remote resource, then synchronize the file to the resource. The ManagedFile handles file uploads with a specific remote path pattern. ```python import tempfile from labgrid.resource import Resource from labgrid import Target f = tempfile.NamedTemporaryFile() your_file = f.name your_resource = Resource(Target("main"), "example") from labgrid.util.managedfile import ManagedFile mf = ManagedFile(your_file, your_resource) mf.sync_to_resource() path = mf.get_remote_path() ``` -------------------------------- ### Acquire a Place Source: https://github.com/labgrid-project/labgrid/blob/master/doc/getting_started.rst Acquire a previously created place using the labgrid-client. Acquiring a place makes its resources available for interaction. ```bash labgrid-venv $ labgrid-client -p example-place acquire ``` -------------------------------- ### SSHDriver explicit_sftp_mode Option Source: https://github.com/labgrid-project/labgrid/blob/master/CHANGES.rst Updates the `SSHDriver`'s `explicit_sftp_mode` option to allow multiple calls to `put()` and `get()`. The `scp()` method also now respects this option. ```python Fix `SSHDriver`'s ``explicit_sftp_mode`` option to allow calls to ``put()`` and ``get()`` multiple times. Also make ``scp()`` respect this option. ``` -------------------------------- ### List Detailed Resources with Labgrid Client Source: https://github.com/labgrid-project/labgrid/blob/master/doc/getting_started.rst Use the labgrid-client with the '-v' flag to display detailed information about exported resources, including their parameters and availability. ```bash labgrid-venv $ labgrid-client -v resources ``` -------------------------------- ### Configure HttpDigitalOutputDriver Source: https://github.com/labgrid-project/labgrid/blob/master/doc/configuration.rst Configuration for HttpDigitalOutputDriver, used to set and get digital output states via HTTP. This driver binds to an HttpDigitalOutput and requires no specific arguments. ```yaml HttpDigitalOutputDriver: {} ```