Skip to content

Commit c333383

Browse files
committed
Adapt test runner to memory initializer strings
The assumption that “-O2” implies “--memory-init-file 1” only holds unless overridden. Since we now have a whole test run where this is not the case, we need to take such an override into account. Refactored existing code into a resuable method. The assumption that “'/*' not in src” implies “cleaned-up sources with no comments” is no longer true, since we may well have a literal “/*” inside the memory initializer string. In fact we have just this for several existing test cases, e.g. fnmatch or strings. I dropped that assertion altogether, since properly fixing it felt more complex (and therefore less reliable) than the thing it's supposed to test for.
1 parent ee31c97 commit c333383

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

tests/runner.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ def skipme(self): # used by tests we ask on the commandline to be skipped, see r
6161
def is_emterpreter(self):
6262
return False
6363

64+
def uses_memory_init_file(self):
65+
if self.emcc_args is None:
66+
return None
67+
elif '--memory-init-file' in self.emcc_args:
68+
return int(self.emcc_args[self.emcc_args.index('--memory-init-file')+1])
69+
else:
70+
return ('-O2' in self.emcc_args or '-O3' in self.emcc_args or '-Oz' in self.emcc_args) and not Settings.SIDE_MODULE
71+
6472
def setUp(self):
6573
Settings.reset()
6674
self.banned_js_engines = []
@@ -251,16 +259,10 @@ def build(self, src, dirname, filename, output_processor=None, main_file=None, a
251259
output_processor(open(filename + '.o.js').read())
252260

253261
if self.emcc_args is not None:
254-
if '--memory-init-file' in self.emcc_args:
255-
memory_init_file = int(self.emcc_args[self.emcc_args.index('--memory-init-file')+1])
256-
else:
257-
memory_init_file = ('-O2' in self.emcc_args or '-O3' in self.emcc_args or '-Oz' in self.emcc_args) and not Settings.SIDE_MODULE
258262
src = open(filename + '.o.js').read()
259-
if memory_init_file:
263+
if self.uses_memory_init_file():
260264
# side memory init file, or an empty one in the js
261265
assert ('/* memory initializer */' not in src) or ('/* memory initializer */ allocate([]' in src)
262-
else:
263-
assert 'memory initializer */' in src or '/*' not in src # memory initializer comment, or cleaned-up source with no comments
264266

265267
def validate_asmjs(self, err):
266268
if 'uccessfully compiled asm.js code' in err and 'asm.js link error' not in err:

tests/test_core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4549,7 +4549,7 @@ def process(filename):
45494549
try_delete(mem_file)
45504550
self.do_run(src, ('size: 7\ndata: 100,-56,50,25,10,77,123\nloop: 100 -56 50 25 10 77 123 \ninput:hi there!\ntexto\n$\n5 : 10,30,20,11,88\nother=some data.\nseeked=me da.\nseeked=ata.\nseeked=ta.\nfscanfed: 10 - hello\n5 bytes to dev/null: 5\nok.\n \ntexte\n', 'size: 7\ndata: 100,-56,50,25,10,77,123\nloop: 100 -56 50 25 10 77 123 \ninput:hi there!\ntexto\ntexte\n$\n5 : 10,30,20,11,88\nother=some data.\nseeked=me da.\nseeked=ata.\nseeked=ta.\nfscanfed: 10 - hello\n5 bytes to dev/null: 5\nok.\n'),
45514551
post_build=post, extra_emscripten_args=['-H', 'libc/fcntl.h'])
4552-
if '-O2' in self.emcc_args:
4552+
if self.uses_memory_init_file():
45534553
assert os.path.exists(mem_file)
45544554

45554555
def test_files_m(self):

0 commit comments

Comments
 (0)