Skip to content

Commit

Permalink
test: add wasi test for symlink() and readlink()
Browse files Browse the repository at this point in the history
This test provides missing coverage for __wasi_path_symlink()
and __wasi_path_readlink().

PR-URL: #31403
Reviewed-By: Jiawen Geng <[email protected]>
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
cjihrig authored and codebytere committed Mar 17, 2020
1 parent fc9c6c3 commit 596920d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/wasi/c/create_symlink.c
Original file line number Diff line number Diff line change
@@ -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);
}
}
1 change: 1 addition & 0 deletions test/wasi/test-wasi-symlinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand Down
Binary file added test/wasi/wasm/create_symlink.wasm
Binary file not shown.

0 comments on commit 596920d

Please sign in to comment.