11#! /bin/sh
22# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
3- # SPDX-License-Identifier: BSD-3-Clause per legal request.
3+ # SPDX-License-Identifier: BSD-3-Clause
44# Waylandsink Playback validation using GStreamer
55# Tests video playback using waylandsink with videotestsrc
66# Validates Weston/Wayland server and display connectivity
@@ -54,6 +54,23 @@ result="FAIL"
5454reason=" unknown"
5555
5656# -------------------- Defaults --------------------
57+ # Validate environment variables if set
58+ if [ -n " $VIDEO_DURATION " ] && ! echo " $VIDEO_DURATION " | grep -q " ^[0-9]\+$" ; then
59+ log_warn " VIDEO_DURATION must be numeric (got '$VIDEO_DURATION ')"
60+ echo " $TESTNAME SKIP" > " $RES_FILE "
61+ exit 0
62+ fi
63+ if [ -n " $RUNTIMESEC " ] && ! echo " $RUNTIMESEC " | grep -q " ^[0-9]\+$" ; then
64+ log_warn " RUNTIMESEC must be numeric (got '$RUNTIMESEC ')"
65+ echo " $TESTNAME SKIP" > " $RES_FILE "
66+ exit 0
67+ fi
68+ if [ -n " $VIDEO_FRAMERATE " ] && ! echo " $VIDEO_FRAMERATE " | grep -q " ^[0-9]\+$" ; then
69+ log_warn " VIDEO_FRAMERATE must be numeric (got '$VIDEO_FRAMERATE ')"
70+ echo " $TESTNAME SKIP" > " $RES_FILE "
71+ exit 0
72+ fi
73+
5774duration=" ${VIDEO_DURATION:- ${RUNTIMESEC:- 30} } "
5875pattern=" ${VIDEO_PATTERN:- smpte} "
5976width=" ${VIDEO_WIDTH:- 1920} "
@@ -75,10 +92,24 @@ while [ $# -gt 0 ]; do
7592 echo " $TESTNAME SKIP" > " $RES_FILE "
7693 exit 0
7794 fi
78- # Parse WIDTHxHEIGHT format (e.g., 1920x1080)
95+ # Parse and validate WIDTHxHEIGHT format (e.g., 1920x1080)
7996 if [ -n " $2 " ]; then
97+ # Validate format contains 'x'
98+ if ! echo " $2 " | grep -q " x" ; then
99+ log_warn " Invalid resolution format '$2 ' - must be WIDTHxHEIGHT"
100+ echo " $TESTNAME SKIP" > " $RES_FILE "
101+ exit 0
102+ fi
103+
80104 width=" ${2%% x* } "
81105 height=" ${2#* x} "
106+
107+ # Validate both width and height are numeric
108+ if ! echo " $width " | grep -q " ^[0-9]\+$" || ! echo " $height " | grep -q " ^[0-9]\+$" ; then
109+ log_warn " Width and height must be numeric values (got width='$width ', height='$height ')"
110+ echo " $TESTNAME SKIP" > " $RES_FILE "
111+ exit 0
112+ fi
82113 fi
83114 shift 2
84115 ;;
@@ -89,8 +120,14 @@ while [ $# -gt 0 ]; do
89120 echo " $TESTNAME SKIP" > " $RES_FILE "
90121 exit 0
91122 fi
92- # If $2 is empty, keep default and shift 2
93- [ -n " $2 " ] && duration=" $2 "
123+ if [ -n " $2 " ]; then
124+ if ! echo " $2 " | grep -q " ^[0-9]\+$" ; then
125+ log_warn " Duration must be a numeric value (got '$2 ')"
126+ echo " $TESTNAME SKIP" > " $RES_FILE "
127+ exit 0
128+ fi
129+ duration=" $2 "
130+ fi
94131 shift 2
95132 ;;
96133
@@ -111,8 +148,15 @@ while [ $# -gt 0 ]; do
111148 echo " $TESTNAME SKIP" > " $RES_FILE "
112149 exit 0
113150 fi
114- # If $2 is empty, keep default and shift 2
115- [ -n " $2 " ] && width=" $2 "
151+ # Validate width is numeric
152+ if [ -n " $2 " ]; then
153+ if ! echo " $2 " | grep -q " ^[0-9]\+$" ; then
154+ log_warn " Width must be a numeric value (got '$2 ')"
155+ echo " $TESTNAME SKIP" > " $RES_FILE "
156+ exit 0
157+ fi
158+ width=" $2 "
159+ fi
116160 shift 2
117161 ;;
118162
@@ -122,8 +166,15 @@ while [ $# -gt 0 ]; do
122166 echo " $TESTNAME SKIP" > " $RES_FILE "
123167 exit 0
124168 fi
125- # If $2 is empty, keep default and shift 2
126- [ -n " $2 " ] && height=" $2 "
169+ # Validate height is numeric
170+ if [ -n " $2 " ]; then
171+ if ! echo " $2 " | grep -q " ^[0-9]\+$" ; then
172+ log_warn " Height must be a numeric value (got '$2 ')"
173+ echo " $TESTNAME SKIP" > " $RES_FILE "
174+ exit 0
175+ fi
176+ height=" $2 "
177+ fi
127178 shift 2
128179 ;;
129180
@@ -133,8 +184,14 @@ while [ $# -gt 0 ]; do
133184 echo " $TESTNAME SKIP" > " $RES_FILE "
134185 exit 0
135186 fi
136- # If $2 is empty, keep default and shift 2
137- [ -n " $2 " ] && framerate=" $2 "
187+ if [ -n " $2 " ]; then
188+ if ! echo " $2 " | grep -q " ^[0-9]\+$" ; then
189+ log_warn " Framerate must be a numeric value (got '$2 ')"
190+ echo " $TESTNAME SKIP" > " $RES_FILE "
191+ exit 0
192+ fi
193+ framerate=" $2 "
194+ fi
138195 shift 2
139196 ;;
140197
210267done
211268
212269# -------------------- Pre-checks --------------------
213- check_dependencies " gst-launch-1.0 gst-inspect-1.0" > /dev/null 2>&1 || {
214- log_warn " Missing gstreamer runtime (gst-launch-1.0/gst-inspect-1.0)"
215- echo " $TESTNAME SKIP" > " $RES_FILE "
216- exit 0
217- }
218-
219- check_dependencies " grep head sed" > /dev/null 2>&1 || {
220- log_warn " Missing required tools (grep, head, sed)"
270+ check_dependencies " gst-launch-1.0 gst-inspect-1.0 grep head sed" > /dev/null 2>&1 || {
271+ log_skip " Missing required tools (gst-launch-1.0, gst-inspect-1.0, grep, head, sed)"
221272 echo " $TESTNAME SKIP" > " $RES_FILE "
222273 exit 0
223274}
@@ -354,23 +405,59 @@ elapsed=$((end_ts - start_ts))
354405log_info " Playback finished: rc=${gstRc} elapsed=${elapsed} s"
355406
356407# -------------------- Validation --------------------
357- # Check for GStreamer errors in log
408+ # Duration threshold (allow 2s slack)
409+ min_duration=$(( duration - 2 ))
410+
411+ # Check for GStreamer errors in both run log and GST debug log
412+ run_log_ok=1
413+ gst_log_ok=1
414+
415+ # Validate run log
358416if ! gstreamer_validate_log " $RUN_LOG " " $TESTNAME " ; then
417+ run_log_ok=0
418+ fi
419+
420+ # Validate last 1000 lines of GST debug log if it exists and has content
421+ if [ -s " $GST_LOG " ]; then
422+ # Create temp file with last 1000 lines
423+ tail -n 1000 " $GST_LOG " > " ${GST_LOG} .tail"
424+ if ! gstreamer_validate_log " ${GST_LOG} .tail" " $TESTNAME " ; then
425+ gst_log_ok=0
426+ fi
427+ rm -f " ${GST_LOG} .tail"
428+ fi
429+
430+ if [ " $run_log_ok " -eq 0 ] || [ " $gst_log_ok " -eq 0 ]; then
359431 result=" FAIL"
360- reason=" GStreamer errors detected in log"
432+ if [ " $run_log_ok " -eq 0 ] && [ " $gst_log_ok " -eq 0 ]; then
433+ reason=" GStreamer errors detected in both run log and GST debug log"
434+ elif [ " $run_log_ok " -eq 0 ]; then
435+ reason=" GStreamer errors detected in run log"
436+ else
437+ reason=" GStreamer errors detected in GST debug log"
438+ fi
361439else
362- # Accept 0 (normal) and 143 (timeout/SIGTERM) as success
363- if [ " $gstRc " -eq 0 ] || [ " $gstRc " -eq 143 ]; then
364- if [ " $elapsed " -ge " $(( duration - 2 )) " ]; then
365- result=" PASS"
366- reason=" Playback completed successfully (rc=$gstRc , elapsed=${elapsed} s)"
367- else
368- result=" FAIL"
369- reason=" Playback exited too quickly (elapsed=${elapsed} s, expected ~${duration} s)"
370- fi
440+ # First check if it ran long enough
441+ if [ " $elapsed " -ge " $min_duration " ]; then
442+ # If it ran long enough, check exit code
443+ case " $gstRc " in
444+ 0) # Normal exit
445+ result=" PASS"
446+ reason=" Playback completed successfully (elapsed=${elapsed} /${duration} s)"
447+ ;;
448+ 124|137|143) # Timeout/kill signals - expected for long duration tests
449+ result=" PASS"
450+ reason=" Playback completed via ${gstRc} (SIGTERM=143, SIGKILL=137, GNU timeout=124) after ${elapsed} /${duration} s"
451+ ;;
452+ * ) # Unexpected return code
453+ result=" FAIL"
454+ reason=" Playback failed with unexpected exit code (rc=$gstRc , elapsed=${elapsed} /${duration} s)"
455+ ;;
456+ esac
371457 else
458+ # Didn't run long enough - always fail regardless of return code
372459 result=" FAIL"
373- reason=" Playback failed (rc= $gstRc )"
460+ reason=" Playback exited too quickly (elapsed= ${elapsed} s, minimum required= ${min_duration} s )"
374461 fi
375462fi
376463
0 commit comments