Console

Console Commands

This section describes some useful commands when testing Linux-based DUTs using off-the-shelf Linux DUT firmware images.

Custom scripts

To facilitate integration with a YAML test plan, custom scripts meant to be executed on the DUT should return output that can be unambiguously parsed over a UART connection.

For example:

user@sbc:~$ /opt/factory-test.bash
Running DUT-based Factory tests.
Testing memory..
100% complete, 0 errors.
Testing peripherals..
:
done.
factory-test:0:PASS
user@sbc:~$

This way, the PLT Test Script only needs to look for factory-test:0:PASS.

While all DUT-based tests can be included in a single script, included in the DUT image, or transferred over USB, there may be cases where it may be useful to interact with standard Linux shell commands from a PLT test plan.

i2cdetect

The i2cdetect command can be used to include a scan of the I2C peripherals detected by the Linux host.

root@sbc:~# i2cdetect -y -a 0 0x00 0x7f
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00: 00 -- -- -- -- -- -- -- 08 -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: 30 31 -- -- 34 35 UU UU -- -- -- -- -- -- -- --
40: -- -- -- -- 44 -- -- -- -- -- -- -- -- -- -- --
50: UU -- 52 -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
root@sbc:~#

Parsing this output in a PLT test plan is rather complicated.

It is easier to test for specific I2C peripherals one by one, as in the example below.

root@sbc:~# i2cdetect -y 0 0x52 0x52 | grep - -- || echo i2c.0.52:$?:PASS
i2c.0.52:0:PASS
root@sbc:~#

In a test script, it makes sense to first scan the bus, so the scan report gets included in the PLT test report, but to then test each peripheral individually.

- ident: I2C.scan
  title: "Scan I2C bus"
  steps:
   - command: uart %UART.dut%
     expect: "i2c.scan:0:PASS"
     send: "i2cdetect -y -a 0 0x00 0x7f && i2c.scan:$?:PASS\r\n"
     timeout: 5s
- ident: I2C.SENSOR1
  title: "Detect Sensor #1"
  steps:
   - command: uart %UART.dut%
     expect: "i2c.0.44:0:PASS"
     send: "i2cdetect -y 0 0x44 0x44 | grep - -- || echo i2c.0.44:$?:PASS\r\n"
     timeout: 1s
- ident: I2C.SENSOR2
  title: "Detect Sensor #2"
  steps:
   - command: uart %UART.dut%
     expect: "i2c.0.52:0:PASS"
     send: "i2cdetect -y 0 0x52 0x52 | grep - -- || echo i2c.0.52:$?:PASS\r\n"
     timeout: 1s

lsusb: List connected USB devices

user@sbc:~$ lsusb
Bus 002 Device 004: ID 05e3:0626 Genesys Logic, Inc. USB3.1 Hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 037: ID 05e3:0610 Genesys Logic, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
user@sbc:~$
user@sbc:~$ lsusb -d 05e3:0610 && echo usb.hub:$?:PASS
Bus 001 Device 037: ID 05e3:0610 Genesys Logic, Inc. Hub
usb.hub:0:PASS
user@sbc:~$
- ident: USB.scan
  title: "Scan USB bus"
  steps:
   - command: uart %UART.dut%
     expect: "usb.scan:0:PASS"
     send: "lsub && usb.scan:$?:PASS\r\n"
     timeout: 5s
- ident: USB.HUB
  title: "Detect USB hub"
  steps:
   - command: uart %UART.dut%
     expect: "usb.hub:0:PASS"
     send: "lsusb -d 05e3:0610 && echo usb.hub:$?:PASS\r\n"
     timeout: 1s

sysfs

Voltages:

root@sbc:~# for i in $(find /sys -type f -name "*volt*"); do echo $i $(cat $i); done
/sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT0/voltage_now 15538000
/sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT0/voltage_min_design 14400000
root@sbc:~#

Temperature sensors:

root@sbc:~# for i in $(find /sys -type f -name "*temp*input"); do echo $i $(cat $i); done
/sys/devices/platform/coretemp.0/hwmon/hwmon5/temp6_input 46000
/sys/devices/platform/coretemp.0/hwmon/hwmon5/temp3_input 48000
/sys/devices/platform/coretemp.0/hwmon/hwmon5/temp7_input 45000
:

The following PLT test plan YAML fragment illustrates extracting a temperature readout into the HWMON5_TEMP6 user key.

- ident: SYSFS.temp
  title: "Temperature"
  steps:
   - command: uart %UART.dut%
     send: "echo hwmon5.6:$(cat /sys/devices/platform/coretemp.0/hwmon/hwmon5/temp6_input):$?:PASS\r\n"
     expect: "hwmon5.6:"
     extract: "hwmon5.6:(.+):0:PASS"
     extractKey: HWMON5_TEMP6
     timeout: 5s

Python

While the PLT platform does not allow running custom python code on the PLT itself, Python scripts running on the DUT or an SBC integrated in a PPC can be controlled from a PLT Test Plan.

pltagent@raspberrypi4-64:~$ python3
Python 3.11.2 (main, Feb  7 2023, 13:52:42) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import binascii
>>> crc = binascii.crc_hqx(b"Hello World", 0)
>>> rc = 0
>>> print(f"crc:0x{crc:04X}:{rc}:PASS")
crc:0x992A:0:PASS
>>>
pltagent@raspberrypi4-64:~$
- ident: PYTHON.crc
  title: "CRC-16/XMODEM"
  steps:
   - command: uart %UART.sbc%
     send: |
       python3
       import binascii
       crc = binascii.crc_hqx(b"Hello World", 0)
       print(f"crc:0x{crc:04X}:PASS")
       quit()
     extract: "crc:0x(....):PASS"
     extractKey: CRC
     timeout: 5s