Skip to content

Commit a0c2f27

Browse files
cjihrigcodebytere
authored andcommitted
test: add wasi test for symlink() and readlink()
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]>
1 parent 3f1212f commit a0c2f27

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

test/wasi/c/create_symlink.c

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <assert.h>
2+
#include <stdio.h>
3+
#include <string.h>
4+
#include <unistd.h>
5+
6+
int main() {
7+
const char* target = "./input.txt";
8+
const char* linkpath = "/sandbox/subdir/test_link";
9+
char readlink_result[128];
10+
size_t result_size = sizeof(readlink_result);
11+
12+
assert(0 == symlink(target, linkpath));
13+
assert(readlink(linkpath, readlink_result, result_size) ==
14+
strlen(target) + 1);
15+
assert(0 == strcmp(readlink_result, target));
16+
17+
FILE* file = fopen(linkpath, "r");
18+
assert(file != NULL);
19+
20+
int c = fgetc(file);
21+
while (c != EOF) {
22+
int wrote = fputc(c, stdout);
23+
assert(wrote != EOF);
24+
c = fgetc(file);
25+
}
26+
}

test/wasi/test-wasi-symlinks.js

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ if (process.argv[2] === 'wasi-child') {
7474
assert.strictEqual(child.stdout.toString(), options.stdout || '');
7575
}
7676

77+
runWASI({ test: 'create_symlink', stdout: 'hello from input.txt' });
7778
runWASI({ test: 'follow_symlink', stdout: 'hello from input.txt' });
7879
runWASI({ test: 'symlink_escape' });
7980
runWASI({ test: 'symlink_loop' });

test/wasi/wasm/create_symlink.wasm

34.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)