mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
test: add wasi readdir() test
This commit provides coverage for __wasi_fd_readdir(). PR-URL: https://github.com/nodejs/node/pull/35202 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
This commit is contained in:
parent
884755f1e5
commit
c3e1bf78c4
50
test/wasi/c/readdir.c
Normal file
50
test/wasi/c/readdir.c
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#include <assert.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main() {
|
||||
DIR* dir;
|
||||
struct dirent* entry;
|
||||
char* platform;
|
||||
int cnt;
|
||||
int has_d_type;
|
||||
|
||||
platform = getenv("NODE_PLATFORM");
|
||||
assert(platform != NULL);
|
||||
has_d_type = (0 != strcmp(platform, "aix") && 0 != strcmp(platform, "sunos"));
|
||||
|
||||
dir = opendir("/sandbox");
|
||||
assert(dir != NULL);
|
||||
|
||||
cnt = 0;
|
||||
errno = 0;
|
||||
while (NULL != (entry = readdir(dir))) {
|
||||
if (strcmp(entry->d_name, "input.txt") == 0 ||
|
||||
strcmp(entry->d_name, "input2.txt") == 0 ||
|
||||
strcmp(entry->d_name, "notadir") == 0) {
|
||||
if (has_d_type) {
|
||||
assert(entry->d_type == DT_REG);
|
||||
} else {
|
||||
assert(entry->d_type == DT_UNKNOWN);
|
||||
}
|
||||
} else if (strcmp(entry->d_name, "subdir") == 0) {
|
||||
if (has_d_type) {
|
||||
assert(entry->d_type == DT_DIR);
|
||||
} else {
|
||||
assert(entry->d_type == DT_UNKNOWN);
|
||||
}
|
||||
} else {
|
||||
assert("unexpected file");
|
||||
}
|
||||
|
||||
cnt++;
|
||||
}
|
||||
|
||||
assert(errno == 0);
|
||||
assert(cnt == 4);
|
||||
closedir(dir);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -84,6 +84,11 @@ if (process.argv[2] === 'wasi-child') {
|
|||
runWASI({ test: 'notdir' });
|
||||
runWASI({ test: 'poll' });
|
||||
runWASI({ test: 'preopen_populates' });
|
||||
|
||||
if (!common.isWindows && process.platform !== 'android') {
|
||||
runWASI({ test: 'readdir' });
|
||||
}
|
||||
|
||||
runWASI({ test: 'read_file', stdout: `hello from input.txt${EOL}` });
|
||||
runWASI({
|
||||
test: 'read_file_twice',
|
||||
|
|
|
|||
BIN
test/wasi/wasm/readdir.wasm
Executable file
BIN
test/wasi/wasm/readdir.wasm
Executable file
Binary file not shown.
Loading…
Reference in New Issue
Block a user