diff options
author | cjihrig <cjihrig@gmail.com> | 2020-01-18 12:52:04 -0500 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2020-01-23 05:22:36 -0800 |
commit | 96058f33a9c72796930a77c97018fda2cbb5ed03 (patch) | |
tree | a9d9e33e04d689f1f9eef0138c38e73db2a09a7f | |
parent | 30173c608749d973db6eae9930b7a10bcd80b2d3 (diff) | |
download | node-new-96058f33a9c72796930a77c97018fda2cbb5ed03.tar.gz |
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>
-rw-r--r-- | test/fixtures/wasi/input2.txt | 1 | ||||
-rw-r--r-- | test/wasi/c/freopen.c | 16 | ||||
-rw-r--r-- | test/wasi/test-wasi.js | 1 | ||||
-rwxr-xr-x | test/wasi/wasm/freopen.wasm | bin | 0 -> 35202 bytes |
4 files changed, 18 insertions, 0 deletions
diff --git a/test/fixtures/wasi/input2.txt b/test/fixtures/wasi/input2.txt new file mode 100644 index 0000000000..6aadea3800 --- /dev/null +++ b/test/fixtures/wasi/input2.txt @@ -0,0 +1 @@ +hello from input2.txt diff --git a/test/wasi/c/freopen.c b/test/wasi/c/freopen.c new file mode 100644 index 0000000000..0f47058da2 --- /dev/null +++ b/test/wasi/c/freopen.c @@ -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); + } +} diff --git a/test/wasi/test-wasi.js b/test/wasi/test-wasi.js index 9c8b2a7527..01d5aa8fe5 100644 --- a/test/wasi/test-wasi.js +++ b/test/wasi/test-wasi.js @@ -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' }); diff --git a/test/wasi/wasm/freopen.wasm b/test/wasi/wasm/freopen.wasm Binary files differnew file mode 100755 index 0000000000..fb417fbe21 --- /dev/null +++ b/test/wasi/wasm/freopen.wasm |