diff options
author | cjihrig <cjihrig@gmail.com> | 2020-01-17 21:27:05 -0500 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2020-01-20 11:02:47 -0500 |
commit | 4f11fb6410728f5b026ea4b9b29775622dc4f849 (patch) | |
tree | 92ca3ec144a2bb6e824e4bd090aad34c55e41df1 /test | |
parent | 7d5a86cc05f3b8782b37c7ed438b3e994f6bd713 (diff) | |
download | node-new-4f11fb6410728f5b026ea4b9b29775622dc4f849.tar.gz |
test: add wasi test for symlink() and readlink()
This test provides missing coverage for __wasi_path_symlink()
and __wasi_path_readlink().
PR-URL: https://github.com/nodejs/node/pull/31403
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/wasi/c/create_symlink.c | 26 | ||||
-rw-r--r-- | test/wasi/test-wasi-symlinks.js | 1 | ||||
-rwxr-xr-x | test/wasi/wasm/create_symlink.wasm | bin | 0 -> 35660 bytes |
3 files changed, 27 insertions, 0 deletions
diff --git a/test/wasi/c/create_symlink.c b/test/wasi/c/create_symlink.c new file mode 100644 index 0000000000..094484ee7d --- /dev/null +++ b/test/wasi/c/create_symlink.c @@ -0,0 +1,26 @@ +#include <assert.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> + +int main() { + const char* target = "./input.txt"; + const char* linkpath = "/sandbox/subdir/test_link"; + char readlink_result[128]; + size_t result_size = sizeof(readlink_result); + + assert(0 == symlink(target, linkpath)); + assert(readlink(linkpath, readlink_result, result_size) == + strlen(target) + 1); + assert(0 == strcmp(readlink_result, target)); + + FILE* file = fopen(linkpath, "r"); + assert(file != NULL); + + int c = fgetc(file); + while (c != EOF) { + int wrote = fputc(c, stdout); + assert(wrote != EOF); + c = fgetc(file); + } +} diff --git a/test/wasi/test-wasi-symlinks.js b/test/wasi/test-wasi-symlinks.js index f6e4d90820..d1ec796125 100644 --- a/test/wasi/test-wasi-symlinks.js +++ b/test/wasi/test-wasi-symlinks.js @@ -74,6 +74,7 @@ if (process.argv[2] === 'wasi-child') { assert.strictEqual(child.stdout.toString(), options.stdout || ''); } + runWASI({ test: 'create_symlink', stdout: 'hello from input.txt' }); runWASI({ test: 'follow_symlink', stdout: 'hello from input.txt' }); runWASI({ test: 'symlink_escape' }); runWASI({ test: 'symlink_loop' }); diff --git a/test/wasi/wasm/create_symlink.wasm b/test/wasi/wasm/create_symlink.wasm Binary files differnew file mode 100755 index 0000000000..1612e975d8 --- /dev/null +++ b/test/wasi/wasm/create_symlink.wasm |