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
34 changes: 34 additions & 0 deletions Runner/suites/Kernel/Baseport/USB/usb_uac/README.md
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 Audio Class Validation

## Overview

This shell script executes on the DUT (Device-Under-Test) and verifies enumeration of connected USB Audio Class (UAC) Devices.

---

## Setup

- Connect USB Audio peripheral(s) to USB port(s) on DUT.
- Only applicable for USB ports that support Host Mode functionality.
- USB Audio peripherals examples: USB headset, microphone, sound card, 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_uac
```
98 changes: 98 additions & 0 deletions Runner/suites/Kernel/Baseport/USB/usb_uac/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/bin/sh

# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
# SPDX-License-Identifier: BSD-3-Clause
# Validate USB Audio Class (UAC) device detection
# Requires at least one USB Audio peripheral (e.g., USB headset, microphone, sound card) connected to a USB Host port.

TESTNAME="usb_uac"

# 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 grep is installed, else skip test
deps_list="grep sed sort wc"
if ! check_dependencies "$deps_list"; then
log_skip "$TESTNAME SKIP - missing dependencies: $deps_list"
echo "$TESTNAME SKIP" >"$RES_FILE"
exit 0
fi

# Count uniques devices with bInterfaceClass = 01 (UAC) under /sys/bus/usb/devices
audio_device_count=0
log_info "=== USB Audio device Detection ==="
audio_device_count=$(
for f in /sys/bus/usb/devices/*/bInterfaceClass; do
[ -r "$f" ] || continue
if grep -qx '01' "$f"; then
d=${f%/bInterfaceClass}
echo "${d##*/}"
fi
done 2>/dev/null | sed 's/:.*$//' | sort -u | wc -l | tr -d '[:space:]'
)

log_info "Number of USB audio devices found: $audio_device_count"

if [ "$audio_device_count" -gt 0 ]; then
log_pass "$TESTNAME : Test Passed - USB Audio device(s) detected"
echo "$TESTNAME PASS" > "$RES_FILE"
exit 0
else
log_fail "$TESTNAME : Test Failed - No 'USB Audio Device' found"
echo "$TESTNAME FAIL" > "$RES_FILE"
exit 0
fi
16 changes: 16 additions & 0 deletions Runner/suites/Kernel/Baseport/USB/usb_uac/usb_uac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
metadata:
name: usb_uac
format: "Lava-Test Test Definition 1.0"
description: "This shell script executes on the DUT (Device-Under-Test) and verifies enumeration of connected USB Audio Class (UAC) Devices."
os:
- linux
scope:
- functional

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

Loading