diff --git a/test/wasi/c/create_symlink.c b/test/wasi/c/create_symlink.c new file mode 100644 index 00000000000000..094484ee7db745 --- /dev/null +++ b/test/wasi/c/create_symlink.c @@ -0,0 +1,26 @@ +#include +#include +#include +#include + +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 f6e4d90820ebce..d1ec796125cb53 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 00000000000000..1612e975d87e5d Binary files /dev/null and b/test/wasi/wasm/create_symlink.wasm differ