| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9ee9688 commit 5e5be99
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,30 +2,72 @@ | |||
| 2 | 2 | #include <poll.h> | |
| 3 | 3 | #include <time.h> | |
| 4 | 4 | #include <unistd.h> | |
| 5 | + #include <stdlib.h> | ||
| 6 | + #include <string.h> | ||
| 5 | 7 | ||
| 6 | 8 | int main(void) { | |
| 7 | - struct pollfd fds[2]; | ||
| 9 | + struct pollfd fds[4]; | ||
| 8 | 10 | time_t before, now; | |
| 9 | 11 | int ret; | |
| 12 | + char* platform; | ||
| 13 | + int is_aix; | ||
| 14 | + int is_win; | ||
| 10 | 15 | ||
| 16 | + platform = getenv("NODE_PLATFORM"); | ||
| 17 | + is_aix = platform != NULL && 0 == strcmp(platform, "aix"); | ||
| 18 | + is_win = platform != NULL && 0 == strcmp(platform, "win32"); | ||
| 19 | + | ||
| 20 | + // Test sleep() behavior. | ||
| 21 | + time(&before); | ||
| 22 | + sleep(1); | ||
| 23 | + time(&now); | ||
| 24 | + assert(now - before >= 1); | ||
| 25 | + | ||
| 26 | + // Test poll() timeout behavior. | ||
| 27 | + fds[0] = (struct pollfd){.fd = -1, .events = 0, .revents = 0}; | ||
| 28 | + time(&before); | ||
| 29 | + ret = poll(fds, 1, 2000); | ||
| 30 | + time(&now); | ||
| 31 | + assert(ret == 0); | ||
| 32 | + assert(now - before >= 2); | ||
| 33 | + | ||
| 34 | + // The rest of the test is unsupported on Windows. | ||
| 35 | + if (is_win) | ||
| 36 | + return 0; | ||
| 37 | + | ||
| 38 | + fds[0] = (struct pollfd){.fd = 1, .events = POLLOUT, .revents = 0}; | ||
| 39 | + fds[1] = (struct pollfd){.fd = 2, .events = POLLOUT, .revents = 0}; | ||
| 40 | + | ||
| 41 | + ret = poll(fds, 2, -1); | ||
| 42 | + assert(ret == 2); | ||
| 43 | + assert(fds[0].revents == POLLOUT); | ||
| 44 | + assert(fds[1].revents == POLLOUT); | ||
| 45 | + | ||
| 46 | + // Make a poll() call with duplicate file descriptors. | ||
| 11 | 47 | fds[0] = (struct pollfd){.fd = 1, .events = POLLOUT, .revents = 0}; | |
| 12 | 48 | fds[1] = (struct pollfd){.fd = 2, .events = POLLOUT, .revents = 0}; | |
| 49 | + fds[2] = (struct pollfd){.fd = 1, .events = POLLOUT, .revents = 0}; | ||
| 50 | + fds[3] = (struct pollfd){.fd = 1, .events = POLLIN, .revents = 0}; | ||
| 13 | 51 | ||
| 14 | 52 | ret = poll(fds, 2, -1); | |
| 15 | 53 | assert(ret == 2); | |
| 16 | 54 | assert(fds[0].revents == POLLOUT); | |
| 17 | 55 | assert(fds[1].revents == POLLOUT); | |
| 56 | + assert(fds[2].revents == 0); | ||
| 57 | + assert(fds[3].revents == 0); | ||
| 18 | 58 | ||
| 59 | + // The original version of this test expected a timeout and return value of | ||
| 60 | + // zero. In the Node test suite, STDIN is not a TTY, and poll() returns one, | ||
| 61 | + // with revents = POLLHUP | POLLIN, except on AIX whose poll() does not | ||
| 62 | + // support POLLHUP. | ||
| 19 | 63 | fds[0] = (struct pollfd){.fd = 0, .events = POLLIN, .revents = 0}; | |
| 20 | - time(&before); | ||
| 21 | 64 | ret = poll(fds, 1, 2000); | |
| 22 | - time(&now); | ||
| 23 | - assert(ret == 0); | ||
| 24 | - assert(now - before >= 2); | ||
| 65 | + assert(ret == 1); | ||
| 25 | 66 | ||
| 26 | - sleep(1); | ||
| 27 | - time(&now); | ||
| 28 | - assert(now - before >= 3); | ||
| 67 | + if (is_aix) | ||
| 68 | + assert(fds[0].revents == POLLIN); | ||
| 69 | + else | ||
| 70 | + assert(fds[0].revents == (POLLHUP | POLLIN)); | ||
| 29 | 71 | ||
| 30 | 72 | return 0; | |
| 31 | 73 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,7 +38,13 @@ if (process.argv[2] === 'wasi-child') { | |||
| 38 | 38 | ||
| 39 | 39 | function runWASI(options) { | |
| 40 | 40 | console.log('executing', options.test); | |
| 41 | - const opts = { env: { ...process.env, NODE_DEBUG_NATIVE: 'wasi' } }; | ||
| 41 | + const opts = { | ||
| 42 | + env: { | ||
| 43 | + ...process.env, | ||
| 44 | + NODE_DEBUG_NATIVE: 'wasi', | ||
| 45 | + NODE_PLATFORM: process.platform | ||
| 46 | + } | ||
| 47 | + }; | ||
| 42 | 48 | ||
| 43 | 49 | if (options.stdin !== undefined) | |
| 44 | 50 | opts.input = options.stdin; | |
@@ -75,7 +81,7 @@ if (process.argv[2] === 'wasi-child') { | |||
| 75 | 81 | runWASI({ test: 'link' }); | |
| 76 | 82 | runWASI({ test: 'main_args' }); | |
| 77 | 83 | runWASI({ test: 'notdir' }); | |
| 78 | - // runWASI({ test: 'poll' }); | ||
| 84 | + runWASI({ test: 'poll' }); | ||
| 79 | 85 | runWASI({ test: 'preopen_populates' }); | |
| 80 | 86 | runWASI({ test: 'read_file', stdout: `hello from input.txt${EOL}` }); | |
| 81 | 87 | runWASI({ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments