diff options
author | cjihrig <cjihrig@gmail.com> | 2020-02-02 13:15:10 -0500 |
---|---|---|
committer | Myles Borins <mylesborins@github.com> | 2020-07-16 17:09:09 -0400 |
commit | 6925ef3b1cccbc82b6fe2b51d58376cd054b06e0 (patch) | |
tree | 3d4d40ebec775e8dc4d31b666a494ebb30cfcbd0 | |
parent | de250c136cf76fdb120b881316ebb08347565e48 (diff) | |
download | node-new-6925ef3b1cccbc82b6fe2b51d58376cd054b06e0.tar.gz |
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: https://github.com/nodejs/node/pull/31617
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
-rw-r--r-- | test/wasi/c/ftruncate.c | 39 | ||||
-rw-r--r-- | test/wasi/test-wasi.js | 1 | ||||
-rwxr-xr-x | test/wasi/wasm/ftruncate.wasm | bin | 0 -> 34111 bytes |
3 files changed, 40 insertions, 0 deletions
diff --git a/test/wasi/c/ftruncate.c b/test/wasi/c/ftruncate.c new file mode 100644 index 0000000000..cf41802a01 --- /dev/null +++ b/test/wasi/c/ftruncate.c @@ -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; +} diff --git a/test/wasi/test-wasi.js b/test/wasi/test-wasi.js index e4bd44e83d..8ebc290d7b 100644 --- a/test/wasi/test-wasi.js +++ b/test/wasi/test-wasi.js @@ -71,6 +71,7 @@ if (process.argv[2] === 'wasi-child') { runWASI({ test: 'exitcode', exitCode: 120 }); runWASI({ test: 'fd_prestat_get_refresh' }); runWASI({ test: 'freopen', stdout: `hello from input2.txt${EOL}` }); + runWASI({ test: 'ftruncate' }); runWASI({ test: 'getentropy' }); // Tests that are currently unsupported on IBM i PASE. diff --git a/test/wasi/wasm/ftruncate.wasm b/test/wasi/wasm/ftruncate.wasm Binary files differnew file mode 100755 index 0000000000..a16e90d98d --- /dev/null +++ b/test/wasi/wasm/ftruncate.wasm |