foolio 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (261) hide show
  1. data/.gitignore +22 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +22 -0
  4. data/README.md +29 -0
  5. data/Rakefile +21 -0
  6. data/examples/timer.rb +20 -0
  7. data/ext/foolio/extconf.rb +34 -0
  8. data/ext/foolio/foolio_ext.c +921 -0
  9. data/ext/foolio/gen.rb +50 -0
  10. data/ext/foolio/make_table.rb +12 -0
  11. data/ext/foolio/templ +243 -0
  12. data/ext/libuv/.gitignore +33 -0
  13. data/ext/libuv/.mailmap +13 -0
  14. data/ext/libuv/.travis.yml +9 -0
  15. data/ext/libuv/AUTHORS +61 -0
  16. data/ext/libuv/LICENSE +44 -0
  17. data/ext/libuv/Makefile +71 -0
  18. data/ext/libuv/README.md +90 -0
  19. data/ext/libuv/common.gypi +178 -0
  20. data/ext/libuv/gyp_uv +73 -0
  21. data/ext/libuv/include/uv-private/eio.h +403 -0
  22. data/ext/libuv/include/uv-private/ev.h +838 -0
  23. data/ext/libuv/include/uv-private/ngx-queue.h +108 -0
  24. data/ext/libuv/include/uv-private/tree.h +768 -0
  25. data/ext/libuv/include/uv-private/uv-unix.h +324 -0
  26. data/ext/libuv/include/uv-private/uv-win.h +517 -0
  27. data/ext/libuv/include/uv.h +1838 -0
  28. data/ext/libuv/src/fs-poll.c +235 -0
  29. data/ext/libuv/src/inet.c +293 -0
  30. data/ext/libuv/src/unix/async.c +148 -0
  31. data/ext/libuv/src/unix/core.c +696 -0
  32. data/ext/libuv/src/unix/cygwin.c +83 -0
  33. data/ext/libuv/src/unix/darwin.c +342 -0
  34. data/ext/libuv/src/unix/dl.c +83 -0
  35. data/ext/libuv/src/unix/eio/Changes +63 -0
  36. data/ext/libuv/src/unix/eio/LICENSE +36 -0
  37. data/ext/libuv/src/unix/eio/Makefile.am +15 -0
  38. data/ext/libuv/src/unix/eio/aclocal.m4 +8957 -0
  39. data/ext/libuv/src/unix/eio/autogen.sh +3 -0
  40. data/ext/libuv/src/unix/eio/config.h.in +86 -0
  41. data/ext/libuv/src/unix/eio/config_cygwin.h +80 -0
  42. data/ext/libuv/src/unix/eio/config_darwin.h +141 -0
  43. data/ext/libuv/src/unix/eio/config_freebsd.h +81 -0
  44. data/ext/libuv/src/unix/eio/config_linux.h +94 -0
  45. data/ext/libuv/src/unix/eio/config_netbsd.h +81 -0
  46. data/ext/libuv/src/unix/eio/config_openbsd.h +137 -0
  47. data/ext/libuv/src/unix/eio/config_sunos.h +84 -0
  48. data/ext/libuv/src/unix/eio/configure.ac +22 -0
  49. data/ext/libuv/src/unix/eio/demo.c +194 -0
  50. data/ext/libuv/src/unix/eio/ecb.h +370 -0
  51. data/ext/libuv/src/unix/eio/eio.3 +3428 -0
  52. data/ext/libuv/src/unix/eio/eio.c +2593 -0
  53. data/ext/libuv/src/unix/eio/eio.pod +969 -0
  54. data/ext/libuv/src/unix/eio/libeio.m4 +195 -0
  55. data/ext/libuv/src/unix/eio/xthread.h +164 -0
  56. data/ext/libuv/src/unix/error.c +105 -0
  57. data/ext/libuv/src/unix/ev/Changes +388 -0
  58. data/ext/libuv/src/unix/ev/LICENSE +36 -0
  59. data/ext/libuv/src/unix/ev/Makefile.am +18 -0
  60. data/ext/libuv/src/unix/ev/Makefile.in +771 -0
  61. data/ext/libuv/src/unix/ev/README +58 -0
  62. data/ext/libuv/src/unix/ev/aclocal.m4 +8957 -0
  63. data/ext/libuv/src/unix/ev/autogen.sh +6 -0
  64. data/ext/libuv/src/unix/ev/config.guess +1526 -0
  65. data/ext/libuv/src/unix/ev/config.h.in +125 -0
  66. data/ext/libuv/src/unix/ev/config.sub +1658 -0
  67. data/ext/libuv/src/unix/ev/config_cygwin.h +123 -0
  68. data/ext/libuv/src/unix/ev/config_darwin.h +122 -0
  69. data/ext/libuv/src/unix/ev/config_freebsd.h +120 -0
  70. data/ext/libuv/src/unix/ev/config_linux.h +141 -0
  71. data/ext/libuv/src/unix/ev/config_netbsd.h +120 -0
  72. data/ext/libuv/src/unix/ev/config_openbsd.h +126 -0
  73. data/ext/libuv/src/unix/ev/config_sunos.h +122 -0
  74. data/ext/libuv/src/unix/ev/configure +13037 -0
  75. data/ext/libuv/src/unix/ev/configure.ac +18 -0
  76. data/ext/libuv/src/unix/ev/depcomp +630 -0
  77. data/ext/libuv/src/unix/ev/ev++.h +816 -0
  78. data/ext/libuv/src/unix/ev/ev.3 +5311 -0
  79. data/ext/libuv/src/unix/ev/ev.c +3925 -0
  80. data/ext/libuv/src/unix/ev/ev.pod +5243 -0
  81. data/ext/libuv/src/unix/ev/ev_epoll.c +266 -0
  82. data/ext/libuv/src/unix/ev/ev_kqueue.c +235 -0
  83. data/ext/libuv/src/unix/ev/ev_poll.c +148 -0
  84. data/ext/libuv/src/unix/ev/ev_port.c +179 -0
  85. data/ext/libuv/src/unix/ev/ev_select.c +310 -0
  86. data/ext/libuv/src/unix/ev/ev_vars.h +203 -0
  87. data/ext/libuv/src/unix/ev/ev_win32.c +153 -0
  88. data/ext/libuv/src/unix/ev/ev_wrap.h +196 -0
  89. data/ext/libuv/src/unix/ev/event.c +402 -0
  90. data/ext/libuv/src/unix/ev/event.h +170 -0
  91. data/ext/libuv/src/unix/ev/install-sh +294 -0
  92. data/ext/libuv/src/unix/ev/libev.m4 +39 -0
  93. data/ext/libuv/src/unix/ev/ltmain.sh +8413 -0
  94. data/ext/libuv/src/unix/ev/missing +336 -0
  95. data/ext/libuv/src/unix/ev/mkinstalldirs +111 -0
  96. data/ext/libuv/src/unix/freebsd.c +326 -0
  97. data/ext/libuv/src/unix/fs.c +739 -0
  98. data/ext/libuv/src/unix/internal.h +188 -0
  99. data/ext/libuv/src/unix/kqueue.c +120 -0
  100. data/ext/libuv/src/unix/linux/inotify.c +239 -0
  101. data/ext/libuv/src/unix/linux/linux-core.c +557 -0
  102. data/ext/libuv/src/unix/linux/syscalls.c +388 -0
  103. data/ext/libuv/src/unix/linux/syscalls.h +124 -0
  104. data/ext/libuv/src/unix/loop-watcher.c +62 -0
  105. data/ext/libuv/src/unix/loop.c +94 -0
  106. data/ext/libuv/src/unix/netbsd.c +108 -0
  107. data/ext/libuv/src/unix/openbsd.c +295 -0
  108. data/ext/libuv/src/unix/pipe.c +259 -0
  109. data/ext/libuv/src/unix/poll.c +114 -0
  110. data/ext/libuv/src/unix/process.c +495 -0
  111. data/ext/libuv/src/unix/signal.c +269 -0
  112. data/ext/libuv/src/unix/stream.c +990 -0
  113. data/ext/libuv/src/unix/sunos.c +481 -0
  114. data/ext/libuv/src/unix/tcp.c +393 -0
  115. data/ext/libuv/src/unix/thread.c +251 -0
  116. data/ext/libuv/src/unix/timer.c +136 -0
  117. data/ext/libuv/src/unix/tty.c +145 -0
  118. data/ext/libuv/src/unix/udp.c +659 -0
  119. data/ext/libuv/src/unix/uv-eio.c +107 -0
  120. data/ext/libuv/src/unix/uv-eio.h +13 -0
  121. data/ext/libuv/src/uv-common.c +380 -0
  122. data/ext/libuv/src/uv-common.h +170 -0
  123. data/ext/libuv/src/win/async.c +100 -0
  124. data/ext/libuv/src/win/atomicops-inl.h +56 -0
  125. data/ext/libuv/src/win/core.c +278 -0
  126. data/ext/libuv/src/win/dl.c +86 -0
  127. data/ext/libuv/src/win/error.c +155 -0
  128. data/ext/libuv/src/win/fs-event.c +510 -0
  129. data/ext/libuv/src/win/fs.c +1948 -0
  130. data/ext/libuv/src/win/getaddrinfo.c +365 -0
  131. data/ext/libuv/src/win/handle-inl.h +149 -0
  132. data/ext/libuv/src/win/handle.c +154 -0
  133. data/ext/libuv/src/win/internal.h +343 -0
  134. data/ext/libuv/src/win/loop-watcher.c +122 -0
  135. data/ext/libuv/src/win/pipe.c +1672 -0
  136. data/ext/libuv/src/win/poll.c +616 -0
  137. data/ext/libuv/src/win/process-stdio.c +500 -0
  138. data/ext/libuv/src/win/process.c +1013 -0
  139. data/ext/libuv/src/win/req-inl.h +220 -0
  140. data/ext/libuv/src/win/req.c +25 -0
  141. data/ext/libuv/src/win/signal.c +57 -0
  142. data/ext/libuv/src/win/stream-inl.h +67 -0
  143. data/ext/libuv/src/win/stream.c +167 -0
  144. data/ext/libuv/src/win/tcp.c +1394 -0
  145. data/ext/libuv/src/win/thread.c +372 -0
  146. data/ext/libuv/src/win/threadpool.c +74 -0
  147. data/ext/libuv/src/win/timer.c +224 -0
  148. data/ext/libuv/src/win/tty.c +1799 -0
  149. data/ext/libuv/src/win/udp.c +716 -0
  150. data/ext/libuv/src/win/util.c +864 -0
  151. data/ext/libuv/src/win/winapi.c +132 -0
  152. data/ext/libuv/src/win/winapi.h +4452 -0
  153. data/ext/libuv/src/win/winsock.c +557 -0
  154. data/ext/libuv/src/win/winsock.h +171 -0
  155. data/ext/libuv/test/benchmark-async-pummel.c +97 -0
  156. data/ext/libuv/test/benchmark-async.c +137 -0
  157. data/ext/libuv/test/benchmark-fs-stat.c +135 -0
  158. data/ext/libuv/test/benchmark-getaddrinfo.c +94 -0
  159. data/ext/libuv/test/benchmark-list.h +127 -0
  160. data/ext/libuv/test/benchmark-loop-count.c +88 -0
  161. data/ext/libuv/test/benchmark-million-timers.c +65 -0
  162. data/ext/libuv/test/benchmark-ping-pongs.c +213 -0
  163. data/ext/libuv/test/benchmark-pound.c +324 -0
  164. data/ext/libuv/test/benchmark-pump.c +462 -0
  165. data/ext/libuv/test/benchmark-sizes.c +44 -0
  166. data/ext/libuv/test/benchmark-spawn.c +162 -0
  167. data/ext/libuv/test/benchmark-tcp-write-batch.c +140 -0
  168. data/ext/libuv/test/benchmark-thread.c +64 -0
  169. data/ext/libuv/test/benchmark-udp-packet-storm.c +247 -0
  170. data/ext/libuv/test/blackhole-server.c +118 -0
  171. data/ext/libuv/test/dns-server.c +321 -0
  172. data/ext/libuv/test/echo-server.c +378 -0
  173. data/ext/libuv/test/fixtures/empty_file +0 -0
  174. data/ext/libuv/test/fixtures/load_error.node +1 -0
  175. data/ext/libuv/test/run-benchmarks.c +64 -0
  176. data/ext/libuv/test/run-tests.c +138 -0
  177. data/ext/libuv/test/runner-unix.c +295 -0
  178. data/ext/libuv/test/runner-unix.h +36 -0
  179. data/ext/libuv/test/runner-win.c +285 -0
  180. data/ext/libuv/test/runner-win.h +42 -0
  181. data/ext/libuv/test/runner.c +355 -0
  182. data/ext/libuv/test/runner.h +159 -0
  183. data/ext/libuv/test/task.h +112 -0
  184. data/ext/libuv/test/test-async.c +118 -0
  185. data/ext/libuv/test/test-callback-order.c +76 -0
  186. data/ext/libuv/test/test-callback-stack.c +203 -0
  187. data/ext/libuv/test/test-connection-fail.c +148 -0
  188. data/ext/libuv/test/test-cwd-and-chdir.c +64 -0
  189. data/ext/libuv/test/test-delayed-accept.c +188 -0
  190. data/ext/libuv/test/test-dlerror.c +58 -0
  191. data/ext/libuv/test/test-error.c +59 -0
  192. data/ext/libuv/test/test-fail-always.c +29 -0
  193. data/ext/libuv/test/test-fs-event.c +474 -0
  194. data/ext/libuv/test/test-fs-poll.c +146 -0
  195. data/ext/libuv/test/test-fs.c +1843 -0
  196. data/ext/libuv/test/test-get-currentexe.c +63 -0
  197. data/ext/libuv/test/test-get-loadavg.c +36 -0
  198. data/ext/libuv/test/test-get-memory.c +38 -0
  199. data/ext/libuv/test/test-getaddrinfo.c +122 -0
  200. data/ext/libuv/test/test-getsockname.c +342 -0
  201. data/ext/libuv/test/test-hrtime.c +54 -0
  202. data/ext/libuv/test/test-idle.c +81 -0
  203. data/ext/libuv/test/test-ipc-send-recv.c +209 -0
  204. data/ext/libuv/test/test-ipc.c +620 -0
  205. data/ext/libuv/test/test-list.h +427 -0
  206. data/ext/libuv/test/test-loop-handles.c +336 -0
  207. data/ext/libuv/test/test-multiple-listen.c +102 -0
  208. data/ext/libuv/test/test-mutexes.c +63 -0
  209. data/ext/libuv/test/test-pass-always.c +28 -0
  210. data/ext/libuv/test/test-ping-pong.c +253 -0
  211. data/ext/libuv/test/test-pipe-bind-error.c +140 -0
  212. data/ext/libuv/test/test-pipe-connect-error.c +96 -0
  213. data/ext/libuv/test/test-platform-output.c +87 -0
  214. data/ext/libuv/test/test-poll-close.c +72 -0
  215. data/ext/libuv/test/test-poll.c +573 -0
  216. data/ext/libuv/test/test-process-title.c +49 -0
  217. data/ext/libuv/test/test-ref.c +338 -0
  218. data/ext/libuv/test/test-run-once.c +48 -0
  219. data/ext/libuv/test/test-semaphore.c +111 -0
  220. data/ext/libuv/test/test-shutdown-close.c +103 -0
  221. data/ext/libuv/test/test-shutdown-eof.c +183 -0
  222. data/ext/libuv/test/test-signal.c +162 -0
  223. data/ext/libuv/test/test-spawn.c +863 -0
  224. data/ext/libuv/test/test-stdio-over-pipes.c +246 -0
  225. data/ext/libuv/test/test-tcp-bind-error.c +191 -0
  226. data/ext/libuv/test/test-tcp-bind6-error.c +154 -0
  227. data/ext/libuv/test/test-tcp-close-while-connecting.c +80 -0
  228. data/ext/libuv/test/test-tcp-close.c +129 -0
  229. data/ext/libuv/test/test-tcp-connect-error-after-write.c +95 -0
  230. data/ext/libuv/test/test-tcp-connect-error.c +70 -0
  231. data/ext/libuv/test/test-tcp-connect-timeout.c +85 -0
  232. data/ext/libuv/test/test-tcp-connect6-error.c +68 -0
  233. data/ext/libuv/test/test-tcp-flags.c +51 -0
  234. data/ext/libuv/test/test-tcp-shutdown-after-write.c +131 -0
  235. data/ext/libuv/test/test-tcp-unexpected-read.c +113 -0
  236. data/ext/libuv/test/test-tcp-write-error.c +168 -0
  237. data/ext/libuv/test/test-tcp-write-to-half-open-connection.c +135 -0
  238. data/ext/libuv/test/test-tcp-writealot.c +170 -0
  239. data/ext/libuv/test/test-thread.c +183 -0
  240. data/ext/libuv/test/test-threadpool.c +57 -0
  241. data/ext/libuv/test/test-timer-again.c +141 -0
  242. data/ext/libuv/test/test-timer.c +152 -0
  243. data/ext/libuv/test/test-tty.c +110 -0
  244. data/ext/libuv/test/test-udp-dgram-too-big.c +86 -0
  245. data/ext/libuv/test/test-udp-ipv6.c +156 -0
  246. data/ext/libuv/test/test-udp-multicast-join.c +139 -0
  247. data/ext/libuv/test/test-udp-multicast-ttl.c +86 -0
  248. data/ext/libuv/test/test-udp-options.c +86 -0
  249. data/ext/libuv/test/test-udp-send-and-recv.c +208 -0
  250. data/ext/libuv/test/test-util.c +97 -0
  251. data/ext/libuv/test/test-walk-handles.c +77 -0
  252. data/ext/libuv/uv.gyp +375 -0
  253. data/ext/libuv/vcbuild.bat +105 -0
  254. data/foolio.gemspec +18 -0
  255. data/lib/foolio.rb +9 -0
  256. data/lib/foolio/handle.rb +27 -0
  257. data/lib/foolio/listener.rb +26 -0
  258. data/lib/foolio/loop.rb +79 -0
  259. data/lib/foolio/stream.rb +109 -0
  260. data/lib/foolio/version.rb +3 -0
  261. metadata +309 -0
