-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Showing
3 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <sys/stat.h> | ||
#include <assert.h> | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
|
||
#define BASE_DIR "/tmp" | ||
#define OUTPUT_DIR BASE_DIR "/testdir" | ||
#define PATH OUTPUT_DIR "/output.txt" | ||
|
||
int main(void) { | ||
struct stat st; | ||
int fd; | ||
|
||
(void)st; | ||
assert(0 == mkdir(OUTPUT_DIR, 0755)); | ||
|
||
fd = open(PATH, O_CREAT | O_WRONLY, 0666); | ||
assert(fd != -1); | ||
|
||
/* Verify that the file is initially empty. */ | ||
assert(0 == fstat(fd, &st)); | ||
assert(st.st_size == 0); | ||
assert(0 == lseek(fd, 0, SEEK_CUR)); | ||
|
||
/* Increase the file size using ftruncate(). */ | ||
assert(0 == ftruncate(fd, 500)); | ||
assert(0 == fstat(fd, &st)); | ||
assert(st.st_size == 500); | ||
assert(0 == lseek(fd, 0, SEEK_CUR)); | ||
|
||
/* Truncate the file using ftruncate(). */ | ||
assert(0 == ftruncate(fd, 300)); | ||
assert(0 == fstat(fd, &st)); | ||
assert(st.st_size == 300); | ||
assert(0 == lseek(fd, 0, SEEK_CUR)); | ||
|
||
assert(0 == close(fd)); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.