- commit
- f225f0b272aca3eaa9a8e11b201412bd07001f8a
- parent
- e41f0d44a2187327a06d1ab694f4186a48df3ca8
- author
- Dami <dami.etoile@gmail.com>
| M | scripts/ | 52 | ++++++++++++++++++++++++------ |
| M | scripts/ | 37 | ++++++++++++++++++++- |
@@ -2,6 +2,25 @@
22 33 set -euo pipefail44 5+GST_INSPECT_MAX_BYTES=10485766+7+run_bounded_gst_inspect() {8+ local timeout_path="$1"9+ local gst_inspect_path="$2"10+ local output_path="$3"11+ local output_size12+ shift 313+14+ if ! "$timeout_path" --signal=TERM --kill-after=2s 5s \15+ "$gst_inspect_path" "$@" 2>/dev/null \16+ | head -c "$((GST_INSPECT_MAX_BYTES + 1))" >"$output_path"17+ then18+ return 119+ fi20+ output_size="$(wc -c <"$output_path" | tr -d '[:space:]')"21+ [[ "$output_size" =~ ^[0-9]+$ && "$output_size" -le "$GST_INSPECT_MAX_BYTES" ]]22+}23+524 gst_property_block_contains() {625 local property="$1"726 local needle="$2"@@ -59,8 +78,11 @@ select_amd_gstva_h264_encoder() {
5978 local require_character="${4:-true}"6079 local override_node="${5:-}"6180 local override_factory="${6:-}"81+ local timeout_path="${7:?timeout command is required}"82+ local output_root="${8:?bounded inspection output directory is required}"6283 local factory6384 local factories85+ local factory_output6486 local inspection6587 local node_name6688 local sysfs_node@@ -72,14 +94,18 @@ select_amd_gstva_h264_encoder() {
7294 render_node=''7395 va_encoder=''7496 va_candidates=''75- factories="$(76- LC_ALL=C "$gst_inspect_path" 2>/dev/null | awk '77- $2 ~ /^va(renderD[0-9]+)?h264(lp)?enc:$/ {78- sub(/:$/, "", $2)79- print $280- }81- ' | sort -u82- )" || return 197+ [[ -d "$output_root" && ! -L "$output_root" ]] || return 198+ if ! LC_ALL=C run_bounded_gst_inspect \99+ "$timeout_path" "$gst_inspect_path" "$output_root/gst-inspect.registry";100+ then101+ return 1102+ fi103+ factories="$(awk '104+ $2 ~ /^va(renderD[0-9]+)?h264(lp)?enc:$/ {105+ sub(/:$/, "", $2)106+ print $2107+ }108+ ' "$output_root/gst-inspect.registry" | sort -u)" || return 183109 84110 for sysfs_node in "$sysfs_root"/renderD*; do85111 [[ -e "$sysfs_node/device/driver" ]] || continue@@ -96,9 +122,13 @@ select_amd_gstva_h264_encoder() {
96122 97123 while IFS= read -r factory; do98124 [[ -n "$factory" ]] || continue99- if ! inspection="$(LC_ALL=C "$gst_inspect_path" "$factory" 2>/dev/null)"; then125+ factory_output="$output_root/gst-inspect.$factory"126+ if ! LC_ALL=C run_bounded_gst_inspect \127+ "$timeout_path" "$gst_inspect_path" "$factory_output" "$factory";128+ then100129 continue101130 fi131+ inspection="$(<"$factory_output")"102132 gst_property_block_contains device-path "Default: \"$candidate\"" \103133 <<<"$inspection" || continue104134 gstva_factory_supports_uat "$inspection" || continue@@ -381,12 +411,14 @@ pw_link="$(command -v pw-link)"
381411 xprop="$(command -v xprop)"382412 gst_launch="$(command -v gst-launch-1.0)"383413 gst_inspect="$(command -v gst-inspect-1.0)"414+timeout_command="$(command -v timeout)"384415 ffmpeg="$(command -v ffmpeg)"385416 [[ -S "$XDG_RUNTIME_DIR/pipewire-0" ]]386417 selection_status=0387418 select_amd_gstva_h264_encoder \388419 "$gst_inspect" /sys/class/drm /dev/dri true \389- "$render_node_override" "$va_encoder_override" || selection_status=$?420+ "$render_node_override" "$va_encoder_override" \421+ "$timeout_command" "$private" || selection_status=$?390422 if [[ "$selection_status" -ne 0 ]]; then391423 if [[ -n "$render_node_override" ]]; then392424 echo "the requested render-node and VA-encoder pair is not eligible for this UAT" >&2@@ -60,6 +60,10 @@ cat >"$bin/gst-inspect-1.0" <<'EOF'
6060 set -euo pipefail6161 6262 fixture="${SIGIL_TEST_FACTORY_FIXTURE:?}"63+if [[ "${SIGIL_TEST_GST_MODE:-}" == oversize-factory && $# -gt 0 ]]; then64+ awk 'BEGIN { for (i = 0; i < 1048578; i++) printf "x" }'65+ exit 066+fi6367 if [[ $# -eq 0 ]]; then6468 awk -F '\t' '{ printf "va: %s: fixture encoder\n", $1 }' "$fixture"6569 exit 0@@ -87,12 +91,26 @@ for property in aud b-frames key-int-max ref-frames target-usage bitrate qpi qpp
8791 done8892 EOF8993 chmod 0755 "$bin/gst-inspect-1.0"94+cat >"$bin/timeout" <<'EOF'95+#!/usr/bin/env bash96+set -euo pipefail97+98+[[ "${SIGIL_TEST_TIMEOUT:-}" != true ]] || exit 12499+[[ "${1:-}" == --signal=TERM ]]100+shift101+[[ "${1:-}" == --kill-after=2s ]]102+shift103+[[ "${1:-}" == 5s ]]104+shift105+exec "$@"106+EOF107+chmod 0755 "$bin/timeout"90108 export SIGIL_TEST_FACTORY_FIXTURE="$factory_fixture"91109 92110 select_fixture() {93111 select_amd_gstva_h264_encoder \94112 "$bin/gst-inspect-1.0" "$sysfs_root" "$device_root" false \95- "${1:-}" "${2:-}"113+ "${1:-}" "${2:-}" "$bin/timeout" "$fixture"96114 }97115 98116 reset_render_nodes@@ -168,6 +186,20 @@ if select_fixture; then
168186 fail 'a factory missing a required writable property was accepted'169187 fi170188 189+SIGIL_TEST_GST_MODE=oversize-factory190+export SIGIL_TEST_GST_MODE191+if select_fixture; then192+ fail 'oversized factory inspection output was accepted'193+fi194+unset SIGIL_TEST_GST_MODE195+196+SIGIL_TEST_TIMEOUT=true197+export SIGIL_TEST_TIMEOUT198+if select_fixture; then199+ fail 'a timed-out GStreamer registry inspection was accepted'200+fi201+unset SIGIL_TEST_TIMEOUT202+171203 printf '%s\t%s\t%s\t%s\n' \172204 x264enc "$device_root/renderD130" cqp,cbr complete \173205 vah264enc-malformed "$device_root/renderD130" cqp,cbr complete \@@ -191,7 +223,8 @@ fi
191223 rm -f -- "$device_root/renderD130"192224 install -m 0600 /dev/null "$device_root/renderD130"193225 if select_amd_gstva_h264_encoder \194- "$bin/gst-inspect-1.0" "$sysfs_root" "$device_root" true '' ''226+ "$bin/gst-inspect-1.0" "$sysfs_root" "$device_root" true '' '' \227+ "$bin/timeout" "$fixture"195228 then196229 fail 'a regular file was accepted as a production DRM character device'197230 fi