#!/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