From 4682f38d057d345e34dee1a38226da7e5487634e Mon Sep 17 00:00:00 2001 From: Aanchal Chaurasia Date: Fri, 27 Feb 2026 14:17:44 +0530 Subject: [PATCH 1/3] Add test script to validate USB UAC The shell script verifies the enumeration of USB Audio Class devices. Signed-off-by: Aanchal Chaurasia --- .../suites/Kernel/Baseport/USB/usb_uac/run.sh | 185 ++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100755 Runner/suites/Kernel/Baseport/USB/usb_uac/run.sh diff --git a/Runner/suites/Kernel/Baseport/USB/usb_uac/run.sh b/Runner/suites/Kernel/Baseport/USB/usb_uac/run.sh new file mode 100755 index 00000000..bb50978c --- /dev/null +++ b/Runner/suites/Kernel/Baseport/USB/usb_uac/run.sh @@ -0,0 +1,185 @@ +#!/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 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 = 01 (UAC) under /sys/bus/usb/devices +log_info "=== USB Audio device Detection ===" +audio_device_list="$( + for f in /sys/bus/usb/devices/*/bInterfaceClass; do + [ -r "$f" ] || continue + if grep -qx '01' "$f"; then + d=${f%/bInterfaceClass} + d=${d%:*} + printf '%s\n' "${d##*/}" + fi + done 2>/dev/null | sort -u +)" + +audio_device_count="$(printf "%s\n" "$audio_device_list" | sed '/^$/d' | wc -l | tr -d '[:space:]')" +log_info "Number of USB audio devices found: $audio_device_count" + +if [ "$audio_device_count" -gt 0 ] 2>/dev/null; then + log_info "=== Enumerated USB Audio Devices ===" + printf '\n%-9s %-9s %-s\n' "DEVICE" "VID:PID" "PRODUCT" + printf '%s\n' "--------------------------------------------------------" + for dev in $(printf "%s\n" "$audio_device_list" | sed '/^$/d'); 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 [ "$audio_device_count" -le 0 ] 2>/dev/null; then + log_fail "$TESTNAME : Test Failed - No 'USB Audio Device' found" + echo "$TESTNAME FAIL" > "$RES_FILE" + exit 0 +fi + +# Verify ALSA is available +if [ ! -r /proc/asound/cards ]; then + log_fail "$TESTNAME : Test Failed - ALSA not available (/proc/asound/cards missing)" + echo "$TESTNAME FAIL" > "$RES_FILE" + exit 0 +fi + +if [ -r /proc/asound/cards ]; then + log_info "ALSA cards (/proc/asound/cards):" + while IFS= read -r line; do + log_info " $line" + done < /proc/asound/cards +fi + +# Identify ALSA cards that correspond to USB +usb_alsa_card_nums="$(sed -n 's/^[[:space:]]*\([0-9][0-9]*\)[[:space:]]\{1,\}\[[^]]*\]:[[:space:]]\{1,\}USB.*/\1/p' /proc/asound/cards | sort -u)" +usb_alsa_card_count="$(printf "%s\n" "$usb_alsa_card_nums" | sed '/^$/d' | wc -l | tr -d '[:space:]')" +log_info "Number of ALSA USB sound cards: $usb_alsa_card_count" + +if [ "$usb_alsa_card_count" -le 0 ] 2>/dev/null; then + log_fail "$TESTNAME : Test Failed - No ALSA 'USB' cards found for detected USB Audio device(s)" + echo "$TESTNAME FAIL" > "$RES_FILE" + exit 0 +fi + +# For each USB ALSA card, ensure playback or capture device nodes exist +missing_nodes=0 +while IFS= read -r c; do + card_path="/sys/class/sound/card$c" + ctrl_dev="/dev/snd/controlC$c" + has_pcm_p=0 + has_pcm_c=0 + + # Detect at least one playback/capture PCM node for the card + for n in /dev/snd/pcmC"${c}"D*p; do + [ -e "$n" ] && has_pcm_p=1 && break + done + for n in /dev/snd/pcmC"${c}"D*c; do + [ -e "$n" ] && has_pcm_c=1 && break + done + + if [ ! -e "$card_path" ]; then + log_fail "Missing sysfs sound card path: $card_path" + missing_nodes=1 + fi + if [ ! -e "$ctrl_dev" ]; then + log_fail "Missing ALSA control device: $ctrl_dev" + missing_nodes=1 + fi + if [ "$has_pcm_p" -ne 1 ] && [ "$has_pcm_c" -ne 1 ]; then + log_fail "Missing ALSA PCM device(s) for card $c (no playback or capture node found)" + missing_nodes=1 + else + msg="ALSA card $c device nodes present:" + [ "$has_pcm_p" -eq 1 ] && msg="$msg playback" + [ "$has_pcm_c" -eq 1 ] && msg="$msg capture" + log_info "$msg" + fi +done </dev/null; then + log_fail "$TESTNAME : Test Failed - One or more ALSA device nodes are missing for USB sound card(s)" + echo "$TESTNAME FAIL" > "$RES_FILE" + exit 0 +fi + +log_pass "$TESTNAME : Test Passed - USB Audio device(s) detected and ALSA device nodes present" +echo "$TESTNAME PASS" > "$RES_FILE" +exit 0 From 9ba012cf9c60baa0b34f1f1e5fed776a6750ee46 Mon Sep 17 00:00:00 2001 From: Aanchal Chaurasia Date: Fri, 27 Feb 2026 14:19:13 +0530 Subject: [PATCH 2/3] Add documentation for Runner/../usb_uac/run.sh Added setup information and basic requirements. This informs the tester of the hardware setup requirement before starting test. Signed-off-by: Aanchal Chaurasia --- .../Kernel/Baseport/USB/usb_uac/README.md | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Runner/suites/Kernel/Baseport/USB/usb_uac/README.md diff --git a/Runner/suites/Kernel/Baseport/USB/usb_uac/README.md b/Runner/suites/Kernel/Baseport/USB/usb_uac/README.md new file mode 100644 index 00000000..72f0f845 --- /dev/null +++ b/Runner/suites/Kernel/Baseport/USB/usb_uac/README.md @@ -0,0 +1,41 @@ +``` +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 validates USB Audio Class (UAC) devices. +The test validation scope includes: +- Successful enumeration of UAC devices and display following details for each device: + - DEVICE (USB device address), VID:PID, and PRODUCT string. +- Validation of ALSA integration: + - Confirm /proc/asound/cards exists. + - Identify ALSA cards corresponding to the UAC device. + - At least one PCM playback or capture node exists for each such card. + +--- + +## 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 +``` From 2431fc7f79e3d6440918c04c3dfd5554f6133727 Mon Sep 17 00:00:00 2001 From: Aanchal Chaurasia Date: Fri, 27 Feb 2026 14:20:07 +0530 Subject: [PATCH 3/3] Add test definition for usb_uac Individual test definition is meant to be used for debugging the test script running in LAVA. Signed-off-by: Aanchal Chaurasia --- .../Kernel/Baseport/USB/usb_uac/usb_uac.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Runner/suites/Kernel/Baseport/USB/usb_uac/usb_uac.yaml diff --git a/Runner/suites/Kernel/Baseport/USB/usb_uac/usb_uac.yaml b/Runner/suites/Kernel/Baseport/USB/usb_uac/usb_uac.yaml new file mode 100644 index 00000000..b324c6be --- /dev/null +++ b/Runner/suites/Kernel/Baseport/USB/usb_uac/usb_uac.yaml @@ -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 +