| @@ -0,0 +1,38 @@ | ||
| /* Copyright (c) 2014, Ben Noordhuis <info@bnoordhuis.nl> | ||
| * | ||
| * Permission to use, copy, modify, and/or distribute this software for any | ||
| * purpose with or without fee is hereby granted, provided that the above | ||
| * copyright notice and this permission notice appear in all copies. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| */ | ||
|
|
||
| #include "uv.h" | ||
| #include "task.h" | ||
|
|
||
| static void timer_cb(uv_timer_t* handle) { | ||
| uv_close((uv_handle_t*) handle, NULL); | ||
| } | ||
|
|
||
|
|
||
| TEST_IMPL(loop_configure) { | ||
| uv_timer_t timer_handle; | ||
| uv_loop_t loop; | ||
| ASSERT(0 == uv_loop_init(&loop)); | ||
| #ifdef _WIN32 | ||
| ASSERT(UV_ENOSYS == uv_loop_configure(&loop, UV_LOOP_BLOCK_SIGNAL, 0)); | ||
| #else | ||
| ASSERT(0 == uv_loop_configure(&loop, UV_LOOP_BLOCK_SIGNAL, SIGPROF)); | ||
| #endif | ||
| ASSERT(0 == uv_timer_init(&loop, &timer_handle)); | ||
| ASSERT(0 == uv_timer_start(&timer_handle, timer_cb, 10, 0)); | ||
| ASSERT(0 == uv_run(&loop, UV_RUN_DEFAULT)); | ||
| ASSERT(0 == uv_loop_close(&loop)); | ||
| return 0; | ||
| } |
| @@ -246,6 +246,9 @@ TEST_IMPL(tcp_ping_pong) { | ||
|
|
||
|
|
||
| TEST_IMPL(tcp_ping_pong_v6) { | ||
| if (!can_ipv6()) | ||
| RETURN_SKIP("IPv6 not supported"); | ||
|
|
||
| tcp_pinger_v6_new(); | ||
| uv_run(uv_default_loop(), UV_RUN_DEFAULT); | ||
|
|
||
| @@ -0,0 +1,99 @@ | ||
| /* Copyright (c) 2015, Ben Noordhuis <info@bnoordhuis.nl> | ||
| * | ||
| * Permission to use, copy, modify, and/or distribute this software for any | ||
| * purpose with or without fee is hereby granted, provided that the above | ||
| * copyright notice and this permission notice appear in all copies. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| */ | ||
|
|
||
| #include "uv.h" | ||
| #include "task.h" | ||
|
|
||
| #ifdef _WIN32 | ||
|
|
||
| TEST_IMPL(pipe_set_non_blocking) { | ||
| RETURN_SKIP("Test not implemented on Windows."); | ||
| } | ||
|
|
||
| #else /* !_WIN32 */ | ||
|
|
||
| #include <errno.h> | ||
| #include <string.h> | ||
| #include <sys/socket.h> | ||
| #include <sys/types.h> | ||
| #include <sys/un.h> | ||
| #include <unistd.h> | ||
|
|
||
| struct thread_ctx { | ||
| uv_barrier_t barrier; | ||
| int fd; | ||
| }; | ||
|
|
||
| static void thread_main(void* arg) { | ||
| struct thread_ctx* ctx; | ||
| char buf[4096]; | ||
| ssize_t n; | ||
|
|
||
| ctx = arg; | ||
| uv_barrier_wait(&ctx->barrier); | ||
|
|
||
| do | ||
| n = read(ctx->fd, buf, sizeof(buf)); | ||
| while (n > 0 || (n == -1 && errno == EINTR)); | ||
|
|
||
| ASSERT(n == 0); | ||
| } | ||
|
|
||
| TEST_IMPL(pipe_set_non_blocking) { | ||
| struct thread_ctx ctx; | ||
| uv_pipe_t pipe_handle; | ||
| uv_thread_t thread; | ||
| size_t nwritten; | ||
| char data[4096]; | ||
| uv_buf_t buf; | ||
| int fd[2]; | ||
| int n; | ||
|
|
||
| ASSERT(0 == uv_pipe_init(uv_default_loop(), &pipe_handle, 0)); | ||
| ASSERT(0 == socketpair(AF_UNIX, SOCK_STREAM, 0, fd)); | ||
| ASSERT(0 == uv_pipe_open(&pipe_handle, fd[0])); | ||
| ASSERT(0 == uv_stream_set_blocking((uv_stream_t*) &pipe_handle, 1)); | ||
|
|
||
| ctx.fd = fd[1]; | ||
| ASSERT(0 == uv_barrier_init(&ctx.barrier, 2)); | ||
| ASSERT(0 == uv_thread_create(&thread, thread_main, &ctx)); | ||
| uv_barrier_wait(&ctx.barrier); | ||
|
|
||
| buf.len = sizeof(data); | ||
| buf.base = data; | ||
| memset(data, '.', sizeof(data)); | ||
|
|
||
| nwritten = 0; | ||
| while (nwritten < 10 << 20) { | ||
| /* The stream is in blocking mode so uv_try_write() should always succeed | ||
| * with the exact number of bytes that we wanted written. | ||
| */ | ||
| n = uv_try_write((uv_stream_t*) &pipe_handle, &buf, 1); | ||
| ASSERT(n == sizeof(data)); | ||
| nwritten += n; | ||
| } | ||
|
|
||
| uv_close((uv_handle_t*) &pipe_handle, NULL); | ||
| ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT)); | ||
|
|
||
| ASSERT(0 == close(fd[1])); /* fd[0] is closed by uv_close(). */ | ||
| ASSERT(0 == uv_thread_join(&thread)); | ||
| uv_barrier_destroy(&ctx.barrier); | ||
|
|
||
| MAKE_VALGRIND_HAPPY(); | ||
| return 0; | ||
| } | ||
|
|
||
| #endif /* !_WIN32 */ |
| @@ -0,0 +1,114 @@ | ||
| /* Copyright Bert Belder, and other libuv contributors. All rights reserved. | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to | ||
| * deal in the Software without restriction, including without limitation the | ||
| * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
| * sell copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
| * IN THE SOFTWARE. | ||
| */ | ||
|
|
||
| #ifdef _WIN32 | ||
|
|
||
| #include <errno.h> | ||
| #include <stdio.h> | ||
|
|
||
| #include "uv.h" | ||
| #include "task.h" | ||
|
|
||
| #ifdef _MSC_VER /* msvc */ | ||
| # define NO_INLINE __declspec(noinline) | ||
| #else /* gcc */ | ||
| # define NO_INLINE __attribute__ ((noinline)) | ||
| #endif | ||
|
|
||
|
|
||
| uv_os_sock_t sock; | ||
| uv_poll_t handle; | ||
|
|
||
| static int close_cb_called = 0; | ||
|
|
||
|
|
||
| static void close_cb(uv_handle_t* h) { | ||
| close_cb_called++; | ||
| } | ||
|
|
||
|
|
||
| static void poll_cb(uv_poll_t* h, int status, int events) { | ||
| ASSERT(0 && "should never get here"); | ||
| } | ||
|
|
||
|
|
||
| static void NO_INLINE close_socket_and_verify_stack() { | ||
| const uint32_t MARKER = 0xDEADBEEF; | ||
| const int VERIFY_AFTER = 10; /* ms */ | ||
| int r; | ||
|
|
||
| volatile uint32_t data[65536]; | ||
| size_t i; | ||
|
|
||
| for (i = 0; i < ARRAY_SIZE(data); i++) | ||
| data[i] = MARKER; | ||
|
|
||
| r = closesocket(sock); | ||
| ASSERT(r == 0); | ||
|
|
||
| uv_sleep(VERIFY_AFTER); | ||
|
|
||
| for (i = 0; i < ARRAY_SIZE(data); i++) | ||
| ASSERT(data[i] == MARKER); | ||
| } | ||
|
|
||
|
|
||
| TEST_IMPL(poll_close_doesnt_corrupt_stack) { | ||
| struct WSAData wsa_data; | ||
| int r; | ||
| unsigned long on; | ||
| struct sockaddr_in addr; | ||
|
|
||
| r = WSAStartup(MAKEWORD(2, 2), &wsa_data); | ||
| ASSERT(r == 0); | ||
|
|
||
| sock = socket(AF_INET, SOCK_STREAM, 0); | ||
| ASSERT(sock != INVALID_SOCKET); | ||
| on = 1; | ||
| r = ioctlsocket(sock, FIONBIO, &on); | ||
| ASSERT(r == 0); | ||
|
|
||
| r = uv_ip4_addr("127.0.0.1", TEST_PORT, &addr); | ||
| ASSERT(r == 0); | ||
|
|
||
| r = connect(sock, (const struct sockaddr*) &addr, sizeof addr); | ||
| ASSERT(r != 0); | ||
| ASSERT(WSAGetLastError() == WSAEWOULDBLOCK); | ||
|
|
||
| r = uv_poll_init_socket(uv_default_loop(), &handle, sock); | ||
| ASSERT(r == 0); | ||
| r = uv_poll_start(&handle, UV_READABLE | UV_WRITABLE, poll_cb); | ||
| ASSERT(r == 0); | ||
|
|
||
| uv_close((uv_handle_t*) &handle, close_cb); | ||
|
|
||
| close_socket_and_verify_stack(); | ||
|
|
||
| r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); | ||
| ASSERT(r == 0); | ||
|
|
||
| ASSERT(close_cb_called == 1); | ||
|
|
||
| MAKE_VALGRIND_HAPPY(); | ||
| return 0; | ||
| } | ||
|
|
||
| #endif /* _WIN32 */ |
| @@ -0,0 +1,44 @@ | ||
| // Copyright Joyent, Inc. and other Node contributors. | ||
| // | ||
| // Permission is hereby granted, free of charge, to any person obtaining a | ||
| // copy of this software and associated documentation files (the | ||
| // "Software"), to deal in the Software without restriction, including | ||
| // without limitation the rights to use, copy, modify, merge, publish, | ||
| // distribute, sublicense, and/or sell copies of the Software, and to permit | ||
| // persons to whom the Software is furnished to do so, subject to the | ||
| // following conditions: | ||
| // | ||
| // The above copyright notice and this permission notice shall be included | ||
| // in all copies or substantial portions of the Software. | ||
| // | ||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
| // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
| // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
| // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
| // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
| // USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
|
||
| var common = require('../common'); | ||
| var assert = require('assert'); | ||
| var fork = require('child_process').fork; | ||
| var N = 4 << 20; // 4 MB | ||
|
|
||
| for (var big = '*'; big.length < N; big += big); | ||
|
|
||
| if (process.argv[2] === 'child') { | ||
| process.send(big); | ||
| process.exit(42); | ||
| } | ||
|
|
||
| var proc = fork(__filename, ['child']); | ||
|
|
||
| proc.on('message', common.mustCall(function(msg) { | ||
| assert.equal(typeof msg, 'string'); | ||
| assert.equal(msg.length, N); | ||
| assert.equal(msg, big); | ||
| })); | ||
|
|
||
| proc.on('exit', common.mustCall(function(exitCode) { | ||
| assert.equal(exitCode, 42); | ||
| })); |
| @@ -49,8 +49,9 @@ server.listen(common.PORT, function() { | ||
| req.end(); | ||
| test(); | ||
| } else { | ||
| req.write('hello', function() { | ||
| timer = setImmediate(write); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| @@ -0,0 +1,44 @@ | ||
| // Copyright Joyent, Inc. and other Node contributors. | ||
| // | ||
| // Permission is hereby granted, free of charge, to any person obtaining a | ||
| // copy of this software and associated documentation files (the | ||
| // "Software"), to deal in the Software without restriction, including | ||
| // without limitation the rights to use, copy, modify, merge, publish, | ||
| // distribute, sublicense, and/or sell copies of the Software, and to permit | ||
| // persons to whom the Software is furnished to do so, subject to the | ||
| // following conditions: | ||
| // | ||
| // The above copyright notice and this permission notice shall be included | ||
| // in all copies or substantial portions of the Software. | ||
| // | ||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
| // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
| // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
| // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
| // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
| // USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
|
||
| var common = require('../common'); | ||
| var assert = require('assert'); | ||
| var spawn = require('child_process').spawn; | ||
| var N = 4 << 20; // 4 MB | ||
|
|
||
| for (var big = '*'; big.length < N; big += big); | ||
|
|
||
| if (process.argv[2] === 'child') { | ||
| process.stdout.write(big); | ||
| process.exit(42); | ||
| } | ||
|
|
||
| var stdio = ['inherit', 'pipe', 'inherit']; | ||
| var proc = spawn(process.execPath, [__filename, 'child'], { stdio: stdio }); | ||
|
|
||
| var chunks = []; | ||
| proc.stdout.setEncoding('utf8'); | ||
| proc.stdout.on('data', chunks.push.bind(chunks)); | ||
|
|
||
| proc.on('exit', common.mustCall(function(exitCode) { | ||
| assert.equal(exitCode, 42); | ||
| assert.equal(chunks.join(''), big); | ||
| })); |
| @@ -0,0 +1,34 @@ | ||
| // Copyright Joyent, Inc. and other Node contributors. | ||
| // | ||
| // Permission is hereby granted, free of charge, to any person obtaining a | ||
| // copy of this software and associated documentation files (the | ||
| // "Software"), to deal in the Software without restriction, including | ||
| // without limitation the rights to use, copy, modify, merge, publish, | ||
| // distribute, sublicense, and/or sell copies of the Software, and to permit | ||
| // persons to whom the Software is furnished to do so, subject to the | ||
| // following conditions: | ||
| // | ||
| // The above copyright notice and this permission notice shall be included | ||
| // in all copies or substantial portions of the Software. | ||
| // | ||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
| // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
| // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
| // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
| // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
| // USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
|
||
| /* | ||
| * This test makes sure that every builtin module can be loaded | ||
| * when the V8's --use-strict command line option is passed to node. | ||
| */ | ||
|
|
||
| var child_process = require('child_process'); | ||
|
|
||
| if (process.argv[2] !== 'child') { | ||
| child_process.fork(__filename, ['child'], { execArgv: ['--use-strict']}); | ||
| } else { | ||
| var natives = process.binding('natives'); | ||
| Object.keys(natives).forEach(require); | ||
| } |