Skip to content

Commit 8857416

Browse files
authored
Avoid using --proxy-to-worker in workerfs tests. NFC (emscripten-core#25816)
Instead just manually run the program in a new worker.
1 parent acb90da commit 8857416

File tree

4 files changed

+29
-30
lines changed

4 files changed

+29
-30
lines changed

test/browser_common.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -908,13 +908,17 @@ def btest(self, filename, expected=None,
908908
cflags=None,
909909
timeout=None,
910910
reporting=Reporting.FULL,
911+
run_in_worker=False,
911912
output_basename='test'):
912913
assert expected, 'a btest must have an expected output'
913914
if cflags is None:
914915
cflags = []
915916
cflags = cflags.copy()
916917
filename = find_browser_test_file(filename)
917-
outfile = output_basename + '.html'
918+
if run_in_worker:
919+
outfile = output_basename + '.js'
920+
else:
921+
outfile = output_basename + '.html'
918922
cflags += ['-o', outfile]
919923
# print('cflags:', cflags)
920924
utils.delete_file(outfile)
@@ -927,7 +931,15 @@ def btest(self, filename, expected=None,
927931
if EMTEST_BROWSER == 'node':
928932
nodejs = self.require_node()
929933
self.node_args += shared.node_pthread_flags(nodejs)
930-
output = self.run_js('test.js')
934+
output = self.run_js(f'{output_basename}.js')
931935
self.assertContained('RESULT: ' + expected[0], output)
932936
else:
933-
self.run_browser(outfile, expected=['/report_result?' + e for e in expected], timeout=timeout)
937+
html_file = outfile
938+
if run_in_worker:
939+
create_file('run_worker.html', f'''\
940+
<script>
941+
new Worker('{output_basename}.js');
942+
</script>
943+
''')
944+
html_file = 'run_worker.html'
945+
self.run_browser(html_file, expected=['/report_result?' + e for e in expected], timeout=timeout)

test/fs/test_workerfs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,13 @@ void test_readlink() {
9898
}
9999

100100
int main() {
101+
printf("in main\n");
101102
test_no_exist();
102103
test_blob_txt();
103104
test_file_txt();
104105
test_chmod();
105106
test_readdir();
106107
test_readlink();
108+
printf("done\n");
107109
return 0;
108110
}

test/fs/test_workerfs_package.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void EMSCRIPTEN_KEEPALIVE finish() {
3636

3737
// all done
3838
printf("success\n");
39-
REPORT_RESULT(1);
39+
REPORT_RESULT(0);
4040
}
4141

4242
int main() {
@@ -80,6 +80,6 @@ int main() {
8080

8181
emscripten_exit_with_live_runtime();
8282

83-
return 1;
83+
return 99;
8484
}
8585

test/test_browser.py

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,14 +1432,14 @@ def test_fs_workerfs(self):
14321432
}, '/work');
14331433
};
14341434
''')
1435-
self.btest_exit('fs/test_workerfs.c', cflags=['-lworkerfs.js', '--pre-js', 'pre.js', '--proxy-to-worker', '-Wno-deprecated', '-lworkerfs.js'])
1435+
self.btest_exit('fs/test_workerfs.c', cflags=['-lworkerfs.js', '--pre-js', 'pre.js'], run_in_worker=True)
14361436

14371437
def test_fs_workerfs_package(self):
14381438
create_file('file1.txt', 'first')
14391439
ensure_dir('sub')
14401440
create_file('sub/file2.txt', 'second')
14411441
self.run_process([FILE_PACKAGER, 'files.data', '--preload', 'file1.txt', 'sub/file2.txt', '--separate-metadata', '--js-output=files.js'])
1442-
self.btest('fs/test_workerfs_package.c', '1', cflags=['-lworkerfs.js', '--proxy-to-worker', '-Wno-deprecated', '-lworkerfs.js'])
1442+
self.btest('fs/test_workerfs_package.c', '0', cflags=['-lworkerfs.js'], run_in_worker=True)
14431443

14441444
def test_fs_lz4fs_package(self):
14451445
# generate data
@@ -1691,8 +1691,7 @@ def test_mmap_lazyfile(self):
16911691
FS.createLazyFile('/', "lazy.txt", "lazydata.dat", true, false);
16921692
}
16931693
''')
1694-
self.cflags += ['--pre-js=pre.js', '--proxy-to-worker', '-Wno-deprecated']
1695-
self.btest_exit('test_mmap_lazyfile.c')
1694+
self.btest_exit('test_mmap_lazyfile.c', cflags=['--pre-js=pre.js'], run_in_worker=True)
16961695

