From 2d2d210db7ebf554c310dc1196c44ba30976d0f0 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sat, 23 May 2020 09:41:20 -0400 Subject: [PATCH 1/2] deps: uvwasi: cherry-pick 9e75217 Original commit message: poll_oneoff: add missing uv_run() in cleanup This allows ASAN to pass. PR-URL: https://github.com/nodejs/node/pull/33521 Reviewed-By: Anna Henningsen Reviewed-By: Jiawen Geng --- deps/uvwasi/src/poll_oneoff.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/deps/uvwasi/src/poll_oneoff.c b/deps/uvwasi/src/poll_oneoff.c index 97b8ef332da71f..a4b1c3c84282fa 100644 --- a/deps/uvwasi/src/poll_oneoff.c +++ b/deps/uvwasi/src/poll_oneoff.c @@ -114,6 +114,8 @@ uvwasi_errno_t uvwasi__poll_oneoff_state_cleanup( for (i = 0; i < state->handle_cnt; i++) uv_close((uv_handle_t*) &state->poll_handles[i], NULL); + uv_run(&state->loop, UV_RUN_NOWAIT); + state->max_fds = 0; state->fdevent_cnt = 0; state->handle_cnt = 0; From a4e6ef7b11d4846c2aa74ae04e24846bf151b7d7 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Fri, 22 May 2020 20:00:59 -0400 Subject: [PATCH 2/2] wasi: refactor and enable poll_oneoff() test This commit refactors and enables the poll_oneoff() WASI test. The refactor includes testing additional cases, as well as some platform specific checks. PR-URL: https://github.com/nodejs/node/pull/33521 Reviewed-By: Anna Henningsen Reviewed-By: Jiawen Geng --- test/wasi/c/poll.c | 58 +++++++++++++++++++++++++++++++++------ test/wasi/test-wasi.js | 10 +++++-- test/wasi/wasm/poll.wasm | Bin 33777 -> 36414 bytes 3 files changed, 58 insertions(+), 10 deletions(-) diff --git a/test/wasi/c/poll.c b/test/wasi/c/poll.c index 6b6ef71fd68c3b..9afb6325a98a03 100644 --- a/test/wasi/c/poll.c +++ b/test/wasi/c/poll.c @@ -2,30 +2,72 @@ #include #include #include +#include +#include int main(void) { - struct pollfd fds[2]; + struct pollfd fds[4]; time_t before, now; int ret; + char* platform; + int is_aix; + int is_win; + platform = getenv("NODE_PLATFORM"); + is_aix = platform != NULL && 0 == strcmp(platform, "aix"); + 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); + + // 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}; - time(&before); ret = poll(fds, 1, 2000); - time(&now); - assert(ret == 0); - assert(now - before >= 2); + assert(ret == 1); - sleep(1); - time(&now); - assert(now - before >= 3); + if (is_aix) + assert(fds[0].revents == POLLIN); + else + assert(fds[0].revents == (POLLHUP | POLLIN)); return 0; } diff --git a/test/wasi/test-wasi.js b/test/wasi/test-wasi.js index 89d8f73d684833..e4bd44e83d186c 100644 --- a/test/wasi/test-wasi.js +++ b/test/wasi/test-wasi.js @@ -38,7 +38,13 @@ if (process.argv[2] === 'wasi-child') { function runWASI(options) { console.log('executing', options.test); - const opts = { env: { ...process.env, NODE_DEBUG_NATIVE: 'wasi' } }; + const opts = { + env: { + ...process.env, + NODE_DEBUG_NATIVE: 'wasi', + NODE_PLATFORM: process.platform + } + }; if (options.stdin !== undefined) opts.input = options.stdin; @@ -75,7 +81,7 @@ if (process.argv[2] === 'wasi-child') { runWASI({ test: 'link' }); runWASI({ test: 'main_args' }); runWASI({ test: 'notdir' }); - // runWASI({ test: 'poll' }); + runWASI({ test: 'poll' }); runWASI({ test: 'preopen_populates' }); runWASI({ test: 'read_file', stdout: `hello from input.txt${EOL}` }); runWASI({ diff --git a/test/wasi/wasm/poll.wasm b/test/wasi/wasm/poll.wasm index 90b39c502ef4dbe3eaa0ca2f1122e3be99e882ea..37e17b8d880ad220cbb89732bd9e67ff31a21ec7 100755 GIT binary patch delta 7576 zcmZ`;31C!3(tg!52?LXmK|&Ie0M)}4Ac1gA2oN_9lK>h{QEm`0C=(0>ka)oaK}CoP zJQ0Kd;Znp43@W<7g1U;wk0|J}{^;V0=X&6->#gip{bnMfl9}m#b$(S{)!j3Ed7C;= zt9E@uY5n{8e2wE&6R+iqi}QNp;~F=P^ZER7PE(cAJw86pijR-C;+rM~@aK)A*#w%0 zEEV6v6Cr!W7Oy{I#fF-oGg9^Qwd;`8E?U^H!so2oU9Z5oTytsEd}pX7)|3AoK~q@!h6e*DsqjbbGpumaH`Ja z49*;=TS2fjx8l~7x(%mjhW9qEcgzKD&|YP{x8)$Wje2j#TDRwRx&yc84kfxHchu}> z)>#8cce0OKx-)!s4(l%5MQ6i7j(x(?T|w&_*4?<9j^u*aowK-mrS1W8j}YAE2JVv3 z(m5w^hdarRQB)_-aNUzJjM2TgC-+*Qdvk9c;!Zk`L!38O_kqED?!)<&x-V??MgGogn%rA^^Kkm;3d|_atc(VM0`A-1yr?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