Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

11
test/wasi/c/cant_dotdot.c Normal file
View File

@ -0,0 +1,11 @@
#include <assert.h>
#include <errno.h>
#include <stdio.h>
int main() {
FILE* file = fopen("/sandbox/../outside.txt", "r");
assert(file == NULL);
assert(errno == ENOTCAPABLE);
return 0;
}

View File

@ -0,0 +1,20 @@
#include <assert.h>
#include <time.h>
int main() {
struct timespec ts;
int r;
// supported clocks
r = clock_getres(CLOCK_REALTIME, &ts);
assert(r == 0);
r = clock_getres(CLOCK_MONOTONIC, &ts);
assert(r == 0);
// don't run these tests until
// https://github.com/WebAssembly/wasi-libc/issues/266
// is resolved
// r = clock_getres(CLOCK_PROCESS_CPUTIME_ID, &ts);
// assert(r == 0);
// r = clock_getres(CLOCK_THREAD_CPUTIME_ID, &ts);
// assert(r == 0);
}

View File

@ -0,0 +1,26 @@
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int main() {
const char* target = "./input-in-subdir.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));
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);
}
}

3
test/wasi/c/exitcode.c Normal file
View File

@ -0,0 +1,3 @@
int main() {
return 120;
}

View File

@ -0,0 +1,8 @@
#include <unistd.h>
int main(void) {
isatty(1);
__builtin_wasm_memory_grow(0, 1);
isatty(1);
return 0;
}

View File

@ -0,0 +1,14 @@
#include <assert.h>
#include <stdio.h>
int main() {
FILE* file = fopen("/sandbox/subdir/input_link.txt", "r");
assert(file != NULL);
char c = fgetc(file);
while (c != EOF) {
int wrote = fputc(c, stdout);
assert(wrote != EOF);
c = fgetc(file);
}
}

16
test/wasi/c/freopen.c Normal file
View File

@ -0,0 +1,16 @@
#include <assert.h>
#include <stdio.h>
int main() {
FILE* file_orig = fopen("/sandbox/input.txt", "r");
assert(file_orig != NULL);
FILE* file_new = freopen("/sandbox/input2.txt", "r", file_orig);
assert(file_new != NULL);
int c = fgetc(file_new);
while (c != EOF) {
int wrote = fputc((char)c, stdout);
assert(wrote != EOF);
c = fgetc(file_new);
}
}

39
test/wasi/c/ftruncate.c Normal file
View File

@ -0,0 +1,39 @@
#include <sys/stat.h>
#include <assert.h>
#include <fcntl.h>
#include <unistd.h>
#define BASE_DIR "/tmp"
#define OUTPUT_DIR BASE_DIR "/testdir"
#define PATH OUTPUT_DIR "/output.txt"
int main(void) {
struct stat st;
int fd;
(void)st;
assert(0 == mkdir(OUTPUT_DIR, 0755));
fd = open(PATH, O_CREAT | O_WRONLY, 0666);
assert(fd != -1);
/* Verify that the file is initially empty. */
assert(0 == fstat(fd, &st));
assert(st.st_size == 0);
assert(0 == lseek(fd, 0, SEEK_CUR));
/* Increase the file size using ftruncate(). */
assert(0 == ftruncate(fd, 500));
assert(0 == fstat(fd, &st));
assert(st.st_size == 500);
assert(0 == lseek(fd, 0, SEEK_CUR));
/* Truncate the file using ftruncate(). */
assert(0 == ftruncate(fd, 300));
assert(0 == fstat(fd, &st));
assert(st.st_size == 300);
assert(0 == lseek(fd, 0, SEEK_CUR));
assert(0 == close(fd));
return 0;
}

18
test/wasi/c/getentropy.c Normal file
View File

