Feature: GstTest in Background accepted/tizen/unified/20220615.135308 submit/tizen/20220615.051712
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Fri, 10 Jun 2022 10:31:58 +0000 (19:31 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 15 Jun 2022 05:15:24 +0000 (14:15 +0900)
Launch a gst pipeline in background for test cases with multiple
gst pipelines collaborating with each other.

Example usage:

gstTestBackground "background pipeline description" TCNAME 0 0 5
// launching the pipeline with 5s timeout for launching-timeout
// Note that the timeout only waits for the pipeline initialization.
// The pipeline shouldn't have indefinite prerolling wait.
// If this pipeline waits for inputs after the launch, make it
// async=false (at sink) so that it may skip prerolling

gstTest "foreground pipeline description, collaborating with above" ...

wait $pid
// the global variable "pid" is the PID of the background pipeline.

// alternatively
kill $pid // the background pipeline is no more needed.

Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
exampleCase/gstTestBackground/runTest.sh [new file with mode: 0755]
ssat-api.sh

diff --git a/exampleCase/gstTestBackground/runTest.sh b/exampleCase/gstTestBackground/runTest.sh
new file mode 100755 (executable)
index 0000000..181b7b3
--- /dev/null
@@ -0,0 +1,56 @@
+#!/usr/bin/env bash
+
+if [[ "$SSATAPILOADED" != "1" ]]
+then
+       SILENT=0
+       INDEPENDENT=1
+       search="ssat-api.sh"
+       source $search
+
+       retcode=$?
+       count=0
+       while (( ${retcode} != 0 ))
+       do
+               count=$((count+1))
+               if (( ${count} > 5 ))
+               then
+                       echo "Cannot find ssat-api.sh"
+                       exit 1
+               fi
+
+               search="../${search}"
+               source $search
+               retcode=$?
+       done
+       printf "${Blue}Independent Mode${NC}\n"
+fi
+
+testInit $1
+
+command -v gst-launch-1.0 || report
+command -v gst-inspect-1.0 || report
+
+filename=$(mktemp)
+gstTestBackground "videotestsrc num-buffers=5 is-live=true  ! video/x-raw,width=64,height=48,framerate=1/1 ! filesink location=${filename}" GBKG1 0 0 5
+testResult 1 GBKG1-AFT "After launching the background" 0
+wait $pid
+testResult 1 GBKG1-CMP "After the background is completed" 0
+
+gst-inspect-1.0 udpsrc &> /dev/null
+val=$?
+if [ "${val}" == "0" ]; then
+       gstTestBackground "udpsrc ! video/x-raw,width=64,height=48,framerate=1/1 ! fakesink async=false" GBKG2 0 0 5
+       testResult 1 GBKG2-AFT "After launching the background" 0
+       kill $pid
+       testResult 1 GBKG2-CMP "After the background is killed" 0
+
+       gstTestBackground "udpsrc ! video/x-raw,width=64,height=48,framerate=1/1 ! fakesink" GBKG3 0 1 5
+       testResult 1 GBKG3-AFT "After launching the background" 0
+       kill $pid
+       testResult 1 GBKG3-CMP "After the background is killed" 0
+else
+       testResult 0 GBKG2 "udpsrc-based gst background test failed: udpsrc not found: gst-inspect returns ${val}." 1
+fi
+
+
+report
index 8d1a93a..a81b61d 100644 (file)
@@ -368,6 +368,62 @@ function gstTest() {
        fi
 }
 
+
+## @fn gstTestBackground()
+## @brief Execute gst-launch in background with given arguments.
+## @param $1 gst-launch-1.0 Arguments, with pipeline description at the end. The pipeline should have async=false for sink elements (skip preroll!).
+## @param $2 test case ID
+## @param $3 set 1 if this is not critical (don't care if it's pass or fail)
+## @param $4 set 1 if this passes if launching the pipeline fails. (pass if timeout expires)
+## @param $5 set timeout for launching the pipeline in seconds (not the pipeline EOS). default = 10.
+## @return $pid The PID of the background gstreamer pipeline.
+function gstTestBackground() {
+       local marker=$(mktemp)
+       local timeout=10
+       local launchSuccess
+       local launchFail
+       local pipeline
+
+       if [ "$4" == "1" ]; then
+               launchSuccess=0
+               launchFail=1
+       else
+               launchSuccess=1
+               launchFail=0
+       fi
+       if [ "$5" == "" ]; then
+               # no changes in timeout. do nothing
+               sleep 0
+       else
+               if [ $5 -gt 0 ]; then
+                       timeout=$5
+               else
+                       # ignore if it's < 1. do nothing
+                       sleep 0
+               fi
+       fi
+
+       pipeline="$1   videotestsrc num-buffers=1 ! video/x-raw,width=4,height=4,format=RGB ! filesink location=${marker}"
+       gst-launch-1.0 $pipeline &
+       pid=$!
+
+       for i in $(seq 1 ${timeout})
+       do
+               if [ -f "$marker" ]; then
+                       markersize=$(stat -c%s ${marker})
+                       if [ $markersize -ge 48 ]; then
+                               testResult ${launchSuccess} $2 "gst-launch in background of case $2" $3
+                               rm ${marker}
+                               return $pid
+                       fi
+               fi
+               sleep 1
+       done
+       rm ${marker}
+       testResult ${launchFail} $2 "gst-launch in background of case $2" $3
+       return ${pid}
+}
+
 ## @fn convertBMP2PNG()
 ## @brief Convert all *.bmp to *.png in the current directory
 ## @todo macronice "bmp2png" searching.