Skip to content

Commit

Permalink
[test] Add new decorators for running tests under different FS backen…
Browse files Browse the repository at this point in the history
…ds (#23177)

- @with_all_fs
- @also_with_nodefs
- @also_with_nodefs_both
  • Loading branch information
sbc100 authored Dec 17, 2024
1 parent 6fa576b commit c17479b
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 145 deletions.
1 change: 1 addition & 0 deletions src/polyfill/atob.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

if (typeof atob == 'undefined') {
if (typeof global != 'undefined' && typeof globalThis == 'undefined') {
/** @suppress{checkTypes} */
globalThis = global;
}

Expand Down
87 changes: 81 additions & 6 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,15 +379,78 @@ def metafunc(self, wasmfs, *args, **kwargs):
if DEBUG:
print('parameterize:wasmfs=%d' % wasmfs)
if wasmfs:
self.set_setting('WASMFS')
self.emcc_args.append('-DWASMFS')
self.setup_wasmfs_test()
else:
self.emcc_args += ['-DMEMFS']
f(self, *args, **kwargs)

parameterize(metafunc, {'': (False,),
'wasmfs': (True,)})
return metafunc


def also_with_nodefs(func):
@wraps(func)
def metafunc(self, fs, *args, **kwargs):
if DEBUG:
print('parameterize:fs=%s' % (fs))
if fs == 'nodefs':
self.setup_nodefs_test()
else:
self.emcc_args += ['-DMEMFS']
assert fs is None
func(self, *args, **kwargs)

parameterize(metafunc, {'': (None,),
'nodefs': ('nodefs',)})
return metafunc


def also_with_nodefs_both(func):
@wraps(func)
def metafunc(self, fs, *args, **kwargs):
if DEBUG:
print('parameterize:fs=%s' % (fs))
if fs == 'nodefs':
self.setup_nodefs_test()
elif fs == 'rawfs':
self.setup_noderawfs_test()
else:
self.emcc_args += ['-DMEMFS']
assert fs is None
func(self, *args, **kwargs)

parameterize(metafunc, {'': (None,),
'nodefs': ('nodefs',),
'rawfs': ('rawfs',)})
return metafunc


def with_all_fs(func):
@wraps(func)
def metafunc(self, fs, *args, **kwargs):
if DEBUG:
print('parameterize:fs=%s' % (fs))
if fs == 'nodefs':
self.setup_nodefs_test()
elif fs == 'rawfs':
self.setup_noderawfs_test()
elif fs == 'wasmfs':
self.setup_wasmfs_test()
else:
self.emcc_args += ['-DMEMFS']
assert fs is None
func(self, *args, **kwargs)

# TODO(sbc): rather than treat WASMFS as orthogonal we should
# probably make it combinatorial with nodefs and noderawfs.
parameterize(metafunc, {'': (None,),
'nodefs': ('nodefs',),
'rawfs': ('rawfs',),
'wasmfs': ('wasmfs',)})
return metafunc


def also_with_noderawfs(func):
assert callable(func)

Expand All @@ -396,9 +459,9 @@ def metafunc(self, rawfs, *args, **kwargs):
if DEBUG:
print('parameterize:rawfs=%d' % rawfs)
if rawfs:
self.require_node()
self.emcc_args += ['-DNODERAWFS']
self.set_setting('NODERAWFS')
self.setup_noderawfs_test()
else:
self.emcc_args += ['-DMEMFS']
func(self, *args, **kwargs)

parameterize(metafunc, {'': (False,),
Expand Down Expand Up @@ -1025,7 +1088,19 @@ def require_wasm2js(self):

def setup_nodefs_test(self):
self.require_node()
self.emcc_args += ['-lnodefs.js', '--pre-js', test_file('setup_nodefs.js')]
if self.get_setting('WASMFS'):
# without this the JS setup code in setup_nodefs.js doesn't work
self.set_setting('FORCE_FILESYSTEM')
self.emcc_args += ['-DNODEFS', '-lnodefs.js', '--pre-js', test_file('setup_nodefs.js')]

def setup_noderawfs_test(self):
self.require_node()
self.emcc_args += ['-DNODERAWFS']
self.set_setting('NODERAWFS')

def setup_wasmfs_test(self):
self.set_setting('WASMFS')
self.emcc_args += ['-DWASMFS']

def setup_node_pthreads(self):
self.require_node()
Expand Down
Loading

0 comments on commit c17479b

Please sign in to comment.