test: add wasi test for freopen()

This test provides missing coverage for __wasi_fd_renumber().

PR-URL: https://github.com/nodejs/node/pull/31432
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
This commit is contained in:
cjihrig 2020-01-18 12:52:04 -05:00 committed by Rich Trott
parent 30173c6087
commit 96058f33a9
4 changed files with 18 additions and 0 deletions

1
test/fixtures/wasi/input2.txt vendored Normal file
View file

@ -0,0 +1 @@
hello from input2.txt

16
test/wasi/c/freopen.c Normal file
View file

@ -0,0 +1,16 @@
#include <assert.h>
#include <stdio.h>
int main() {
FILE* file_orig = fopen("/sandbox/input.txt", "r");
assert(file_orig != NULL);
FILE* file_new = freopen("/sandbox/input2.txt", "r", file_orig);
assert(file_new != NULL);
int c = fgetc(file_new);
while (c != EOF) {
int wrote = fputc((char)c, stdout);
assert(wrote != EOF);
c = fgetc(file_new);
}
}

View file

@ -60,6 +60,7 @@ if (process.argv[2] === 'wasi-child') {
runWASI({ test: 'clock_getres' });
runWASI({ test: 'exitcode', exitCode: 120 });
runWASI({ test: 'fd_prestat_get_refresh' });
runWASI({ test: 'freopen', stdout: `hello from input2.txt${EOL}` });
runWASI({ test: 'getentropy' });
runWASI({ test: 'getrusage' });
runWASI({ test: 'gettimeofday' });

BIN
test/wasi/wasm/freopen.wasm Executable file

Binary file not shown.