Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NODERAWFS] Revert #18163 #22393

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/library_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ FS.staticInit();
this.node_ops = {};
this.stream_ops = {};
this.rdev = rdev;
this.readMode = 292/*{{{ cDefs.S_IRUGO }}}*/ | 73/*{{{ cDefs.S_IXUGO }}}*/;
this.writeMode = 146/*{{{ cDefs.S_IWUGO }}}*/;
this.readMode = {{{ cDefs.S_IRUGO }}} | {{{ cDefs.S_IXUGO }}};
this.writeMode = {{{ cDefs.S_IWUGO }}};
}
get read() {
return (this.mode & this.readMode) === this.readMode;
Expand Down
16 changes: 11 additions & 5 deletions src/library_noderawfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ addToLibrary({
// Override the init function with our own
FS.init = NODERAWFS.init;`,
$NODERAWFS: {
init(input, output, error) {
// Call the original FS.init, this will setup the
// stdin, stdout and stderr devices
VFS.init(input, output, error);

init() {
var _wrapNodeError = function(func) {
return function(...args) {
try {
Expand All @@ -39,6 +35,9 @@ addToLibrary({
/** @suppress {partialAlias} */
FS[_key] = _wrapNodeError(NODERAWFS[_key]);
}

// Setup the stdin, stdout and stderr devices
FS.createStandardStreams();
},
lookup(parent, name) {
#if ASSERTIONS
Expand All @@ -55,6 +54,13 @@ addToLibrary({
var mode = NODEFS.getMode(path);
return { path, node: { id: st.ino, mode, node_ops: NODERAWFS, path }};
},
createStandardStreams() {
// FIXME: tty is set to true to appease isatty(), the underlying ioctl syscalls still needs to be implemented, see issue #22264.
FS.createStream({ nfd: 0, position: 0, path: '', flags: 0, tty: true, seekable: false }, 0);
for (var i = 1; i < 3; i++) {
FS.createStream({ nfd: i, position: 0, path: '', flags: {{{ cDefs.O_TRUNC | cDefs.O_CREAT | cDefs.O_WRONLY }}}, tty: true, seekable: false }, i);
}
},
// generic function for all node creation
cwd() { return process.cwd(); },
chdir(...args) { process.chdir(...args); },
Expand Down
2 changes: 1 addition & 1 deletion test/other/test_fflush_fs_exit.out
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Hey1
Hey2
Hey2
kleisauke marked this conversation as resolved.
Show resolved Hide resolved
26 changes: 22 additions & 4 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,6 @@ def test_stdin(self, args):
os.system(f'cat in.txt | {cmd} > out.txt')
self.assertContained('abcdef\nghijkl\neof', read_file('out.txt'))

@also_with_noderawfs
@crossplatform
def test_module_stdin(self):
self.set_setting('FORCE_FILESYSTEM')
Expand All @@ -1687,18 +1686,36 @@ def test_module_stdin(self):
self.emcc_args += ['--pre-js', 'pre.js']
self.do_runf('module/test_stdin.c', 'hello, world!')

@also_with_noderawfs
@crossplatform
def test_module_stdout_stderr(self):
self.set_setting('FORCE_FILESYSTEM')
create_file('pre.js', '''
let stdout = [];
let stderr = [];

Module['stdout'] = (char) => stdout.push(char);
Module['stderr'] = (char) => stderr.push(char);
Module['postRun'] = () => {
assert(stderr.length === 0, 'stderr should be empty. \\n' +
'stderr: \\n' + stderr);
assert(UTF8ArrayToString(stdout, 0).startsWith('hello, world!'), 'stdout should start with the famous greeting. \\n' +
'stdout: \\n' + stdout);
}
''')
self.emcc_args += ['--pre-js', 'pre.js']
self.do_runf('hello_world.c')

@crossplatform
def test_module_print_printerr(self):
self.set_setting('FORCE_FILESYSTEM')
create_file('pre.js', '''
let stdout = '';
let stderr = '';

Module['print'] = (text) => stdout += text;
Module['printErr'] = (text) => stderr += text;
Module['postRun'] = () => {
assert(stderr == '', 'stderr should be empty. \\n' +
assert(stderr === '', 'stderr should be empty. \\n' +
'stderr: \\n' + stderr);
assert(stdout.startsWith('hello, world!'), 'stdout should start with the famous greeting. \\n' +
'stdout: \\n' + stdout);
Expand Down Expand Up @@ -9713,7 +9730,7 @@ def test_ioctl(self):
# ioctl requires filesystem
self.do_other_test('test_ioctl.c', emcc_args=['-sFORCE_FILESYSTEM'])

@also_with_noderawfs
# @also_with_noderawfs # NODERAWFS reports ENOTTY, see issue #22264.
def test_ioctl_termios(self):
# ioctl requires filesystem
self.do_other_test('test_ioctl_termios.c', emcc_args=['-sFORCE_FILESYSTEM'])
Expand All @@ -9730,6 +9747,7 @@ def test_fflush_fs(self):
# fflush with the full filesystem will flush from libc, but not the JS logging, which awaits a newline
self.do_other_test('test_fflush_fs.cpp', emcc_args=['-sFORCE_FILESYSTEM'])

@also_with_noderawfs
def test_fflush_fs_exit(self):
# on exit, we can send out a newline as no more code will run
self.do_other_test('test_fflush_fs_exit.cpp', emcc_args=['-sFORCE_FILESYSTEM', '-sEXIT_RUNTIME'])
Expand Down
Loading