summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2020-01-17 21:27:05 -0500
committercjihrig <cjihrig@gmail.com>2020-01-20 11:02:47 -0500
commit4f11fb6410728f5b026ea4b9b29775622dc4f849 (patch)
tree92ca3ec144a2bb6e824e4bd090aad34c55e41df1 /test
parent7d5a86cc05f3b8782b37c7ed438b3e994f6bd713 (diff)
downloadnode-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.c26
-rw-r--r--test/wasi/test-wasi-symlinks.js1
-rwxr-xr-xtest/wasi/wasm/create_symlink.wasmbin0 -> 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
new file mode 100755
index 0000000000..1612e975d8
--- /dev/null
+++ b/test/wasi/wasm/create_symlink.wasm
Binary files differ