[test] Set a `gstTestBackground` SSAT tc as not critical
[platform/upstream/nnstreamer.git] / tests / nnstreamer_edge / query / runTest.sh
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: LGPL-2.1-only
3 #
4 # @file runTest.sh
5 # @author Gichan Jang <gichan2.jang@samsung.com>
6 # @date Aug 25 2021
7 # @brief SSAT Test Cases for tensor query
8 #
9 if [[ "$SSATAPILOADED" != "1" ]]; then
10     SILENT=0
11     INDEPENDENT=1
12     search="ssat-api.sh"
13     source $search
14     printf "${Blue}Independent Mode${NC}"
15 fi
16
17 # This is compatible with SSAT (https://github.com/myungjoo/SSAT)
18 testInit $1
19
20 PATH_TO_PLUGIN="../../build"
21 PERFORMANCE=0
22 # The client has to wait enough time for the server to be ready.
23 # Related issue: https://github.com/nnstreamer/nnstreamer/issues/3657
24 SLEEPTIME_SEC=5
25 TIMEOUT_SEC=10
26
27 check_query=$(gst-inspect-1.0 --gst-plugin-path=${PATH_TO_PLUGIN} tensor_query_serversrc | grep TensorQueryServerSrc)
28 if [[ ! $check_query ]]; then
29     echo "Cannot find tensor query plugins. Skip tests."
30     report
31     exit
32 fi
33
34 ## @brief Execute file comparison test if the file exist
35 function _callCompareTest() {
36     if [[ ! -f "$1" || ! -f "$2" ]]; then
37         echo "$1 or $2 don't exist."
38         return
39     fi
40
41     callCompareTest $1 $2 $3 "$4" $5 $6
42 }
43
44 # Run tensor query server as echo server with default address option.
45 PORT=`python3 ../../get_available_port.py`
46 gstTestBackground "--gst-plugin-path=${PATH_TO_PLUGIN} tensor_query_serversrc port=${PORT} ! other/tensors,format=static,num_tensors=1,dimensions=(string)3:300:300:1,types=(string)uint8,framerate=0/1 ! tensor_query_serversink async=false" 1-1 1 0 30
47 pid=$!
48 gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} videotestsrc is-live=true num-buffers=10 ! videoconvert ! videoscale ! video/x-raw,width=300,height=300,format=RGB ! tensor_converter ! tee name = t t. ! queue ! multifilesink location= raw1_%1d.log t. ! queue ! tensor_query_client dest-port=${PORT} ! multifilesink location=result1_%1d.log sync=true " 1-2 0 0 $PERFORMANCE $TIMEOUT_SEC
49 _callCompareTest raw1_0.log result1_0.log 1-3 "Compare 1-3" 1 0
50 _callCompareTest raw1_1.log result1_1.log 1-4 "Compare 1-4" 1 0
51 _callCompareTest raw1_2.log result1_2.log 1-5 "Compare 1-5" 1 0
52 # Since the server operates in the background, wait for the server to stop before starting the next test.
53 kill -9 $pid &> /dev/null
54 wait $pid
55
56 # A server that mimics as if it takes a long time to process using identity element.
57 PORT=`python3 ../../get_available_port.py`
58 gstTestBackground "--gst-plugin-path=${PATH_TO_PLUGIN} tensor_query_serversrc port=${PORT} ! other/tensors,format=static,num_tensors=1,dimensions=(string)3:300:300:1,types=(string)uint8,framerate=0/1 ! identity sleep-time=500000 ! tensor_query_serversink async=false" 1.1-1 1 0 30
59 pid=$!
60 gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} videotestsrc is-live=true num-buffers=50 ! videoconvert ! videoscale ! video/x-raw,width=300,height=300,format=RGB,framerate=10/1 ! tensor_converter ! tee name = t t. ! queue ! multifilesink location= raw1.1_%1d.log t. ! queue ! tensor_query_client max-request=3 dest-port=${PORT} ! multifilesink location=result1.1_%1d.log sync=true " 1.1-2 0 0 $PERFORMANCE $TIMEOUT_SEC
61 _callCompareTest raw1.1_0.log result1.1_0.log 1.1-3 "Compare 1.1-3" 1 0
62 _callCompareTest raw1.1_1.log result1.1_1.log 1.1-4 "Compare 1.1-4" 1 0
63 # The third result should fail because third input buffer has been dropped.
64 _callCompareTest raw1.1_2.log result1.1_2.log 1.1-5 "[Fail test] Compare 1.1-5" 1 1
65 kill -9 $pid &> /dev/null
66 wait $pid
67
68 # Run tensor query server as echo server with given address option. (multi clients)
69 PORT1=`python3 ../../get_available_port.py`
70 gstTestBackground "--gst-plugin-path=${PATH_TO_PLUGIN} tensor_query_serversrc host=127.0.0.1 port=${PORT1} ! other/tensors,format=static,num_tensors=1,dimensions=(string)3:300:300:1,types=(string)uint8,framerate=0/1 ! tensor_query_serversink async=false" 2-1 1 0 30
71 pid=$!
72 gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} videotestsrc is-live=true num-buffers=10  ! videoconvert ! videoscale ! video/x-raw,width=300,height=300,format=RGB ! tensor_converter ! tee name = t t. ! queue ! multifilesink location= raw2_%1d.log t. ! queue ! tensor_query_client host=127.0.0.1 port=0 dest-host=127.0.0.1 dest-port=${PORT1} ! multifilesink location=result2_%1d.log" 2-2 0 0 $PERFORMANCE $TIMEOUT_SEC
73 gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} videotestsrc is-live=true num-buffers=10  ! videoconvert ! videoscale ! video/x-raw,width=300,height=300,format=RGB ! tensor_converter ! tee name = t t. ! queue ! multifilesink location= raw2_2_%1d.log t. ! queue ! tensor_query_client host=127.0.0.1 port=0 dest-host=127.0.0.1 dest-port=${PORT1} ! multifilesink location=result2_2_%1d.log" 2-3 0 0 $PERFORMANCE $TIMEOUT_SEC
74 _callCompareTest raw2_0.log result2_0.log 2-4 "Compare 2-4" 1 0
75 _callCompareTest raw2_1.log result2_1.log 2-5 "Compare 2-5" 1 0
76 _callCompareTest raw2_2.log result2_2.log 2-6 "Compare 2-6" 1 0
77 _callCompareTest raw2_2_0.log result2_2_0.log 2-7 "Compare 2-7" 1 0
78 _callCompareTest raw2_2_1.log result2_2_1.log 2-8 "Compare 2-8" 1 0
79 _callCompareTest raw2_2_2.log result2_2_2.log 2-9 "Compare 2-9" 1 0
80 kill -9 $pid &> /dev/null
81 wait $pid
82
83 # Test flexible tensors
84 PORT=`python3 ../../get_available_port.py`
85 gstTestBackground "--gst-plugin-path=${PATH_TO_PLUGIN} tensor_query_serversrc port=${PORT} ! other/tensors,format=flexible,framerate=0/1 ! tensor_query_serversink async=false" 3-1 1 0 30
86 pid=$!
87 gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} videotestsrc is-live=true num-buffers=10  ! videoconvert ! videoscale ! video/x-raw,width=300,height=300,format=RGB ! tensor_converter ! other/tensors,format=flexible ! tee name = t t. ! queue ! multifilesink location= raw3_%1d.log t. ! queue ! tensor_query_client port=0 dest-port=${PORT} ! multifilesink location=result3_%1d.log" 3-2 0 0 $PERFORMANCE $TIMEOUT_SEC
88 _callCompareTest raw3_0.log result3_0.log 3-3 "Compare 3-3" 1 0
89 _callCompareTest raw3_1.log result3_1.log 3-4 "Compare 3-4" 1 0
90 _callCompareTest raw3_2.log result3_2.log 3-5 "Compare 3-5" 1 0
91 kill -9 $pid &> /dev/null
92 wait $pid
93
94 # Test multiple query server src and sink.
95 PORT1=`python3 ../../get_available_port.py`
96 PORT2=`python3 ../../get_available_port.py`
97 PORT3=`python3 ../../get_available_port.py`
98 PORT4=`python3 ../../get_available_port.py`
99 gstTestBackground "--gst-plugin-path=${PATH_TO_PLUGIN} tensor_query_serversrc id=0 port=${PORT1} ! other/tensors,format=flexible,framerate=0/1 ! tensor_query_serversink id=0 async=false \
100     tensor_query_serversrc id=1 port=${PORT2} ! other/tensors,format=flexible ! tensor_query_serversink id=1 async=false" 5-1 1 0 30
101 pid=$!
102 # Client pipeline 5-2 is connected to server ID 0.
103 gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} \
104     videotestsrc is-live=true num-buffers=10  ! videoconvert ! videoscale ! video/x-raw,width=640,height=480,format=RGB ! \
105     tensor_converter ! other/tensors,format=flexible ! tee name=t \
106         t. ! queue ! multifilesink location= raw5_2_%1d.log \
107         t. ! queue ! tensor_query_client dest-port=${PORT1} port=${PORT3} ! multifilesink location=result5_2_%1d.log" 5-2 0 0 $PERFORMANCE $TIMEOUT_SEC
108 # Client pipeline 5-3 is connected to server ID 1.
109 gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} \
110     videotestsrc is-live=true pattern=13 num-buffers=10  ! videoconvert ! videoscale ! video/x-raw,width=300,height=300,format=RGB ! \
111     tensor_converter ! other/tensors,format=flexible ! tee name=t \
112         t. ! queue ! multifilesink location= raw5_3_%1d.log \
113         t. ! queue ! tensor_query_client dest-port=${PORT2} port=${PORT4} ! multifilesink location=result5_3_%1d.log" 5-3 0 0 $PERFORMANCE $TIMEOUT_SEC
114 _callCompareTest raw5_2_0.log result5_2_0.log 5-4 "Compare 5-4" 1 0
115 _callCompareTest raw5_2_1.log result5_2_1.log 5-5 "Compare 5-5" 1 0
116 _callCompareTest raw5_2_2.log result5_2_2.log 5-6 "Compare 5-6" 1 0
117 _callCompareTest raw5_3_0.log result5_3_0.log 5-7 "Compare 5-7" 1 0
118 _callCompareTest raw5_3_1.log result5_3_1.log 5-8 "Compare 5-8" 1 0
119 _callCompareTest raw5_3_2.log result5_3_2.log 5-9 "Compare 5-9" 1 0
120 kill -9 $pid &> /dev/null
121 wait $pid
122
123 # Sever src cap: Video, Server sink cap: Viedo test
124 PORT=`python3 ../../get_available_port.py`
125 gstTestBackground "--gst-plugin-path=${PATH_TO_PLUGIN} tensor_query_serversrc port=${PORT} ! video/x-raw,width=300,height=300,format=RGB,framerate=0/1 ! tensor_query_serversink async=false" 6-1 1 0 30
126 pid=$!
127 gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} videotestsrc is-live=true num-buffers=10  ! videoconvert ! videoscale ! video/x-raw,width=300,height=300,format=RGB ! tee name = t t. ! queue ! multifilesink location= raw6_%1d.log t. ! queue ! tensor_query_client port=0 dest-port=${PORT} ! multifilesink location=result6_%1d.log" 6-2 0 0 $PERFORMANCE $TIMEOUT_SEC
128 _callCompareTest raw6_0.log result6_0.log 6-3 "Compare 6-3" 1 0
129 _callCompareTest raw6_1.log result6_1.log 6-4 "Compare 6-4" 1 0
130 _callCompareTest raw6_2.log result6_2.log 6-5 "Compare 6-5" 1 0
131 kill -9 $pid &> /dev/null
132 wait $pid
133
134 # Sever src cap: Video, Server sink cap: Tensor test
135 PORT=`python3 ../../get_available_port.py`
136 gstTestBackground "--gst-plugin-path=${PATH_TO_PLUGIN} tensor_query_serversrc port=${PORT} ! video/x-raw,width=300,height=300,format=RGB,framerate=0/1 ! tensor_converter ! tensor_query_serversink async=false" 7-1 1 0 30
137 pid=$!
138 gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} videotestsrc is-live=true num-buffers=10  ! videoconvert ! videoscale ! video/x-raw,width=300,height=300,format=RGB ! tee name = t t. ! queue ! multifilesink location= raw7_%1d.log t. ! queue ! tensor_query_client port=0 dest-port=${PORT} ! multifilesink location=result7_%1d.log" 7-2 0 0 $PERFORMANCE $TIMEOUT_SEC
139 _callCompareTest raw7_0.log result7_0.log 7-3 "Compare 7-3" 1 0
140 _callCompareTest raw7_1.log result7_1.log 7-4 "Compare 7-4" 1 0
141 _callCompareTest raw7_2.log result7_2.log 7-5 "Compare 7-5" 1 0
142 kill -9 $pid &> /dev/null
143 wait $pid
144
145 # Sever src cap: Tensor, Server sink cap: Video test
146 PORT=`python3 ../../get_available_port.py`
147 gstTestBackground "--gst-plugin-path=${PATH_TO_PLUGIN} tensor_query_serversrc port=${PORT} ! other/tensors,format=static,num_tensors=1,dimensions=(string)3:300:300:1,types=(string)uint8,framerate=0/1 ! tensor_decoder mode=direct_video ! videoconvert ! tensor_query_serversink async=false" 8-1 1 0 30
148 pid=$!
149 gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} videotestsrc is-live=true num-buffers=10  ! videoconvert ! videoscale ! video/x-raw,width=300,height=300,format=RGB ! tensor_converter ! tee name = t t. ! queue ! multifilesink location= raw8_%1d.log t. ! queue ! tensor_query_client port=0 dest-port=${PORT} ! multifilesink location=result8_%1d.log" 8-2 0 0 $PERFORMANCE $TIMEOUT_SEC
150 _callCompareTest raw8_0.log result8_0.log 8-3 "Compare 8-3" 1 0
151 _callCompareTest raw8_1.log result8_1.log 8-4 "Compare 8-4" 1 0
152 _callCompareTest raw8_2.log result8_2.log 8-5 "Compare 8-5" 1 0
153 kill -9 $pid &> /dev/null
154 wait $pid
155
156 if [ -f /usr/sbin/mosquitto ]
157 then
158   testResult 1 9-0 "mosquitto mqtt broker search" 1
159 else
160   testResult 0 9-0 "mosquitto mqtt broker search" 1
161   rm *.log
162   report
163   exit
164 fi
165
166 # 1. Launch mosquitto
167 PORT=`python3 ../../get_available_port.py`
168 /usr/sbin/mosquitto -p ${PORT}&
169 mospid=$!
170
171 # 2. Tests that require mosquitto
172
173 # Test Query-hybrid. Get server info from broker.
174 gstTestBackground "--gst-plugin-path=${PATH_TO_PLUGIN} tensor_query_serversrc id=12345 port=0 dest-port=${PORT} topic=passthrough connect-type=HYBRID ! other/tensors,format=flexible,framerate=0/1 ! tee name = t t. ! queue ! multifilesink location=server1_%1d.log t. ! queue ! tensor_query_serversink id=12345 connect-type=HYBRID async=false" 9-1 1 0 5
175 pid=$!
176 gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} videotestsrc num-buffers=10 is-live=true ! videoconvert ! videoscale ! video/x-raw,width=300,height=300,format=RGB ! tensor_converter ! other/tensors,format=flexible ! tee name = t t. ! queue ! multifilesink location= raw4_%1d.log t. ! queue ! tensor_query_client connect-type=HYBRID port=0 dest-host=127.0.0.1 dest-port=${PORT} topic=passthrough ! multifilesink location=result4_%1d.log" 9-3 0 0 $PERFORMANCE $TIMEOUT_SEC
177 _callCompareTest raw4_0.log result4_0.log 9-4 "Compare the raw file and client received file 9-4" 1 0
178 _callCompareTest raw4_1.log result4_1.log 9-5 "Compare the raw file and client received file 9-5" 1 0
179 _callCompareTest raw4_2.log result4_2.log 9-6 "Compare the raw file and client received file 9-6" 1 0
180 _callCompareTest server1_0.log result4_0.log 9-7 "Compare the server 1 received file and client received file 9-7" 1 0
181 _callCompareTest server1_1.log result4_1.log 9-8 "Compare the server 1 received file and client received file 9-8" 1 0
182 _callCompareTest server1_2.log result4_2.log 9-9 "Compare the server 1 received file and client received file 9-9" 1 0
183
184 kill -9 $pid &> /dev/null
185 wait $pid
186
187
188 # 3. Terminate mosquitto
189
190 kill -9 $mospid &> /dev/null
191
192 rm *.log
193
194 report