@ -0,0 +1,18 @@
#include <assert.h>
#include <unistd.h>
int main() {
char buf[256] = {0};
int r = getentropy(buf, 256);
assert(r == 0);
for (int i = 0; i < 256; i++) {
if (buf[i] != 0) {
return 0;
}
}
// if this ever is reached, we either have a bug or should buy a lottery
// ticket
return 1;
}

34
test/wasi/c/getrusage.c Normal file
View File

@ -0,0 +1,34 @@
#include <assert.h>
#include <sys/resource.h>
int main() {
struct rusage ru1;
struct rusage ru2;
long long s1;
long long us1;
long long s2;
long long us2;
int r;
int success = 0;
r = getrusage(RUSAGE_SELF, &ru1);
assert(r == 0);
s1 = ru1.ru_utime.tv_sec;
us1 = ru1.ru_utime.tv_usec;
for (int i = 0; i < 10000; i++) {
r = getrusage(RUSAGE_SELF, &ru2);
assert(r == 0);
s2 = ru2.ru_utime.tv_sec;
us2 = ru2.ru_utime.tv_usec;
assert(s1 <= s2);
// Verify that some time has passed.
if (s2 > s1 || (s2 == s1 && us2 > us1)) {
success = 1;
break;
}
}
assert(success == 1);
}

View File

@ -0,0 +1,35 @@
#include <assert.h>
#include <stdlib.h>
#include <sys/time.h>
int main() {
struct timeval tv1;
struct timeval tv2;
long long s1;
long long us1;
long long s2;
long long us2;
int r;
int success = 0;
r = gettimeofday(&tv1, NULL);
assert(r == 0);
s1 = tv1.tv_sec;
us1 = tv1.tv_usec;
for (int i = 0; i < 10000; i++) {
r = gettimeofday(&tv2, NULL);
assert(r == 0);
s2 = tv2.tv_sec;
us2 = tv2.tv_usec;
assert(s1 <= s2);
// Verify that some time has passed.
if (s2 > s1 || (s2 == s1 && us2 > us1)) {
success = 1;
break;
}
}
assert(success == 1);
}

17
test/wasi/c/link.c Normal file
View File

@ -0,0 +1,17 @@
#include <assert.h>
#include <unistd.h>
#include <sys/stat.h>
#define OLD "/sandbox/input.txt"
#define NEW "/tmp/output.txt"
int main() {
struct stat st_old;
struct stat st_new;
assert(0 == stat(OLD, &st_old));
assert(0 == link(OLD, NEW));
assert(0 == stat(NEW, &st_new));
assert(st_old.st_ino == st_new.st_ino);
return 0;
}

10
test/wasi/c/main_args.c Normal file
View File

@ -0,0 +1,10 @@
#include <assert.h>
#include <string.h>
int main(int argc, char** argv) {
assert(argc == 3);
assert(0 == strcmp(argv[0], "foo"));
assert(0 == strcmp(argv[1], "-bar"));
assert(0 == strcmp(argv[2], "--baz=value"));
return 0;
}

11
test/wasi/c/notdir.c Normal file
View File

@ -0,0 +1,11 @@
#include <assert.h>
#include <dirent.h>
#include <errno.h>
int main() {
DIR* dir = opendir("/sandbox/notadir");
assert(dir == NULL);
assert(errno == ENOTDIR);
return 0;
}

76
test/wasi/c/poll.c Normal file
View File

