This repository has been archived by the owner on Oct 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wasi: port more wasi libc integration tests
This commit ports the following tests from nodejs/node#27850. - clock_getres - getentropy (currently disabled) - getrusage - gettimeofday - notdir - preopen_populates - read_file_twice - stat - stdin - write_file This commit completes the implementations of fd_filestat_get() and path_filestat_get(), which are needed for the stat test. This commit also adds clock_res_get() and partial clock_time_get() support.
- Loading branch information
Showing
24 changed files
with
293 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#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); | ||
r = clock_getres(CLOCK_PROCESS_CPUTIME_ID, &ts); | ||
assert(r == 0); | ||
r = clock_getres(CLOCK_THREAD_CPUTIME_ID, &ts); | ||
assert(r == 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <assert.h> | ||
#include <sys/resource.h> | ||
|
||
int main() { | ||
struct rusage ru1; | ||
getrusage(RUSAGE_SELF, &ru1); | ||
|
||
for (int i = 0; i < 1000; i++) { | ||
} | ||
|
||
struct rusage ru2; | ||
getrusage(RUSAGE_SELF, &ru2); | ||
|
||
// assert that some time has passed | ||
long long s1 = ru1.ru_utime.tv_sec; | ||
long long us1 = ru1.ru_utime.tv_usec; | ||
long long s2 = ru2.ru_utime.tv_sec; | ||
long long us2 = ru2.ru_utime.tv_usec; | ||
assert(s1 <= s2); | ||
if (s1 == s2) { | ||
// strictly less than, so the timestamps can't be equal | ||
assert(us1 < us2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <assert.h> | ||
#include <stdlib.h> | ||
#include <sys/time.h> | ||
|
||
int main() { | ||
struct timeval tv1; | ||
gettimeofday(&tv1, NULL); | ||
|
||
for (int i = 0; i < 1000; i++) { | ||
} | ||
|
||
struct timeval tv2; | ||
gettimeofday(&tv2, NULL); | ||
|
||
// assert that some time has passed | ||
long long s1 = tv1.tv_sec; | ||
long long us1 = tv1.tv_usec; | ||
long long s2 = tv2.tv_sec; | ||
long long us2 = tv2.tv_usec; | ||
assert(s1 <= s2); | ||
if (s1 == s2) { | ||
// strictly less than, so the timestamps can't be equal | ||
assert(us1 < us2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
int main(void) { | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#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 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); | ||
|
||
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); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
Oops, something went wrong.