-
Notifications
You must be signed in to change notification settings - Fork 29
Add test script to validate USB HID #259
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| SPDX-License-Identifier: BSD-3-Clause-Clear | ||
|
|
||
| # USB HID Validation | ||
|
|
||
| ## Overview | ||
|
|
||
| This shell script executes on the DUT (Device-Under-Test) and verifies enumeration of connected USB Human Interface Devices (HID). | ||
|
|
||
| --- | ||
|
|
||
| ## Setup | ||
|
|
||
| - Connect USB HID peripheral(s) to USB port(s) on DUT. | ||
| - Only applicable for USB ports that support Host Mode functionality. | ||
| - USB HID peripherals examples: Mouse, Keyboard, USB headset, 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_hid | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| #!/bin/sh | ||
|
|
||
| # Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| # SPDX-License-Identifier: BSD-3-Clause-Clear | ||
|
|
||
| # Validate USB HID device detection | ||
| # Requires at least one USB HID peripheral (keyboard/mouse, etc.) connected to a USB Host port. | ||
|
|
||
| # Robustly find and source init_env | ||
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. identation.. please have one leading space |
||
| # shellcheck disable=SC1090 | ||
| . "$INIT_ENV" | ||
achauras-qcom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| __INIT_ENV_LOADED=1 | ||
| fi | ||
| # Always source functestlib.sh, using $TOOLS exported by init_env | ||
| # shellcheck disable=SC1090,SC1091 | ||
| . "$TOOLS/functestlib.sh" | ||
|
|
||
| TESTNAME="usb_hid" | ||
| test_path=$(find_test_case_by_name "$TESTNAME") | ||
| cd "$test_path" || exit 1 | ||
| # shellcheck disable=SC2034 | ||
| res_file="./$TESTNAME.res" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency with your existing scripts, prefer 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" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But the script also uses sed sort wc. Check: grep sed sort wc |
||
| check_dependencies "$deps_list" | ||
|
|
||
| # Count uniques devices with bInterfaceClass = 03 (HID) under /sys/bus/usb/devices | ||
| hid_device_count=0 | ||
| log_info "=== USB HID device Detection ===" | ||
| hid_device_count=$( | ||
| for f in /sys/bus/usb/devices/*/bInterfaceClass; do | ||
| [ -r "$f" ] || continue | ||
| if grep -qx '03' "$f"; then | ||
| d=${f%/bInterfaceClass} | ||
| echo "${d##*/}" | ||
| fi | ||
| done | sed 's/:.*$//' | sort -u | wc -l) | ||
|
|
||
| echo "$hid_device_count" | ||
|
|
||
| log_info "Number of HID devices found: $hid_device_count" | ||
|
|
||
| if [ "$hid_device_count" -gt 0 ]; then | ||
| log_pass "$TESTNAME : Test Passed - USB HID device(s) detected" | ||
| echo "$TESTNAME PASS" > "$res_file" | ||
| exit 0 | ||
| else | ||
| log_fail "$TESTNAME : Test Failed - No USB 'Human Interface Device' found" | ||
| echo "$TESTNAME FAIL" > "$res_file" | ||
| exit 1 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can prevent the yaml step from running. always use |
||
| fi | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| metadata: | ||
| name: usb_hid | ||
| format: "Lava-Test Test Definition 1.0" | ||
| description: "This shell script executes on the DUT (Device-Under-Test) and verifies enumeration of connected USB Human Interface Devices (HID)." | ||
| os: | ||
| - linux | ||
| scope: | ||
| - functional | ||
|
|
||
| run: | ||
| steps: | ||
| - REPO_PATH=$PWD | ||
| - cd Runner/suites/Kernel/Baseport/usb_hid | ||
| - ./run.sh | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
| - $REPO_PATH/Runner/utils/send-to-lava.sh usb_hid.res | ||
|
|
||
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.
The quick example uses placeholders like and — we usually show:
cd Runner && ./run-test.sh usb_hid
OR direct ./run.sh from the test folder (you already do in YAML).