From b3103ef956667f353db5a9e36dc09e51d5a99d85 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Sat, 14 Dec 2024 08:53:54 -0800 Subject: [PATCH] Unify code for setting up nodefs tests. NFC --- test/common.py | 4 +++ test/fs/test_fs_rename_on_existing.c | 37 ++++---------------- test/fs/test_fs_symlink_resolution.c | 8 ----- test/fs/test_mmap.c | 42 ++++++++++------------- test/fs/test_mmap.out | 10 +++--- test/fs/test_nodefs_cloexec.c | 27 ++++----------- test/fs/test_nodefs_dup.c | 50 ++++++++++++---------------- test/fs/test_nodefs_rw.c | 21 ++---------- test/other/alias/main.c | 44 +++++++++++------------- test/setup_nodefs.js | 6 ++++ test/stdio/test_fgetc_ungetc.c | 15 ++------- test/test_core.py | 43 +++++++++++++----------- test/test_other.py | 15 ++++----- test/unistd/access.c | 5 --- test/unistd/misc.c | 10 ++---- test/unistd/truncate.c | 26 --------------- test/unistd/unlink.c | 12 ++----- 17 files changed, 127 insertions(+), 248 deletions(-) create mode 100644 test/setup_nodefs.js diff --git a/test/common.py b/test/common.py index ecb50a93f243a..8ff05424e146f 100644 --- a/test/common.py +++ b/test/common.py @@ -1023,6 +1023,10 @@ def require_wasm2js(self): if self.is_2gb() or self.is_4gb(): self.skipTest('wasm2js does not support over 2gb of memory') + def setup_nodefs_test(self): + self.require_node() + self.emcc_args += ['-lnodefs.js', '--pre-js', test_file('setup_nodefs.js')] + def setup_node_pthreads(self): self.require_node() self.emcc_args += ['-Wno-pthreads-mem-growth', '-pthread'] diff --git a/test/fs/test_fs_rename_on_existing.c b/test/fs/test_fs_rename_on_existing.c index 8c32bc3ed1b49..c6113f87dcc69 100644 --- a/test/fs/test_fs_rename_on_existing.c +++ b/test/fs/test_fs_rename_on_existing.c @@ -8,21 +8,6 @@ #include #include - -#if defined(__EMSCRIPTEN__) -#include -#endif - -void makedir(const char *dir) { - int rtn = mkdir(dir, 0777); - assert(rtn == 0); -} - -void changedir(const char *dir) { - int rtn = chdir(dir); - assert(rtn == 0); -} - static void create_file(const char *path, const char *buffer) { printf("creating: %s\n", path); int fd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0666); @@ -35,21 +20,11 @@ static void create_file(const char *path, const char *buffer) { close(fd); } - -void setup() { -#if defined(__EMSCRIPTEN__) && defined(NODEFS) - makedir("working"); - EM_ASM(FS.mount(NODEFS, { root: '.' }, 'working')); - changedir("working"); -#endif -} - int main() { - setup(); - create_file("a", "abc"); - create_file("b", "xyz"); - assert(rename("a", "b") == 0); - assert(unlink("b") == 0); - create_file("b", "xyz"); - printf("success\n"); + create_file("a", "abc"); + create_file("b", "xyz"); + assert(rename("a", "b") == 0); + assert(unlink("b") == 0); + create_file("b", "xyz"); + printf("success\n"); } diff --git a/test/fs/test_fs_symlink_resolution.c b/test/fs/test_fs_symlink_resolution.c index 1c6d88c63a6ec..9ef6756652234 100644 --- a/test/fs/test_fs_symlink_resolution.c +++ b/test/fs/test_fs_symlink_resolution.c @@ -6,9 +6,6 @@ #include #include #include -#if defined(__EMSCRIPTEN__) -#include "emscripten.h" -#endif void makedir(const char *dir) { int rtn = mkdir(dir, 0777); @@ -29,11 +26,6 @@ static void create_file(const char *path) { } void setup() { -#if defined(__EMSCRIPTEN__) && defined(NODEFS) - makedir("working"); - EM_ASM(FS.mount(NODEFS, { root: '.' }, 'working')); - changedir("working"); -#endif makedir("a"); makedir("b"); makedir("b/c"); diff --git a/test/fs/test_mmap.c b/test/fs/test_mmap.c index 5d3927d8a4fd6..1968485fda19e 100644 --- a/test/fs/test_mmap.c +++ b/test/fs/test_mmap.c @@ -19,16 +19,16 @@ void test_mmap_read() { // Use mmap to read in.txt - EM_ASM(FS.writeFile('yolo/in.txt', 'mmap ftw!')); + EM_ASM(FS.writeFile('in.txt', 'mmap ftw!')); - int fd = open("yolo/in.txt", O_RDONLY); + int fd = open("in.txt", O_RDONLY); assert(fd >= 0); int filesize = 9; char* map = (char*)mmap(NULL, filesize, PROT_READ, MAP_PRIVATE, fd, 0); assert(map != MAP_FAILED); - printf("yolo/in.txt content="); + printf("in.txt content="); for (int i = 0; i < filesize; i++) { printf("%c", map[i]); } @@ -42,7 +42,7 @@ void test_mmap_read() { void test_mmap_write() { // Use mmap to write out.txt - int fd = open("yolo/out.txt", O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600); + int fd = open("out.txt", O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600); assert(fd >= 0); const char* text = "written mmap"; @@ -64,12 +64,12 @@ void test_mmap_write() { close(fd); { - FILE* fd = fopen("yolo/out.txt", "r"); + FILE* fd = fopen("out.txt", "r"); assert(fd >= 0); char buffer[15]; memset(buffer, 0, 15); fread(buffer, 1, 14, fd); - printf("yolo/out.txt content=%s\n", buffer); + printf("out.txt content=%s\n", buffer); fclose(fd); } } @@ -79,7 +79,7 @@ void test_mmap_readonly() { // but make sure it's not overwritten on munmap const char* readonlytext = "readonly mmap\0"; const char* text = "write mmap\0"; - const char* path = "yolo/outreadonly.txt"; + const char* path = "outreadonly.txt"; size_t readonlytextsize = strlen(readonlytext); size_t textsize = strlen(text); @@ -102,18 +102,18 @@ void test_mmap_readonly() { close(fd); { - FILE* fd = fopen("yolo/outreadonly.txt", "r"); + FILE* fd = fopen("outreadonly.txt", "r"); assert(fd >= 0); char buffer[16]; memset(buffer, 0, 16); fread(buffer, 1, 15, fd); - printf("yolo/outreadonly.txt content=%s\n", buffer); + printf("outreadonly.txt content=%s\n", buffer); fclose(fd); } } void test_mmap_private() { - int fd = open("yolo/private.txt", O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600); + int fd = open("private.txt", O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600); assert(fd >= 0); const char* text = "written mmap"; @@ -135,18 +135,18 @@ void test_mmap_private() { close(fd); { - FILE* fd = fopen("yolo/private.txt", "r"); + FILE* fd = fopen("private.txt", "r"); assert(fd >= 0); char buffer[15]; memset(buffer, 0, 15); fread(buffer, 1, 14, fd); - printf("yolo/private.txt content=%s\n", buffer); + printf("private.txt content=%s\n", buffer); fclose(fd); } } void test_mmap_shared_with_offset() { - int fd = open("yolo/sharedoffset.txt", O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600); + int fd = open("sharedoffset.txt", O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600); assert(fd > 0); const char* text = "written shared mmap with offset"; @@ -176,7 +176,7 @@ void test_mmap_shared_with_offset() { close(fd); { - FILE* fd = fopen("yolo/sharedoffset.txt", "r"); + FILE* fd = fopen("sharedoffset.txt", "r"); assert(fd >= 0); size_t offset = sysconf(_SC_PAGE_SIZE) * 2; @@ -185,14 +185,14 @@ void test_mmap_shared_with_offset() { fseek(fd, offset, SEEK_SET); fread(buffer, 1, 32, fd); // expect text written from mmap operation to appear at offset in the file - printf("yolo/sharedoffset.txt content=%s %zu\n", buffer, offset); + printf("sharedoffset.txt content=%s %zu\n", buffer, offset); fclose(fd); } } void test_mmap_hint() { // mmap with a address is expected to fail - int fd = open("yolo/private.txt", O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600); + int fd = open("private.txt", O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600); assert(fd != -1); size_t map_size = 1 << 16; @@ -225,7 +225,7 @@ void test_mmap_hint() { */ void test_mmap_overallocate() { #if !defined(NODEFS) && !defined(NODERAWFS) && !defined(WASMFS) - int fd = open("yolo/overallocatedfile.txt", O_RDWR | O_CREAT, (mode_t)0600); + int fd = open("overallocatedfile.txt", O_RDWR | O_CREAT, (mode_t)0600); assert(fd != -1); const size_t textsize = 33; @@ -236,7 +236,7 @@ void test_mmap_overallocate() { } EM_ASM({ - const stream = FS.streams.find(stream => stream.path.indexOf('yolo/overallocatedfile.txt') >= 0); + const stream = FS.streams.find(stream => stream.path.indexOf('overallocatedfile.txt') >= 0); assert(stream.node.usedBytes === Number($0), 'Used bytes on the over-allocated file (' + stream.node.usedBytes + ') ' + 'should be ' + $0 @@ -264,12 +264,6 @@ void test_mmap_overallocate() { } int main() { - EM_ASM( - FS.mkdir('yolo'); -#if NODEFS - FS.mount(NODEFS, { root: '.' }, 'yolo'); -#endif - ); test_mmap_read(); test_mmap_write(); test_mmap_readonly(); diff --git a/test/fs/test_mmap.out b/test/fs/test_mmap.out index ee49ac9d3f560..b5da67362363d 100644 --- a/test/fs/test_mmap.out +++ b/test/fs/test_mmap.out @@ -1,5 +1,5 @@ -yolo/in.txt content=mmap ftw! -yolo/out.txt content=written mmap -yolo/outreadonly.txt content=readonly mmap -yolo/private.txt content= -yolo/sharedoffset.txt content=written shared mmap with offset 131072 +in.txt content=mmap ftw! +out.txt content=written mmap +outreadonly.txt content=readonly mmap +private.txt content= +sharedoffset.txt content=written shared mmap with offset 131072 diff --git a/test/fs/test_nodefs_cloexec.c b/test/fs/test_nodefs_cloexec.c index 45f7ff62936cf..e4a969e7f5eb8 100644 --- a/test/fs/test_nodefs_cloexec.c +++ b/test/fs/test_nodefs_cloexec.c @@ -11,24 +11,11 @@ #include #include -#ifdef NODERAWFS -#define CWD "" -#else -#define CWD "/working/" -#endif - -int main(void) -{ - EM_ASM( -#ifdef NODERAWFS - FS.close(FS.open('test.txt', 'w')); -#else - FS.mkdir('/working'); - FS.mount(NODEFS, {root: '.'}, '/working'); - FS.close(FS.open('/working/test.txt', 'w')); -#endif - ); - assert(open(CWD "test.txt", O_RDONLY | O_CLOEXEC) != -1); - printf("success\n"); - return 0; +int main(void) { + EM_ASM( + FS.close(FS.open('test.txt', 'w')); + ); + assert(open("test.txt", O_RDONLY | O_CLOEXEC) != -1); + printf("success\n"); + return 0; } diff --git a/test/fs/test_nodefs_dup.c b/test/fs/test_nodefs_dup.c index abf34935b11c3..f21cc8e43ba9f 100644 --- a/test/fs/test_nodefs_dup.c +++ b/test/fs/test_nodefs_dup.c @@ -11,35 +11,27 @@ #include #include -#ifdef NODERAWFS -#define CWD "" -#else -#define CWD "/working/" -#endif +int main(void) { + EM_ASM( + FS.close(FS.open('test.txt', 'w')); + ); -int main(void) -{ - EM_ASM( -#ifdef NODERAWFS - FS.close(FS.open('test.txt', 'w')); -#else - FS.mkdir('/working'); - FS.mount(NODEFS, {root: '.'}, '/working'); - FS.close(FS.open('/working/test.txt', 'w')); -#endif - ); - int fd1 = open(CWD "test.txt", O_WRONLY); - int fd2 = dup(fd1); - int fd3 = fcntl(fd1, F_DUPFD_CLOEXEC, 0); + int fd = open("test.txt", O_CREAT, 0444); + assert(fd > 0); + close(fd); - assert(fd1 == 3); - assert(fd2 == 4); - assert(fd3 == 5); - assert(close(fd1) == 0); - assert(write(fd2, "abcdef", 6) == 6); - assert(close(fd2) == 0); - assert(write(fd3, "ghijkl", 6) == 6); - assert(close(fd3) == 0); - printf("success\n"); - return 0; + int fd1 = open("test.txt", O_WRONLY); + int fd2 = dup(fd1); + int fd3 = fcntl(fd1, F_DUPFD_CLOEXEC, 0); + + assert(fd1 == 3); + assert(fd2 == 4); + assert(fd3 == 5); + assert(close(fd1) == 0); + assert(write(fd2, "abcdef", 6) == 6); + assert(close(fd2) == 0); + assert(write(fd3, "ghijkl", 6) == 6); + assert(close(fd3) == 0); + printf("success\n"); + return 0; } diff --git a/test/fs/test_nodefs_rw.c b/test/fs/test_nodefs_rw.c index e6221fec1a15d..48cebcba932ff 100644 --- a/test/fs/test_nodefs_rw.c +++ b/test/fs/test_nodefs_rw.c @@ -11,12 +11,6 @@ #include #include -#ifdef NODERAWFS -#define CWD "" -#else -#define CWD "/working/" -#endif - int main() { FILE *file; int res; @@ -28,17 +22,8 @@ int main() { fs.writeFileSync('foobar.txt', 'yeehaw'); ); -#ifndef NODERAWFS - // mount the current folder as a NODEFS instance - // inside of emscripten - EM_ASM( - FS.mkdir('/working'); - FS.mount(NODEFS, { root: '.' }, '/working'); - ); -#endif - // read and validate the contents of the file - file = fopen(CWD "foobar.txt", "r"); + file = fopen("foobar.txt", "r"); assert(file); res = fread(buffer, sizeof(char), 6, file); assert(res == 6); @@ -49,7 +34,7 @@ int main() { assert(!strcmp(buffer, "yeehaw")); // write out something new - file = fopen(CWD "foobar.txt", "w"); + file = fopen("foobar.txt", "w"); assert(file); res = fwrite("cheez", sizeof(char), 5, file); assert(res == 5); @@ -62,7 +47,7 @@ int main() { assert(contents === 'cheez'); ); - file = fopen(CWD "csfsq", "r"); + file = fopen("csfsq", "r"); assert(file == NULL); assert(errno == ENOENT); diff --git a/test/other/alias/main.c b/test/other/alias/main.c index ff59a398f2d6a..958767b4464e4 100644 --- a/test/other/alias/main.c +++ b/test/other/alias/main.c @@ -10,33 +10,29 @@ #include int bar(void) { - return 42; + return 42; } int foo(void) __attribute__((alias("bar"))); -int main() -{ - EM_ASM({ - FS.mkdir('/working'); - FS.mount(NODEFS, { root: '.' }, '/working'); - }); - void *handle = dlopen("/working/side.wasm", RTLD_NOW); - if (!handle) { - printf("dlopen failed: %s", dlerror()); - return 1; - } +int main() { + void *handle = dlopen("side.wasm", RTLD_NOW); + if (!handle) { + printf("dlopen failed: %s", dlerror()); + return 1; + } - typedef int (*func_type)(void); - func_type exportedfn = (func_type)dlsym(handle, "callAlias"); - if (!exportedfn) { - const char *err = dlerror(); - printf("ERROR: dlsym failed: for callAlias: %s", err); - return 1; - } - if (exportedfn() != 42) - return 1; - dlclose(handle); - printf("success\n"); - return 0; + typedef int (*func_type)(void); + func_type exportedfn = (func_type)dlsym(handle, "callAlias"); + if (!exportedfn) { + const char *err = dlerror(); + printf("ERROR: dlsym failed: for callAlias: %s", err); + return 1; + } + if (exportedfn() != 42) { + return 1; + } + dlclose(handle); + printf("success\n"); + return 0; } diff --git a/test/setup_nodefs.js b/test/setup_nodefs.js new file mode 100644 index 0000000000000..5d1c38dd7898c --- /dev/null +++ b/test/setup_nodefs.js @@ -0,0 +1,6 @@ +Module['onRuntimeInitialized'] = () => { + out('mounting node filesystem under /nodefs'); + FS.mkdir('/nodefs'); + FS.mount(NODEFS, { root: '.' }, '/nodefs'); + FS.chdir('/nodefs'); +}; diff --git a/test/stdio/test_fgetc_ungetc.c b/test/stdio/test_fgetc_ungetc.c index afa90bcda67a5..e67087e416fb6 100644 --- a/test/stdio/test_fgetc_ungetc.c +++ b/test/stdio/test_fgetc_ungetc.c @@ -12,10 +12,6 @@ #include #include -#ifdef __EMSCRIPTEN__ -#include -#endif - static void create_file(const char *path, const char *buffer, int mode) { int fd = open(path, O_WRONLY | O_CREAT | O_EXCL, mode); assert(fd >= 0); @@ -27,7 +23,7 @@ static void create_file(const char *path, const char *buffer, int mode) { } void setup() { - create_file("/tmp/file.txt", "cd", 0666); + create_file("file.txt", "cd", 0666); } void test() { @@ -35,7 +31,7 @@ void test() { int err; char buffer[256]; - file = fopen("/tmp/file.txt", "r"); + file = fopen("file.txt", "r"); assert(file); // pushing EOF always returns EOF @@ -88,13 +84,6 @@ void test() { } int main() { -#ifdef __EMSCRIPTEN__ -#ifdef NODEFS - EM_ASM(FS.mount(NODEFS, { root: '.' }, '/tmp')); -#elif MEMFS - EM_ASM(FS.mount(MEMFS, {}, '/tmp')); -#endif -#endif setup(); test(); return 0; diff --git a/test/test_core.py b/test/test_core.py index d3fff94c5a8ec..6685b5a89918a 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -4920,7 +4920,7 @@ def test_dylink_hyper_dupe(self): @requires_node def test_dylink_load_compiled_side_module(self): self.set_setting('FORCE_FILESYSTEM') - self.emcc_args.append('-lnodefs.js') + self.setup_nodefs_test() if not self.has_changed_setting('INITIAL_MEMORY'): self.set_setting('INITIAL_MEMORY', '64mb') # This test loads the module at runtime with loadWebAssemblyModule so we @@ -4934,9 +4934,7 @@ def test_dylink_load_compiled_side_module(self): extern int sidef(); int main() { EM_ASM({ - FS.mkdir('/working'); - FS.mount(NODEFS, { root: '.' }, '/working'); - var libData = FS.readFile('/working/liblib.so', {encoding: 'binary'}); + var libData = FS.readFile('liblib.so', {encoding: 'binary'}); if (!(libData instanceof Uint8Array)) { libData = new Uint8Array(libData); } @@ -4950,8 +4948,7 @@ def test_dylink_load_compiled_side_module(self): side=r''' #include int sidef() { return 10; } - ''', - expected=['sidef: 10']) + ''', expected=['sidef: 10']) @needs_dylink def test_dylink_dso_needed(self): @@ -5417,8 +5414,7 @@ def test_fgetc_ungetc(self, fs): print('TODO: update this test once the musl ungetc-on-EOF-stream bug is fixed upstream and reaches us') self.emcc_args += ['-D' + fs] if fs == 'NODEFS': - self.require_node() - self.emcc_args += ['-lnodefs.js'] + self.setup_nodefs_test() self.do_runf('stdio/test_fgetc_ungetc.c', 'success') def test_fgetc_unsigned(self): @@ -5680,7 +5676,8 @@ def test_fs_base(self): @is_slow_test @requires_node def test_fs_nodefs_rw(self): - self.emcc_args += ['-lnodefs.js'] + if not self.get_setting('NODERAWFS'): + self.setup_nodefs_test() self.set_setting('SYSCALL_DEBUG') self.do_runf('fs/test_nodefs_rw.c', 'success') if self.maybe_closure(): @@ -5691,7 +5688,8 @@ def test_fs_nodefs_rw(self): def test_fs_nodefs_cloexec(self): if self.get_setting('WASMFS'): self.set_setting('FORCE_FILESYSTEM') - self.emcc_args += ['-lnodefs.js'] + if not self.get_setting('NODERAWFS'): + self.setup_nodefs_test() self.do_runf('fs/test_nodefs_cloexec.c', 'success') @also_with_noderawfs @@ -5699,7 +5697,8 @@ def test_fs_nodefs_cloexec(self): def test_fs_nodefs_dup(self): if self.get_setting('WASMFS'): self.set_setting('FORCE_FILESYSTEM') - self.emcc_args += ['-lnodefs.js'] + if not self.get_setting('NODERAWFS'): + self.setup_nodefs_test() self.do_runf('fs/test_nodefs_dup.c', 'success') @requires_node @@ -5789,15 +5788,14 @@ def test_fs_append(self): self.do_runf('fs/test_append.c', 'success') @parameterized({ - 'memfs': ['MEMFS'], + '': ['MEMFS'], 'nodefs': ['NODEFS'], 'noderaswfs': ['NODERAWFS'], 'wasmfs': ['WASMFS'] }) def test_fs_mmap(self, fs): if fs == 'NODEFS': - self.require_node() - self.emcc_args += ['-lnodefs.js'] + self.setup_nodefs_test() if fs == 'NODERAWFS': self.require_node() self.emcc_args += ['-lnodefs.js', '-lnoderawfs.js'] @@ -5888,6 +5886,8 @@ def test_fs_symlink_resolution(self, args): if nodefs: self.skipTest('NODEFS in WasmFS') self.set_setting('FORCE_FILESYSTEM') + if '-DNODEFS' in args: + self.setup_nodefs_test() self.do_runf('fs/test_fs_symlink_resolution.c', 'success', emcc_args=args) @parameterized({ @@ -5898,12 +5898,13 @@ def test_fs_symlink_resolution(self, args): def test_fs_rename_on_existing(self, args): if self.get_setting('WASMFS'): self.set_setting('FORCE_FILESYSTEM') + if '-DNODEFS' in args: + self.setup_nodefs_test() self.do_runf('fs/test_fs_rename_on_existing.c', 'success', emcc_args=args) def test_sigalrm(self): self.do_runf('test_sigalrm.c', 'Received alarm!') - self.set_setting('EXIT_RUNTIME') - self.do_runf('test_sigalrm.c', 'Received alarm!') + self.do_runf('test_sigalrm.c', 'Received alarm!', emcc_args=['-sEXIT_RUNTIME']) def test_signals(self): self.do_core_test('test_signals.c') @@ -5938,6 +5939,8 @@ def test_unistd_access(self, args): if nodefs: self.skipTest('NODEFS in WasmFS') self.emcc_args += ['-sFORCE_FILESYSTEM'] + if '-DNODEFS' in args: + self.setup_nodefs_test() # On windows we have slighly different output because we the same # level of permissions are not available. For example, on windows # its not possible have a file that is not readable, but writable. @@ -5982,8 +5985,7 @@ def test_unistd_truncate(self, fs): self.skipTest('TODO: NODEFS in WasmFS') self.emcc_args += ['-sFORCE_FILESYSTEM'] if fs == 'NODEFS': - self.emcc_args += ['-lnodefs.js'] - self.require_node() + self.setup_nodefs_test() self.do_run_in_out_file_test('unistd/truncate.c') @no_windows("Windows throws EPERM rather than EACCES or EINVAL") @@ -6047,6 +6049,8 @@ def test_unistd_unlink(self, fs): # 0 if root user if os.geteuid() == 0: self.emcc_args += ['-DSKIP_ACCESS_TESTS'] + if fs == 'NODEFS': + self.setup_nodefs_test() self.do_runf('unistd/unlink.c', 'success') @@ -6107,8 +6111,7 @@ def test_unistd_io(self): def test_unistd_misc(self, fs): self.emcc_args += ['-D' + fs] if fs == 'NODEFS': - self.require_node() - self.emcc_args += ['-lnodefs.js'] + self.setup_nodefs_test() self.do_run_in_out_file_test('unistd/misc.c', interleaved_output=False) @also_with_standalone_wasm() diff --git a/test/test_other.py b/test/test_other.py index 0b827f6aad0b5..def3e5a460f0a 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -9015,7 +9015,7 @@ def test_export_aliasee(self): self.run_process(cmd) # build main module - args = ['-g', '-sEXPORTED_FUNCTIONS=_main,_foo', '-sMAIN_MODULE=2', '-lnodefs.js'] + args = ['-g', '-sEXPORTED_FUNCTIONS=_main,_foo', '-sMAIN_MODULE=2', '-sNODERAWFS'] cmd = [EMCC, test_file('other/alias/main.c'), '-o', 'main.js'] + args print(' '.join(cmd)) self.run_process(cmd) @@ -14783,10 +14783,8 @@ def test_windows_nodefs_execution_permission(self): void setup() { EM_ASM( - FS.mkdir('/working'); - FS.mount(NODEFS, { root: '.' }, '/working'); - FS.mkdir('/working/new-dir'); - FS.writeFile('/working/new-dir/test.txt', 'test'); + FS.mkdir('new-dir'); + FS.writeFile('new-dir/test.txt', 'test'); ); } @@ -14794,13 +14792,13 @@ def test_windows_nodefs_execution_permission(self): int err; struct stat s; memset(&s, 0, sizeof(s)); - err = stat("/working/new-dir", &s); + err = stat("new-dir", &s); assert(S_ISDIR(s.st_mode)); assert(s.st_mode & S_IXUSR); assert(s.st_mode & S_IXGRP); assert(s.st_mode & S_IXOTH); - err = stat("/working/new-dir/test.txt", &s); + err = stat("new-dir/test.txt", &s); assert(s.st_mode & S_IXUSR); assert(s.st_mode & S_IXGRP); assert(s.st_mode & S_IXOTH); @@ -14814,7 +14812,8 @@ def test_windows_nodefs_execution_permission(self): return EXIT_SUCCESS; } ''' - self.do_run(src, emcc_args=['-lnodefs.js']) + self.setup_nodefs_test() + self.do_run(src) @parameterized({ 'wasm2js': (True,), diff --git a/test/unistd/access.c b/test/unistd/access.c index c125c919a892f..ca0d16ad82130 100644 --- a/test/unistd/access.c +++ b/test/unistd/access.c @@ -16,11 +16,6 @@ int main() { EM_ASM( - FS.mkdir('working'); -#if NODEFS - FS.mount(NODEFS, { root: '.' }, 'working'); -#endif - FS.chdir('working'); FS.writeFile('forbidden', ""); FS.chmod('forbidden', 0o000); FS.writeFile('readable', ""); FS.chmod('readable', 0o444); FS.writeFile('writeable', ""); FS.chmod('writeable', 0o222); diff --git a/test/unistd/misc.c b/test/unistd/misc.c index 0964e4739a2a7..76c35c1776a84 100644 --- a/test/unistd/misc.c +++ b/test/unistd/misc.c @@ -12,15 +12,11 @@ #include #include #include -#include +#include + int main() { - EM_ASM( - FS.mkdir('working'); -#if NODEFS - FS.mount(NODEFS, { root: '.' }, 'working'); -#endif - ); + mkdir("working", 0777); int f = open("working", O_RDONLY); assert(f); diff --git a/test/unistd/truncate.c b/test/unistd/truncate.c index 4aa53f609ed02..af9b0d698deef 100644 --- a/test/unistd/truncate.c +++ b/test/unistd/truncate.c @@ -11,23 +11,8 @@ #include #include #include -#ifdef __EMSCRIPTEN__ -#include -#endif void setup() { -#ifdef __EMSCRIPTEN__ - EM_ASM( - FS.mkdir('working'); -#if NODEFS - FS.mount(NODEFS, { root: '.' }, 'working'); -#endif - FS.chdir('working'); - FS.writeFile('towrite', 'abcdef'); - FS.writeFile('toread', 'abcdef'); - FS.chmod('toread', 0o444); - ); -#else FILE* f = fopen("towrite", "w"); fwrite("abcdef", 6, 1, f); fclose(f); @@ -36,7 +21,6 @@ void setup() { fclose(f); chmod("toread", 0444); -#endif } int main() { @@ -118,15 +102,5 @@ int main() { memset(&s, 0, sizeof s); errno = 0; -#ifdef __EMSCRIPTEN__ - // Restore full permissions on all created files so that python test runner rmtree - // won't have problems on deleting the files. On Windows, calling shutil.rmtree() - // will fail if any of the files are read-only. - EM_ASM( - FS.chmod('toread', 0o777); - ); -#else - chmod("toread", 0777); -#endif return 0; } diff --git a/test/unistd/unlink.c b/test/unistd/unlink.c index c7cdb23f67fc2..09a22f07ff3da 100644 --- a/test/unistd/unlink.c +++ b/test/unistd/unlink.c @@ -13,9 +13,6 @@ #include #include #include -#ifdef __EMSCRIPTEN__ -#include -#endif static void create_file(const char *path, const char *buffer, int mode) { printf("creating: %s\n", path); @@ -30,13 +27,6 @@ static void create_file(const char *path, const char *buffer, int mode) { void setup() { mkdir("working", 0777); -#ifdef __EMSCRIPTEN__ - EM_ASM( -#if NODEFS - FS.mount(NODEFS, { root: '.' }, 'working'); -#endif - ); -#endif chdir("working"); create_file("file", "test", 0777); create_file("file1", "test", 0777); @@ -148,8 +138,10 @@ void test() { // WASMFS behaviour will match the native FS. #ifndef __APPLE__ getcwd(buffer, sizeof(buffer)); + printf("CWD: %s\n", buffer); err = rmdir(buffer); assert(err == -1); + printf("rmdir: %s\n", strerror(errno)); #if defined(NODERAWFS) || defined(WASMFS) assert(errno == ENOTEMPTY); #else