Skip to content

Commit dbe2d85

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 <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Jiawen Geng <[email protected]>
1 parent 3fb3079 commit dbe2d85

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

‎test/fixtures/wasi/input2.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello from input2.txt

‎test/wasi/c/freopen.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include<assert.h>
2+
#include<stdio.h>
3+
4+
intmain(){
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+
intc=fgetc(file_new);
11+
while (c!=EOF){
12+
intwrote=fputc((char)c, stdout);
13+
assert(wrote!=EOF);
14+
c=fgetc(file_new);
15+
}
16+
}

‎test/wasi/test-wasi.js‎

Lines changed: 1 addition & 0 deletions
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)