-
Notifications
You must be signed in to change notification settings - Fork 31
Add test script to validate USB MSD #265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
achauras-qcom
wants to merge
3
commits into
qualcomm-linux:main
Choose a base branch
from
achauras-qcom:feature/usb-msd
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| ``` | ||
| Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| SPDX-License-Identifier: BSD-3-Clause | ||
| ``` | ||
|
|
||
| # 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 | ||
| ``` | ||
| cd Runner | ||
| ./run-test.sh usb_msd | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| #!/bin/sh | ||
|
|
||
| # Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
| # 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. | ||
|
|
||
| TESTNAME="usb_msd" | ||
|
|
||
| # Robustly find and source init_env | ||
| SCRIPT_DIR="$( | ||
| cd "$(dirname "$0")" || exit 1 | ||
| pwd | ||
| )" | ||
|
|
||
| # Default result file (works even before functestlib is available) | ||
| # shellcheck disable=SC2034 | ||
| RES_FILE="$SCRIPT_DIR/${TESTNAME}.res" | ||
|
|
||
| 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 | ||
| echo "$TESTNAME SKIP" >"$RES_FILE" 2>/dev/null || true | ||
| exit 0 | ||
| 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" | ||
|
|
||
| # Resolve test path and cd (single SKIP/exit path) | ||
| SKIP_REASON="" | ||
| test_path=$(find_test_case_by_name "$TESTNAME") | ||
| if [ -z "$test_path" ] || [ ! -d "$test_path" ]; then | ||
| SKIP_REASON="$TESTNAME SKIP - test path not found" | ||
| elif ! cd "$test_path"; then | ||
| SKIP_REASON="$TESTNAME SKIP - cannot cd into $test_path" | ||
| else | ||
| RES_FILE="$test_path/${TESTNAME}.res" | ||
| fi | ||
|
|
||
| if [ -n "$SKIP_REASON" ]; then | ||
| log_skip "$SKIP_REASON" | ||
| echo "$TESTNAME SKIP" >"$RES_FILE" 2>/dev/null || true | ||
| exit 0 | ||
| fi | ||
|
|
||
| log_info "-----------------------------------------------------------------------------------------" | ||
| log_info "-------------------Starting $TESTNAME Testcase----------------------------" | ||
| log_info "=== Test Initialization ===" | ||
|
|
||
| # Check if dependecies are installed, else skip test | ||
| deps_list="grep sed sort wc tr" | ||
| if ! check_dependencies "$deps_list"; then | ||
| log_skip "$TESTNAME SKIP - missing dependencies: $deps_list" | ||
| echo "$TESTNAME SKIP" >"$RES_FILE" | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Detect unique devices with bInterfaceClass = 08 (MSD) under /sys/bus/usb/devices | ||
| log_info "=== USB Mass Storage device Detection ===" | ||
| msd_device_list="$( | ||
| for f in /sys/bus/usb/devices/*/bInterfaceClass; do | ||
| [ -r "$f" ] || continue | ||
| if grep -qx '08' "$f"; then | ||
| d=${f%/bInterfaceClass} | ||
| d=${d%:*} | ||
| printf '%s\n' "${d##*/}" | ||
| fi | ||
| done 2>/dev/null | sort -u | ||
| )" | ||
|
|
||
| msd_device_count="$(printf "%s\n" "$msd_device_list" | sed '/^$/d' | wc -l | tr -d '[:space:]')" | ||
| log_info "Number of MSD devices found: $msd_device_count" | ||
|
|
||
| if [ "$msd_device_count" -gt 0 ] 2>/dev/null; then | ||
| log_info "=== Enumerated Mass Storage Devices ===" | ||
| printf '\n%-9s %-9s %-s\n' "DEVICE" "VID:PID" "PRODUCT" | ||
| printf '%s\n' "--------------------------------------------------------" | ||
| printf "%s\n" "$msd_device_list" | sed '/^$/d' | while IFS= read -r dev; do | ||
| sys="/sys/bus/usb/devices/$dev" | ||
| vid=$([ -r "$sys/idVendor" ] && tr -d '[:space:]' < "$sys/idVendor" || echo -) | ||
| pid=$([ -r "$sys/idProduct" ] && tr -d '[:space:]' < "$sys/idProduct" || echo -) | ||
| if [ -r "$sys/product" ]; then | ||
| product=$(tr -d '\000' < "$sys/product") | ||
| else | ||
| product="-" | ||
| fi | ||
| printf '%-9s %-9s %-s\n' "$dev" "$vid:$pid" "$product" | ||
| done | ||
| printf '\n' | ||
| fi | ||
|
|
||
| if [ "$msd_device_count" -gt 0 ]; then | ||
| log_pass "$TESTNAME : Test Passed - USB Mass Storage device(s) detected" | ||
| echo "$TESTNAME PASS" > "$RES_FILE" | ||
| exit 0 | ||
| else | ||
| log_fail "$TESTNAME : Test Failed - No USB 'Mass Storage Device' found" | ||
| echo "$TESTNAME FAIL" > "$RES_FILE" | ||
| exit 0 | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/usb_msd | ||
| - ./run.sh || true | ||
| - $REPO_PATH/Runner/utils/send-to-lava.sh usb_msd.res | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Print a small table of detected MSD devices
Right now you only output a count. In failures, we’ll want quick visibility into what enumerated (VID:PID/product).
This is especially useful when a device enumerates but storage doesn’t fully appear as block devices.