rbuv 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +5 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +0 -1
- data/README.md +6 -1
- data/Rakefile +42 -0
- data/deps/libuv/.gitignore +34 -0
- data/deps/libuv/.mailmap +16 -0
- data/deps/libuv/AUTHORS +81 -0
- data/deps/libuv/ChangeLog +45 -0
- data/deps/libuv/LICENSE +41 -0
- data/deps/libuv/Makefile +53 -0
- data/deps/libuv/README.md +118 -0
- data/deps/libuv/build.mk +164 -0
- data/deps/libuv/checksparse.sh +230 -0
- data/deps/libuv/common.gypi +197 -0
- data/deps/libuv/config-mingw.mk +48 -0
- data/deps/libuv/config-unix.mk +167 -0
- data/deps/libuv/gyp_uv +98 -0
- data/deps/libuv/include/uv-private/ngx-queue.h +129 -0
- data/deps/libuv/include/uv-private/stdint-msvc2008.h +247 -0
- data/deps/libuv/include/uv-private/tree.h +768 -0
- data/deps/libuv/include/uv-private/uv-bsd.h +34 -0
- data/deps/libuv/include/uv-private/uv-darwin.h +61 -0
- data/deps/libuv/include/uv-private/uv-linux.h +34 -0
- data/deps/libuv/include/uv-private/uv-sunos.h +44 -0
- data/deps/libuv/include/uv-private/uv-unix.h +332 -0
- data/deps/libuv/include/uv-private/uv-win.h +585 -0
- data/deps/libuv/include/uv.h +1987 -0
- data/deps/libuv/src/fs-poll.c +248 -0
- data/deps/libuv/src/inet.c +298 -0
- data/deps/libuv/src/unix/aix.c +393 -0
- data/deps/libuv/src/unix/async.c +281 -0
- data/deps/libuv/src/unix/core.c +714 -0
- data/deps/libuv/src/unix/cygwin.c +93 -0
- data/deps/libuv/src/unix/darwin-proctitle.m +78 -0
- data/deps/libuv/src/unix/darwin.c +431 -0
- data/deps/libuv/src/unix/dl.c +83 -0
- data/deps/libuv/src/unix/error.c +109 -0
- data/deps/libuv/src/unix/freebsd.c +343 -0
- data/deps/libuv/src/unix/fs.c +869 -0
- data/deps/libuv/src/unix/fsevents.c +299 -0
- data/deps/libuv/src/unix/getaddrinfo.c +159 -0
- data/deps/libuv/src/unix/internal.h +259 -0
- data/deps/libuv/src/unix/kqueue.c +347 -0
- data/deps/libuv/src/unix/linux-core.c +724 -0
- data/deps/libuv/src/unix/linux-inotify.c +236 -0
- data/deps/libuv/src/unix/linux-syscalls.c +388 -0
- data/deps/libuv/src/unix/linux-syscalls.h +150 -0
- data/deps/libuv/src/unix/loop-watcher.c +64 -0
- data/deps/libuv/src/unix/loop.c +114 -0
- data/deps/libuv/src/unix/netbsd.c +353 -0
- data/deps/libuv/src/unix/openbsd.c +304 -0
- data/deps/libuv/src/unix/pipe.c +261 -0
- data/deps/libuv/src/unix/poll.c +108 -0
- data/deps/libuv/src/unix/process.c +501 -0
- data/deps/libuv/src/unix/proctitle.c +103 -0
- data/deps/libuv/src/unix/signal.c +455 -0
- data/deps/libuv/src/unix/stream.c +1380 -0
- data/deps/libuv/src/unix/sunos.c +647 -0
- data/deps/libuv/src/unix/tcp.c +357 -0
- data/deps/libuv/src/unix/thread.c +431 -0
- data/deps/libuv/src/unix/threadpool.c +286 -0
- data/deps/libuv/src/unix/timer.c +153 -0
- data/deps/libuv/src/unix/tty.c +179 -0
- data/deps/libuv/src/unix/udp.c +715 -0
- data/deps/libuv/src/uv-common.c +431 -0
- data/deps/libuv/src/uv-common.h +204 -0
- data/deps/libuv/src/version.c +60 -0
- data/deps/libuv/src/win/async.c +99 -0
- data/deps/libuv/src/win/atomicops-inl.h +56 -0
- data/deps/libuv/src/win/core.c +310 -0
- data/deps/libuv/src/win/dl.c +86 -0
- data/deps/libuv/src/win/error.c +164 -0
- data/deps/libuv/src/win/fs-event.c +506 -0
- data/deps/libuv/src/win/fs.c +1951 -0
- data/deps/libuv/src/win/getaddrinfo.c +365 -0
- data/deps/libuv/src/win/handle-inl.h +164 -0
- data/deps/libuv/src/win/handle.c +153 -0
- data/deps/libuv/src/win/internal.h +346 -0
- data/deps/libuv/src/win/loop-watcher.c +124 -0
- data/deps/libuv/src/win/pipe.c +1656 -0
- data/deps/libuv/src/win/poll.c +615 -0
- data/deps/libuv/src/win/process-stdio.c +503 -0
- data/deps/libuv/src/win/process.c +1048 -0
- data/deps/libuv/src/win/req-inl.h +224 -0
- data/deps/libuv/src/win/req.c +25 -0
- data/deps/libuv/src/win/signal.c +354 -0
- data/deps/libuv/src/win/stream-inl.h +67 -0
- data/deps/libuv/src/win/stream.c +198 -0
- data/deps/libuv/src/win/tcp.c +1422 -0
- data/deps/libuv/src/win/thread.c +666 -0
- data/deps/libuv/src/win/threadpool.c +82 -0
- data/deps/libuv/src/win/timer.c +230 -0
- data/deps/libuv/src/win/tty.c +1857 -0
- data/deps/libuv/src/win/udp.c +744 -0
- data/deps/libuv/src/win/util.c +946 -0
- data/deps/libuv/src/win/winapi.c +152 -0
- data/deps/libuv/src/win/winapi.h +4476 -0
- data/deps/libuv/src/win/winsock.c +560 -0
- data/deps/libuv/src/win/winsock.h +171 -0
- data/deps/libuv/test/benchmark-async-pummel.c +119 -0
- data/deps/libuv/test/benchmark-async.c +139 -0
- data/deps/libuv/test/benchmark-fs-stat.c +136 -0
- data/deps/libuv/test/benchmark-getaddrinfo.c +91 -0
- data/deps/libuv/test/benchmark-list.h +163 -0
- data/deps/libuv/test/benchmark-loop-count.c +90 -0
- data/deps/libuv/test/benchmark-million-async.c +112 -0
- data/deps/libuv/test/benchmark-million-timers.c +77 -0
- data/deps/libuv/test/benchmark-multi-accept.c +432 -0
- data/deps/libuv/test/benchmark-ping-pongs.c +212 -0
- data/deps/libuv/test/benchmark-pound.c +325 -0
- data/deps/libuv/test/benchmark-pump.c +459 -0
- data/deps/libuv/test/benchmark-sizes.c +45 -0
- data/deps/libuv/test/benchmark-spawn.c +163 -0
- data/deps/libuv/test/benchmark-tcp-write-batch.c +141 -0
- data/deps/libuv/test/benchmark-thread.c +64 -0
- data/deps/libuv/test/benchmark-udp-pummel.c +238 -0
- data/deps/libuv/test/blackhole-server.c +118 -0
- data/deps/libuv/test/dns-server.c +329 -0
- data/deps/libuv/test/echo-server.c +384 -0
- data/deps/libuv/test/fixtures/empty_file +0 -0
- data/deps/libuv/test/fixtures/load_error.node +1 -0
- data/deps/libuv/test/run-benchmarks.c +64 -0
- data/deps/libuv/test/run-tests.c +159 -0
- data/deps/libuv/test/runner-unix.c +328 -0
- data/deps/libuv/test/runner-unix.h +36 -0
- data/deps/libuv/test/runner-win.c +318 -0
- data/deps/libuv/test/runner-win.h +43 -0
- data/deps/libuv/test/runner.c +394 -0
- data/deps/libuv/test/runner.h +165 -0
- data/deps/libuv/test/task.h +122 -0
- data/deps/libuv/test/test-active.c +83 -0
- data/deps/libuv/test/test-async.c +136 -0
- data/deps/libuv/test/test-barrier.c +98 -0
- data/deps/libuv/test/test-callback-order.c +77 -0
- data/deps/libuv/test/test-callback-stack.c +204 -0
- data/deps/libuv/test/test-condvar.c +173 -0
- data/deps/libuv/test/test-connection-fail.c +150 -0
- data/deps/libuv/test/test-cwd-and-chdir.c +64 -0
- data/deps/libuv/test/test-delayed-accept.c +189 -0
- data/deps/libuv/test/test-dlerror.c +58 -0
- data/deps/libuv/test/test-embed.c +136 -0
- data/deps/libuv/test/test-error.c +59 -0
- data/deps/libuv/test/test-fail-always.c +29 -0
- data/deps/libuv/test/test-fs-event.c +504 -0
- data/deps/libuv/test/test-fs-poll.c +148 -0
- data/deps/libuv/test/test-fs.c +1899 -0
- data/deps/libuv/test/test-get-currentexe.c +63 -0
- data/deps/libuv/test/test-get-loadavg.c +36 -0
- data/deps/libuv/test/test-get-memory.c +38 -0
- data/deps/libuv/test/test-getaddrinfo.c +120 -0
- data/deps/libuv/test/test-getsockname.c +344 -0
- data/deps/libuv/test/test-hrtime.c +54 -0
- data/deps/libuv/test/test-idle.c +82 -0
- data/deps/libuv/test/test-ipc-send-recv.c +218 -0
- data/deps/libuv/test/test-ipc.c +625 -0
- data/deps/libuv/test/test-list.h +492 -0
- data/deps/libuv/test/test-loop-handles.c +337 -0
- data/deps/libuv/test/test-loop-stop.c +73 -0
- data/deps/libuv/test/test-multiple-listen.c +103 -0
- data/deps/libuv/test/test-mutexes.c +63 -0
- data/deps/libuv/test/test-pass-always.c +28 -0
- data/deps/libuv/test/test-ping-pong.c +250 -0
- data/deps/libuv/test/test-pipe-bind-error.c +144 -0
- data/deps/libuv/test/test-pipe-connect-error.c +98 -0
- data/deps/libuv/test/test-platform-output.c +87 -0
- data/deps/libuv/test/test-poll-close.c +73 -0
- data/deps/libuv/test/test-poll.c +575 -0
- data/deps/libuv/test/test-process-title.c +49 -0
- data/deps/libuv/test/test-ref.c +415 -0
- data/deps/libuv/test/test-run-nowait.c +46 -0
- data/deps/libuv/test/test-run-once.c +49 -0
- data/deps/libuv/test/test-semaphore.c +111 -0
- data/deps/libuv/test/test-shutdown-close.c +105 -0
- data/deps/libuv/test/test-shutdown-eof.c +184 -0
- data/deps/libuv/test/test-signal-multiple-loops.c +270 -0
- data/deps/libuv/test/test-signal.c +152 -0
- data/deps/libuv/test/test-spawn.c +938 -0
- data/deps/libuv/test/test-stdio-over-pipes.c +250 -0
- data/deps/libuv/test/test-tcp-bind-error.c +198 -0
- data/deps/libuv/test/test-tcp-bind6-error.c +159 -0
- data/deps/libuv/test/test-tcp-close-while-connecting.c +81 -0
- data/deps/libuv/test/test-tcp-close.c +130 -0
- data/deps/libuv/test/test-tcp-connect-error-after-write.c +96 -0
- data/deps/libuv/test/test-tcp-connect-error.c +71 -0
- data/deps/libuv/test/test-tcp-connect-timeout.c +86 -0
- data/deps/libuv/test/test-tcp-connect6-error.c +69 -0
- data/deps/libuv/test/test-tcp-flags.c +52 -0
- data/deps/libuv/test/test-tcp-open.c +175 -0
- data/deps/libuv/test/test-tcp-read-stop.c +73 -0
- data/deps/libuv/test/test-tcp-shutdown-after-write.c +132 -0
- data/deps/libuv/test/test-tcp-unexpected-read.c +114 -0
- data/deps/libuv/test/test-tcp-write-to-half-open-connection.c +136 -0
- data/deps/libuv/test/test-tcp-writealot.c +171 -0
- data/deps/libuv/test/test-thread.c +183 -0
- data/deps/libuv/test/test-threadpool-cancel.c +311 -0
- data/deps/libuv/test/test-threadpool.c +77 -0
- data/deps/libuv/test/test-timer-again.c +142 -0
- data/deps/libuv/test/test-timer.c +266 -0
- data/deps/libuv/test/test-tty.c +111 -0
- data/deps/libuv/test/test-udp-dgram-too-big.c +87 -0
- data/deps/libuv/test/test-udp-ipv6.c +158 -0
- data/deps/libuv/test/test-udp-multicast-join.c +140 -0
- data/deps/libuv/test/test-udp-multicast-ttl.c +87 -0
- data/deps/libuv/test/test-udp-open.c +154 -0
- data/deps/libuv/test/test-udp-options.c +87 -0
- data/deps/libuv/test/test-udp-send-and-recv.c +210 -0
- data/deps/libuv/test/test-util.c +97 -0
- data/deps/libuv/test/test-walk-handles.c +78 -0
- data/deps/libuv/uv.gyp +431 -0
- data/deps/libuv/vcbuild.bat +128 -0
- data/ext/rbuv/debug.h +27 -0
- data/ext/rbuv/error.c +7 -0
- data/ext/rbuv/error.h +10 -0
- data/ext/rbuv/extconf.rb +35 -0
- data/ext/rbuv/handle.c +40 -0
- data/ext/rbuv/handle.h +14 -0
- data/ext/rbuv/libuv.mk +12 -0
- data/ext/rbuv/loop.c +50 -0
- data/ext/rbuv/loop.h +13 -0
- data/ext/rbuv/rbuv.c +15 -0
- data/ext/rbuv/rbuv.h +27 -0
- data/ext/rbuv/timer.c +133 -0
- data/ext/rbuv/timer.h +13 -0
- data/lib/rbuv/timer.rb +7 -0
- data/lib/rbuv/version.rb +1 -1
- data/lib/rbuv.rb +24 -2
- data/rbuv.gemspec +5 -1
- data/spec/spec_helper.rb +22 -0
- data/spec/timer_spec.rb +144 -0
- metadata +278 -9
@@ -0,0 +1,337 @@
|
|
1
|
+
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
2
|
+
*
|
3
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
* of this software and associated documentation files (the "Software"), to
|
5
|
+
* deal in the Software without restriction, including without limitation the
|
6
|
+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
* sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
* furnished to do so, subject to the following conditions:
|
9
|
+
*
|
10
|
+
* The above copyright notice and this permission notice shall be included in
|
11
|
+
* all copies or substantial portions of the Software.
|
12
|
+
*
|
13
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
18
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
19
|
+
* IN THE SOFTWARE.
|
20
|
+
*/
|
21
|
+
|
22
|
+
/* Tests commented out with XXX are ones that are failing on Linux */
|
23
|
+
|
24
|
+
/*
|
25
|
+
* Purpose of this test is to check semantics of starting and stopping
|
26
|
+
* prepare, check and idle watchers.
|
27
|
+
*
|
28
|
+
* - A watcher must be able to safely stop or close itself;
|
29
|
+
* - Once a watcher is stopped or closed its callback should never be called.
|
30
|
+
* - If a watcher is closed, it is implicitly stopped and its close_cb should
|
31
|
+
* be called exactly once.
|
32
|
+
* - A watcher can safely start and stop other watchers of the same type.
|
33
|
+
* - Prepare and check watchers are called once per event loop iterations.
|
34
|
+
* - All active idle watchers are queued when the event loop has no more work
|
35
|
+
* to do. This is done repeatedly until all idle watchers are inactive.
|
36
|
+
* - If a watcher starts another watcher of the same type its callback is not
|
37
|
+
* immediately queued. For check and prepare watchers, that means that if
|
38
|
+
* a watcher makes another of the same type active, it'll not be called until
|
39
|
+
* the next event loop iteration. For idle. watchers this means that the
|
40
|
+
* newly activated idle watcher might not be queued immediately.
|
41
|
+
* - Prepare, check, idle watchers keep the event loop alive even when they're
|
42
|
+
* not active.
|
43
|
+
*
|
44
|
+
* This is what the test globally does:
|
45
|
+
*
|
46
|
+
* - prepare_1 is always active and counts event loop iterations. It also
|
47
|
+
* creates and starts prepare_2 every other iteration. Finally it verifies
|
48
|
+
* that no idle watchers are active before polling.
|
49
|
+
* - prepare_2 is started by prepare_1 every other iteration. It immediately
|
50
|
+
* stops itself. It verifies that a watcher is not queued immediately
|
51
|
+
* if created by another watcher of the same type.
|
52
|
+
* - There's a check watcher that stops the event loop after a certain number
|
53
|
+
* of iterations. It starts a varying number of idle_1 watchers.
|
54
|
+
* - Idle_1 watchers stop themselves after being called a few times. All idle_1
|
55
|
+
* watchers try to start the idle_2 watcher if it is not already started or
|
56
|
+
* awaiting its close callback.
|
57
|
+
* - The idle_2 watcher always exists but immediately closes itself after
|
58
|
+
* being started by a check_1 watcher. It verifies that a watcher is
|
59
|
+
* implicitly stopped when closed, and that a watcher can close itself
|
60
|
+
* safely.
|
61
|
+
* - There is a repeating timer. It does not keep the event loop alive
|
62
|
+
* (ev_unref) but makes sure that the loop keeps polling the system for
|
63
|
+
* events.
|
64
|
+
*/
|
65
|
+
|
66
|
+
|
67
|
+
#include "uv.h"
|
68
|
+
#include "task.h"
|
69
|
+
|
70
|
+
#include <math.h>
|
71
|
+
|
72
|
+
|
73
|
+
#define IDLE_COUNT 7
|
74
|
+
#define ITERATIONS 21
|
75
|
+
#define TIMEOUT 100
|
76
|
+
|
77
|
+
|
78
|
+
static uv_prepare_t prepare_1_handle;
|
79
|
+
static uv_prepare_t prepare_2_handle;
|
80
|
+
|
81
|
+
static uv_check_t check_handle;
|
82
|
+
|
83
|
+
static uv_idle_t idle_1_handles[IDLE_COUNT];
|
84
|
+
static uv_idle_t idle_2_handle;
|
85
|
+
|
86
|
+
static uv_timer_t timer_handle;
|
87
|
+
|
88
|
+
|
89
|
+
static int loop_iteration = 0;
|
90
|
+
|
91
|
+
static int prepare_1_cb_called = 0;
|
92
|
+
static int prepare_1_close_cb_called = 0;
|
93
|
+
|
94
|
+
static int prepare_2_cb_called = 0;
|
95
|
+
static int prepare_2_close_cb_called = 0;
|
96
|
+
|
97
|
+
static int check_cb_called = 0;
|
98
|
+
static int check_close_cb_called = 0;
|
99
|
+
|
100
|
+
static int idle_1_cb_called = 0;
|
101
|
+
static int idle_1_close_cb_called = 0;
|
102
|
+
static int idles_1_active = 0;
|
103
|
+
|
104
|
+
static int idle_2_cb_called = 0;
|
105
|
+
static int idle_2_close_cb_called = 0;
|
106
|
+
static int idle_2_cb_started = 0;
|
107
|
+
static int idle_2_is_active = 0;
|
108
|
+
|
109
|
+
|
110
|
+
static void timer_cb(uv_timer_t* handle, int status) {
|
111
|
+
ASSERT(handle == &timer_handle);
|
112
|
+
ASSERT(status == 0);
|
113
|
+
}
|
114
|
+
|
115
|
+
|
116
|
+
static void idle_2_close_cb(uv_handle_t* handle) {
|
117
|
+
LOG("IDLE_2_CLOSE_CB\n");
|
118
|
+
|
119
|
+
ASSERT(handle == (uv_handle_t*)&idle_2_handle);
|
120
|
+
|
121
|
+
ASSERT(idle_2_is_active);
|
122
|
+
|
123
|
+
idle_2_close_cb_called++;
|
124
|
+
idle_2_is_active = 0;
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
static void idle_2_cb(uv_idle_t* handle, int status) {
|
129
|
+
LOG("IDLE_2_CB\n");
|
130
|
+
|
131
|
+
ASSERT(handle == &idle_2_handle);
|
132
|
+
ASSERT(status == 0);
|
133
|
+
|
134
|
+
idle_2_cb_called++;
|
135
|
+
|
136
|
+
uv_close((uv_handle_t*)handle, idle_2_close_cb);
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
static void idle_1_cb(uv_idle_t* handle, int status) {
|
141
|
+
int r;
|
142
|
+
|
143
|
+
LOG("IDLE_1_CB\n");
|
144
|
+
|
145
|
+
ASSERT(handle != NULL);
|
146
|
+
ASSERT(status == 0);
|
147
|
+
|
148
|
+
ASSERT(idles_1_active > 0);
|
149
|
+
|
150
|
+
/* Init idle_2 and make it active */
|
151
|
+
if (!idle_2_is_active && !uv_is_closing((uv_handle_t*)&idle_2_handle)) {
|
152
|
+
r = uv_idle_init(uv_default_loop(), &idle_2_handle);
|
153
|
+
ASSERT(r == 0);
|
154
|
+
r = uv_idle_start(&idle_2_handle, idle_2_cb);
|
155
|
+
ASSERT(r == 0);
|
156
|
+
idle_2_is_active = 1;
|
157
|
+
idle_2_cb_started++;
|
158
|
+
}
|
159
|
+
|
160
|
+
idle_1_cb_called++;
|
161
|
+
|
162
|
+
if (idle_1_cb_called % 5 == 0) {
|
163
|
+
r = uv_idle_stop((uv_idle_t*)handle);
|
164
|
+
ASSERT(r == 0);
|
165
|
+
idles_1_active--;
|
166
|
+
}
|
167
|
+
}
|
168
|
+
|
169
|
+
|
170
|
+
static void idle_1_close_cb(uv_handle_t* handle) {
|
171
|
+
LOG("IDLE_1_CLOSE_CB\n");
|
172
|
+
|
173
|
+
ASSERT(handle != NULL);
|
174
|
+
|
175
|
+
idle_1_close_cb_called++;
|
176
|
+
}
|
177
|
+
|
178
|
+
|
179
|
+
static void prepare_1_close_cb(uv_handle_t* handle) {
|
180
|
+
LOG("PREPARE_1_CLOSE_CB");
|
181
|
+
ASSERT(handle == (uv_handle_t*)&prepare_1_handle);
|
182
|
+
|
183
|
+
prepare_1_close_cb_called++;
|
184
|
+
}
|
185
|
+
|
186
|
+
|
187
|
+
static void check_close_cb(uv_handle_t* handle) {
|
188
|
+
LOG("CHECK_CLOSE_CB\n");
|
189
|
+
ASSERT(handle == (uv_handle_t*)&check_handle);
|
190
|
+
|
191
|
+
check_close_cb_called++;
|
192
|
+
}
|
193
|
+
|
194
|
+
|
195
|
+
static void prepare_2_close_cb(uv_handle_t* handle) {
|
196
|
+
LOG("PREPARE_2_CLOSE_CB\n");
|
197
|
+
ASSERT(handle == (uv_handle_t*)&prepare_2_handle);
|
198
|
+
|
199
|
+
prepare_2_close_cb_called++;
|
200
|
+
}
|
201
|
+
|
202
|
+
|
203
|
+
static void check_cb(uv_check_t* handle, int status) {
|
204
|
+
int i, r;
|
205
|
+
|
206
|
+
LOG("CHECK_CB\n");
|
207
|
+
|
208
|
+
ASSERT(handle == &check_handle);
|
209
|
+
ASSERT(status == 0);
|
210
|
+
|
211
|
+
if (loop_iteration < ITERATIONS) {
|
212
|
+
/* Make some idle watchers active */
|
213
|
+
for (i = 0; i < 1 + (loop_iteration % IDLE_COUNT); i++) {
|
214
|
+
r = uv_idle_start(&idle_1_handles[i], idle_1_cb);
|
215
|
+
ASSERT(r == 0);
|
216
|
+
idles_1_active++;
|
217
|
+
}
|
218
|
+
|
219
|
+
} else {
|
220
|
+
/* End of the test - close all handles */
|
221
|
+
uv_close((uv_handle_t*)&prepare_1_handle, prepare_1_close_cb);
|
222
|
+
uv_close((uv_handle_t*)&check_handle, check_close_cb);
|
223
|
+
uv_close((uv_handle_t*)&prepare_2_handle, prepare_2_close_cb);
|
224
|
+
|
225
|
+
for (i = 0; i < IDLE_COUNT; i++) {
|
226
|
+
uv_close((uv_handle_t*)&idle_1_handles[i], idle_1_close_cb);
|
227
|
+
}
|
228
|
+
|
229
|
+
/* This handle is closed/recreated every time, close it only if it is */
|
230
|
+
/* active.*/
|
231
|
+
if (idle_2_is_active) {
|
232
|
+
uv_close((uv_handle_t*)&idle_2_handle, idle_2_close_cb);
|
233
|
+
}
|
234
|
+
}
|
235
|
+
|
236
|
+
check_cb_called++;
|
237
|
+
}
|
238
|
+
|
239
|
+
|
240
|
+
static void prepare_2_cb(uv_prepare_t* handle, int status) {
|
241
|
+
int r;
|
242
|
+
|
243
|
+
LOG("PREPARE_2_CB\n");
|
244
|
+
|
245
|
+
ASSERT(handle == &prepare_2_handle);
|
246
|
+
ASSERT(status == 0);
|
247
|
+
|
248
|
+
/* prepare_2 gets started by prepare_1 when (loop_iteration % 2 == 0), */
|
249
|
+
/* and it stops itself immediately. A started watcher is not queued */
|
250
|
+
/* until the next round, so when this callback is made */
|
251
|
+
/* (loop_iteration % 2 == 0) cannot be true. */
|
252
|
+
ASSERT(loop_iteration % 2 != 0);
|
253
|
+
|
254
|
+
r = uv_prepare_stop((uv_prepare_t*)handle);
|
255
|
+
ASSERT(r == 0);
|
256
|
+
|
257
|
+
prepare_2_cb_called++;
|
258
|
+
}
|
259
|
+
|
260
|
+
|
261
|
+
static void prepare_1_cb(uv_prepare_t* handle, int status) {
|
262
|
+
int r;
|
263
|
+
|
264
|
+
LOG("PREPARE_1_CB\n");
|
265
|
+
|
266
|
+
ASSERT(handle == &prepare_1_handle);
|
267
|
+
ASSERT(status == 0);
|
268
|
+
|
269
|
+
if (loop_iteration % 2 == 0) {
|
270
|
+
r = uv_prepare_start(&prepare_2_handle, prepare_2_cb);
|
271
|
+
ASSERT(r == 0);
|
272
|
+
}
|
273
|
+
|
274
|
+
prepare_1_cb_called++;
|
275
|
+
loop_iteration++;
|
276
|
+
|
277
|
+
printf("Loop iteration %d of %d.\n", loop_iteration, ITERATIONS);
|
278
|
+
}
|
279
|
+
|
280
|
+
|
281
|
+
TEST_IMPL(loop_handles) {
|
282
|
+
int i;
|
283
|
+
int r;
|
284
|
+
|
285
|
+
r = uv_prepare_init(uv_default_loop(), &prepare_1_handle);
|
286
|
+
ASSERT(r == 0);
|
287
|
+
r = uv_prepare_start(&prepare_1_handle, prepare_1_cb);
|
288
|
+
ASSERT(r == 0);
|
289
|
+
|
290
|
+
r = uv_check_init(uv_default_loop(), &check_handle);
|
291
|
+
ASSERT(r == 0);
|
292
|
+
r = uv_check_start(&check_handle, check_cb);
|
293
|
+
ASSERT(r == 0);
|
294
|
+
|
295
|
+
/* initialize only, prepare_2 is started by prepare_1_cb */
|
296
|
+
r = uv_prepare_init(uv_default_loop(), &prepare_2_handle);
|
297
|
+
ASSERT(r == 0);
|
298
|
+
|
299
|
+
for (i = 0; i < IDLE_COUNT; i++) {
|
300
|
+
/* initialize only, idle_1 handles are started by check_cb */
|
301
|
+
r = uv_idle_init(uv_default_loop(), &idle_1_handles[i]);
|
302
|
+
ASSERT(r == 0);
|
303
|
+
}
|
304
|
+
|
305
|
+
/* don't init or start idle_2, both is done by idle_1_cb */
|
306
|
+
|
307
|
+
/* the timer callback is there to keep the event loop polling */
|
308
|
+
/* unref it as it is not supposed to keep the loop alive */
|
309
|
+
r = uv_timer_init(uv_default_loop(), &timer_handle);
|
310
|
+
ASSERT(r == 0);
|
311
|
+
r = uv_timer_start(&timer_handle, timer_cb, TIMEOUT, TIMEOUT);
|
312
|
+
ASSERT(r == 0);
|
313
|
+
uv_unref((uv_handle_t*)&timer_handle);
|
314
|
+
|
315
|
+
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
316
|
+
ASSERT(r == 0);
|
317
|
+
|
318
|
+
ASSERT(loop_iteration == ITERATIONS);
|
319
|
+
|
320
|
+
ASSERT(prepare_1_cb_called == ITERATIONS);
|
321
|
+
ASSERT(prepare_1_close_cb_called == 1);
|
322
|
+
|
323
|
+
ASSERT(prepare_2_cb_called == floor(ITERATIONS / 2.0));
|
324
|
+
ASSERT(prepare_2_close_cb_called == 1);
|
325
|
+
|
326
|
+
ASSERT(check_cb_called == ITERATIONS);
|
327
|
+
ASSERT(check_close_cb_called == 1);
|
328
|
+
|
329
|
+
/* idle_1_cb should be called a lot */
|
330
|
+
ASSERT(idle_1_close_cb_called == IDLE_COUNT);
|
331
|
+
|
332
|
+
ASSERT(idle_2_close_cb_called == idle_2_cb_started);
|
333
|
+
ASSERT(idle_2_is_active == 0);
|
334
|
+
|
335
|
+
MAKE_VALGRIND_HAPPY();
|
336
|
+
return 0;
|
337
|
+
}
|
@@ -0,0 +1,73 @@
|
|
1
|
+
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
2
|
+
*
|
3
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
* of this software and associated documentation files (the "Software"), to
|
5
|
+
* deal in the Software without restriction, including without limitation the
|
6
|
+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
* sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
* furnished to do so, subject to the following conditions:
|
9
|
+
*
|
10
|
+
* The above copyright notice and this permission notice shall be included in
|
11
|
+
* all copies or substantial portions of the Software.
|
12
|
+
*
|
13
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
18
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
19
|
+
* IN THE SOFTWARE.
|
20
|
+
*/
|
21
|
+
|
22
|
+
#include "uv.h"
|
23
|
+
#include "task.h"
|
24
|
+
|
25
|
+
static uv_prepare_t prepare_handle;
|
26
|
+
static uv_timer_t timer_handle;
|
27
|
+
static int prepare_called = 0;
|
28
|
+
static int timer_called = 0;
|
29
|
+
static int num_ticks = 10;
|
30
|
+
|
31
|
+
|
32
|
+
static void prepare_cb(uv_prepare_t* handle, int status) {
|
33
|
+
ASSERT(handle == &prepare_handle);
|
34
|
+
ASSERT(status == 0);
|
35
|
+
prepare_called++;
|
36
|
+
if (prepare_called == num_ticks)
|
37
|
+
uv_prepare_stop(handle);
|
38
|
+
}
|
39
|
+
|
40
|
+
|
41
|
+
static void timer_cb(uv_timer_t* handle, int status) {
|
42
|
+
ASSERT(handle == &timer_handle);
|
43
|
+
ASSERT(status == 0);
|
44
|
+
timer_called++;
|
45
|
+
if (timer_called == 1)
|
46
|
+
uv_stop(uv_default_loop());
|
47
|
+
else if (timer_called == num_ticks)
|
48
|
+
uv_timer_stop(handle);
|
49
|
+
}
|
50
|
+
|
51
|
+
|
52
|
+
TEST_IMPL(loop_stop) {
|
53
|
+
int r;
|
54
|
+
uv_prepare_init(uv_default_loop(), &prepare_handle);
|
55
|
+
uv_prepare_start(&prepare_handle, prepare_cb);
|
56
|
+
uv_timer_init(uv_default_loop(), &timer_handle);
|
57
|
+
uv_timer_start(&timer_handle, timer_cb, 100, 100);
|
58
|
+
|
59
|
+
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
60
|
+
ASSERT(r != 0);
|
61
|
+
ASSERT(timer_called == 1);
|
62
|
+
|
63
|
+
r = uv_run(uv_default_loop(), UV_RUN_NOWAIT);
|
64
|
+
ASSERT(r != 0);
|
65
|
+
ASSERT(prepare_called == 3);
|
66
|
+
|
67
|
+
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
68
|
+
ASSERT(r == 0);
|
69
|
+
ASSERT(timer_called == 10);
|
70
|
+
ASSERT(prepare_called == 10);
|
71
|
+
|
72
|
+
return 0;
|
73
|
+
}
|
@@ -0,0 +1,103 @@
|
|
1
|
+
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
2
|
+
*
|
3
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
* of this software and associated documentation files (the "Software"), to
|
5
|
+
* deal in the Software without restriction, including without limitation the
|
6
|
+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
* sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
* furnished to do so, subject to the following conditions:
|
9
|
+
*
|
10
|
+
* The above copyright notice and this permission notice shall be included in
|
11
|
+
* all copies or substantial portions of the Software.
|
12
|
+
*
|
13
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
18
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
19
|
+
* IN THE SOFTWARE.
|
20
|
+
*/
|
21
|
+
|
22
|
+
#include "uv.h"
|
23
|
+
#include "task.h"
|
24
|
+
#include <stdio.h>
|
25
|
+
#include <stdlib.h>
|
26
|
+
|
27
|
+
static int connection_cb_called = 0;
|
28
|
+
static int close_cb_called = 0;
|
29
|
+
static int connect_cb_called = 0;
|
30
|
+
static uv_tcp_t server;
|
31
|
+
static uv_tcp_t client;
|
32
|
+
|
33
|
+
|
34
|
+
static void close_cb(uv_handle_t* handle) {
|
35
|
+
ASSERT(handle != NULL);
|
36
|
+
close_cb_called++;
|
37
|
+
}
|
38
|
+
|
39
|
+
|
40
|
+
static void connection_cb(uv_stream_t* tcp, int status) {
|
41
|
+
ASSERT(status == 0);
|
42
|
+
uv_close((uv_handle_t*)&server, close_cb);
|
43
|
+
connection_cb_called++;
|
44
|
+
}
|
45
|
+
|
46
|
+
|
47
|
+
static void start_server(void) {
|
48
|
+
struct sockaddr_in addr = uv_ip4_addr("0.0.0.0", TEST_PORT);
|
49
|
+
int r;
|
50
|
+
|
51
|
+
r = uv_tcp_init(uv_default_loop(), &server);
|
52
|
+
ASSERT(r == 0);
|
53
|
+
|
54
|
+
r = uv_tcp_bind(&server, addr);
|
55
|
+
ASSERT(r == 0);
|
56
|
+
|
57
|
+
r = uv_listen((uv_stream_t*)&server, 128, connection_cb);
|
58
|
+
ASSERT(r == 0);
|
59
|
+
|
60
|
+
r = uv_listen((uv_stream_t*)&server, 128, connection_cb);
|
61
|
+
ASSERT(r == 0);
|
62
|
+
}
|
63
|
+
|
64
|
+
|
65
|
+
static void connect_cb(uv_connect_t* req, int status) {
|
66
|
+
ASSERT(req != NULL);
|
67
|
+
ASSERT(status == 0);
|
68
|
+
free(req);
|
69
|
+
uv_close((uv_handle_t*)&client, close_cb);
|
70
|
+
connect_cb_called++;
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
static void client_connect(void) {
|
75
|
+
struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
|
76
|
+
uv_connect_t* connect_req = malloc(sizeof *connect_req);
|
77
|
+
int r;
|
78
|
+
|
79
|
+
ASSERT(connect_req != NULL);
|
80
|
+
|
81
|
+
r = uv_tcp_init(uv_default_loop(), &client);
|
82
|
+
ASSERT(r == 0);
|
83
|
+
|
84
|
+
r = uv_tcp_connect(connect_req, &client, addr, connect_cb);
|
85
|
+
ASSERT(r == 0);
|
86
|
+
}
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
TEST_IMPL(multiple_listen) {
|
91
|
+
start_server();
|
92
|
+
|
93
|
+
client_connect();
|
94
|
+
|
95
|
+
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
96
|
+
|
97
|
+
ASSERT(connection_cb_called == 1);
|
98
|
+
ASSERT(connect_cb_called == 1);
|
99
|
+
ASSERT(close_cb_called == 2);
|
100
|
+
|
101
|
+
MAKE_VALGRIND_HAPPY();
|
102
|
+
return 0;
|
103
|
+
}
|
@@ -0,0 +1,63 @@
|
|
1
|
+
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
2
|
+
*
|
3
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
* of this software and associated documentation files (the "Software"), to
|
5
|
+
* deal in the Software without restriction, including without limitation the
|
6
|
+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
* sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
* furnished to do so, subject to the following conditions:
|
9
|
+
*
|
10
|
+
* The above copyright notice and this permission notice shall be included in
|
11
|
+
* all copies or substantial portions of the Software.
|
12
|
+
*
|
13
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
18
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
19
|
+
* IN THE SOFTWARE.
|
20
|
+
*/
|
21
|
+
|
22
|
+
#include "uv.h"
|
23
|
+
#include "task.h"
|
24
|
+
|
25
|
+
#include <stdio.h>
|
26
|
+
#include <stdlib.h>
|
27
|
+
|
28
|
+
|
29
|
+
/* The mutex and rwlock tests are really poor.
|
30
|
+
* They're very basic sanity checks and nothing more.
|
31
|
+
* Apologies if that rhymes.
|
32
|
+
*/
|
33
|
+
|
34
|
+
TEST_IMPL(thread_mutex) {
|
35
|
+
uv_mutex_t mutex;
|
36
|
+
int r;
|
37
|
+
|
38
|
+
r = uv_mutex_init(&mutex);
|
39
|
+
ASSERT(r == 0);
|
40
|
+
|
41
|
+
uv_mutex_lock(&mutex);
|
42
|
+
uv_mutex_unlock(&mutex);
|
43
|
+
uv_mutex_destroy(&mutex);
|
44
|
+
|
45
|
+
return 0;
|
46
|
+
}
|
47
|
+
|
48
|
+
|
49
|
+
TEST_IMPL(thread_rwlock) {
|
50
|
+
uv_rwlock_t rwlock;
|
51
|
+
int r;
|
52
|
+
|
53
|
+
r = uv_rwlock_init(&rwlock);
|
54
|
+
ASSERT(r == 0);
|
55
|
+
|
56
|
+
uv_rwlock_rdlock(&rwlock);
|
57
|
+
uv_rwlock_rdunlock(&rwlock);
|
58
|
+
uv_rwlock_wrlock(&rwlock);
|
59
|
+
uv_rwlock_wrunlock(&rwlock);
|
60
|
+
uv_rwlock_destroy(&rwlock);
|
61
|
+
|
62
|
+
return 0;
|
63
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
2
|
+
*
|
3
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
* of this software and associated documentation files (the "Software"), to
|
5
|
+
* deal in the Software without restriction, including without limitation the
|
6
|
+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
* sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
* furnished to do so, subject to the following conditions:
|
9
|
+
*
|
10
|
+
* The above copyright notice and this permission notice shall be included in
|
11
|
+
* all copies or substantial portions of the Software.
|
12
|
+
*
|
13
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
18
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
19
|
+
* IN THE SOFTWARE.
|
20
|
+
*/
|
21
|
+
|
22
|
+
#include "task.h"
|
23
|
+
|
24
|
+
|
25
|
+
TEST_IMPL(pass_always) {
|
26
|
+
/* This test always passes. It is used to test the test runner. */
|
27
|
+
return 0;
|
28
|
+
}
|