4 # hostcmd_testrunner.sh - container-emulated non-predefined FSCommand
5 # invocation test runner generator
7 # Copyright (C) 2017 Free Software Foundation, Inc.
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 # * Support of FSCommand call via MovieClip.getURL() (bug #46944)
28 # <https://savannah.gnu.org/bugs/?46944>
29 # * Undefined FSCommand parameter passing via MovieClip.getURL() (bug #50393)
30 # <https://savannah.gnu.org/bugs/?50393>
33 # ./hostcmd_testrunner.sh <builddir> <srcdir> <swfversion> <swf>
35 # Generated test runner's exit codes:
36 # 0 if tester ran completely
37 # non-zero if tester encountered an error
40 # The generated test file requires a filesystem that supports named pipes.
43 # Check for generation parameters
48 echo "Usage: $0 <builddir> <srcdir> <swfversion> <swf>" >&2
52 shift $
(($OPTIND - 1))
55 echo "Usage: $0 <builddir> <srcdir> <swfversion> <swf>" >&2
59 # Load generation parameters
68 # Generate the test runner
72 echo "# Environment variables"
73 env |
grep '^GNASH' |
while read reply
75 echo "export \"${reply}\""
80 # Filenames and constants
81 LOGFILE=${top_builddir}/testoutlog.\$\$
82 PIPE2CONTAINER=${top_builddir}/tocontainer.\$\$
83 PIPE2PLAYER=${top_builddir}/toplayer.\$\$
92 # check_equals(\$op1, \$op2, \$msg)
93 # Equality checker and counter
98 PASSED=\`expr "\$PASSED" + 1\`
100 echo "FAILED: \$3 (\"\$1\" != \"\$2\")"
101 FAILED=\`expr "\$FAILED" + 1\`
103 TESTED=\`expr "\$TESTED" + 1\`
106 # xcheck_equals(\$op1, \$op2, \$msg)
107 # Equality checker and counter (for expected failure)
112 PASSED=\`expr "\$PASSED" + 1\`
114 echo "XFAILED: \$3 (\"\$1\" != \"\$2\")"
115 FAILED=\`expr "\$FAILED" + 1\`
117 TESTED=\`expr "\$TESTED" + 1\`
120 # check_totals(\$op, \$msg)
123 check_equals "\$TESTED" "\$1" "\$2"
126 # check_error(\$bool, \$msg)
127 # Assert \$bool is 0; if not, flag error in the test, and exit
131 echo "ERROR: \$2" >&2
136 # read_timeout(\$varname, \$timeout)
137 # Read one line from standard input, with a specified timeout (in seconds)
139 trap 'trap - USR1; return 142' USR1
140 (sleep "\$2" && kill -USR1 "\$\$" > /dev/null 2>&1) &
144 kill "\$TIMEOUTPID" > /dev/null 2>&1
149 # Create required named pipes
150 if [ \! -p "\$PIPE2CONTAINER" ]
152 mkfifo "\$PIPE2CONTAINER"
153 check_error "\$?" "Failed to create a named pipe: \$PIPE2CONTAINER"
155 if [ \! -p "\$PIPE2PLAYER" ]
157 mkfifo "\$PIPE2PLAYER"
158 check_error "\$?" "Failed to create a named pipe: \$PIPE2PLAYER"
161 # Open player-to-host pipe
162 exec 3<> "\$PIPE2CONTAINER"
163 check_error \$? "Failed to open a named pipe: \$PIPE2CONTAINER"
165 # Open host-to-player pipe
166 exec 4<> "\$PIPE2PLAYER"
167 check_error \$? "Failed to open a named pipe: \$PIPE2PLAYER"
170 "${top_builddir}/gui/gnash" -r 0 -vv -F 3:4 "${swf}" > "\$LOGFILE" 2>&1 &
173 # Wait until the SWF code start running, by loop-checking logfile
174 STARTCOUNTDOWN=\$STARTTIMEOUT
175 while [ \$STARTCOUNTDOWN -gt 0 ]
177 if grep "TRACE: STARTOFTEST" "\$LOGFILE" 2>&1 > /dev/null
182 STARTCOUNTDOWN=\`expr \$STARTCOUNTDOWN - 1\`
185 [ \$STARTCOUNTDOWN -ne 0 ]
186 check_equals \$? 0 "Gnash-side ActionScript code should be successfully started"
189 # getURL-based FSCommand tests
192 # Read for no-name no-parameter FSCommand statement
193 read_timeout LINE \$READTIMEOUT <&3
194 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string></string><string></string></arguments></invoke>' "Gnash should correctly pass getURL-based no-name FSCommand call with no parameter"
196 # Read for no-name string-parameter FSCommand statement
197 read_timeout LINE \$READTIMEOUT <&3
198 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string></string><string>This is a string for empty call</string></arguments></invoke>' "Gnash should correctly pass getURL-based no-name FSCommand call with string parameter"
200 # Read for no-parameter FSCommand statement
201 read_timeout LINE \$READTIMEOUT <&3
202 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>noarg</string><string></string></arguments></invoke>' "Gnash should correctly pass getURL-based FSCommand call with no parameter"
204 # Read for string-parameter FSCommand statement
205 read_timeout LINE \$READTIMEOUT <&3
206 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>stringarg</string><string>This is a string</string></arguments></invoke>' "Gnash should correctly pass getURL-based FSCommand call with string parameter"
208 # Read for full-of-symbols-string-parameter FSCommand statement
209 read_timeout LINE \$READTIMEOUT <&3
210 xcheck_equals "\$LINE" "<invoke name=\"fsCommand\" returntype=\"xml\"><arguments><string>weirdstringarg</string><string>!@#\\\$%^&*()_+-={}|[]:\";'<>?,./~\\\`</string></arguments></invoke>" "Gnash should correctly pass getURL-based FSCommand call with full-of-symbols string parameter"
212 # Read for integer-parameter FSCommand statement
213 read_timeout LINE \$READTIMEOUT <&3
214 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>integerarg</string><string>9876</string></arguments></invoke>' "Gnash should correctly pass getURL-based FSCommand call with integer parameter"
216 # Read for floating-point-parameter FSCommand statement
217 read_timeout LINE \$READTIMEOUT <&3
218 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>floatarg</string><string>9876.5432</string></arguments></invoke>' "Gnash should correctly pass getURL-based FSCommand call with floating point parameter"
220 # Read for infinity-parameter FSCommand statement
221 read_timeout LINE \$READTIMEOUT <&3
222 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>infinitearg</string><string>Infinity</string></arguments></invoke>' "Gnash should correctly pass getURL-based FSCommand call with infinity parameter"
224 # Read for negative-infinity-parameter FSCommand statement
225 read_timeout LINE \$READTIMEOUT <&3
226 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>neginfinitearg</string><string>-Infinity</string></arguments></invoke>' "Gnash should correctly pass getURL-based FSCommand call with negative infinity parameter"
228 # Read for not-a-number-parameter FSCommand statement
229 read_timeout LINE \$READTIMEOUT <&3
230 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>nanarg</string><string>NaN</string></arguments></invoke>' "Gnash should correctly pass getURL-based FSCommand call with not-a-number parameter"
232 # Read for boolean-parameter FSCommand statement
233 read_timeout LINE \$READTIMEOUT <&3
234 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>booleanarg</string><string>true</string></arguments></invoke>' "Gnash should correctly pass getURL-based FSCommand call with boolean parameter"
236 # Read for null-parameter FSCommand statement
237 read_timeout LINE \$READTIMEOUT <&3
238 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>nullarg</string><string>null</string></arguments></invoke>' "Gnash should correctly pass getURL-based FSCommand call with null parameter"
240 if [ $swfversion -ge 7 ]
242 # Read for undefined-parameter FSCommand statement (SWF7-above form)
243 read_timeout LINE \$READTIMEOUT <&3
244 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>undefinedarg</string><string>undefined</string></arguments></invoke>' "Gnash should correctly pass getURL-based FSCommand call with undefined parameter"
246 # Read for undefined-parameter FSCommand statement (SWF6-below form)
247 read_timeout LINE \$READTIMEOUT <&3
248 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>undefinedarg</string><string></string></arguments></invoke>' "Gnash should correctly pass getURL-based FSCommand call with undefined parameter"
251 # Read for array-parameter FSCommand statement
252 read_timeout LINE \$READTIMEOUT <&3
253 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>arrayarg</string><string>The,quick,brown,fox,jumps,over,the,lazy,dog</string></arguments></invoke>' "Gnash should correctly pass getURL-based FSCommand call with array parameter"
255 # Read for object-parameter FSCommand statement
256 read_timeout LINE \$READTIMEOUT <&3
257 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>objectarg</string><string>[object Object]</string></arguments></invoke>' "Gnash should correctly pass getURL-based FSCommand call with object parameter"
259 # Read for object-with-custom-string-parameter FSCommand statement
260 read_timeout LINE \$READTIMEOUT <&3
261 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>object_customstringarg</string><string>This is a custom Object.toString()</string></arguments></invoke>' "Gnash should correctly pass getURL-based FSCommand call with object parameter bearing custom toString()"
263 # Read for function-parameter FSCommand statement
264 read_timeout LINE \$READTIMEOUT <&3
265 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>functionarg</string><string>[type Function]</string></arguments></invoke>' "Gnash should correctly pass getURL-based FSCommand call with function parameter"
268 # MovieClip-based FSCommand tests
271 # Read for no-name no-parameter FSCommand statement
272 read_timeout LINE \$READTIMEOUT <&3
273 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string></string><string></string></arguments></invoke>' "Gnash should correctly pass MovieClip-based no-name FSCommand call with no parameter"
275 # Read for no-name string-parameter FSCommand statement
276 read_timeout LINE \$READTIMEOUT <&3
277 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string></string><string>This is a string for empty call</string></arguments></invoke>' "Gnash should correctly pass MovieClip-based no-name FSCommand call with string parameter"
279 # Read for no-parameter FSCommand statement
280 read_timeout LINE \$READTIMEOUT <&3
281 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>m_noarg</string><string></string></arguments></invoke>' "Gnash should correctly pass MovieClip-based FSCommand call with no parameter"
283 # Read for string-parameter FSCommand statement
284 read_timeout LINE \$READTIMEOUT <&3
285 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>m_stringarg</string><string>This is a string</string></arguments></invoke>' "Gnash should correctly pass MovieClip-based FSCommand call with string parameter"
287 # Read for full-of-symbols-string-parameter FSCommand statement
288 read_timeout LINE \$READTIMEOUT <&3
289 xcheck_equals "\$LINE" "<invoke name=\"fsCommand\" returntype=\"xml\"><arguments><string>m_weirdstringarg</string><string>!@#\\\$%^&*()_+-={}|[]:\";'<>?,./~\\\`</string></arguments></invoke>" "Gnash should correctly pass MovieClip-based FSCommand call with full-of-symbols string parameter"
291 # Read for integer-parameter FSCommand statement
292 read_timeout LINE \$READTIMEOUT <&3
293 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>m_integerarg</string><string>9876</string></arguments></invoke>' "Gnash should correctly pass MovieClip-based FSCommand call with integer parameter"
295 # Read for floating-point-parameter FSCommand statement
296 read_timeout LINE \$READTIMEOUT <&3
297 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>m_floatarg</string><string>9876.5432</string></arguments></invoke>' "Gnash should correctly pass MovieClip-based FSCommand call with floating point parameter"
299 # Read for infinity-parameter FSCommand statement
300 read_timeout LINE \$READTIMEOUT <&3
301 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>m_infinitearg</string><string>Infinity</string></arguments></invoke>' "Gnash should correctly pass MovieClip-based FSCommand call with infinity parameter"
303 # Read for negative-infinity-parameter FSCommand statement
304 read_timeout LINE \$READTIMEOUT <&3
305 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>m_neginfinitearg</string><string>-Infinity</string></arguments></invoke>' "Gnash should correctly pass MovieClip-based FSCommand call with negative infinity parameter"
307 # Read for not-a-number-parameter FSCommand statement
308 read_timeout LINE \$READTIMEOUT <&3
309 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>m_nanarg</string><string>NaN</string></arguments></invoke>' "Gnash should correctly pass MovieClip-based FSCommand call with not-a-number parameter"
311 # Read for boolean-parameter FSCommand statement
312 read_timeout LINE \$READTIMEOUT <&3
313 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>m_booleanarg</string><string>true</string></arguments></invoke>' "Gnash should correctly pass MovieClip-based FSCommand call with boolean parameter"
315 # Read for null-parameter FSCommand statement
316 read_timeout LINE \$READTIMEOUT <&3
317 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>m_nullarg</string><string>null</string></arguments></invoke>' "Gnash should correctly pass MovieClip-based FSCommand call with null parameter"
319 # Read for undefined-parameter FSCommand statement
320 read_timeout LINE \$READTIMEOUT <&3
321 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>m_undefinedarg</string><string></string></arguments></invoke>' "Gnash should pass undefined parameter of MovieClip-based FSCommand call as empty string"
323 # Read for array-parameter FSCommand statement
324 read_timeout LINE \$READTIMEOUT <&3
325 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>m_arrayarg</string><string>The,quick,brown,fox,jumps,over,the,lazy,dog</string></arguments></invoke>' "Gnash should correctly pass MovieClip-based FSCommand call with array parameter"
327 # Read for object-parameter FSCommand statement
328 read_timeout LINE \$READTIMEOUT <&3
329 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>m_objectarg</string><string>[object Object]</string></arguments></invoke>' "Gnash should correctly pass MovieClip-based FSCommand call with object parameter"
331 # Read for object-with-custom-string-parameter FSCommand statement
332 read_timeout LINE \$READTIMEOUT <&3
333 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>m_object_customstringarg</string><string>This is a custom Object.toString()</string></arguments></invoke>' "Gnash should correctly pass MovieClip-based FSCommand call with object parameter bearing custom toString()"
335 # Read for function-parameter FSCommand statement
336 read_timeout LINE \$READTIMEOUT <&3
337 check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>m_functionarg</string><string>[type Function]</string></arguments></invoke>' "Gnash should correctly pass MovieClip-based FSCommand call with function parameter"
343 # Force Gnash to exit
347 # Show player-side output
352 # Check for total number of test run
353 check_totals "35" "There should be 35 tests run"
355 # Remove temporary files
357 rm "\$PIPE2CONTAINER"