@ -0,0 +1,76 @@
#include <assert.h>
#include <poll.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
struct pollfd fds[4];
time_t before, now;
int ret;
char* platform;
int is_aix_or_os400;
int is_win;
platform = getenv("NODE_PLATFORM");
is_aix_or_os400 = platform != NULL && (0 == strcmp(platform, "aix") || 0 == strcmp(platform, "os400"));
is_win = platform != NULL && 0 == strcmp(platform, "win32");
// Test sleep() behavior.
time(&before);
sleep(1);
time(&now);
assert(now - before >= 1);
// Test poll() timeout behavior.
fds[0] = (struct pollfd){.fd = -1, .events = 0, .revents = 0};
time(&before);
ret = poll(fds, 1, 2000);
time(&now);
assert(ret == 0);
assert(now - before >= 2);
// V8 has a bug that allows unsupported parts of this test to run,
// causing the test to fail. poll_win.c is a workaround.
// https://github.com/nodejs/node/issues/51822
// The rest of the test is unsupported on Windows.
if (is_win)
return 0;
fds[0] = (struct pollfd){.fd = 1, .events = POLLOUT, .revents = 0};
fds[1] = (struct pollfd){.fd = 2, .events = POLLOUT, .revents = 0};
ret = poll(fds, 2, -1);
assert(ret == 2);
assert(fds[0].revents == POLLOUT);
assert(fds[1].revents == POLLOUT);
// Make a poll() call with duplicate file descriptors.
fds[0] = (struct pollfd){.fd = 1, .events = POLLOUT, .revents = 0};
fds[1] = (struct pollfd){.fd = 2, .events = POLLOUT, .revents = 0};
fds[2] = (struct pollfd){.fd = 1, .events = POLLOUT, .revents = 0};
fds[3] = (struct pollfd){.fd = 1, .events = POLLIN, .revents = 0};
ret = poll(fds, 2, -1);
assert(ret == 2);
assert(fds[0].revents == POLLOUT);
assert(fds[1].revents == POLLOUT);
assert(fds[2].revents == 0);
assert(fds[3].revents == 0);
// The original version of this test expected a timeout and return value of
// zero. In the Node test suite, STDIN is not a TTY, and poll() returns one,
// with revents = POLLHUP | POLLIN, except on AIX whose poll() does not
// support POLLHUP.
fds[0] = (struct pollfd){.fd = 0, .events = POLLIN, .revents = 0};
ret = poll(fds, 1, 2000);
assert(ret == 1);
if (is_aix_or_os400)
assert(fds[0].revents == POLLIN);
else
assert(fds[0].revents == (POLLHUP | POLLIN));
return 0;
}

26
test/wasi/c/poll_win.c Normal file
View File

@ -0,0 +1,26 @@
#include <assert.h>
#include <poll.h>
#include <time.h>
#include <unistd.h>
int main(void) {
struct pollfd fds[4];
time_t before, now;
int ret;
// Test sleep() behavior.
time(&before);
sleep(1);
time(&now);
assert(now - before >= 1);
// Test poll() timeout behavior.
fds[0] = (struct pollfd){.fd = -1, .events = 0, .revents = 0};
time(&before);
ret = poll(fds, 1, 2000);
time(&now);
assert(ret == 0);
assert(now - before >= 2);
return 0;
}

View File

@ -0,0 +1,3 @@
int main(void) {
return 0;
}

14
test/wasi/c/read_file.c Normal file
View File

@ -0,0 +1,14 @@
#include <assert.h>
#include <stdio.h>
int main() {
FILE* file = fopen("/sandbox/input.txt", "r");
assert(file != NULL);
char c = fgetc(file);
while (c != EOF) {
int wrote = fputc(c, stdout);
assert(wrote != EOF);
c = fgetc(file);
}
}

View File

@ -0,0 +1,16 @@
#include <assert.h>
#include <stdio.h>
int main() {
for (int i = 0; i < 2; i++) {
FILE* file = fopen("/sandbox/input.txt", "r");
assert(file != NULL);
char c = fgetc(file);
while (c != EOF) {
int wrote = fputc(c, stdout);
assert(wrote != EOF);
c = fgetc(file);
}
}
}

41
test/wasi/c/readdir.c Normal file
View File

@ -0,0 +1,41 @@
#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);
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) {
assert(entry->d_type == DT_REG);
} else if (strcmp(entry->d_name, "subdir") == 0) {
assert(entry->d_type == DT_DIR);
} else {
assert("unexpected file");
}
cnt++;
}
assert(errno == 0);
assert(cnt == 4);
closedir(dir);
return 0;
}

