Add automated tests on function-type FSCommand parameter passing.
[gnash.git] / testsuite / misc-mtasc.all / extcommtests-runner.sh
blobb16563059c7628ee9778c4cc6627bfaf620e4dff
1 #!/bin/sh
3 #
4 # extcommtests-runner.sh: container-emulated, automated
5 # ExternalInterface test generator
6 #
7 # Copyright (C) 2015, 2016 Free Software Foundation, Inc.
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 # Original author: Nutchanon Wetchasit <Nutchanon.Wetchasit@gmail.com>
26 # The generated test runner checks Gnash for:
27 # * ExternalInterface.addCallback() issues (bug #37223)
28 # <https://savannah.gnu.org/bugs/?37223>
29 # * ExternalInterface.call()'s delayed return value issue (bug #46131)
30 # <https://savannah.gnu.org/bugs/?46131>
31 # * Single-argument ExternalInterface.call() issue (bug #46878)
32 # <https://savannah.gnu.org/bugs/?46878>
34 # Usage:
35 # ./extcommtests-runner.sh <builddir> <srcdir> <swf>
37 # Exit codes:
38 # 0 if tester ran completely
39 # non-zero if tester encountered an error
41 # Note:
42 # The generated test file requires a filesystem that supports a named pipe.
45 # Check for generation parameters
46 while getopts "" name
48 case $name in
50 echo "Usage: $0 <builddir> <srcdir> <swf>" >&2
51 exit 1;;
52 esac
53 done
54 shift $(($OPTIND - 1))
55 if [ "$#" -ne 3 ]
56 then
57 echo "Usage: $0 <builddir> <srcdir> <swf>" >&2
58 exit 1
61 # Load generation parameters
62 top_builddir=$1
63 shift
64 top_srcdir=$1
65 shift
66 swf=$1
68 # Generate the test runner
69 echo "#!/bin/sh"
70 echo
72 echo "# Environment variables"
73 env | grep '^GNASH' | while read reply
75 echo "export \"${reply}\""
76 done
78 timeout=10
80 cat << EOF
82 # Filenames and constants
83 LOGFILE=${top_builddir}/testoutlog.\$\$
84 PIPE2CONTAINER=${top_builddir}/tocontainer.\$\$
85 PIPE2PLAYER=${top_builddir}/toplayer.\$\$
86 READTIMEOUT=5
88 # Test counts
89 TESTED=0
90 FAILED=0
91 XFAILED=0
92 PASSED=0
93 XPASSED=0
95 # check_equals(\$op1, \$op2, \$msg)
96 # Equality checker and counter
97 check_equals() {
98 if [ "\$1" = "\$2" ]
99 then
100 echo "PASSED: \$3"
101 PASSED=\`expr "\$PASSED" + 1\`
102 else
103 echo "FAILED: \$3 (\"\$1\" != \"\$2\")"
104 FAILED=\`expr "\$FAILED" + 1\`
106 TESTED=\`expr "\$TESTED" + 1\`
109 # check_totals(\$op, \$msg)
110 # Test count checker
111 check_totals() {
112 check_equals "\$TESTED" "\$1" "\$2"
115 # check_error(\$bool, \$msg)
116 # Assert \$bool is 0; if not, flag error in the test, and exit
117 check_error() {
118 if [ "\$1" -ne 0 ]
119 then
120 echo "ERROR: \$2" >&2
121 exit 1
125 # read_timeout(\$varname, \$timeout)
126 # Read one line from standard input, with a specified timeout (in seconds)
127 read_timeout() {
128 trap 'trap - USR1; return 142' USR1
129 (sleep "\$2" && kill -USR1 "\$\$" > /dev/null 2>&1) &
130 TIMEOUTPID=\$!
131 read "\$1"
132 READERROR=\$?
133 kill "\$TIMEOUTPID" > /dev/null 2>&1
134 trap - USR1
135 return \$READERROR
138 # Create required named pipes
139 if [ \! -p "\$PIPE2CONTAINER" ]
140 then
141 mkfifo "\$PIPE2CONTAINER"
142 check_error "\$?" "Failed to create a named pipe: \$PIPE2CONTAINER"
144 if [ \! -p "\$PIPE2PLAYER" ]
145 then
146 mkfifo "\$PIPE2PLAYER"
147 check_error "\$?" "Failed to create a named pipe: \$PIPE2PLAYER"
150 # Open player-to-host pipe
151 exec 3<> "\$PIPE2CONTAINER"
152 check_error \$? "Failed to open a named pipe: \$PIPE2CONTAINER"
154 # Open host-to-player pipe
155 exec 4<> "\$PIPE2PLAYER"
156 check_error \$? "Failed to open a named pipe: \$PIPE2PLAYER"
158 # Start player
159 "${top_builddir}/gui/gnash" -r 0 -t ${timeout} -vv -F 3:4 "${swf}" > "\$LOGFILE" 2>&1 &
160 GNASHPID=\$!
162 # Read for script_call callback registration statement
163 read_timeout LINE \$READTIMEOUT <&3
164 check_equals \
165 "\$LINE" \
166 '<invoke name="addMethod" returntype="xml"><arguments><string>script_call</string></arguments></invoke>' \
167 "Gnash should properly register script_call ExternalInterface callback"
169 # Read for script_nothis1 callback registration statement
170 read_timeout LINE \$READTIMEOUT <&3
171 check_equals \
172 "\$LINE" \
173 '<invoke name="addMethod" returntype="xml"><arguments><string>script_nothis1</string></arguments></invoke>' \
174 "Gnash should properly register script_nothis1 ExternalInterface callback"
176 # Read for script_nothis2 callback registration statement
177 read_timeout LINE \$READTIMEOUT <&3
178 check_equals \
179 "\$LINE" \
180 '<invoke name="addMethod" returntype="xml"><arguments><string>script_nothis2</string></arguments></invoke>' \
181 "Gnash should properly register script_nothis2 ExternalInterface callback"
183 # Read for script_globalcheck callback registration statement
184 read_timeout LINE \$READTIMEOUT <&3
185 check_equals \
186 "\$LINE" \
187 '<invoke name="addMethod" returntype="xml"><arguments><string>script_globalcheck</string></arguments></invoke>' \
188 "Gnash should properly register script_globalcheck ExternalInterface callback"
190 # Read for script_longarglist callback registration statement
191 read_timeout LINE \$READTIMEOUT <&3
192 check_equals \
193 "\$LINE" \
194 '<invoke name="addMethod" returntype="xml"><arguments><string>script_longarglist</string></arguments></invoke>' \
195 "Gnash should properly register script_longarglist ExternalInterface callback"
197 # Read for js_simple JavaScript function invocation statement
198 read_timeout LINE \$READTIMEOUT <&3
199 check_equals \
200 "\$LINE" \
201 '<invoke name="js_simple" returntype="xml"><arguments><string>js_simple</string></arguments></invoke>' \
202 "Gnash should call JavaScript's js_simple function correctly"
204 # Return string value from js_simple function
205 echo '<string>Correct</string>' >&4
207 # Test using multiple ExternalInterface.call() in row
208 NUMBER=1
209 for READING in "one" "two" "three" "four" "five" "six" "seven" "eight" "nine" \
210 "ten" "eleven" "twelve" "thirteen" "fourteen" "fifteen" "sixteen" \
211 "seventeen" "eighteen" "nineteen" "twenty"
213 # Read for js_readnumber JavaScript function invocation statement
214 read_timeout LINE \$READTIMEOUT <&3
215 check_equals \
216 "\$LINE" \
217 "<invoke name=\"js_readnumber\" returntype=\"xml\"><arguments><string>js_readnumber</string><number>\$NUMBER</number></arguments></invoke>" \
218 "Gnash should call JavaScript's js_readnumber function with parameter \$NUMBER correctly"
220 # Return string value from js_readnumber function
221 echo "<string>\$READING</string>" >&4
223 NUMBER=\`expr \$NUMBER + 1\`
224 done
226 # Pause a bit, so the next script_call invoke doesn't get mixed up with
227 # the previous return value data
228 sleep 1
230 # Call the script_call callback
231 echo '<invoke name="script_call" returntype="xml"><arguments><string>Hello</string><string>World</string></arguments></invoke>' >&4
233 # Read for callback return value statement
234 read_timeout LINE \$READTIMEOUT <&3
235 check_equals "\$LINE" '<string>Too</string>' "Gnash should return a correct value from script_call ExternalInterface callback"
237 # Call the script_nothis1 callback
238 echo '<invoke name="script_nothis1" returntype="xml"><arguments></arguments></invoke>' >&4
240 # Read for callback return value statement
241 read_timeout LINE \$READTIMEOUT <&3
242 check_equals "\$LINE" '<void/>' "Gnash should return a correct value from script_nothis1 ExternalInterface callback"
244 # Call the script_nothis2 callback
245 echo '<invoke name="script_nothis2" returntype="xml"><arguments></arguments></invoke>' >&4
247 # Read for callback return value statement
248 read_timeout LINE \$READTIMEOUT <&3
249 check_equals "\$LINE" '<void/>' "Gnash should return a correct value from script_nothis2 ExternalInterface callback"
251 # Call the script_globalcheck callback
252 echo '<invoke name="script_globalcheck" returntype="xml"><arguments></arguments></invoke>' >&4
254 # Read for callback return value statement
255 read_timeout LINE \$READTIMEOUT <&3
256 check_equals "\$LINE" '<void/>' "Gnash should return a correct value from script_globalcheck ExternalInterface callback"
258 # Call the script_longarglist callback
259 echo '<invoke name="script_longarglist" returntype="xml"><arguments><string>The</string><string>quick</string><string>brown</string><string>fox</string><string>jumps</string><string>over</string><string>the</string><string>lazy</string><string>dog</string></arguments></invoke>' >&4
261 # Read for callback return value statement
262 read_timeout LINE \$READTIMEOUT <&3
263 check_equals "\$LINE" '<string>Pangram</string>' "Gnash should return a correct value from script_longarglist ExternalInterface callback"
265 # Close pipes
266 exec 3<&-
267 exec 4<&-
269 # Wait for Gnash to exit
270 wait \$GNASHPID
271 check_equals "\$?" "0" "Gnash should terminate successfully"
273 # Show player-side output
274 exec 5< "\$LOGFILE"
275 cat <&5
276 exec 5<&-
278 # Include total number of tests from player side
279 exec 5< "\$LOGFILE"
280 PLAYERPASSED=\`grep "TRACE: PASSED:" <&5 | wc -l\`
281 exec 5<&-
282 exec 5< "\$LOGFILE"
283 PLAYERXPASSED=\`grep "TRACE: XPASSED:" <&5 | wc -l\`
284 exec 5<&-
285 exec 5< "\$LOGFILE"
286 PLAYERFAILED=\`grep "TRACE: FAILED:" <&5 | wc -l\`
287 exec 5<&-
288 exec 5< "\$LOGFILE"
289 PLAYERXFAILED=\`grep "TRACE: XFAILED:" <&5 | wc -l\`
290 exec 5<&-
291 PASSED=\`expr "\$PASSED" + "\$PLAYERPASSED"\`
292 XPASSED=\`expr "\$XPASSED" + "\$PLAYERXPASSED"\`
293 FAILED=\`expr "\$FAILED" + "\$PLAYERFAILED"\`
294 XFAILED=\`expr "\$XFAILED" + "\$PLAYERXFAILED"\`
295 TESTED=\`expr "\$TESTED" + "\$PLAYERPASSED" + "\$PLAYERXPASSED" + "\$PLAYERFAILED" + "\$PLAYERXFAILED"\`
297 # Check for total number of test run
298 check_totals "94" "There should be 94 tests run"
300 # Remove temporary files
301 rm "\$LOGFILE"
302 rm "\$PIPE2CONTAINER"
303 rm "\$PIPE2PLAYER"