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_msd/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 MSD Validation

## Overview

This shell script executes on the DUT (Device-Under-Test) and verifies enumeration of connected USB Mass Storage Devices (MSD).

---

## Setup

- Connect USB MSD peripheral(s) to USB port(s) on DUT.
- Only applicable for USB ports that support Host Mode functionality.
- USB MSD peripherals examples: USB flash drive, external HDD/SSD, 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_msd
```
67 changes: 67 additions & 0 deletions Runner/suites/Kernel/Baseport/usb_msd/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/sh

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

# Validate USB Mass Storage device detection
# Requires at least one USB Mass Storage peripheral (USB flash drive, external HDD/SSD, etc.) connected to a USB Host port.

# Robustly find and source init_env
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's have repo standard way..

SCRIPT_DIR="$(
cd "$(dirname "$0")" || exit 1
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be ${__INIT_ENV_LOADED:-} to avoid unbound surprises.

# 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_msd"
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 ==="

# Check if grep is installed, else skip test
deps_list="grep"
check_dependencies "$deps_list"

# Count interfaces with bInterfaceClass = 08 (MSD) under /sys/bus/usb/devices
msd_iface_count=0
log_info "=== USB Mass Storage device Detection ==="
msd_iface_count="$(cat /sys/bus/usb/devices/*/bInterfaceClass 2>/dev/null | grep -i '08' | wc -l)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Counting bInterfaceClass=08 is OK for “device enumerated”, but it does not guarantee
usb-storage driver bound
block device appeared (/dev/sdX)
mountable storage exists
After class detection, verify block device presence via one of:
lsblk -ndo NAME,TRAN | grep -q ' usb' (if lsblk exists)
/sys/block/sd*/device + check it’s USB-backed
/sys/bus/usb/drivers/usb-storage/ entries (driver bound)
Even a best-effort optional check is valuable:
If tools missing → SKIP that sub-check, don’t fail the test.


printf "Number of MSD interfaces found: $msd_iface_count"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use log_info "Number of HID interfaces found: $msd_iface_count"


if [ "$msd_iface_count" -gt 0 ]; then
log_pass "$TESTNAME : Test Passed - USB Mass Storage interface(s) detected"
echo "$TESTNAME PASS" > "$res_file"
exit 0
else
log_fail "$TESTNAME : Test Failed - No 'Mass Storage' interface found"
echo "$TESTNAME FAIL" > "$res_file"
exit 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exit 0 always so LAVA doesn’t stop the job unexpectedly

fi

log_info "-------------------Completed $TESTNAME Testcase----------------------------"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove or move above after PASS/ FAIL decision making.

16 changes: 16 additions & 0 deletions Runner/suites/Kernel/Baseport/usb_msd/usb_msd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
metadata:
name: usb-msd
format: "Lava-Test Test Definition 1.0"
description: "This shell script executes on the DUT (Device-Under-Test) and verifies enumeration of connected USB Mass Storage Devices (MSD)."
os:
- linux
scope:
- functional

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still uses || true for both run.sh and send-to-lava. Please remove error masking


Loading