Skip to content

Commit 2cb551d

Browse files
authored
Run test_fs_js_api all FS backends and fix related issues (#23897)
I order to make the tests work I had to convert all paths to relative paths but I don't think that should effect any of the tests. A couple bug fixes were needed to make this work: 1. FS.FS_mkdirTree was fixes such that if works for relative directory tree. 2. NODERAWFS truncate requires the same workaround as it already had for ftruncate. 3. NODERAWFS close now fails correctly when called more than once.
1 parent d6ebc74 commit 2cb551d

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

src/lib/libnoderawfs.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,13 @@ addToLibrary({
113113
var stream = FS.getStreamChecked(fd);
114114
fs.fchownSync(stream.nfd, owner, group);
115115
},
116-
truncate(...args) { fs.truncateSync(...args); },
116+
truncate(path, len) {
117+
// See https://github.com/nodejs/node/issues/35632
118+
if (len < 0) {
119+
throw new FS.ErrnoError({{{ cDefs.EINVAL }}});
120+
}
121+
return fs.truncateSync(path, len);
122+
},
117123
ftruncate(fd, len) {
118124
// See https://github.com/nodejs/node/issues/35632
119125
if (len < 0) {
@@ -160,7 +166,7 @@ addToLibrary({
160166
},
161167
close(stream) {
162168
VFS.closeStream(stream.fd);
163-
if (!stream.stream_ops && --stream.shared.refcnt === 0) {
169+
if (!stream.stream_ops && --stream.shared.refcnt <= 0) {
164170
// This stream is created by our Node.js filesystem, close the
165171
// native file descriptor when its reference count drops to 0.
166172
fs.closeSync(stream.nfd);

test/fs/test_fs_js_api.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ void test_fs_mkdirTree() {
406406
assert(ex.name === "ErrnoError" && ex.errno === 2 /* EACCES */);
407407
);
408408

409-
chdir("test1");
409+
chdir("/test1");
410410
EM_ASM(
411411
FS.mkdirTree("foo/bar"); // Relative path
412412
);
@@ -448,22 +448,37 @@ void test_fs_utime() {
448448
remove("utimetest");
449449
}
450450

451+
#if !defined(NODERAWFS)
452+
// NODERAWFS don't support absolute paths since we cannot write the
453+
// actual root directory.
454+
// In addition, abs paths testing is not really running correctly
455+
// when we build run with NODEFS because the NODEFS filesystem is mounted
456+
// at /nodefs in that case.
457+
// TODO(sbc): Refactor these tests such that they test both relative
458+
// and absolute paths, and don't depend on write access to the root
459+
// directory.
460+
#define ABS_PATH_OK
461+
#endif
462+
451463
int main() {
452-
test_fs_open();
464+
#ifdef ABS_PATH_OK
453465
test_fs_createPath();
466+
test_fs_mkdirTree();
467+
test_fs_close();
468+
test_fs_readlink();
469+
test_fs_rmdir();
470+
#endif
471+
test_fs_open();
454472
test_fs_readFile();
455473
test_fs_rename();
456-
test_fs_readlink();
457474
test_fs_read();
458-
test_fs_rmdir();
459-
test_fs_close();
460475
test_fs_mknod();
461476
test_fs_truncate();
462477
#if WASMFS
463478
// TODO: Fix legacy API FS.mmap bug involving emscripten_builtin_memalign
464479
test_fs_mmap();
465480
#endif
466-
test_fs_mkdirTree();
481+
467482
test_fs_utime();
468483

469484
puts("success");

test/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5756,7 +5756,7 @@ def test_fs_writeFile(self):
57565756
self.set_setting("FORCE_FILESYSTEM")
57575757
self.do_run_in_out_file_test('fs/test_writeFile.cpp')
57585758

5759-
@also_with_wasmfs
5759+
@with_all_fs
57605760
def test_fs_js_api(self):
57615761
self.set_setting("FORCE_FILESYSTEM")
57625762
self.do_runf('fs/test_fs_js_api.c', 'success')

0 commit comments

Comments
 (0)