Files
vx/tests/test_lspci.sh
SFG545 0db2ec12c5 Add PCI device enumeration and configuration utilities
This commit introduces a new PCI library and associated tools for inspecting and modifying PCI configuration space via Linux sysfs. The following changes were made:

- Implemented `pci.c` and `pci.h` for PCI device management, including enumeration, attribute reading, and configuration space access.
- Added `setpci` command-line utility for reading and writing PCI configuration registers, with support for filtering devices by vendor, device, and slot.
- Created manual pages for `setpci` to document its usage and options.
- Developed test scripts for both `lspci` and `setpci` to ensure functionality and correctness of the new features.

These additions enhance the ability to interact with PCI devices, providing a robust framework for device management and configuration.
2026-03-22 19:04:16 -05:00

49 lines
1.4 KiB
Bash

#!/bin/sh
_test_name="lspci"
. "$(dirname "$0")/harness.sh"
setup_tmpdir
LSPCI="$VX lspci"
echo "Running lspci tests..."
dev_path="/sys/bus/pci/devices/$(ls /sys/bus/pci/devices | head -n 1)"
slot="$(basename "$dev_path")"
short_slot="$(printf '%s' "$slot" | sed 's/^0000://')"
vendor="$(sed 's/^0x//' "$dev_path/vendor")"
device="$(sed 's/^0x//' "$dev_path/device")"
class="$(sed 's/^0x//' "$dev_path/class" | cut -c1-4)"
out="$($LSPCI | sed -n '1p')"
if [ -n "$out" ]; then
pass "basic: lists at least one device"
else
fail "basic: lists at least one device" "got empty output"
fi
out="$($LSPCI -D -s "$slot")"
case "$out" in
"$slot "*) pass "filter: -D preserves domain-qualified slot" ;;
*) fail "filter: -D preserves domain-qualified slot" "got: $out" ;;
esac
out="$($LSPCI -n -s "$short_slot")"
expected="$short_slot $class: $vendor:$device"
case "$out" in
"$expected"*) pass "numeric: -n shows class and ids" ;;
*) fail "numeric: -n shows class and ids" "expected prefix: $expected, got: $out" ;;
esac
out="$($LSPCI -d "$vendor:$device" | sed -n '1p')"
case "$out" in
*"$vendor"*|*"$device"*) pass "filter: -d finds matching device" ;;
"") fail "filter: -d finds matching device" "got empty output" ;;
*) pass "filter: -d finds matching device" ;;
esac
hex_out="$($LSPCI -x -s "$short_slot")"
printf '%s\n' "$hex_out" > hex.out
check_grep " 00:" hex.out "hex: emits config dump"
summary