Skip to content

Commit

Permalink
reduce and document overlapped file package test
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeOsborn committed Feb 6, 2025
1 parent 1b9db86 commit 3e2760e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 29 deletions.
10 changes: 5 additions & 5 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1883,17 +1883,17 @@ def setup():

@also_with_wasmfs
def test_emscripten_overlapped_package(self):
# test that a program that loads multiple file_packager.py packages has a correctly initialized filesystem.
# this exercises https://github.com/emscripten-core/emscripten/issues/23602 whose root cause was a difference
# between JS FS and WASMFS behavior.
def setup():
create_file('script1.js', '''
Module._set(456);
''')
ensure_dir('sub')
create_file('sub/file1.txt', 'first')
create_file('sub/file2.txt', 'second')

setup()
self.run_process([FILE_PACKAGER, 'test.data', '--preload', 'sub/file1.txt@/target/file1.txt'], stdout=open('script2.js', 'w'))
self.run_process([FILE_PACKAGER, 'test2.data', '--preload', 'sub/file2.txt@/target/file2.txt'], stdout=open('script3.js', 'w'))
self.run_process([FILE_PACKAGER, 'test.data', '--preload', 'sub/file1.txt@/target/file1.txt'], stdout=open('script1.js', 'w'))
self.run_process([FILE_PACKAGER, 'test2.data', '--preload', 'sub/file2.txt@/target/file2.txt'], stdout=open('script2.js', 'w'))
self.btest_exit('test_emscripten_overlapped_package.c', args=['-sFORCE_FILESYSTEM'])
self.clear()

Expand Down
28 changes: 4 additions & 24 deletions test/test_emscripten_overlapped_package.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013 The Emscripten Authors. All rights reserved.
// Copyright 2025 The Emscripten Authors. All rights reserved.
// Emscripten is available under two separate licenses, the MIT license and the
// University of Illinois/NCSA Open Source License. Both these licenses can be
// found in the LICENSE file.
Expand All @@ -10,15 +10,11 @@

#include <emscripten.h>

int value = 0;

EMSCRIPTEN_KEEPALIVE void set(int x) {
printf("set! %d\n", x);
value = x;
void error2() {
printf("fail2\n");
}

void load3() {
printf("load3\n");
void load2() {
char buffer[10];
memset(buffer, 0, 10);
FILE *f = fopen("/target/file1.txt", "r");
Expand All @@ -34,25 +30,9 @@ void load3() {
fclose(f);
assert(strcmp(buffer, "second") == 0);
exit(0);
}

void error3() {
printf("fail3\n");
}

void error2() {
printf("fail2\n");
}

void load2() {
printf("load2\n");
emscripten_async_load_script("script3.js", load3, error3);
}

void load1() {
printf("load1\n");
assert(value == 456);

emscripten_async_load_script("script2.js", load2, error2);
}

Expand Down

0 comments on commit 3e2760e

Please sign in to comment.