@@ -0,0 +1,427 @@
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
+ TEST_DECLARE (platform_output)
23
+ TEST_DECLARE (callback_order)
24
+ TEST_DECLARE (run_once)
25
+ TEST_DECLARE (semaphore_1)
26
+ TEST_DECLARE (semaphore_2)
27
+ TEST_DECLARE (semaphore_3)
28
+ TEST_DECLARE (tty)
29
+ TEST_DECLARE (stdio_over_pipes)
30
+ TEST_DECLARE (ipc_listen_before_write)
31
+ TEST_DECLARE (ipc_listen_after_write)
32
+ #ifndef _WIN32
33
+ TEST_DECLARE (ipc_send_recv_pipe)
34
+ #endif
35
+ TEST_DECLARE (ipc_send_recv_tcp)
36
+ TEST_DECLARE (ipc_tcp_connection)
37
+ TEST_DECLARE (tcp_ping_pong)
38
+ TEST_DECLARE (tcp_ping_pong_v6)
39
+ TEST_DECLARE (pipe_ping_pong)
40
+ TEST_DECLARE (delayed_accept)
41
+ TEST_DECLARE (multiple_listen)
42
+ TEST_DECLARE (tcp_writealot)
43
+ TEST_DECLARE (tcp_connect_error_after_write)
44
+ TEST_DECLARE (tcp_shutdown_after_write)
45
+ TEST_DECLARE (tcp_bind_error_addrinuse)
46
+ TEST_DECLARE (tcp_bind_error_addrnotavail_1)
47
+ TEST_DECLARE (tcp_bind_error_addrnotavail_2)
48
+ TEST_DECLARE (tcp_bind_error_fault)
49
+ TEST_DECLARE (tcp_bind_error_inval)
50
+ TEST_DECLARE (tcp_bind_localhost_ok)
51
+ TEST_DECLARE (tcp_listen_without_bind)
52
+ TEST_DECLARE (tcp_connect_error_fault)
53
+ TEST_DECLARE (tcp_connect_timeout)
54
+ TEST_DECLARE (tcp_close_while_connecting)
55
+ TEST_DECLARE (tcp_close)
56
+ TEST_DECLARE (tcp_flags)
57
+ TEST_DECLARE (tcp_write_error)
58
+ TEST_DECLARE (tcp_write_to_half_open_connection)
59
+ TEST_DECLARE (tcp_unexpected_read)
60
+ TEST_DECLARE (tcp_bind6_error_addrinuse)
61
+ TEST_DECLARE (tcp_bind6_error_addrnotavail)
62
+ TEST_DECLARE (tcp_bind6_error_fault)
63
+ TEST_DECLARE (tcp_bind6_error_inval)
64
+ TEST_DECLARE (tcp_bind6_localhost_ok)
65
+ TEST_DECLARE (udp_send_and_recv)
66
+ TEST_DECLARE (udp_multicast_join)
67
+ TEST_DECLARE (udp_multicast_ttl)
68
+ TEST_DECLARE (udp_dgram_too_big)
69
+ TEST_DECLARE (udp_dual_stack)
70
+ TEST_DECLARE (udp_ipv6_only)
71
+ TEST_DECLARE (udp_options)
72
+ TEST_DECLARE (pipe_bind_error_addrinuse)
73
+ TEST_DECLARE (pipe_bind_error_addrnotavail)
74
+ TEST_DECLARE (pipe_bind_error_inval)
75
+ TEST_DECLARE (pipe_listen_without_bind)
76
+ TEST_DECLARE (pipe_connect_bad_name)
77
+ TEST_DECLARE (pipe_connect_to_file)
78
+ TEST_DECLARE (connection_fail)
79
+ TEST_DECLARE (connection_fail_doesnt_auto_close)
80
+ TEST_DECLARE (shutdown_close_tcp)
81
+ TEST_DECLARE (shutdown_close_pipe)
82
+ TEST_DECLARE (shutdown_eof)
83
+ TEST_DECLARE (callback_stack)
84
+ TEST_DECLARE (error_message)
85
+ TEST_DECLARE (timer)
86
+ TEST_DECLARE (timer_again)
87
+ TEST_DECLARE (timer_start_twice)
88
+ TEST_DECLARE (idle_starvation)
89
+ TEST_DECLARE (loop_handles)
90
+ TEST_DECLARE (get_loadavg)
91
+ TEST_DECLARE (walk_handles)
92
+ TEST_DECLARE (ref)
93
+ TEST_DECLARE (idle_ref)
94
+ TEST_DECLARE (async_ref)
95
+ TEST_DECLARE (prepare_ref)
96
+ TEST_DECLARE (check_ref)
97
+ TEST_DECLARE (unref_in_prepare_cb)
98
+ TEST_DECLARE (timer_ref)
99
+ TEST_DECLARE (timer_ref2)
100
+ TEST_DECLARE (fs_event_ref)
101
+ TEST_DECLARE (fs_poll_ref)
102
+ TEST_DECLARE (tcp_ref)
103
+ TEST_DECLARE (tcp_ref2)
104
+ TEST_DECLARE (tcp_ref3)
105
+ TEST_DECLARE (tcp_ref4)
106
+ TEST_DECLARE (udp_ref)
107
+ TEST_DECLARE (udp_ref2)
108
+ TEST_DECLARE (udp_ref3)
109
+ TEST_DECLARE (pipe_ref)
110
+ TEST_DECLARE (pipe_ref2)
111
+ TEST_DECLARE (pipe_ref3)
112
+ TEST_DECLARE (pipe_ref4)
113
+ TEST_DECLARE (process_ref)
114
+ TEST_DECLARE (async)
115
+ TEST_DECLARE (get_currentexe)
116
+ TEST_DECLARE (process_title)
117
+ TEST_DECLARE (cwd_and_chdir)
118
+ TEST_DECLARE (get_memory)
119
+ TEST_DECLARE (hrtime)
120
+ TEST_DECLARE (getaddrinfo_basic)
121
+ TEST_DECLARE (getaddrinfo_concurrent)
122
+ TEST_DECLARE (getsockname_tcp)
123
+ TEST_DECLARE (getsockname_udp)
124
+ TEST_DECLARE (fail_always)
125
+ TEST_DECLARE (pass_always)
126
+ TEST_DECLARE (spawn_fails)
127
+ TEST_DECLARE (spawn_exit_code)
128
+ TEST_DECLARE (spawn_stdout)
129
+ TEST_DECLARE (spawn_stdin)
130
+ TEST_DECLARE (spawn_stdio_greater_than_3)
131
+ TEST_DECLARE (spawn_ignored_stdio)
132
+ TEST_DECLARE (spawn_and_kill)
133
+ TEST_DECLARE (spawn_detached)
134
+ TEST_DECLARE (spawn_and_kill_with_std)
135
+ TEST_DECLARE (spawn_and_ping)
136
+ TEST_DECLARE (spawn_setuid_fails)
137
+ TEST_DECLARE (spawn_setgid_fails)
138
+ TEST_DECLARE (spawn_stdout_to_file)
139
+ TEST_DECLARE (fs_poll)
140
+ TEST_DECLARE (kill)
141
+ TEST_DECLARE (fs_file_noent)
142
+ TEST_DECLARE (fs_file_nametoolong)
143
+ TEST_DECLARE (fs_file_loop)
144
+ TEST_DECLARE (fs_file_async)
145
+ TEST_DECLARE (fs_file_sync)
146
+ TEST_DECLARE (fs_async_dir)
147
+ TEST_DECLARE (fs_async_sendfile)
148
+ TEST_DECLARE (fs_fstat)
149
+ TEST_DECLARE (fs_chmod)
150
+ TEST_DECLARE (fs_chown)
151
+ TEST_DECLARE (fs_link)
152
+ TEST_DECLARE (fs_symlink)
153
+ TEST_DECLARE (fs_symlink_dir)
154
+ TEST_DECLARE (fs_utime)
155
+ TEST_DECLARE (fs_futime)
156
+ TEST_DECLARE (fs_file_open_append)
157
+ TEST_DECLARE (fs_stat_missing_path)
158
+ TEST_DECLARE (fs_read_file_eof)
159
+ TEST_DECLARE (fs_event_watch_dir)
160
+ TEST_DECLARE (fs_event_watch_file)
161
+ TEST_DECLARE (fs_event_watch_file_twice)
162
+ TEST_DECLARE (fs_event_watch_file_current_dir)
163
+ TEST_DECLARE (fs_event_no_callback_on_close)
164
+ TEST_DECLARE (fs_event_immediate_close)
165
+ TEST_DECLARE (fs_event_close_with_pending_event)
166
+ TEST_DECLARE (fs_event_close_in_callback)
167
+ TEST_DECLARE (fs_readdir_empty_dir)
168
+ TEST_DECLARE (fs_readdir_file)
169
+ TEST_DECLARE (fs_open_dir)
170
+ TEST_DECLARE (fs_rename_to_existing_file)
171
+ TEST_DECLARE (threadpool_queue_work_simple)
172
+ TEST_DECLARE (threadpool_multiple_event_loops)
173
+ TEST_DECLARE (thread_mutex)
174
+ TEST_DECLARE (thread_rwlock)
175
+ TEST_DECLARE (thread_create)
176
+ TEST_DECLARE (strlcpy)
177
+ TEST_DECLARE (strlcat)
178
+ TEST_DECLARE (dlerror)
179
+ TEST_DECLARE (poll_duplex)
180
+ TEST_DECLARE (poll_unidirectional)
181
+ TEST_DECLARE (poll_close)
182
+ TEST_DECLARE (we_get_signal)
183
+ TEST_DECLARE (we_get_signals)
184
+ #ifdef _WIN32
185
+ TEST_DECLARE (spawn_detect_pipe_name_collisions_on_windows)
186
+ TEST_DECLARE (argument_escaping)
187
+ TEST_DECLARE (environment_creation)
188
+ TEST_DECLARE (listen_with_simultaneous_accepts)
189
+ TEST_DECLARE (listen_no_simultaneous_accepts)
190
+ TEST_DECLARE (fs_stat_root)
191
+ #else
192
+ TEST_DECLARE (spawn_setuid_setgid)
193
+ #endif
194
+ HELPER_DECLARE (tcp4_echo_server)
195
+ HELPER_DECLARE (tcp6_echo_server)
196
+ HELPER_DECLARE (udp4_echo_server)
197
+ HELPER_DECLARE (pipe_echo_server)
198
+
199
+
200
+ TASK_LIST_START
201
+ TEST_OUTPUT_ENTRY (platform_output)
202
+
203
+ #if 0
204
+ TEST_ENTRY (callback_order)
205
+ #endif
206
+ TEST_ENTRY (run_once)
207
+ TEST_ENTRY (semaphore_1)
208
+ TEST_ENTRY (semaphore_2)
209
+ TEST_ENTRY (semaphore_3)
210
+
211
+ TEST_ENTRY (pipe_connect_bad_name)
212
+ TEST_ENTRY (pipe_connect_to_file)
213
+
214
+ TEST_ENTRY (tty)
215
+ TEST_ENTRY (stdio_over_pipes)
216
+ TEST_ENTRY (ipc_listen_before_write)
217
+ TEST_ENTRY (ipc_listen_after_write)
218
+ #ifndef _WIN32
219
+ TEST_ENTRY (ipc_send_recv_pipe)
220
+ #endif
221
+ TEST_ENTRY (ipc_send_recv_tcp)
222
+ TEST_ENTRY (ipc_tcp_connection)
223
+
224
+ TEST_ENTRY (tcp_ping_pong)
225
+ TEST_HELPER (tcp_ping_pong, tcp4_echo_server)
226
+
227
+ TEST_ENTRY (tcp_ping_pong_v6)
228
+ TEST_HELPER (tcp_ping_pong_v6, tcp6_echo_server)
229
+
230
+ TEST_ENTRY (pipe_ping_pong)
231
+ TEST_HELPER (pipe_ping_pong, pipe_echo_server)
232
+
233
+ TEST_ENTRY (delayed_accept)
234
+ TEST_ENTRY (multiple_listen)
235
+
236
+ TEST_ENTRY (tcp_writealot)
237
+ TEST_HELPER (tcp_writealot, tcp4_echo_server)
238
+
239
+ TEST_ENTRY (tcp_shutdown_after_write)
240
+ TEST_HELPER (tcp_shutdown_after_write, tcp4_echo_server)
241
+
242
+ TEST_ENTRY (tcp_connect_error_after_write)
243
+ TEST_ENTRY (tcp_bind_error_addrinuse)
244
+ TEST_ENTRY (tcp_bind_error_addrnotavail_1)
245
+ TEST_ENTRY (tcp_bind_error_addrnotavail_2)
246
+ TEST_ENTRY (tcp_bind_error_fault)
247
+ TEST_ENTRY (tcp_bind_error_inval)
248
+ TEST_ENTRY (tcp_bind_localhost_ok)
249
+ TEST_ENTRY (tcp_listen_without_bind)
250
+ TEST_ENTRY (tcp_connect_error_fault)
251
+ TEST_ENTRY (tcp_connect_timeout)
252
+ TEST_ENTRY (tcp_close_while_connecting)
253
+ TEST_ENTRY (tcp_close)
254
+ TEST_ENTRY (tcp_flags)
255
+ TEST_ENTRY (tcp_write_error)
256
+ TEST_ENTRY (tcp_write_to_half_open_connection)
257
+ TEST_ENTRY (tcp_unexpected_read)
258
+
259
+ TEST_ENTRY (tcp_bind6_error_addrinuse)
260
+ TEST_ENTRY (tcp_bind6_error_addrnotavail)
261
+ TEST_ENTRY (tcp_bind6_error_fault)
262
+ TEST_ENTRY (tcp_bind6_error_inval)
263
+ TEST_ENTRY (tcp_bind6_localhost_ok)
264
+
265
+ TEST_ENTRY (udp_send_and_recv)
266
+ TEST_ENTRY (udp_dgram_too_big)
267
+ TEST_ENTRY (udp_dual_stack)
268
+ TEST_ENTRY (udp_ipv6_only)
269
+ TEST_ENTRY (udp_options)
270
+ TEST_ENTRY (udp_multicast_join)
271
+ TEST_ENTRY (udp_multicast_ttl)
272
+
273
+ TEST_ENTRY (pipe_bind_error_addrinuse)
274
+ TEST_ENTRY (pipe_bind_error_addrnotavail)
275
+ TEST_ENTRY (pipe_bind_error_inval)
276
+ TEST_ENTRY (pipe_listen_without_bind)
277
+
278
+ TEST_ENTRY (connection_fail)
279
+ TEST_ENTRY (connection_fail_doesnt_auto_close)
280
+
281
+ TEST_ENTRY (shutdown_close_tcp)
282
+ TEST_HELPER (shutdown_close_tcp, tcp4_echo_server)
283
+ TEST_ENTRY (shutdown_close_pipe)
284
+ TEST_HELPER (shutdown_close_pipe, pipe_echo_server)
285
+
286
+ TEST_ENTRY (shutdown_eof)
287
+ TEST_HELPER (shutdown_eof, tcp4_echo_server)
288
+
289
+ TEST_ENTRY (callback_stack)
290
+ TEST_HELPER (callback_stack, tcp4_echo_server)
291
+
292
+ TEST_ENTRY (error_message)
293
+
294
+ TEST_ENTRY (timer)
295
+ TEST_ENTRY (timer_again)
296
+ TEST_ENTRY (timer_start_twice)
297
+
298
+ TEST_ENTRY (idle_starvation)
299
+
300
+ TEST_ENTRY (ref)
301
+ TEST_ENTRY (idle_ref)
302
+ TEST_ENTRY (fs_poll_ref)
303
+ TEST_ENTRY (async_ref)
304
+ TEST_ENTRY (prepare_ref)
305
+ TEST_ENTRY (check_ref)
306
+ TEST_ENTRY (unref_in_prepare_cb)
307
+ TEST_ENTRY (timer_ref)
308
+ TEST_ENTRY (timer_ref2)
309
+ TEST_ENTRY (fs_event_ref)
310
+ TEST_ENTRY (tcp_ref)
311
+ TEST_ENTRY (tcp_ref2)
312
+ TEST_ENTRY (tcp_ref3)
313
+ TEST_HELPER (tcp_ref3, tcp4_echo_server)
314
+ TEST_ENTRY (tcp_ref4)
315
+ TEST_HELPER (tcp_ref4, tcp4_echo_server)
316
+ TEST_ENTRY (udp_ref)
317
+ TEST_ENTRY (udp_ref2)
318
+ TEST_ENTRY (udp_ref3)
319
+ TEST_HELPER (udp_ref3, udp4_echo_server)
320
+ TEST_ENTRY (pipe_ref)
321
+ TEST_ENTRY (pipe_ref2)
322
+ TEST_ENTRY (pipe_ref3)
323
+ TEST_HELPER (pipe_ref3, pipe_echo_server)
324
+ TEST_ENTRY (pipe_ref4)
325
+ TEST_HELPER (pipe_ref4, pipe_echo_server)
326
+ TEST_ENTRY (process_ref)
327
+
328
+ TEST_ENTRY (loop_handles)
329
+ TEST_ENTRY (walk_handles)
330
+
331
+ TEST_ENTRY (async)
332
+
333
+ TEST_ENTRY (get_currentexe)
334
+
335
+ TEST_ENTRY (process_title)
336
+
337
+ TEST_ENTRY (cwd_and_chdir)
338
+
339
+ TEST_ENTRY (get_memory)
340
+
341
+ TEST_ENTRY (get_loadavg)
342
+
343
+ TEST_ENTRY (hrtime)
344
+
345
+ TEST_ENTRY (getaddrinfo_basic)
346
+ TEST_ENTRY (getaddrinfo_concurrent)
347
+
348
+ TEST_ENTRY (getsockname_tcp)
349
+ TEST_ENTRY (getsockname_udp)
350
+
351
+ TEST_ENTRY (poll_duplex)
352
+ TEST_ENTRY (poll_unidirectional)
353
+ TEST_ENTRY (poll_close)
354
+
355
+ TEST_ENTRY (spawn_fails)
356
+ TEST_ENTRY (spawn_exit_code)
357
+ TEST_ENTRY (spawn_stdout)
358
+ TEST_ENTRY (spawn_stdin)
359
+ TEST_ENTRY (spawn_stdio_greater_than_3)
360
+ TEST_ENTRY (spawn_ignored_stdio)
361
+ TEST_ENTRY (spawn_and_kill)
362
+ TEST_ENTRY (spawn_detached)
363
+ TEST_ENTRY (spawn_and_kill_with_std)
364
+ TEST_ENTRY (spawn_and_ping)
365
+ TEST_ENTRY (spawn_setuid_fails)
366
+ TEST_ENTRY (spawn_setgid_fails)
367
+ TEST_ENTRY (spawn_stdout_to_file)
368
+ TEST_ENTRY (fs_poll)
369
+ TEST_ENTRY (kill)
370
+
371
+ TEST_ENTRY (we_get_signal)
372
+ TEST_ENTRY (we_get_signals)
373
+
374
+ #ifdef _WIN32
375
+ TEST_ENTRY (spawn_detect_pipe_name_collisions_on_windows)
376
+ TEST_ENTRY (argument_escaping)
377
+ TEST_ENTRY (environment_creation)
378
+ TEST_ENTRY (listen_with_simultaneous_accepts)
379
+ TEST_ENTRY (listen_no_simultaneous_accepts)
380
+ TEST_ENTRY (fs_stat_root)
381
+ #else
382
+ TEST_ENTRY (spawn_setuid_setgid)
383
+ #endif
384
+
385
+ TEST_ENTRY (fs_file_noent)
386
+ TEST_ENTRY (fs_file_nametoolong)
387
+ TEST_ENTRY (fs_file_loop)
388
+ TEST_ENTRY (fs_file_async)
389
+ TEST_ENTRY (fs_file_sync)
390
+ TEST_ENTRY (fs_async_dir)
391
+ TEST_ENTRY (fs_async_sendfile)
392
+ TEST_ENTRY (fs_fstat)
393
+ TEST_ENTRY (fs_chmod)
394
+ TEST_ENTRY (fs_chown)
395
+ TEST_ENTRY (fs_utime)
396
+ TEST_ENTRY (fs_futime)
397
+ TEST_ENTRY (fs_symlink)
398
+ TEST_ENTRY (fs_symlink_dir)
399
+ TEST_ENTRY (fs_stat_missing_path)
400
+ TEST_ENTRY (fs_read_file_eof)
401
+ TEST_ENTRY (fs_file_open_append)
402
+ TEST_ENTRY (fs_event_watch_dir)
403
+ TEST_ENTRY (fs_event_watch_file)
404
+ TEST_ENTRY (fs_event_watch_file_twice)
405
+ TEST_ENTRY (fs_event_watch_file_current_dir)
406
+ TEST_ENTRY (fs_event_no_callback_on_close)
407
+ TEST_ENTRY (fs_event_immediate_close)
408
+ TEST_ENTRY (fs_event_close_with_pending_event)
409
+ TEST_ENTRY (fs_event_close_in_callback)
410
+ TEST_ENTRY (fs_readdir_empty_dir)
411
+ TEST_ENTRY (fs_readdir_file)
412
+ TEST_ENTRY (fs_open_dir)
413
+ TEST_ENTRY (fs_rename_to_existing_file)
414
+ TEST_ENTRY (threadpool_queue_work_simple)
415
+ TEST_ENTRY (threadpool_multiple_event_loops)
416
+ TEST_ENTRY (thread_mutex)
417
+ TEST_ENTRY (thread_rwlock)
418
+ TEST_ENTRY (thread_create)
419
+ TEST_ENTRY (strlcpy)
420
+ TEST_ENTRY (strlcat)
421
+ TEST_ENTRY (dlerror)
422
+ #if 0
423
+ /* These are for testing the test runner. */
424
+ TEST_ENTRY (fail_always)
425
+ TEST_ENTRY (pass_always)
426
+ #endif
427
+ TASK_LIST_END
@@ -0,0 +1,336 @@
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());
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
+ return 0;
336
+ }