4 # extgetvariable_testrunner.sh, container-emulated, automated
5 # GetVariable plugin function test generator
7 # Copyright (C) 2015 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 # This test runner checks Gnash for:
27 # * GetVariable() datatype issues (bug #42395)
28 # <https://savannah.gnu.org/bugs/?42395>
29 # * Timeline variable declaration issue (bug #45840) in SWF5 environment
30 # <https://savannah.gnu.org/bugs/?45840>
33 # ./extgetvariable_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.\$\$
91 # check_equals(\$op1, \$op2, \$msg)
92 # Equality checker and counter
97 PASSED=\`expr "\$PASSED" + 1\`
99 echo "FAILED: \$3 (\"\$1\" != \"\$2\")"
100 FAILED=\`expr "\$FAILED" + 1\`
102 TESTED=\`expr "\$TESTED" + 1\`
105 # xcheck_equals(\$op1, \$op2, \$msg)
106 # Equality checker and counter (for expected failure)
111 PASSED=\`expr "\$PASSED" + 1\`
113 echo "XFAILED: \$3 (\"\$1\" != \"\$2\")"
114 FAILED=\`expr "\$FAILED" + 1\`
116 TESTED=\`expr "\$TESTED" + 1\`
119 # check_totals(\$op, \$msg)
122 check_equals "\$TESTED" "\$1" "\$2"
125 # check_error(\$bool, \$msg)
126 # Assert \$bool is 0; if not, flag error in the test, and exit
130 echo "ERROR: \$2" >&2
135 # read_timeout(\$varname, \$timeout)
136 # Read one line from standard input, with a specified timeout (in seconds)
138 trap 'trap - USR1; return 142' USR1
139 (sleep "\$2" && kill -USR1 "\$\$" > /dev/null 2>&1) &
143 kill "\$TIMEOUTPID" > /dev/null 2>&1
148 # Create required named pipes
149 if [ \! -p "\$PIPE2CONTAINER" ]
151 mkfifo "\$PIPE2CONTAINER"
152 check_error "\$?" "Failed to create a named pipe: \$PIPE2CONTAINER"
154 if [ \! -p "\$PIPE2PLAYER" ]
156 mkfifo "\$PIPE2PLAYER"
157 check_error "\$?" "Failed to create a named pipe: \$PIPE2PLAYER"
160 # Open player-to-host pipe
161 exec 3<> "\$PIPE2CONTAINER"
162 check_error \$? "Failed to open a named pipe: \$PIPE2CONTAINER"
164 # Open host-to-player pipe
165 exec 4<> "\$PIPE2PLAYER"
166 check_error \$? "Failed to open a named pipe: \$PIPE2PLAYER"
169 "${top_builddir}/gui/gnash" -r 0 -vv -F 3:4 "${swf}" > "\$LOGFILE" 2>&1 &
172 # Wait until the SWF code finish running, by loop-checking logfile
173 STARTCOUNTDOWN=\$READTIMEOUT
174 while [ \$STARTCOUNTDOWN -gt 0 ]
176 if grep "TRACE: ENDOFTEST" "\$LOGFILE" 2>&1 > /dev/null
181 STARTCOUNTDOWN=\`expr \$STARTCOUNTDOWN - 1\`
184 [ \$STARTCOUNTDOWN -ne 0 ]
185 check_equals \$? 0 "Gnash-side ActionScript code should be successfully run"
187 # Call string-returning GetVariable() on string variable
188 echo '<invoke name="GetVariable" returntype="xml"><arguments><string>string_variable</string></arguments></invoke>' >&4
190 # Read for value statement
191 read_timeout LINE \$READTIMEOUT <&3
192 check_equals "\$LINE" '<string>This is a string</string>' "Gnash should return a correct value from GetVariable call on string"
194 # Call string-returning GetVariable() on integer variable
195 echo '<invoke name="GetVariable" returntype="xml"><arguments><string>integer_variable</string></arguments></invoke>' >&4
197 # Read for return value statement
198 read_timeout LINE \$READTIMEOUT <&3
199 check_equals "\$LINE" '<string>9876</string>' "Gnash should return a correct value from GetVariable call on integer"
201 # Call string-returning GetVariable() on floating-point variable
202 echo '<invoke name="GetVariable" returntype="xml"><arguments><string>float_variable</string></arguments></invoke>' >&4
204 # Read for return value statement
205 read_timeout LINE \$READTIMEOUT <&3
206 check_equals "\$LINE" '<string>9876.5432</string>' "Gnash should return a correct value from GetVariable call on floating point"
208 # Call string-returning GetVariable() on positive infinite
209 # floating-point variable
210 echo '<invoke name="GetVariable" returntype="xml"><arguments><string>infinite_variable</string></arguments></invoke>' >&4
212 # Read for return value statement
213 read_timeout LINE \$READTIMEOUT <&3
214 check_equals "\$LINE" '<string>Infinity</string>' "Gnash should return a correct value from GetVariable call on infinity floating point"
216 # Call string-returning GetVariable() on negative infinite
217 # floating-point variable
218 echo '<invoke name="GetVariable" returntype="xml"><arguments><string>neginfinite_variable</string></arguments></invoke>' >&4
220 # Read for return value statement
221 read_timeout LINE \$READTIMEOUT <&3
222 check_equals "\$LINE" '<string>-Infinity</string>' "Gnash should return a correct value from GetVariable call on negative infinity floating point"
224 # Call string-returning GetVariable() on non-number floating-point variable
225 echo '<invoke name="GetVariable" returntype="xml"><arguments><string>nan_variable</string></arguments></invoke>' >&4
227 # Read for return value statement
228 read_timeout LINE \$READTIMEOUT <&3
229 check_equals "\$LINE" '<string>NaN</string>' "Gnash should return a correct value from GetVariable call on non-number floating point"
231 # Call string-returning GetVariable() on boolean variable
232 echo '<invoke name="GetVariable" returntype="xml"><arguments><string>boolean_variable</string></arguments></invoke>' >&4
234 # Read for return value statement
235 read_timeout LINE \$READTIMEOUT <&3
236 check_equals "\$LINE" '<string>true</string>' "Gnash should return a correct value from GetVariable call on boolean"
238 # Call string-returning GetVariable() on null variable
239 echo '<invoke name="GetVariable" returntype="xml"><arguments><string>null_variable</string></arguments></invoke>' >&4
241 # Read for return value statement
242 read_timeout LINE \$READTIMEOUT <&3
243 check_equals "\$LINE" '<string>null</string>' "Gnash should return a correct value from GetVariable call on null"
245 # Call string-returning GetVariable() on unassigned variable
246 echo '<invoke name="GetVariable" returntype="xml"><arguments><string>unassigned_variable</string></arguments></invoke>' >&4
248 # Read for return value statement
249 read_timeout LINE \$READTIMEOUT <&3
250 if [ "${swfversion}" -gt 6 ]
252 check_equals "\$LINE" '<string>undefined</string>' "Gnash should return a correct value from GetVariable call on unassigned variable"
254 check_equals "\$LINE" '<string></string>' "Gnash should return a correct value from GetVariable call on unassigned variable"
257 # Call string-returning GetVariable() on variable with undefined value
258 echo '<invoke name="GetVariable" returntype="xml"><arguments><string>undefined_variable</string></arguments></invoke>' >&4
260 # Read for return value statement
261 read_timeout LINE \$READTIMEOUT <&3
262 if [ "${swfversion}" -gt 6 ]
264 check_equals "\$LINE" '<string>undefined</string>' "Gnash should return a correct value from GetVariable call on variable with undefined value"
266 check_equals "\$LINE" '<string></string>' "Gnash should return a correct value from GetVariable call on variable with undefined value"
269 # Call string-returning GetVariable() on non-existent variable
270 echo '<invoke name="GetVariable" returntype="xml"><arguments><string>nonexistent_variable</string></arguments></invoke>' >&4
272 # Read for return value statement
273 read_timeout LINE \$READTIMEOUT <&3
274 check_equals "\$LINE" '<null/>' "Gnash should return a correct value from GetVariable call on non-existent variable"
276 # Call string-returning GetVariable() on string array variable
277 echo '<invoke name="GetVariable" returntype="xml"><arguments><string>array_variable</string></arguments></invoke>' >&4
279 # Read for return value statement
280 read_timeout LINE \$READTIMEOUT <&3
281 check_equals "\$LINE" '<string>The,quick,brown,fox,jumps,over,the,lazy,dog</string>' "Gnash should return a correct value from GetVariable call on array variable"
283 # Call string-returning GetVariable() on object variable
284 echo '<invoke name="GetVariable" returntype="xml"><arguments><string>object_variable</string></arguments></invoke>' >&4
286 # Read for return value statement
287 read_timeout LINE \$READTIMEOUT <&3
288 check_equals "\$LINE" '<string>[object Object]</string>' "Gnash should return a correct value from GetVariable call on object variable"
290 # Call string-returning GetVariable() on object variable
291 # with custom toString() method
292 echo '<invoke name="GetVariable" returntype="xml"><arguments><string>object_variable_customstring</string></arguments></invoke>' >&4
294 # Read for return value statement
295 read_timeout LINE \$READTIMEOUT <&3
296 check_equals "\$LINE" '<string>This is a custom Object.toString()</string>' "Gnash should return a correct value from GetVariable call on object variable with custom toString()"
298 # Call string-returning GetVariable() on function variable
299 echo '<invoke name="GetVariable" returntype="xml"><arguments><string>function_variable</string></arguments></invoke>' >&4
301 # Read for return value statement
302 read_timeout LINE \$READTIMEOUT <&3
303 check_equals "\$LINE" '<string>[type Function]</string>' "Gnash should return a correct value from GetVariable call on function variable"
309 # Force Gnash to exit
313 # Check for total number of test run
314 check_totals "16" "There should be 16 tests run"
316 # Remove temporary files
318 rm "\$PIPE2CONTAINER"