1- #!/usr/bin/env python
1+ #!/usr/bin/env python3
22#
33# Copyright 2015 WebAssembly Community Group participants
44#
1919import subprocess
2020import sys
2121
22- from scripts .test .support import run_command , split_wast , node_test_glue , node_has_webassembly
22+ from scripts .test .support import run_command , split_wast , write_wast , node_test_glue , node_has_webassembly
2323from scripts .test .shared import (
2424 ASM2WASM , MOZJS , NODEJS , WASM_OPT , WASM_AS , WASM_DIS ,
2525 WASM_CTOR_EVAL , WASM_REDUCE , WASM_METADCE , BINARYEN_INSTALL_DIR ,
3030
3131
3232def update_asm_js_tests ():
33- print '[ processing and updating testcases... ]\n '
33+ print ( '[ processing and updating testcases... ]\n ' )
3434 for asm in sorted (os .listdir ('test' )):
3535 if asm .endswith ('.asm.js' ):
3636 for precise in [0 , 1 , 2 ]:
@@ -57,15 +57,15 @@ def update_asm_js_tests():
5757 cmd += ['--no-legalize-javascript-ffi' ]
5858 if precise and opts :
5959 # test mem init importing
60- open ('a.mem' , 'wb' ).write (asm )
60+ open ('a.mem' , 'wb' ).write (bytes ( asm , 'utf-8' ) )
6161 cmd += ['--mem-init=a.mem' ]
6262 if asm [0 ] == 'e' :
6363 cmd += ['--mem-base=1024' ]
6464 if '4GB' in asm :
6565 cmd += ['--mem-max=4294967296' ]
6666 if 'i64' in asm or 'wasm-only' in asm or 'noffi' in asm :
6767 cmd += ['--wasm-only' ]
68- print ' ' .join (cmd )
68+ print ( ' ' .join (cmd ) )
6969 actual = run_command (cmd )
7070 with open (os .path .join ('test' , wasm ), 'w' ) as o :
7171 o .write (actual )
@@ -75,33 +75,33 @@ def update_asm_js_tests():
7575
7676
7777def update_wasm_opt_tests ():
78- print '\n [ checking wasm-opt -o notation... ]\n '
78+ print ( '\n [ checking wasm-opt -o notation... ]\n ' )
7979 wast = os .path .join ('test' , 'hello_world.wast' )
8080 cmd = WASM_OPT + [wast , '-o' , 'a.wast' , '-S' ]
8181 run_command (cmd )
8282 open (wast , 'w' ).write (open ('a.wast' ).read ())
8383
84- print '\n [ checking wasm-opt parsing & printing... ]\n '
84+ print ( '\n [ checking wasm-opt parsing & printing... ]\n ' )
8585 for t in sorted (os .listdir (os .path .join ('test' , 'print' ))):
8686 if t .endswith ('.wast' ):
87- print '..' , t
87+ print ( '..' , t )
8888 wasm = os .path .basename (t ).replace ('.wast' , '' )
8989 cmd = WASM_OPT + [os .path .join ('test' , 'print' , t ), '--print' , '-all' ]
90- print ' ' , ' ' .join (cmd )
90+ print ( ' ' , ' ' .join (cmd ) )
9191 actual = subprocess .check_output (cmd )
92- print cmd , actual
93- with open (os .path .join ('test' , 'print' , wasm + '.txt' ), 'w ' ) as o :
92+ print ( cmd , actual )
93+ with open (os .path .join ('test' , 'print' , wasm + '.txt' ), 'wb ' ) as o :
9494 o .write (actual )
9595 cmd = WASM_OPT + [os .path .join ('test' , 'print' , t ), '--print-minified' , '-all' ]
96- print ' ' , ' ' .join (cmd )
96+ print ( ' ' , ' ' .join (cmd ) )
9797 actual = subprocess .check_output (cmd )
98- with open (os .path .join ('test' , 'print' , wasm + '.minified.txt' ), 'w ' ) as o :
98+ with open (os .path .join ('test' , 'print' , wasm + '.minified.txt' ), 'wb ' ) as o :
9999 o .write (actual )
100100
101- print '\n [ checking wasm-opt passes... ]\n '
101+ print ( '\n [ checking wasm-opt passes... ]\n ' )
102102 for t in sorted (os .listdir (os .path .join ('test' , 'passes' ))):
103103 if t .endswith (('.wast' , '.wasm' )):
104- print '..' , t
104+ print ( '..' , t )
105105 binary = '.wasm' in t
106106 base = os .path .basename (t ).replace ('.wast' , '' ).replace ('.wasm' , '' )
107107 passname = base
@@ -112,8 +112,7 @@ def update_wasm_opt_tests():
112112 actual = ''
113113 for module , asserts in split_wast (t ):
114114 assert len (asserts ) == 0
115- with open ('split.wast' , 'w' ) as o :
116- o .write (module )
115+ write_wast ('split.wast' , module )
117116 cmd = WASM_OPT + opts + ['split.wast' , '--print' ]
118117 actual += run_command (cmd )
119118 with open (os .path .join ('test' , 'passes' , base + ('.bin' if binary else '' ) + '.txt' ), 'w' ) as o :
@@ -127,21 +126,21 @@ def update_wasm_opt_tests():
127126 with open (t + '.wat' , 'w' ) as o :
128127 o .write (i .read ())
129128
130- print '\n [ checking wasm-opt testcases... ]\n '
129+ print ( '\n [ checking wasm-opt testcases... ]\n ' )
131130 for t in os .listdir ('test' ):
132131 if t .endswith ('.wast' ) and not t .startswith ('spec' ):
133- print '..' , t
132+ print ( '..' , t )
134133 t = os .path .join ('test' , t )
135134 f = t + '.from-wast'
136135 cmd = WASM_OPT + [t , '--print' , '-all' ]
137136 actual = run_command (cmd )
138137 actual = actual .replace ('printing before:\n ' , '' )
139138 open (f , 'w' ).write (actual )
140139
141- print '\n [ checking wasm-opt debugInfo read-write... ]\n '
140+ print ( '\n [ checking wasm-opt debugInfo read-write... ]\n ' )
142141 for t in os .listdir ('test' ):
143142 if t .endswith ('.fromasm' ) and 'debugInfo' in t :
144- print '..' , t
143+ print ( '..' , t )
145144 t = os .path .join ('test' , t )
146145 f = t + '.read-written'
147146 run_command (WASM_AS + [t , '--source-map=a.map' , '-o' , 'a.wasm' , '-g' ])
@@ -151,21 +150,21 @@ def update_wasm_opt_tests():
151150
152151
153152def update_bin_fmt_tests ():
154- print '\n [ checking binary format testcases... ]\n '
153+ print ( '\n [ checking binary format testcases... ]\n ' )
155154 for wast in sorted (os .listdir ('test' )):
156155 if wast .endswith ('.wast' ) and wast not in []: # blacklist some known failures
157156 for debug_info in [0 , 1 ]:
158157 cmd = WASM_AS + [os .path .join ('test' , wast ), '-o' , 'a.wasm' , '-all' ]
159158 if debug_info :
160159 cmd += ['-g' ]
161- print ' ' .join (cmd )
160+ print ( ' ' .join (cmd ) )
162161 if os .path .exists ('a.wasm' ):
163162 os .unlink ('a.wasm' )
164163 subprocess .check_call (cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
165164 assert os .path .exists ('a.wasm' )
166165
167166 cmd = WASM_DIS + ['a.wasm' , '-o' , 'a.wast' ]
168- print ' ' .join (cmd )
167+ print ( ' ' .join (cmd ) )
169168 if os .path .exists ('a.wast' ):
170169 os .unlink ('a.wast' )
171170 subprocess .check_call (cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
@@ -179,7 +178,7 @@ def update_bin_fmt_tests():
179178
180179
181180def update_example_tests ():
182- print '\n [ checking example testcases... ]\n '
181+ print ( '\n [ checking example testcases... ]\n ' )
183182 for t in sorted (os .listdir (os .path .join ('test' , 'example' ))):
184183 output_file = os .path .join (options .binaryen_bin , 'example' )
185184 libdir = os .path .join (BINARYEN_INSTALL_DIR , 'lib' )
@@ -188,11 +187,11 @@ def update_example_tests():
188187 # check if there is a trace in the file, if so, we should build it
189188 out = subprocess .Popen ([os .path .join ('scripts' , 'clean_c_api_trace.py' ), os .path .join ('test' , 'example' , t )], stdout = subprocess .PIPE ).communicate ()[0 ]
190189 if len (out ) == 0 :
191- print ' (no trace in ' , t , ')'
190+ print ( ' (no trace in ' , t , ')' )
192191 continue
193- print ' (will check trace in ' , t , ')'
192+ print ( ' (will check trace in ' , t , ')' )
194193 src = 'trace.cpp'
195- with open (src , 'w ' ) as o :
194+ with open (src , 'wb ' ) as o :
196195 o .write (out )
197196 expected = os .path .join ('test' , 'example' , t + '.txt' )
198197 else :
@@ -204,26 +203,26 @@ def update_example_tests():
204203 extra = [os .environ .get ('CC' ) or 'gcc' ,
205204 src , '-c' , '-o' , 'example.o' ,
206205 '-Isrc' , '-g' , '-L' + libdir , '-pthread' ]
207- print 'build: ' , ' ' .join (extra )
206+ print ( 'build: ' , ' ' .join (extra ) )
208207 if src .endswith ('.cpp' ):
209208 extra += ['-std=c++11' ]
210- print os .getcwd ()
209+ print ( os .getcwd () )
211210 subprocess .check_call (extra )
212211 # Link against the binaryen C library DSO, using rpath
213212 cmd = ['example.o' , '-L' + libdir , '-lbinaryen' , '-Wl,-rpath,' + os .path .abspath (libdir )] + cmd
214- print ' ' , t , src , expected
213+ print ( ' ' , t , src , expected )
215214 if os .environ .get ('COMPILER_FLAGS' ):
216215 for f in os .environ .get ('COMPILER_FLAGS' ).split (' ' ):
217216 cmd .append (f )
218217 cmd = [os .environ .get ('CXX' ) or 'g++' , '-std=c++11' ] + cmd
219218 try :
220- print 'link: ' , ' ' .join (cmd )
219+ print ( 'link: ' , ' ' .join (cmd ) )
221220 subprocess .check_call (cmd )
222- print 'run...' , output_file
221+ print ( 'run...' , output_file )
223222 proc = subprocess .Popen ([output_file ], stdout = subprocess .PIPE , stderr = subprocess .PIPE )
224223 actual , err = proc .communicate ()
225224 assert proc .returncode == 0 , [proc .returncode , actual , err ]
226- with open (expected , 'w ' ) as o :
225+ with open (expected , 'wb ' ) as o :
227226 o .write (actual )
228227 finally :
229228 os .remove (output_file )
@@ -233,10 +232,10 @@ def update_example_tests():
233232
234233
235234def update_wasm_dis_tests ():
236- print '\n [ checking wasm-dis on provided binaries... ]\n '
235+ print ( '\n [ checking wasm-dis on provided binaries... ]\n ' )
237236 for t in os .listdir ('test' ):
238237 if t .endswith ('.wasm' ) and not t .startswith ('spec' ):
239- print '..' , t
238+ print ( '..' , t )
240239 t = os .path .join ('test' , t )
241240 cmd = WASM_DIS + [t ]
242241 if os .path .isfile (t + '.map' ):
@@ -248,19 +247,19 @@ def update_wasm_dis_tests():
248247
249248def update_binaryen_js_tests ():
250249 if not (MOZJS or NODEJS ):
251- print 'no vm to run binaryen.js tests'
250+ print ( 'no vm to run binaryen.js tests' )
252251 return
253252
254253 if not os .path .exists (BINARYEN_JS ):
255- print 'no binaryen.js build to test'
254+ print ( 'no binaryen.js build to test' )
256255 return
257256
258- print '\n [ checking binaryen.js testcases... ]\n '
257+ print ( '\n [ checking binaryen.js testcases... ]\n ' )
259258 node_has_wasm = NODEJS and node_has_webassembly (NODEJS )
260259 for s in sorted (os .listdir (os .path .join ('test' , 'binaryen.js' ))):
261260 if not s .endswith ('.js' ):
262261 continue
263- print s
262+ print ( s )
264263 f = open ('a.js' , 'w' )
265264 f .write (open (BINARYEN_JS ).read ())
266265 if NODEJS :
@@ -279,14 +278,14 @@ def update_binaryen_js_tests():
279278 with open (os .path .join ('test' , 'binaryen.js' , s + '.txt' ), 'w' ) as o :
280279 o .write (out )
281280 else :
282- print 'Skipping ' + test_path + ' because WebAssembly might not be supported'
281+ print ( 'Skipping ' + test_path + ' because WebAssembly might not be supported' )
283282
284283
285284def update_ctor_eval_tests ():
286- print '\n [ checking wasm-ctor-eval... ]\n '
285+ print ( '\n [ checking wasm-ctor-eval... ]\n ' )
287286 for t in os .listdir (os .path .join ('test' , 'ctor-eval' )):
288287 if t .endswith (('.wast' , '.wasm' )):
289- print '..' , t
288+ print ( '..' , t )
290289 t = os .path .join ('test' , 'ctor-eval' , t )
291290 ctors = open (t + '.ctors' ).read ().strip ()
292291 cmd = WASM_CTOR_EVAL + [t , '-o' , 'a.wast' , '-S' , '--ctors' , ctors ]
@@ -298,10 +297,10 @@ def update_ctor_eval_tests():
298297
299298
300299def update_metadce_tests ():
301- print '\n [ checking wasm-metadce... ]\n '
300+ print ( '\n [ checking wasm-metadce... ]\n ' )
302301 for t in os .listdir (os .path .join ('test' , 'metadce' )):
303302 if t .endswith (('.wast' , '.wasm' )):
304- print '..' , t
303+ print ( '..' , t )
305304 t = os .path .join ('test' , 'metadce' , t )
306305 graph = t + '.graph.txt'
307306 cmd = WASM_METADCE + [t , '--graph-file=' + graph , '-o' , 'a.wast' , '-S' ]
@@ -317,14 +316,14 @@ def update_metadce_tests():
317316def update_reduce_tests ():
318317 if not has_shell_timeout ():
319318 return
320- print '\n [ checking wasm-reduce ]\n '
319+ print ( '\n [ checking wasm-reduce ]\n ' )
321320 for t in os .listdir (os .path .join ('test' , 'reduce' )):
322321 if t .endswith ('.wast' ):
323- print '..' , t
322+ print ( '..' , t )
324323 t = os .path .join ('test' , 'reduce' , t )
325324 # convert to wasm
326325 run_command (WASM_AS + [t , '-o' , 'a.wasm' ])
327- print run_command (WASM_REDUCE + ['a.wasm' , '--command=%s b.wasm --fuzz-exec' % WASM_OPT [0 ], '-t' , 'b.wasm' , '-w' , 'c.wasm' ])
326+ print ( run_command (WASM_REDUCE + ['a.wasm' , '--command=%s b.wasm --fuzz-exec' % WASM_OPT [0 ], '-t' , 'b.wasm' , '-w' , 'c.wasm' ]) )
328327 expected = t + '.txt'
329328 run_command (WASM_DIS + ['c.wasm' , '-o' , expected ])
330329
@@ -342,7 +341,7 @@ def main():
342341 update_reduce_tests ()
343342 update_binaryen_js_tests ()
344343
345- print '\n [ success! ]'
344+ print ( '\n [ success! ]' )
346345
347346
348347if __name__ == '__main__' :
0 commit comments