Skip to content
Open
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
37 changes: 37 additions & 0 deletions Runner/suites/Kernel/Baseport/usb_ls/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
```
Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
SPDX-License-Identifier: BSD-3-Clause-Clear
```

# USB Low Speed Validation

## Overview

This shell script executes on the DUT (Device-Under-Test) and verifies successful enumeration of connected USB Devices in Low Speed (LS - 1.5 Mb/s) .

---

## Setup

- Connect LS USB peripheral(s) to USB port(s) on DUT.
- Only applicable for USB ports that support Host Mode functionality.
- USB peripherals examples: Mass Storage devices (pendrives, SSD, hard drives, etc.), HID devices (Mouse, Keyboard, USB headset, USB camera, etc.)

---

## Usage
### Instructions:
1. **Copy the test suite to the target device** using `scp` or any preferred method.
2. **Navigate to the test directory** on the target device.
3. **Run the test script** using the test runner or directly.

---

### Quick Example
```bash
git clone <this-repo>
cd <this-repo>
scp -r common Runner user@target_device_ip:<path-on-device>
ssh user@target_device_ip
cd <path-on-device>/Runner && ./run-test.sh usb_ls
```
115 changes: 115 additions & 0 deletions Runner/suites/Kernel/Baseport/usb_ls/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/bin/sh

# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
# SPDX-License-Identifier: BSD-3-Clause-Clear

# Validate that at least one non-hub USB peripheral is enumerated at LowSpeed (<= 1.5 Mb/s).
# This test ignores hubs and only considers actual USB devices.

# Robustly find and source init_env
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
INIT_ENV=""
SEARCH="$SCRIPT_DIR"
while [ "$SEARCH" != "/" ]; do
if [ -f "$SEARCH/init_env" ]; then
INIT_ENV="$SEARCH/init_env"
break
fi
SEARCH=$(dirname "$SEARCH")
done

if [ -z "$INIT_ENV" ]; then
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
exit 1
fi

# Only source if not already loaded (idempotent)
if [ -z "$__INIT_ENV_LOADED" ]; then
# shellcheck disable=SC1090
. "$INIT_ENV"
__INIT_ENV_LOADED=1
fi
# Always source functestlib.sh, using $TOOLS exported by init_env
# shellcheck disable=SC1090,SC1091
. "$TOOLS/functestlib.sh"

TESTNAME="usb_ls"
test_path=$(find_test_case_by_name "$TESTNAME")
cd "$test_path" || exit 1
# shellcheck disable=SC2034
res_file="./$TESTNAME.res"

log_info "-----------------------------------------------------------------------------------------"
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
log_info "=== Test Initialization ==="

log_info "=== Detecting non-hub LowSpeed USB devices (<= 1.5 Mb/s) ==="

# We rely on sysfs entries under /sys/bus/usb/devices for authoritative device speed.
# Criteria:
# - Only consider entries with bDeviceClass (device-level), skip interface-only entries.
# - Ignore hubs: device class 0x09 (9).
# - Consider a device LowSpeed if the integer part of speed is 1 (covers 1.0 and 1.5 Mb/s).
# Note: sysfs 'speed' commonly reports "1.5" for LowSpeed devices; integer extraction yields 1.

non_hub_count=0
ls_count=0

for d in /sys/bus/usb/devices/*; do
[ -d "$d" ] || continue

# Must be a device (has bDeviceClass); skip interface/function entries like 1-1:1.0
if [ ! -f "$d/bDeviceClass" ]; then
continue
fi

class="$(tr -d '[:space:]' 2>/dev/null < "$d/bDeviceClass")"
case "$class" in
09|9|0x09|0X09) # Hub device; ignore
continue
;;
esac

raw_speed="$(cat "$d/speed" 2>/dev/null || echo 0)"
speed_int="${raw_speed%%.*}"
case "$speed_int" in
''|*[!0-9]*)
speed_int=0
;;
esac

busnum="$(cat "$d/busnum" 2>/dev/null || echo "?")"
devnum="$(cat "$d/devnum" 2>/dev/null || echo "?")"
idVendor="$(cat "$d/idVendor" 2>/dev/null || echo "0000")"
idProduct="$(cat "$d/idProduct" 2>/dev/null || echo "0000")"
product="$(cat "$d/product" 2>/dev/null || true)"
[ -n "$product" ] || product="(unknown)"

echo "Device: $busnum $devnum ${idVendor}:${idProduct} \"$product\" ${raw_speed}"

non_hub_count=$((non_hub_count + 1))
# LowSpeed if integer part equals 1 (covers 1.5 and 1.0 Mb/s)
if [ "$speed_int" -eq 1 ]; then
ls_count=$((ls_count + 1))
fi
done

echo "LowSpeed (<=1.5 Mb/s) device count: $ls_count"

if [ "$non_hub_count" -eq 0 ]; then
log_fail "$TESTNAME : Test Failed - No non-hub USB peripherals detected. Only hubs or no devices present."
echo "$TESTNAME FAIL" > "$res_file"
exit 1
fi

if [ "$ls_count" -gt 0 ]; then
log_pass "$TESTNAME : Test Passed - $ls_count LowSpeed device(s) found among $non_hub_count non-hub device(s)."
echo "$TESTNAME PASS" > "$res_file"
exit 0
else
log_fail "$TESTNAME : Test Failed - No non-hub USB device enumerated at LowSpeed (<= 1.5 Mb/s)."
echo "$TESTNAME FAIL" > "$res_file"
exit 1
fi

log_info "-------------------Completed $TESTNAME Testcase----------------------------"
16 changes: 16 additions & 0 deletions Runner/suites/Kernel/Baseport/usb_ls/usb_ls.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
metadata:
name: usb-ls
format: "Lava-Test Test Definition 1.0"
description: "This shell script executes on the DUT (Device-Under-Test) and verifies successful enumeration of connected USB Devices in Low Speed (LS)."
os:
- linux
scope:
- functional

run:
steps:
- REPO_PATH=$PWD
- cd Runner/suites/Kernel/Baseport/usb_ls
- ./run.sh || true
- $REPO_PATH/Runner/utils/send-to-lava.sh usb_ls.res || true

Loading