17
test/wasi/c/sock.c Normal file
View File

@ -0,0 +1,17 @@
#include <sys/socket.h>
#include <stddef.h>
#include <errno.h>
#include <assert.h>
#include <stdio.h>
// TODO(mhdawson): Update once sock_accept is implemented in uvwasi
int main(void) {
int fd = 0 ;
socklen_t addrlen = 0;
int flags = 0;
int ret = accept(10, NULL, &addrlen);
assert(ret == -1);
assert(errno == EBADF);
return 0;
}

73
test/wasi/c/stat.c Normal file
View File

@ -0,0 +1,73 @@
#include <sys/stat.h>
#include <assert.h>
#include <fcntl.h>
#include <time.h>
#include <unistd.h>
#define BASE_DIR "/tmp"
#define OUTPUT_DIR BASE_DIR "/testdir"
#define PATH OUTPUT_DIR "/output.txt"
#define SIZE 500
int main(void) {
struct timespec times[2];
struct stat st;
int fd;
int ret;
off_t pos;
(void)st;
ret = mkdir(OUTPUT_DIR, 0755);
assert(ret == 0);
fd = open(PATH, O_CREAT | O_WRONLY, 0666);
assert(fd != -1);
pos = lseek(fd, SIZE - 1, SEEK_SET);
assert(pos == SIZE - 1);
ret = (int)write(fd, "", 1);
assert(ret == 1);
ret = fstat(fd, &st);
assert(ret == 0);
assert(st.st_size == SIZE);
times[0].tv_sec = 4;
times[0].tv_nsec = 0;
times[1].tv_sec = 9;
times[1].tv_nsec = 0;
assert(0 == futimens(fd, times));
assert(0 == fstat(fd, &st));
assert(4 == st.st_atime);
assert(9 == st.st_mtime);
ret = close(fd);
assert(ret == 0);
ret = access(PATH, R_OK);
assert(ret == 0);
ret = stat(PATH, &st);
assert(ret == 0);
assert(st.st_size == SIZE);
ret = unlink(PATH);
assert(ret == 0);
ret = stat(PATH, &st);
assert(ret == -1);
ret = stat(OUTPUT_DIR, &st);
assert(ret == 0);
assert(S_ISDIR(st.st_mode));
ret = rmdir(OUTPUT_DIR);
assert(ret == 0);
ret = stat(OUTPUT_DIR, &st);
assert(ret == -1);
return 0;
}

13
test/wasi/c/stdin.c Normal file
View File

@ -0,0 +1,13 @@
#include <stdio.h>
int main(void) {
char x[32];
if (fgets(x, sizeof x, stdin) == NULL) {
return ferror(stdin);
}
if (fputs(x, stdout) == EOF) {
return ferror(stdout);
}
return 0;
}

View File

@ -0,0 +1,9 @@
#include <assert.h>
#include <errno.h>
#include <stdio.h>
int main() {
FILE* file = fopen("/sandbox/subdir/outside.txt", "r");
assert(file == NULL);
assert(errno == ENOTCAPABLE);
}

View File

@ -0,0 +1,9 @@
#include <assert.h>
#include <errno.h>
#include <stdio.h>
int main() {
FILE* file = fopen("/sandbox/subdir/loop1", "r");
assert(file == NULL);
assert(errno == ELOOP);
}

15
test/wasi/c/write_file.c Normal file
View File

@ -0,0 +1,15 @@
#include <assert.h>
#include <stdio.h>
#include <string.h>
static char* message = "hello, file!";
int main() {
FILE* file = fopen("/tmp/output.txt", "w");
assert(file != NULL);
int nwritten = fprintf(file, "%s", message);
assert(nwritten == strlen(message));
int r = fclose(file);
assert(r == 0);
}