Skip to content

Commit 7aecdda

Browse files
authored
Parameterize more browser tests. NFC (#20894)
1 parent 0d9ec2a commit 7aecdda

File tree

1 file changed

+87
-48
lines changed

1 file changed

+87
-48
lines changed

test/test_browser.py

Lines changed: 87 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4256,21 +4256,26 @@ def test_pthread_custom_pthread_main_url(self):
42564256
delete_file('test.worker.js')
42574257
self.run_browser('test2.html', '/report_result?exit:0')
42584258

4259-
# Test that if the main thread is performing a futex wait while a pthread needs it to do a proxied operation (before that pthread would wake up the main thread), that it's not a deadlock.
4259+
# Test that if the main thread is performing a futex wait while a pthread
4260+
# needs it to do a proxied operation (before that pthread would wake up the
4261+
# main thread), that it's not a deadlock.
42604262
@requires_threads
42614263
def test_pthread_proxying_in_futex_wait(self):
42624264
self.btest_exit('pthread/test_pthread_proxying_in_futex_wait.cpp', args=['-O3', '-pthread', '-sPTHREAD_POOL_SIZE'])
42634265

42644266
# Test that sbrk() operates properly in multithreaded conditions
42654267
@requires_threads
4266-
def test_pthread_sbrk(self):
4267-
for aborting_malloc in [0, 1]:
4268-
print('aborting malloc=' + str(aborting_malloc))
4269-
# With aborting malloc = 1, test allocating memory in threads
4270-
# With aborting malloc = 0, allocate so much memory in threads that some of the allocations fail.
4271-
self.btest_exit('pthread/test_pthread_sbrk.cpp', args=['-O3', '-pthread', '-sPTHREAD_POOL_SIZE=8', '-sABORTING_MALLOC=' + str(aborting_malloc), '-DABORTING_MALLOC=' + str(aborting_malloc), '-sINITIAL_MEMORY=128MB'])
4268+
@parameterized({
4269+
'': (['-DABORTING_MALLOC=0', '-sABORTING_MALLOC=0'],),
4270+
'aborting_malloc': (['-DABORTING_MALLOC=1'],),
4271+
})
4272+
def test_pthread_sbrk(self, args):
4273+
# With aborting malloc = 1, test allocating memory in threads
4274+
# With aborting malloc = 0, allocate so much memory in threads that some of the allocations fail.
4275+
self.btest_exit('pthread/test_pthread_sbrk.cpp', args=['-O3', '-pthread', '-sPTHREAD_POOL_SIZE=8', '-sINITIAL_MEMORY=128MB'] + args)
42724276

4273-
# Test that -sABORTING_MALLOC=0 works in both pthreads and non-pthreads builds. (sbrk fails gracefully)
4277+
# Test that -sABORTING_MALLOC=0 works in both pthreads and non-pthreads
4278+
# builds. (sbrk fails gracefully)
42744279
@parameterized({
42754280
'': ([],),
42764281
'mt': (['-pthread'],),
@@ -4280,7 +4285,8 @@ def test_pthread_gauge_available_memory(self, args):
42804285
for opts in [[], ['-O2']]:
42814286
self.btest('gauge_available_memory.cpp', expected='1', args=['-sABORTING_MALLOC=0'] + args + opts)
42824287

4283-
# Test that the proxying operations of user code from pthreads to main thread work
4288+
# Test that the proxying operations of user code from pthreads to main thread
4289+
# work
42844290
@disabled('https://github.com/emscripten-core/emscripten/issues/18210')
42854291
@requires_threads
42864292
def test_pthread_run_on_main_thread(self):
@@ -4291,27 +4297,31 @@ def test_pthread_run_on_main_thread(self):
42914297
def test_pthread_run_on_main_thread_flood(self):
42924298
self.btest_exit('pthread/test_pthread_run_on_main_thread_flood.cpp', args=['-O3', '-pthread', '-sPTHREAD_POOL_SIZE'])
42934299

4294-
# Test that it is possible to asynchronously call a JavaScript function on the main thread.
4300+
# Test that it is possible to asynchronously call a JavaScript function on the
4301+
# main thread.
42954302
@requires_threads
42964303
def test_pthread_call_async(self):
42974304
self.btest_exit('pthread/call_async.c', args=['-pthread'])
42984305

4299-
# Test that it is possible to synchronously call a JavaScript function on the main thread and get a return value back.
4306+
# Test that it is possible to synchronously call a JavaScript function on the
4307+
# main thread and get a return value back.
43004308
@requires_threads
43014309
def test_pthread_call_sync_on_main_thread(self):
43024310
self.set_setting('EXPORTED_FUNCTIONS', '_main,_malloc')
43034311
self.btest_exit('pthread/call_sync_on_main_thread.c', args=['-O3', '-pthread', '-sPROXY_TO_PTHREAD', '-DPROXY_TO_PTHREAD=1', '--js-library', test_file('pthread/call_sync_on_main_thread.js')])
43044312
self.btest_exit('pthread/call_sync_on_main_thread.c', args=['-O3', '-pthread', '-DPROXY_TO_PTHREAD=0', '--js-library', test_file('pthread/call_sync_on_main_thread.js')])
43054313
self.btest_exit('pthread/call_sync_on_main_thread.c', args=['-Oz', '-DPROXY_TO_PTHREAD=0', '--js-library', test_file('pthread/call_sync_on_main_thread.js')])
43064314

4307-
# Test that it is possible to asynchronously call a JavaScript function on the main thread.
4315+
# Test that it is possible to asynchronously call a JavaScript function on the
4316+
# main thread.
43084317
@requires_threads
43094318
def test_pthread_call_async_on_main_thread(self):
43104319
self.btest('pthread/call_async_on_main_thread.c', expected='7', args=['-O3', '-pthread', '-sPROXY_TO_PTHREAD', '-DPROXY_TO_PTHREAD=1', '--js-library', test_file('pthread/call_async_on_main_thread.js')])
43114320
self.btest('pthread/call_async_on_main_thread.c', expected='7', args=['-O3', '-pthread', '-DPROXY_TO_PTHREAD=0', '--js-library', test_file('pthread/call_async_on_main_thread.js')])
43124321
self.btest('pthread/call_async_on_main_thread.c', expected='7', args=['-Oz', '-DPROXY_TO_PTHREAD=0', '--js-library', test_file('pthread/call_async_on_main_thread.js')])
43134322

4314-
# Tests that spawning a new thread does not cause a reinitialization of the global data section of the application memory area.
4323+
# Tests that spawning a new thread does not cause a reinitialization of the
4324+
# global data section of the application memory area.
43154325
@requires_threads
43164326
def test_pthread_global_data_initialization(self):
43174327
# --memory-init-file mode disabled because WASM=0 does not seem to work with EXPORT_NAME
@@ -4332,7 +4342,9 @@ def test_pthread_global_data_initialization_in_sync_compilation_mode(self):
43324342
args = ['-sWASM_ASYNC_COMPILATION=0']
43334343
self.btest_exit('pthread/test_pthread_global_data_initialization.c', args=args + mem_init_mode + ['-pthread', '-sPROXY_TO_PTHREAD', '-sPTHREAD_POOL_SIZE'])
43344344

4335-
# Test that emscripten_get_now() reports coherent wallclock times across all pthreads, instead of each pthread independently reporting wallclock times since the launch of that pthread.
4345+
# Test that emscripten_get_now() reports coherent wallclock times across all
4346+
# pthreads, instead of each pthread independently reporting wallclock times
4347+
# since the launch of that pthread.
43364348
@requires_threads
43374349
def test_pthread_clock_drift(self):
43384350
self.btest_exit('pthread/test_pthread_clock_drift.cpp', args=['-O3', '-pthread', '-sPROXY_TO_PTHREAD'])
@@ -4341,7 +4353,8 @@ def test_pthread_clock_drift(self):
43414353
def test_pthread_utf8_funcs(self):
43424354
self.btest_exit('pthread/test_pthread_utf8_funcs.cpp', args=['-pthread', '-sPTHREAD_POOL_SIZE'])
43434355

4344-
# Test the emscripten_futex_wake(addr, INT_MAX); functionality to wake all waiters
4356+
# Test the emscripten_futex_wake(addr, INT_MAX); functionality to wake all
4357+
# waiters
43454358
@also_with_wasm2js
43464359
@requires_threads
43474360
def test_pthread_wake_all(self):
@@ -4605,8 +4618,10 @@ def test_small_js_flags(self):
46054618
if not self.is_wasm64():
46064619
self.assertLess(abs(size - 4800), 100)
46074620

4608-
# Tests that it is possible to initialize and render WebGL content in a pthread by using OffscreenCanvas.
4609-
# -DTEST_CHAINED_WEBGL_CONTEXT_PASSING: Tests that it is possible to transfer WebGL canvas in a chain from main thread -> thread 1 -> thread 2 and then init and render WebGL content there.
4621+
# Tests that it is possible to initialize and render WebGL content in a
4622+
# pthread by using OffscreenCanvas. -DTEST_CHAINED_WEBGL_CONTEXT_PASSING:
4623+
# Tests that it is possible to transfer WebGL canvas in a chain from main
4624+
# thread -> thread 1 -> thread 2 and then init and render WebGL content there.
46104625
@no_chrome('see https://crbug.com/961765')
46114626
@parameterized({
46124627
'': ([],),
@@ -4618,8 +4633,11 @@ def test_small_js_flags(self):
46184633
def test_webgl_offscreen_canvas_in_pthread(self, args):
46194634
self.btest('gl_in_pthread.cpp', expected='1', args=args + ['-pthread', '-sPTHREAD_POOL_SIZE=2', '-sOFFSCREENCANVAS_SUPPORT', '-lGL'])
46204635

4621-
# Tests that it is possible to render WebGL content on a <canvas> on the main thread, after it has once been used to render WebGL content in a pthread first
4622-
# -DTEST_MAIN_THREAD_EXPLICIT_COMMIT: Test the same (WebGL on main thread after pthread), but by using explicit .commit() to swap on the main thread instead of implicit "swap when rAF ends" logic
4636+
# Tests that it is possible to render WebGL content on a <canvas> on the main
4637+
# thread, after it has once been used to render WebGL content in a pthread
4638+
# first -DTEST_MAIN_THREAD_EXPLICIT_COMMIT: Test the same (WebGL on main
4639+
# thread after pthread), but by using explicit .commit() to swap on the main
4640+
# thread instead of implicit "swap when rAF ends" logic
46234641
@parameterized({
46244642
'': ([],),
46254643
'explicit': (['-DTEST_MAIN_THREAD_EXPLICIT_COMMIT'],),
@@ -4698,12 +4716,15 @@ def test_webgl_timer_query(self, args):
46984716
'': ([],),
46994717
'threads': (['-pthread', '-sPROXY_TO_PTHREAD'],)
47004718
})
4701-
def test_webgl_offscreen_framebuffer(self, threads):
4719+
@parameterized({
4720+
'v1': ([],),
4721+
'v2': (['-sFULL_ES2'],),
4722+
'v3': (['-sFULL_ES3'],),
4723+
})
4724+
def test_webgl_offscreen_framebuffer(self, version, threads):
47024725
# Tests all the different possible versions of libgl
4703-
for version in [[], ['-sFULL_ES3'], ['-sFULL_ES3']]:
4704-
args = ['-lGL', '-sOFFSCREEN_FRAMEBUFFER', '-DEXPLICIT_SWAP=1'] + threads + version
4705-
print('with args: %s' % str(args))
4706-
self.btest_exit('webgl_draw_triangle.c', args=args)
4726+
args = ['-lGL', '-sOFFSCREEN_FRAMEBUFFER', '-DEXPLICIT_SWAP=1'] + threads + version
4727+
self.btest_exit('webgl_draw_triangle.c', args=args)
47074728

47084729
# Tests that VAOs can be used even if WebGL enableExtensionsByDefault is set to 0.
47094730
@requires_graphics_hardware
@@ -4739,9 +4760,16 @@ def test_webgl_workaround_webgl_uniform_upload_bug(self):
47394760
def test_webgl_array_of_structs_uniform(self):
47404761
self.btest('webgl_array_of_structs_uniform.c', args=['-lGL', '-sMAX_WEBGL_VERSION=2'], reference='browser/webgl_array_of_structs_uniform.png')
47414762

4742-
# Tests that if a WebGL context is created in a pthread on a canvas that has not been transferred to that pthread, WebGL calls are then proxied to the main thread
4743-
# -DTEST_OFFSCREEN_CANVAS=1: Tests that if a WebGL context is created on a pthread that has the canvas transferred to it via using Emscripten's EMSCRIPTEN_PTHREAD_TRANSFERRED_CANVASES="#canvas", then OffscreenCanvas is used
4744-
# -DTEST_OFFSCREEN_CANVAS=2: Tests that if a WebGL context is created on a pthread that has the canvas transferred to it via automatic transferring of Module.canvas when EMSCRIPTEN_PTHREAD_TRANSFERRED_CANVASES is not defined, then OffscreenCanvas is also used
4763+
# Tests that if a WebGL context is created in a pthread on a canvas that has
4764+
# not been transferred to that pthread, WebGL calls are then proxied to the
4765+
# main thread -DTEST_OFFSCREEN_CANVAS=1: Tests that if a WebGL context is
4766+
# created on a pthread that has the canvas transferred to it via using
4767+
# Emscripten's EMSCRIPTEN_PTHREAD_TRANSFERRED_CANVASES="#canvas", then
4768+
# OffscreenCanvas is used -DTEST_OFFSCREEN_CANVAS=2: Tests that if a WebGL
4769+
# context is created on a pthread that has the canvas transferred to it via
4770+
# automatic transferring of Module.canvas when
4771+
# EMSCRIPTEN_PTHREAD_TRANSFERRED_CANVASES is not defined, then OffscreenCanvas
4772+
# is also used
47454773
@parameterized({
47464774
'': ([False],),
47474775
'asyncify': ([True],),
@@ -4750,38 +4778,49 @@ def test_webgl_array_of_structs_uniform(self):
47504778
@requires_offscreen_canvas
47514779
@requires_graphics_hardware
47524780
def test_webgl_offscreen_canvas_in_proxied_pthread(self, asyncify):
4753-
cmd = ['-pthread', '-sOFFSCREENCANVAS_SUPPORT', '-lGL', '-sGL_DEBUG', '-sPROXY_TO_PTHREAD']
4781+
args = ['-pthread', '-sOFFSCREENCANVAS_SUPPORT', '-lGL', '-sGL_DEBUG', '-sPROXY_TO_PTHREAD']
47544782
if asyncify:
47554783
# given the synchronous render loop here, asyncify is needed to see intermediate frames and
47564784
# the gradual color change
4757-
cmd += ['-sASYNCIFY', '-DASYNCIFY']
4758-
print(str(cmd))
4759-
self.btest_exit('gl_in_proxy_pthread.cpp', args=cmd)
4785+
args += ['-sASYNCIFY', '-DASYNCIFY']
4786+
self.btest_exit('gl_in_proxy_pthread.cpp', args=args)
47604787

47614788
@parameterized({
4789+
'': ([],),
47624790
'proxy': (['-sPROXY_TO_PTHREAD'],),
4791+
})
4792+
@parameterized({
4793+
'': ([],),
4794+
'blocking': (['-DTEST_SYNC_BLOCKING_LOOP=1'],),
4795+
})
4796+
@parameterized({
47634797
'': ([],),
4798+
'offscreen': (['-sOFFSCREENCANVAS_SUPPORT', '-sOFFSCREEN_FRAMEBUFFER'],),
47644799
})
47654800
@requires_threads
47664801
@requires_graphics_hardware
47674802
@requires_offscreen_canvas
4768-
def test_webgl_resize_offscreencanvas_from_main_thread(self, args):
4769-
for args2 in [[], ['-DTEST_SYNC_BLOCKING_LOOP=1']]:
4770-
for args3 in [[], ['-sOFFSCREENCANVAS_SUPPORT', '-sOFFSCREEN_FRAMEBUFFER']]:
4771-
cmd = args + args2 + args3 + ['-pthread', '-lGL', '-sGL_DEBUG']
4772-
print(str(cmd))
4773-
self.btest_exit('resize_offscreencanvas_from_main_thread.cpp', args=cmd)
4774-
4775-
@requires_graphics_hardware
4776-
def test_webgl_simple_enable_extensions(self):
4777-
for webgl_version in [1, 2]:
4778-
for simple_enable_extensions in [0, 1]:
4779-
cmd = ['-DWEBGL_CONTEXT_VERSION=' + str(webgl_version),
4780-
'-DWEBGL_SIMPLE_ENABLE_EXTENSION=' + str(simple_enable_extensions),
4781-
'-sMAX_WEBGL_VERSION=2',
4782-
'-sGL_SUPPORT_AUTOMATIC_ENABLE_EXTENSIONS=' + str(simple_enable_extensions),
4783-
'-sGL_SUPPORT_SIMPLE_ENABLE_EXTENSIONS=' + str(simple_enable_extensions)]
4784-
self.btest_exit('webgl2_simple_enable_extensions.c', args=cmd)
4803+
def test_webgl_resize_offscreencanvas_from_main_thread(self, args1, args2, args3):
4804+
cmd = args1 + args2 + args3 + ['-pthread', '-lGL', '-sGL_DEBUG']
4805+
print(str(cmd))
4806+
self.btest_exit('resize_offscreencanvas_from_main_thread.cpp', args=cmd)
4807+
4808+
@requires_graphics_hardware
4809+
@parameterized({
4810+
'v1': (1,),
4811+
'v2': (2,),
4812+
})
4813+
@parameterized({
4814+
'enable': (1,),
4815+
'disable': (0,),
4816+
})
4817+
def test_webgl_simple_extensions(self, simple_enable_extensions, webgl_version):
4818+
cmd = ['-DWEBGL_CONTEXT_VERSION=' + str(webgl_version),
4819+
'-DWEBGL_SIMPLE_ENABLE_EXTENSION=' + str(simple_enable_extensions),
4820+
'-sMAX_WEBGL_VERSION=2',
4821+
'-sGL_SUPPORT_AUTOMATIC_ENABLE_EXTENSIONS=' + str(simple_enable_extensions),
4822+
'-sGL_SUPPORT_SIMPLE_ENABLE_EXTENSIONS=' + str(simple_enable_extensions)]
4823+
self.btest_exit('webgl2_simple_enable_extensions.c', args=cmd)
47854824

47864825
@parameterized({
47874826
'': ([],),

0 commit comments

Comments
 (0)