Skip to content

Commit 38ea536

Browse files
cjihrigcodebytere
authored andcommitted
test: add wasi test for freopen()
This test provides missing coverage for __wasi_fd_renumber(). PR-URL: #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>
1 parent 9811ebe commit 38ea536

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

test/fixtures/wasi/input2.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello from input2.txt

test/wasi/c/freopen.c

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <assert.h>
2+
#include <stdio.h>
3+
4+
int main() {
5+
FILE* file_orig = fopen("/sandbox/input.txt", "r");
6+
assert(file_orig != NULL);
7+
FILE* file_new = freopen("/sandbox/input2.txt", "r", file_orig);
8+
assert(file_new != NULL);
9+
10+
int c = fgetc(file_new);
11+
while (c != EOF) {
12+
int wrote = fputc((char)c, stdout);
13+
assert(wrote != EOF);
14+
c = fgetc(file_new);
15+
}
16+
}

test/wasi/test-wasi.js

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ if (process.argv[2] === 'wasi-child') {
6060
runWASI({ test: 'clock_getres' });
6161
runWASI({ test: 'exitcode', exitCode: 120 });
6262
runWASI({ test: 'fd_prestat_get_refresh' });
63+
runWASI({ test: 'freopen', stdout: `hello from input2.txt${EOL}` });
6364
runWASI({ test: 'getentropy' });
6465
runWASI({ test: 'getrusage' });
6566
runWASI({ test: 'gettimeofday' });

test/wasi/wasm/freopen.wasm

34.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)