@@ -11,6 +11,18 @@ SCRIPT_DIR="$(
1111 pwd
1212) "
1313
14+ TESTNAME=" Waylandsink_Playback"
15+ RES_FILE=" ${SCRIPT_DIR} /${TESTNAME} .res"
16+ LOG_DIR=" ${SCRIPT_DIR} /logs"
17+ OUTDIR=" $LOG_DIR /$TESTNAME "
18+ GST_LOG=" $OUTDIR /gst.log"
19+ RUN_LOG=" $OUTDIR /run.log"
20+
21+ mkdir -p " $OUTDIR " > /dev/null 2>&1 || true
22+ : > " $RES_FILE "
23+ : > " $GST_LOG "
24+ : > " $RUN_LOG "
25+
1426INIT_ENV=" "
1527SEARCH=" $SCRIPT_DIR "
1628while [ " $SEARCH " != " /" ]; do
3850# shellcheck disable=SC1091
3951[ -f " $TOOLS /lib_display.sh" ] && . " $TOOLS /lib_display.sh"
4052
41- TESTNAME=" Waylandsink_Playback"
42- RES_FILE=" ${SCRIPT_DIR} /${TESTNAME} .res"
43- LOG_DIR=" ${SCRIPT_DIR} /logs"
44- OUTDIR=" $LOG_DIR /$TESTNAME "
45- GST_LOG=" $OUTDIR /gst.log"
46- RUN_LOG=" $OUTDIR /run.log"
47-
48- mkdir -p " $OUTDIR " > /dev/null 2>&1 || true
49- : > " $RES_FILE "
50- : > " $GST_LOG "
51- : > " $RUN_LOG "
52-
5353result=" FAIL"
5454reason=" unknown"
5555
5656# -------------------- Defaults --------------------
5757# Validate environment variables if set
58- if [ -n " $VIDEO_DURATION " ] && ! echo " $VIDEO_DURATION " | grep -q " ^[0-9]\+$" ; then
58+ if [ -n " ${ VIDEO_DURATION:- } " ] && ! echo " $VIDEO_DURATION " | grep -q " ^[0-9]\+$" ; then
5959 log_warn " VIDEO_DURATION must be numeric (got '$VIDEO_DURATION ')"
6060 echo " $TESTNAME SKIP" > " $RES_FILE "
6161 exit 0
6262fi
63- if [ -n " $RUNTIMESEC " ] && ! echo " $RUNTIMESEC " | grep -q " ^[0-9]\+$" ; then
63+ if [ -n " ${ RUNTIMESEC:- } " ] && ! echo " $RUNTIMESEC " | grep -q " ^[0-9]\+$" ; then
6464 log_warn " RUNTIMESEC must be numeric (got '$RUNTIMESEC ')"
6565 echo " $TESTNAME SKIP" > " $RES_FILE "
6666 exit 0
6767fi
68- if [ -n " $VIDEO_FRAMERATE " ] && ! echo " $VIDEO_FRAMERATE " | grep -q " ^[0-9]\+$" ; then
68+ if [ -n " ${ VIDEO_FRAMERATE:- } " ] && ! echo " $VIDEO_FRAMERATE " | grep -q " ^[0-9]\+$" ; then
6969 log_warn " VIDEO_FRAMERATE must be numeric (got '$VIDEO_FRAMERATE ')"
7070 echo " $TESTNAME SKIP" > " $RES_FILE "
7171 exit 0
7272fi
73+ if [ -n " ${VIDEO_GST_DEBUG:- ${GST_DEBUG_LEVEL:- } } " ] && ! echo " ${VIDEO_GST_DEBUG:- ${GST_DEBUG_LEVEL:- } } " | grep -q " ^[0-9]\+$" ; then
74+ log_warn " GST debug level must be numeric (got '${VIDEO_GST_DEBUG:- ${GST_DEBUG_LEVEL:- } } ')"
75+ echo " $TESTNAME SKIP" > " $RES_FILE "
76+ exit 0
77+ fi
7378
7479duration=" ${VIDEO_DURATION:- ${RUNTIMESEC:- 30} } "
7580pattern=" ${VIDEO_PATTERN:- smpte} "
@@ -79,7 +84,10 @@ framerate="${VIDEO_FRAMERATE:-30}"
7984gstDebugLevel=" ${VIDEO_GST_DEBUG:- ${GST_DEBUG_LEVEL:- 2} } "
8085
8186cleanup () {
82- pkill -x gst-launch-1.0 > /dev/null 2>&1 || true
87+ # Best-effort: try to kill only children first; fall back to name-based kill
88+ if ! pkill -P " $$ " -x gst-launch-1.0 > /dev/null 2>&1 ; then
89+ pkill -x gst-launch-1.0 > /dev/null 2>&1 || true
90+ fi
8391}
8492trap cleanup INT TERM EXIT
8593
@@ -201,8 +209,12 @@ while [ $# -gt 0 ]; do
201209 echo " $TESTNAME SKIP" > " $RES_FILE "
202210 exit 0
203211 fi
204- # If $2 is empty, keep default and shift 2
205- [ -n " $2 " ] && gstDebugLevel=" $2 "
212+ if ! echo " $2 " | grep -q " ^[0-9]\+$" ; then
213+ log_warn " GST debug level must be numeric (got '$2 ')"
214+ echo " $TESTNAME SKIP" > " $RES_FILE "
215+ exit 0
216+ fi
217+ gstDebugLevel=" $2 "
206218 shift 2
207219 ;;
208220
266278 esac
267279done
268280
281+ # Basic sanity
282+ if [ " $duration " -le 0 ] || [ " $width " -le 0 ] || [ " $height " -le 0 ] || [ " $framerate " -le 0 ]; then
283+ log_warn " Invalid parameters: duration=$duration width=$width height=$height framerate=$framerate "
284+ echo " $TESTNAME SKIP" > " $RES_FILE "
285+ exit 0
286+ fi
287+
269288# -------------------- Pre-checks --------------------
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)"
289+ check_dependencies " gst-launch-1.0 gst-inspect-1.0 grep head sed tail date mktemp " > /dev/null 2>&1 || {
290+ log_skip " Missing required tools (gst-launch-1.0, gst-inspect-1.0, grep, head, sed, tail, date, mktemp )"
272291 echo " $TESTNAME SKIP" > " $RES_FILE "
273292 exit 0
274293}
@@ -293,6 +312,22 @@ if command -v display_connected_summary >/dev/null 2>&1; then
293312 fi
294313fi
295314
315+ # Fallback: check /sys/class/drm/*/status
316+ if [ " $have_connector " -eq 0 ]; then
317+ drm_connected=" "
318+ for st in /sys/class/drm/card* -* /status; do
319+ [ -f " $st " ] || continue
320+ if grep -qi " connected" " $st " ; then
321+ conn=$( basename " $( dirname " $st " ) " )
322+ drm_connected=" ${drm_connected}${drm_connected: +,}${conn} "
323+ fi
324+ done
325+ if [ -n " $drm_connected " ]; then
326+ have_connector=1
327+ log_info " Connected display (drm sysfs): $drm_connected "
328+ fi
329+ fi
330+
296331if [ " $have_connector " -eq 0 ]; then
297332 log_warn " No connected DRM display found, skipping ${TESTNAME} ."
298333 echo " $TESTNAME SKIP" > " $RES_FILE "
@@ -330,6 +365,9 @@ if [ -z "$sock" ]; then
330365 fi
331366 if [ -n " $sock " ]; then
332367 log_info " Weston started successfully with socket: $sock "
368+ if command -v adopt_wayland_env_from_socket > /dev/null 2>&1 ; then
369+ adopt_wayland_env_from_socket " $sock " > /dev/null 2>&1 || true
370+ fi
333371 fi
334372 else
335373 log_warn " weston_pick_env_or_start failed"
@@ -340,10 +378,10 @@ if [ -z "$sock" ]; then
340378 if command -v discover_wayland_socket_anywhere > /dev/null 2>&1 ; then
341379 sock=$( discover_wayland_socket_anywhere | head -n 1 || true)
342380 fi
343- if [ -n " $sock " ] && command -v adopt_wayland_env_from_socket > /dev/null 2>&1 ; then
381+ if [ -n " $sock " ]; then
344382 log_info " Weston created Wayland socket: $sock "
345- if ! adopt_wayland_env_from_socket " $sock " ; then
346- log_warn " Failed to adopt env from $sock "
383+ if command -v adopt_wayland_env_from_socket > /dev/null 2>&1 ; then
384+ adopt_wayland_env_from_socket " $sock " > /dev/null 2>&1 || true
347385 fi
348386 fi
349387 fi
362400# Verify Wayland connection
363401if command -v wayland_connection_ok > /dev/null 2>&1 ; then
364402 if ! wayland_connection_ok; then
365- log_fail " Wayland connection test failed; cannot run ${TESTNAME} ."
403+ log_warn " Wayland connection test failed; skipping ${TESTNAME} ."
366404 echo " $TESTNAME SKIP" > " $RES_FILE "
367405 exit 0
368406 fi
@@ -384,16 +422,20 @@ export GST_DEBUG="$gstDebugLevel"
384422export GST_DEBUG_FILE=" $GST_LOG "
385423
386424# -------------------- Build and run pipeline --------------------
425+ # Make source real-time to match duration validation.
387426num_buffers=$(( duration * framerate))
388427
389- pipeline=" videotestsrc num-buffers=${num_buffers} pattern=${pattern} ! video/x-raw,width=${width} ,height=${height} ,framerate=${framerate} /1 ! videoconvert ! waylandsink"
428+ pipeline=" videotestsrc is-live=true num-buffers=${num_buffers} pattern=${pattern} ! video/x-raw,width=${width} ,height=${height} ,framerate=${framerate} /1 ! videoconvert ! waylandsink"
390429
391430log_info " Pipeline: $pipeline "
392431
393432# Run with timeout
394433start_ts=$( date +%s)
395434
396- if gstreamer_run_gstlaunch_timeout " $(( duration + 10 )) " " $pipeline " >> " $RUN_LOG " 2>&1 ; then
435+ # Give some slack, but timeout should still be treated as a real failure for this test
436+ timeout_sec=$(( duration + 15 ))
437+
438+ if gstreamer_run_gstlaunch_timeout " $timeout_sec " " $pipeline " >> " $RUN_LOG " 2>&1 ; then
397439 gstRc=0
398440else
399441 gstRc=$?
@@ -405,8 +447,11 @@ elapsed=$((end_ts - start_ts))
405447log_info " Playback finished: rc=${gstRc} elapsed=${elapsed} s"
406448
407449# -------------------- Validation --------------------
408- # Duration threshold (allow 2s slack)
409- min_duration=$(( duration - 2 ))
450+ if [ " $duration " -gt 2 ]; then
451+ min_duration=$(( duration - 2 ))
452+ else
453+ min_duration=0
454+ fi
410455
411456# Check for GStreamer errors in both run log and GST debug log
412457run_log_ok=1
419464
420465# Validate last 1000 lines of GST debug log if it exists and has content
421466if [ -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
467+ tmp_tail=$( mktemp " ${OUTDIR} /gst.tail.XXXXXX" 2> /dev/null || mktemp) || tmp_tail=" "
468+ if [ -n " $tmp_tail " ]; then
469+ tail -n 1000 " $GST_LOG " > " $tmp_tail " 2> /dev/null || true
470+ if ! gstreamer_validate_log " $tmp_tail " " $TESTNAME " ; then
471+ gst_log_ok=0
472+ fi
473+ rm -f " $tmp_tail " > /dev/null 2>&1 || true
474+ else
475+ # If mktemp failed, fall back to validating the full GST log
476+ if ! gstreamer_validate_log " $GST_LOG " " $TESTNAME " ; then
477+ gst_log_ok=0
478+ fi
426479 fi
427480 rm -f " ${GST_LOG} .tail"
428481fi
@@ -445,9 +498,13 @@ else
445498 result=" PASS"
446499 reason=" Playback completed successfully (elapsed=${elapsed} /${duration} s)"
447500 ;;
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"
501+ 124)
502+ result=" FAIL"
503+ reason=" Playback timed out (timeout=${timeout_sec} s, elapsed=${elapsed} s) - pipeline did not exit cleanly"
504+ ;;
505+ 137|143)
506+ result=" FAIL"
507+ reason=" Playback killed by signal (rc=$gstRc , elapsed=${elapsed} s) - unexpected termination"
451508 ;;
452509 * ) # Unexpected return code
453510 result=" FAIL"
@@ -461,6 +518,16 @@ else
461518 fi
462519fi
463520
521+ # Helpful tails on failure (stdout visibility in CI)
522+ if [ " $result " != " PASS" ]; then
523+ log_info " ---- gst-launch output (tail) ----"
524+ tail -n 120 " $RUN_LOG " 2> /dev/null || true
525+ if [ -s " $GST_LOG " ]; then
526+ log_info " ---- GST debug log (tail) ----"
527+ tail -n 120 " $GST_LOG " 2> /dev/null || true
528+ fi
529+ fi
530+
464531# -------------------- Emit result --------------------
465532case " $result " in
466533 PASS)
0 commit comments