Skip to content

Add test script to validate USB UAC#266

Open
achauras-qcom wants to merge 1 commit into
qualcomm-linux:mainfrom
achauras-qcom:feature/usb-uac
Open

Add test script to validate USB UAC#266
achauras-qcom wants to merge 1 commit into
qualcomm-linux:mainfrom
achauras-qcom:feature/usb-uac

Conversation

@achauras-qcom

Copy link
Copy Markdown
Contributor

The shell script verifies the enumeration of USB Audio Devices connected to DUT.

@achauras-qcom achauras-qcom force-pushed the feature/usb-uac branch 2 times, most recently from 6877bdd to 9f1040f Compare February 17, 2026 11:41

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Commit ordering / path inconsistency (important for clean history)

Create files directly in Runner/suites/Kernel/Baseport/USB/usb_uac/ from patch 1 onward, and drop patch 4/4 entirely.
Alternative:
Move patch 4/4 earlier (as 1/4), then add script/README/YAML into the final location.

audio_device_count=$(
for f in /sys/bus/usb/devices/*/bInterfaceClass; do
[ -r "$f" ] || continue
if grep -qx '01' "$f"; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Validate more than bInterfaceClass == 01

# 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=$(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add ALSA/device-node checks (/dev/snd, /proc/asound/cards, aplay -l, arecord -l where available)
Print detected UAC device details (VID:PID, product, device path)

log_info "=== Test Initialization ==="

# Check if grep is installed, else skip test
deps_list="grep sed sort wc"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add missing dependency tr

done 2>/dev/null | sed 's/:.*$//' | sort -u | wc -l | tr -d '[:space:]'
)

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Distinguish playback-only vs capture-only devices and also log bound driver info from sysfs


- 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Improve README to clarify exact validation scope

echo "$TESTNAME PASS" > "$RES_FILE"
exit 0
else
log_fail "$TESTNAME : Test Failed - No 'USB Audio Device' found"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Consider whether “no UAC device attached” should be FAIL or SKIP

Comment thread Runner/suites/Kernel/Baseport/USB/usb_uac/run.sh Fixed
Comment thread Runner/suites/Kernel/Baseport/USB/usb_uac/run.sh Fixed
@achauras-qcom

Copy link
Copy Markdown
Contributor Author

Output for UAC device connected:
root@rb3gen2-core-kit:/var# ./run.sh
[INFO] -----------------------------------------------------------------------------------------
[INFO] -------------------Starting usb_uac Testcase----------------------------
[INFO] === Test Initialization ===
[INFO] === USB Audio device Detection ===
[INFO] Number of USB audio devices found: 1
[INFO] === Enumerated USB Audio Devices ===

DEVICE VID:PID PRODUCT

1-1 04e8:a05e Samsung USB C Earphones

[INFO] ALSA cards (/proc/asound/cards):
[INFO] 0 [QCS6490RB3Gen2 ]: qcs6490 - QCS6490-RB3Gen2
[INFO] QCS6490-RB3Gen2
[INFO] 1 [Earphones ]: USB-Audio - Samsung USB C Earphones
[INFO] Samsung Samsung USB C Earphones at usb-xhci-hcd.4.auto-1, full speed
[INFO] Number of ALSA USB sound cards: 1
[INFO] ALSA card 1 device nodes present: playback capture
[PASS] usb_uac : Test Passed - USB Audio device(s) detected and ALSA device nodes present

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

squash it to one commit.


# Default result file (works even before functestlib is available)
# shellcheck disable=SC2034
RES_FILE="$SCRIPT_DIR/${TESTNAME}.res"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

current default is ./${TESTNAME}.res, so early SKIP paths before cd "$test_path" can write the result file into an unexpected working directory.

@achauras-qcom achauras-qcom Apr 30, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Skip paths before cd "$test_path" could reliably write result file in "$SCRIPT_DIR", please correct me if my understanding is wrong. Does default result file need to be changed to "./${TESTNAME}.res" instead of "$SCRIPT_DIR/${TESTNAME}.res"?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Skip paths before cd "$test_path" could reliably write result file in "$SCRIPT_DIR", please correct me if my understanding is wrong. Does default result file need to be changed to "./${TESTNAME}.res" instead of "$SCRIPT_DIR/${TESTNAME}.res"?

Yes, your understanding is correct.

Using:

RES_FILE="$SCRIPT_DIR/${TESTNAME}.res"

is better for the early SKIP paths before cd "$test_path" because the script may be launched from any working directory. If we used:

RES_FILE="./${TESTNAME}.res"

then early failures such as missing init_env could write the result into the caller's current directory instead of the testcase directory.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Using RES_FILE="$SCRIPT_DIR/${TESTNAME}.res" for early skip paths in the script

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

when a UAC interface enumerates but ALSA integration is incomplete, we still lose useful debug context in CI logs. Add a DRIVER column and populate it from the relevant interface driver symlink in sysfs.

DEVICE    VID:PID   DRIVER      PRODUCT
1-1       04e8:a05e snd-usb-audio Samsung USB C Earphones

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added driver info as well for each UAC device.

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)"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

tighten PASS to require all detected UAC-backed ALSA cards to have playback/capture nodes, or
at least log an explicit ratio such as usable ALSA USB cards: X/Y so partial failures are visible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added missing nodes info for each UAC device as part of debug logs and also logging explicit ratio of usable ALSA USB cards.

The shell script verifies the enumeration of USB Audio Class devices.

Signed-off-by: Aanchal Chaurasia <achauras@qti.qualcomm.com>
@github-actions

Copy link
Copy Markdown

@ualcomm/qualcomm-linux-testing.triage This pull request has been marked as stale due to 30 days of inactivity and will automatically close after an additional 5 days.

@github-actions github-actions Bot added the Stale label Jun 29, 2026
@achauras-qcom

Copy link
Copy Markdown
Contributor Author

Srikanth Muppandam (@smuppand) May you please review the latest changes?

@github-actions github-actions Bot removed the Stale label Jul 2, 2026
# Check if dependencies are installed, else skip test
deps_list="grep sed sort wc tr readlink"
if ! check_dependencies "$deps_list"; then
log_skip "$TESTNAME SKIP - missing dependencies: $deps_list"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

deps_list does not include every external command used by the script. For example, head is used later when extracting vidpid, driver_info, and product_info, but it is not part of the dependency check.

deps_list="grep sed sort wc tr readlink"
if ! check_dependencies "$deps_list"; then
log_skip "$TESTNAME SKIP - missing dependencies: $deps_list"
echo "$TESTNAME SKIP" >"$RES_FILE"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

check_dependencies from functestlib.sh exits by default when dependencies are missing, so the if ! check_dependencies "$deps_list"; then ... block will normally not run.

Recommended fix: either call check_dependencies "$deps_list" directly, or set CHECK_DEPS_NO_EXIT=1 before the call if this script wants to handle the failure itself.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

USB ALSA card discovery depends on parsing /proc/asound/cards with a regex that only accepts card descriptions beginning with USB.

Recommended fix: discover candidate cards from /sys/class/sound/card*/device first, resolve each card’s parent USB interface/device, and match that against the detected UAC device list; use /proc/asound/cards only for logging.

card_map=""
while IFS= read -r c; do
[ -n "$c" ] || continue
link="$(readlink "/sys/class/sound/card${c}/device" 2>/dev/null || true)"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The card-to-USB mapping uses readlink without -f, then extracts only the basename. if the symlink target shape differs across kernels or ends in an intermediate sound object rather than the USB interface name, parent="${base%%:*}" can produce the wrong USB device id and mark a valid card as unmapped.

Recommended fix: use readlink -f "/sys/class/sound/card${c}/device" and walk upward until a directory with idVendor/idProduct or a USB interface pattern is found, then map that stable parent.

# Look up device details for debug messages
vidpid="$(printf "%b" "$dev_info_db" | sed -n "s/^${dev}|\\([^|]*\\)|.*/\\1/p" | head -n1)"
driver_info="$(printf "%b" "$dev_info_db" | sed -n "s/^${dev}|[^|]*|\\([^|]*\\)|.*/\\1/p" | head -n1)"
product_info="$(printf "%b" "$dev_info_db" | sed -n "s/^${dev}|[^|]*|[^|]*|\\(.*\\)$/\\1/p" | head -n1)"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The script interpolates raw USB device ids into sed regexes when looking up dev_info_db. USB device ids can contain dots, which are regex metacharacters. A device such as 1-2.3 can match unintended rows if similarly named devices exist, producing wrong VID/PID/product logs and potentially confusing failure triage.

Recommended fix: avoid regex interpolation for structured data; use awk -F'|' -v dev="$dev" '$1 == dev {print $2; exit}' or another literal-field comparison.

# Cards mapped to this USB device
cards_for_dev="$(printf "%b" "$card_map" | sed -n "s/^${dev}|\\([0-9][0-9]*\\)$/\\1/p" | tr '\n' ' ' | sed 's/[[:space:]]*$//')"

if [ -z "$cards_for_dev" ]; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The same raw-device-id regex issue is used to derive cards_for_dev from card_map. This is more than a logging issue; a wrong match here can map the wrong ALSA card to a UAC device or fail to map a valid one.

Recommended fix: replace the sed lookup with literal field matching, for example awk -F'|' -v dev="$dev" '$1 == dev {print $2}', then join results.

# Check for PCM devices (playback/capture)
pcm_found=0

for pcm in "$card_path"/pcmC"${c}"D*p "$card_path"/pcmC"${c}"D*c; do

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PCM node validation manually scans "$card_path"/pcmC"${c}"D*p and *c. This assumes sysfs PCM naming/layout and duplicates ALSA PCM enumeration logic that could be checked more directly through /proc/asound/pcm or aplay -l/arecord -l.

Recommended fix: for the card being validated, confirm playback/capture PCMs from /proc/asound/pcm or ALSA tooling, then check matching /dev/snd/pcmC* nodes only as the final device-node check.

-------------------------------------------------------------------------------
<dev> <vid:pid> <snd-usb-audio> <product>
```
The test PASS requires all detected UAC devices to have associated ALSA nodes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The README says PASS requires all detected UAC devices to have associated ALSA nodes, but it does not describe the expected behavior when no USB audio peripheral is connected. The script currently reports FAIL in that case. lab users may schedule this test on boards without an attached UAC peripheral and interpret the result incorrectly.

Recommended fix: document “no UAC device connected” as an expected FAIL, or add a YAML/script parameter such as USB_UAC_REQUIRED=1 so labs can choose FAIL vs SKIP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants