Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 55ba743

Browse filesBrowse files
cjihrigaddaleax
authored andcommitted
test: add WASI test for file resizing
This commit adds a WASI test to cover the following functions: - __wasi_fd_filestat_set_size() - __wasi_fd_tell() PR-URL: #31617 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 6ddeee4 commit 55ba743
Copy full SHA for 55ba743

File tree

Expand file treeCollapse file tree

3 files changed

+40
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+40
-0
lines changed
Open diff view settings
Collapse file

‎test/wasi/c/ftruncate.c‎

Copy file name to clipboard
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <sys/stat.h>
2+
#include <assert.h>
3+
#include <fcntl.h>
4+
#include <unistd.h>
5+
6+
#define BASE_DIR "/tmp"
7+
#define OUTPUT_DIR BASE_DIR "/testdir"
8+
#define PATH OUTPUT_DIR "/output.txt"
9+
10+
int main(void) {
11+
struct stat st;
12+
int fd;
13+
14+
(void)st;
15+
assert(0 == mkdir(OUTPUT_DIR, 0755));
16+
17+
fd = open(PATH, O_CREAT | O_WRONLY, 0666);
18+
assert(fd != -1);
19+
20+
/* Verify that the file is initially empty. */
21+
assert(0 == fstat(fd, &st));
22+
assert(st.st_size == 0);
23+
assert(0 == lseek(fd, 0, SEEK_CUR));
24+
25+
/* Increase the file size using ftruncate(). */
26+
assert(0 == ftruncate(fd, 500));
27+
assert(0 == fstat(fd, &st));
28+
assert(st.st_size == 500);
29+
assert(0 == lseek(fd, 0, SEEK_CUR));
30+
31+
/* Truncate the file using ftruncate(). */
32+
assert(0 == ftruncate(fd, 300));
33+
assert(0 == fstat(fd, &st));
34+
assert(st.st_size == 300);
35+
assert(0 == lseek(fd, 0, SEEK_CUR));
36+
37+
assert(0 == close(fd));
38+
return 0;
39+
}
Collapse file

‎test/wasi/test-wasi.js‎

Copy file name to clipboardExpand all lines: test/wasi/test-wasi.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ if (process.argv[2] === 'wasi-child') {
7171
runWASI({ test: 'exitcode', exitCode: 120 });
7272
runWASI({ test: 'fd_prestat_get_refresh' });
7373
runWASI({ test: 'freopen', stdout: `hello from input2.txt${EOL}` });
74+
runWASI({ test: 'ftruncate' });
7475
runWASI({ test: 'getentropy' });
7576

7677
// Tests that are currently unsupported on IBM i PASE.
Collapse file

‎test/wasi/wasm/ftruncate.wasm‎

Copy file name to clipboard
33.3 KB
Binary file not shown.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.