16971696
@no_wasmfs('https://github.com/emscripten-core/emscripten/issues/19608')
16981697
@no_firefox('keeps sending OPTIONS requests, and eventually errors')
@@ -3634,8 +3633,8 @@ def test_dlopen_blocking(self):
36343633
# verify that dynamic linking works in all kinds of in-browser environments.
36353634
# don't mix different kinds in a single test.
36363635
@parameterized({
3637-
'': (0,),
3638-
'inworker': (1,),
3636+
'': (False,),
3637+
'inworker': (True,),
36393638
})
36403639
def test_dylink_dso_needed(self, inworker):
36413640
if not inworker:
@@ -3669,10 +3668,7 @@ def do_run(src, expected_output, cflags):
36693668
return rtn;
36703669
}
36713670
''' % expected_output)
3672-
# --proxy-to-worker only when linking the main module
3673-
if inworker:
3674-
cflags += ['--proxy-to-worker', '-Wno-deprecated']
3675-
self.btest_exit('test_dylink_dso_needed.c', cflags=['--post-js', 'post.js'] + cflags)
3671+
self.btest_exit('test_dylink_dso_needed.c', cflags=['--post-js', 'post.js'] + cflags, run_in_worker=inworker)
36763672

36773673
self._test_dylink_dso_needed(do_run)
36783674

@@ -4651,12 +4647,12 @@ def test_fetch_sync(self):
46514647
shutil.copy(test_file('gears.png'), '.')
46524648
self.btest_exit('fetch/test_fetch_sync.c', cflags=['-sFETCH', '-pthread', '-sPROXY_TO_PTHREAD'])
46534649

4654-
# Tests that the Fetch API works for synchronous XHRs when used with --proxy-to-worker.
4650+
# Tests that the Fetch API works for synchronous XHRs when program is run in a worker
46554651
@no_firefox('https://github.com/emscripten-core/emscripten/issues/16868')
46564652
@also_with_wasm2js
46574653
def test_fetch_sync_xhr_in_proxy_to_worker(self):
46584654
shutil.copy(test_file('gears.png'), '.')
4659-
self.btest_exit('fetch/test_fetch_sync_xhr.cpp', cflags=['-sFETCH_DEBUG', '-sFETCH', '--proxy-to-worker', '-Wno-deprecated'])
4655+
self.btest_exit('fetch/test_fetch_sync_xhr.cpp', cflags=['-sFETCH_DEBUG', '-sFETCH'], run_in_worker=True)
46604656

46614657
@disabled('https://github.com/emscripten-core/emscripten/issues/16746')
46624658
def test_fetch_idb_store(self):
@@ -4914,11 +4910,7 @@ def test_single_file_locate_file(self):
49144910

49154911
# Tests that SINGLE_FILE works as intended in a Worker in JS output
49164912
def test_single_file_worker_js(self):
4917-
self.compile_btest('browser_test_hello_world.c', ['-o', 'test.js', '--proxy-to-worker', '-Wno-deprecated', '-sSINGLE_FILE'])
4918-
create_file('test.html', '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"></head><body><script src="test.js"></script></body></html>')
4919-
self.run_browser('test.html', '/report_result?0')
4920-
self.assertExists('test.js')
4921-
self.assertNotExists('test.worker.js')
4913+
self.btest_exit('browser_test_hello_world.c', cflags=['-sSINGLE_FILE'], run_in_worker=True)
49224914

49234915
# Tests that pthreads code works as intended in a Worker. That is, a pthreads-using
49244916
# program can run either on the main thread (normal tests) or when we start it in
@@ -4929,14 +4921,7 @@ def test_single_file_worker_js(self):
49294921
'limited_env': (['-sENVIRONMENT=worker'],),
49304922
})
49314923
def test_pthreads_started_in_worker(self, args):
4932-
self.set_setting('EXIT_RUNTIME')
4933-
self.compile_btest('pthread/test_pthread_atomics.c', ['-o', 'test.js', '-pthread', '-sPTHREAD_POOL_SIZE=8'] + args, reporting=Reporting.JS_ONLY)
4934-
create_file('test.html', '''
4935-
<script>
4936-
new Worker('test.js');
4937-
</script>
4938-
''')
4939-
self.run_browser('test.html', '/report_result?exit:0')
4924+
self.btest_exit('pthread/test_pthread_atomics.c', cflags=['-o', 'test.js', '-pthread', '-sPTHREAD_POOL_SIZE=8'] + args, run_in_worker=True)
49404925

49414926
def test_access_file_after_heap_resize(self):
49424927
create_file('test.txt', 'hello from file')

0 commit comments

Comments
 (0)