rbuv 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (233) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/Gemfile +0 -1
  6. data/README.md +6 -1
  7. data/Rakefile +42 -0
  8. data/deps/libuv/.gitignore +34 -0
  9. data/deps/libuv/.mailmap +16 -0
  10. data/deps/libuv/AUTHORS +81 -0
  11. data/deps/libuv/ChangeLog +45 -0
  12. data/deps/libuv/LICENSE +41 -0
  13. data/deps/libuv/Makefile +53 -0
  14. data/deps/libuv/README.md +118 -0
  15. data/deps/libuv/build.mk +164 -0
  16. data/deps/libuv/checksparse.sh +230 -0
  17. data/deps/libuv/common.gypi +197 -0
  18. data/deps/libuv/config-mingw.mk +48 -0
  19. data/deps/libuv/config-unix.mk +167 -0
  20. data/deps/libuv/gyp_uv +98 -0
  21. data/deps/libuv/include/uv-private/ngx-queue.h +129 -0
  22. data/deps/libuv/include/uv-private/stdint-msvc2008.h +247 -0
  23. data/deps/libuv/include/uv-private/tree.h +768 -0
  24. data/deps/libuv/include/uv-private/uv-bsd.h +34 -0
  25. data/deps/libuv/include/uv-private/uv-darwin.h +61 -0
  26. data/deps/libuv/include/uv-private/uv-linux.h +34 -0
  27. data/deps/libuv/include/uv-private/uv-sunos.h +44 -0
  28. data/deps/libuv/include/uv-private/uv-unix.h +332 -0
  29. data/deps/libuv/include/uv-private/uv-win.h +585 -0
  30. data/deps/libuv/include/uv.h +1987 -0
  31. data/deps/libuv/src/fs-poll.c +248 -0
  32. data/deps/libuv/src/inet.c +298 -0
  33. data/deps/libuv/src/unix/aix.c +393 -0
  34. data/deps/libuv/src/unix/async.c +281 -0
  35. data/deps/libuv/src/unix/core.c +714 -0
  36. data/deps/libuv/src/unix/cygwin.c +93 -0
  37. data/deps/libuv/src/unix/darwin-proctitle.m +78 -0
  38. data/deps/libuv/src/unix/darwin.c +431 -0
  39. data/deps/libuv/src/unix/dl.c +83 -0
  40. data/deps/libuv/src/unix/error.c +109 -0
  41. data/deps/libuv/src/unix/freebsd.c +343 -0
  42. data/deps/libuv/src/unix/fs.c +869 -0
  43. data/deps/libuv/src/unix/fsevents.c +299 -0
  44. data/deps/libuv/src/unix/getaddrinfo.c +159 -0
  45. data/deps/libuv/src/unix/internal.h +259 -0
  46. data/deps/libuv/src/unix/kqueue.c +347 -0
  47. data/deps/libuv/src/unix/linux-core.c +724 -0
  48. data/deps/libuv/src/unix/linux-inotify.c +236 -0
  49. data/deps/libuv/src/unix/linux-syscalls.c +388 -0
  50. data/deps/libuv/src/unix/linux-syscalls.h +150 -0
  51. data/deps/libuv/src/unix/loop-watcher.c +64 -0
  52. data/deps/libuv/src/unix/loop.c +114 -0
  53. data/deps/libuv/src/unix/netbsd.c +353 -0
  54. data/deps/libuv/src/unix/openbsd.c +304 -0
  55. data/deps/libuv/src/unix/pipe.c +261 -0
  56. data/deps/libuv/src/unix/poll.c +108 -0
  57. data/deps/libuv/src/unix/process.c +501 -0
  58. data/deps/libuv/src/unix/proctitle.c +103 -0
  59. data/deps/libuv/src/unix/signal.c +455 -0
  60. data/deps/libuv/src/unix/stream.c +1380 -0
  61. data/deps/libuv/src/unix/sunos.c +647 -0
  62. data/deps/libuv/src/unix/tcp.c +357 -0
  63. data/deps/libuv/src/unix/thread.c +431 -0
  64. data/deps/libuv/src/unix/threadpool.c +286 -0
  65. data/deps/libuv/src/unix/timer.c +153 -0
  66. data/deps/libuv/src/unix/tty.c +179 -0
  67. data/deps/libuv/src/unix/udp.c +715 -0
  68. data/deps/libuv/src/uv-common.c +431 -0
  69. data/deps/libuv/src/uv-common.h +204 -0
  70. data/deps/libuv/src/version.c +60 -0
  71. data/deps/libuv/src/win/async.c +99 -0
  72. data/deps/libuv/src/win/atomicops-inl.h +56 -0
  73. data/deps/libuv/src/win/core.c +310 -0
  74. data/deps/libuv/src/win/dl.c +86 -0
  75. data/deps/libuv/src/win/error.c +164 -0
  76. data/deps/libuv/src/win/fs-event.c +506 -0
  77. data/deps/libuv/src/win/fs.c +1951 -0
  78. data/deps/libuv/src/win/getaddrinfo.c +365 -0
  79. data/deps/libuv/src/win/handle-inl.h +164 -0
  80. data/deps/libuv/src/win/handle.c +153 -0
  81. data/deps/libuv/src/win/internal.h +346 -0
  82. data/deps/libuv/src/win/loop-watcher.c +124 -0
  83. data/deps/libuv/src/win/pipe.c +1656 -0
  84. data/deps/libuv/src/win/poll.c +615 -0
  85. data/deps/libuv/src/win/process-stdio.c +503 -0
  86. data/deps/libuv/src/win/process.c +1048 -0
  87. data/deps/libuv/src/win/req-inl.h +224 -0
  88. data/deps/libuv/src/win/req.c +25 -0
  89. data/deps/libuv/src/win/signal.c +354 -0
  90. data/deps/libuv/src/win/stream-inl.h +67 -0
  91. data/deps/libuv/src/win/stream.c +198 -0
  92. data/deps/libuv/src/win/tcp.c +1422 -0
  93. data/deps/libuv/src/win/thread.c +666 -0
  94. data/deps/libuv/src/win/threadpool.c +82 -0
  95. data/deps/libuv/src/win/timer.c +230 -0
  96. data/deps/libuv/src/win/tty.c +1857 -0
  97. data/deps/libuv/src/win/udp.c +744 -0
  98. data/deps/libuv/src/win/util.c +946 -0
  99. data/deps/libuv/src/win/winapi.c +152 -0
  100. data/deps/libuv/src/win/winapi.h +4476 -0
  101. data/deps/libuv/src/win/winsock.c +560 -0
  102. data/deps/libuv/src/win/winsock.h +171 -0
  103. data/deps/libuv/test/benchmark-async-pummel.c +119 -0
  104. data/deps/libuv/test/benchmark-async.c +139 -0
  105. data/deps/libuv/test/benchmark-fs-stat.c +136 -0
  106. data/deps/libuv/test/benchmark-getaddrinfo.c +91 -0
  107. data/deps/libuv/test/benchmark-list.h +163 -0
  108. data/deps/libuv/test/benchmark-loop-count.c +90 -0
  109. data/deps/libuv/test/benchmark-million-async.c +112 -0
  110. data/deps/libuv/test/benchmark-million-timers.c +77 -0
  111. data/deps/libuv/test/benchmark-multi-accept.c +432 -0
  112. data/deps/libuv/test/benchmark-ping-pongs.c +212 -0
  113. data/deps/libuv/test/benchmark-pound.c +325 -0
  114. data/deps/libuv/test/benchmark-pump.c +459 -0
  115. data/deps/libuv/test/benchmark-sizes.c +45 -0
  116. data/deps/libuv/test/benchmark-spawn.c +163 -0
  117. data/deps/libuv/test/benchmark-tcp-write-batch.c +141 -0
  118. data/deps/libuv/test/benchmark-thread.c +64 -0
  119. data/deps/libuv/test/benchmark-udp-pummel.c +238 -0
  120. data/deps/libuv/test/blackhole-server.c +118 -0
  121. data/deps/libuv/test/dns-server.c +329 -0
  122. data/deps/libuv/test/echo-server.c +384 -0
  123. data/deps/libuv/test/fixtures/empty_file +0 -0
  124. data/deps/libuv/test/fixtures/load_error.node +1 -0
  125. data/deps/libuv/test/run-benchmarks.c +64 -0
  126. data/deps/libuv/test/run-tests.c +159 -0
  127. data/deps/libuv/test/runner-unix.c +328 -0
  128. data/deps/libuv/test/runner-unix.h +36 -0
  129. data/deps/libuv/test/runner-win.c +318 -0
  130. data/deps/libuv/test/runner-win.h +43 -0
  131. data/deps/libuv/test/runner.c +394 -0
  132. data/deps/libuv/test/runner.h +165 -0
  133. data/deps/libuv/test/task.h +122 -0
  134. data/deps/libuv/test/test-active.c +83 -0
  135. data/deps/libuv/test/test-async.c +136 -0
  136. data/deps/libuv/test/test-barrier.c +98 -0
  137. data/deps/libuv/test/test-callback-order.c +77 -0
  138. data/deps/libuv/test/test-callback-stack.c +204 -0
  139. data/deps/libuv/test/test-condvar.c +173 -0
  140. data/deps/libuv/test/test-connection-fail.c +150 -0
  141. data/deps/libuv/test/test-cwd-and-chdir.c +64 -0
  142. data/deps/libuv/test/test-delayed-accept.c +189 -0
  143. data/deps/libuv/test/test-dlerror.c +58 -0
  144. data/deps/libuv/test/test-embed.c +136 -0
  145. data/deps/libuv/test/test-error.c +59 -0
  146. data/deps/libuv/test/test-fail-always.c +29 -0
  147. data/deps/libuv/test/test-fs-event.c +504 -0
  148. data/deps/libuv/test/test-fs-poll.c +148 -0
  149. data/deps/libuv/test/test-fs.c +1899 -0
  150. data/deps/libuv/test/test-get-currentexe.c +63 -0
  151. data/deps/libuv/test/test-get-loadavg.c +36 -0
  152. data/deps/libuv/test/test-get-memory.c +38 -0
  153. data/deps/libuv/test/test-getaddrinfo.c +120 -0
  154. data/deps/libuv/test/test-getsockname.c +344 -0
  155. data/deps/libuv/test/test-hrtime.c +54 -0
  156. data/deps/libuv/test/test-idle.c +82 -0
  157. data/deps/libuv/test/test-ipc-send-recv.c +218 -0
  158. data/deps/libuv/test/test-ipc.c +625 -0
  159. data/deps/libuv/test/test-list.h +492 -0
  160. data/deps/libuv/test/test-loop-handles.c +337 -0
  161. data/deps/libuv/test/test-loop-stop.c +73 -0
  162. data/deps/libuv/test/test-multiple-listen.c +103 -0
  163. data/deps/libuv/test/test-mutexes.c +63 -0
  164. data/deps/libuv/test/test-pass-always.c +28 -0
  165. data/deps/libuv/test/test-ping-pong.c +250 -0
  166. data/deps/libuv/test/test-pipe-bind-error.c +144 -0
  167. data/deps/libuv/test/test-pipe-connect-error.c +98 -0
  168. data/deps/libuv/test/test-platform-output.c +87 -0
  169. data/deps/libuv/test/test-poll-close.c +73 -0
  170. data/deps/libuv/test/test-poll.c +575 -0
  171. data/deps/libuv/test/test-process-title.c +49 -0
  172. data/deps/libuv/test/test-ref.c +415 -0
  173. data/deps/libuv/test/test-run-nowait.c +46 -0
  174. data/deps/libuv/test/test-run-once.c +49 -0
  175. data/deps/libuv/test/test-semaphore.c +111 -0
  176. data/deps/libuv/test/test-shutdown-close.c +105 -0
  177. data/deps/libuv/test/test-shutdown-eof.c +184 -0
  178. data/deps/libuv/test/test-signal-multiple-loops.c +270 -0
  179. data/deps/libuv/test/test-signal.c +152 -0
  180. data/deps/libuv/test/test-spawn.c +938 -0
  181. data/deps/libuv/test/test-stdio-over-pipes.c +250 -0
  182. data/deps/libuv/test/test-tcp-bind-error.c +198 -0
  183. data/deps/libuv/test/test-tcp-bind6-error.c +159 -0
  184. data/deps/libuv/test/test-tcp-close-while-connecting.c +81 -0
  185. data/deps/libuv/test/test-tcp-close.c +130 -0
  186. data/deps/libuv/test/test-tcp-connect-error-after-write.c +96 -0
  187. data/deps/libuv/test/test-tcp-connect-error.c +71 -0
  188. data/deps/libuv/test/test-tcp-connect-timeout.c +86 -0
  189. data/deps/libuv/test/test-tcp-connect6-error.c +69 -0
  190. data/deps/libuv/test/test-tcp-flags.c +52 -0
  191. data/deps/libuv/test/test-tcp-open.c +175 -0
  192. data/deps/libuv/test/test-tcp-read-stop.c +73 -0
  193. data/deps/libuv/test/test-tcp-shutdown-after-write.c +132 -0
  194. data/deps/libuv/test/test-tcp-unexpected-read.c +114 -0
  195. data/deps/libuv/test/test-tcp-write-to-half-open-connection.c +136 -0
  196. data/deps/libuv/test/test-tcp-writealot.c +171 -0
  197. data/deps/libuv/test/test-thread.c +183 -0
  198. data/deps/libuv/test/test-threadpool-cancel.c +311 -0
  199. data/deps/libuv/test/test-threadpool.c +77 -0
  200. data/deps/libuv/test/test-timer-again.c +142 -0
  201. data/deps/libuv/test/test-timer.c +266 -0
  202. data/deps/libuv/test/test-tty.c +111 -0
  203. data/deps/libuv/test/test-udp-dgram-too-big.c +87 -0
  204. data/deps/libuv/test/test-udp-ipv6.c +158 -0
  205. data/deps/libuv/test/test-udp-multicast-join.c +140 -0
  206. data/deps/libuv/test/test-udp-multicast-ttl.c +87 -0
  207. data/deps/libuv/test/test-udp-open.c +154 -0
  208. data/deps/libuv/test/test-udp-options.c +87 -0
  209. data/deps/libuv/test/test-udp-send-and-recv.c +210 -0
  210. data/deps/libuv/test/test-util.c +97 -0
  211. data/deps/libuv/test/test-walk-handles.c +78 -0
  212. data/deps/libuv/uv.gyp +431 -0
  213. data/deps/libuv/vcbuild.bat +128 -0
  214. data/ext/rbuv/debug.h +27 -0
  215. data/ext/rbuv/error.c +7 -0
  216. data/ext/rbuv/error.h +10 -0
  217. data/ext/rbuv/extconf.rb +35 -0
  218. data/ext/rbuv/handle.c +40 -0
  219. data/ext/rbuv/handle.h +14 -0
  220. data/ext/rbuv/libuv.mk +12 -0
  221. data/ext/rbuv/loop.c +50 -0
  222. data/ext/rbuv/loop.h +13 -0
  223. data/ext/rbuv/rbuv.c +15 -0
  224. data/ext/rbuv/rbuv.h +27 -0
  225. data/ext/rbuv/timer.c +133 -0
  226. data/ext/rbuv/timer.h +13 -0
  227. data/lib/rbuv/timer.rb +7 -0
  228. data/lib/rbuv/version.rb +1 -1
  229. data/lib/rbuv.rb +24 -2
  230. data/rbuv.gemspec +5 -1
  231. data/spec/spec_helper.rb +22 -0
  232. data/spec/timer_spec.rb +144 -0
  233. metadata +278 -9
@@ -0,0 +1,394 @@
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 <stdio.h>
23
+ #include <string.h>
24
+
25
+ #include "runner.h"
26
+ #include "task.h"
27
+ #include "uv.h"
28
+
29
+ char executable_path[PATHMAX] = { '\0' };
30
+
31
+ int tap_output = 0;
32
+
33
+
34
+ static void log_progress(int total, int passed, int failed, const char* name) {
35
+ if (total == 0)
36
+ total = 1;
37
+
38
+ LOGF("[%% %3d|+ %3d|- %3d]: %s", (int) ((passed + failed) / ((double) total) * 100.0),
39
+ passed, failed, name);
40
+ }
41
+
42
+
43
+ const char* fmt(double d) {
44
+ static char buf[1024];
45
+ static char* p;
46
+ uint64_t v;
47
+
48
+ if (p == NULL)
49
+ p = buf;
50
+
51
+ p += 31;
52
+
53
+ if (p >= buf + sizeof(buf))
54
+ return "<buffer too small>";
55
+
56
+ v = (uint64_t) d;
57
+
58
+ #if 0 /* works but we don't care about fractional precision */
59
+ if (d - v >= 0.01) {
60
+ *--p = '0' + (uint64_t) (d * 100) % 10;
61
+ *--p = '0' + (uint64_t) (d * 10) % 10;
62
+ *--p = '.';
63
+ }
64
+ #endif
65
+
66
+ if (v == 0)
67
+ *--p = '0';
68
+
69
+ while (v) {
70
+ if (v) *--p = '0' + (v % 10), v /= 10;
71
+ if (v) *--p = '0' + (v % 10), v /= 10;
72
+ if (v) *--p = '0' + (v % 10), v /= 10;
73
+ if (v) *--p = ',';
74
+ }
75
+
76
+ return p;
77
+ }
78
+
79
+
80
+ int run_tests(int timeout, int benchmark_output) {
81
+ int total, passed, failed, current;
82
+ task_entry_t* task;
83
+
84
+ /* Count the number of tests. */
85
+ total = 0;
86
+ for (task = TASKS; task->main; task++) {
87
+ if (!task->is_helper) {
88
+ total++;
89
+ }
90
+ }
91
+
92
+ if (tap_output) {
93
+ LOGF("1..%d\n", total);
94
+ }
95
+
96
+ /* Run all tests. */
97
+ passed = 0;
98
+ failed = 0;
99
+ current = 1;
100
+ for (task = TASKS; task->main; task++) {
101
+ if (task->is_helper) {
102
+ continue;
103
+ }
104
+
105
+ if (!tap_output)
106
+ rewind_cursor();
107
+
108
+ if (!benchmark_output && !tap_output) {
109
+ log_progress(total, passed, failed, task->task_name);
110
+ }
111
+
112
+ if (run_test(task->task_name, timeout, benchmark_output, current) == 0) {
113
+ passed++;
114
+ } else {
115
+ failed++;
116
+ }
117
+ current++;
118
+ }
119
+
120
+ if (!tap_output)
121
+ rewind_cursor();
122
+
123
+ if (!benchmark_output && !tap_output) {
124
+ log_progress(total, passed, failed, "Done.\n");
125
+ }
126
+
127
+ return failed;
128
+ }
129
+
130
+
131
+ int run_test(const char* test,
132
+ int timeout,
133
+ int benchmark_output,
134
+ int test_count) {
135
+ char errmsg[1024] = "no error";
136
+ process_info_t processes[1024];
137
+ process_info_t *main_proc;
138
+ task_entry_t* task;
139
+ int process_count;
140
+ int result;
141
+ int status;
142
+ int i;
143
+
144
+ status = 255;
145
+ main_proc = NULL;
146
+ process_count = 0;
147
+
148
+ #ifndef _WIN32
149
+ /* Clean up stale socket from previous run. */
150
+ remove(TEST_PIPENAME);
151
+ #endif
152
+
153
+ /* If it's a helper the user asks for, start it directly. */
154
+ for (task = TASKS; task->main; task++) {
155
+ if (task->is_helper && strcmp(test, task->process_name) == 0) {
156
+ return task->main();
157
+ }
158
+ }
159
+
160
+ /* Start the helpers first. */
161
+ for (task = TASKS; task->main; task++) {
162
+ if (strcmp(test, task->task_name) != 0) {
163
+ continue;
164
+ }
165
+
166
+ /* Skip the test itself. */
167
+ if (!task->is_helper) {
168
+ continue;
169
+ }
170
+
171
+ if (process_start(task->task_name,
172
+ task->process_name,
173
+ &processes[process_count],
174
+ 1 /* is_helper */) == -1) {
175
+ snprintf(errmsg,
176
+ sizeof errmsg,
177
+ "Process `%s` failed to start.",
178
+ task->process_name);
179
+ goto out;
180
+ }
181
+
182
+ process_count++;
183
+ }
184
+
185
+ /* Give the helpers time to settle. Race-y, fix this. */
186
+ uv_sleep(250);
187
+
188
+ /* Now start the test itself. */
189
+ for (task = TASKS; task->main; task++) {
190
+ if (strcmp(test, task->task_name) != 0) {
191
+ continue;
192
+ }
193
+
194
+ if (task->is_helper) {
195
+ continue;
196
+ }
197
+
198
+ if (process_start(task->task_name,
199
+ task->process_name,
200
+ &processes[process_count],
201
+ 0 /* !is_helper */) == -1) {
202
+ snprintf(errmsg,
203
+ sizeof errmsg,
204
+ "Process `%s` failed to start.",
205
+ task->process_name);
206
+ goto out;
207
+ }
208
+
209
+ main_proc = &processes[process_count];
210
+ process_count++;
211
+ break;
212
+ }
213
+
214
+ if (main_proc == NULL) {
215
+ snprintf(errmsg,
216
+ sizeof errmsg,
217
+ "No test with that name: %s",
218
+ test);
219
+ goto out;
220
+ }
221
+
222
+ result = process_wait(main_proc, 1, timeout);
223
+ if (result == -1) {
224
+ FATAL("process_wait failed");
225
+ } else if (result == -2) {
226
+ /* Don't have to clean up the process, process_wait() has killed it. */
227
+ snprintf(errmsg,
228
+ sizeof errmsg,
229
+ "timeout");
230
+ goto out;
231
+ }
232
+
233
+ status = process_reap(main_proc);
234
+ if (status != 0) {
235
+ snprintf(errmsg,
236
+ sizeof errmsg,
237
+ "exit code %d",
238
+ status);
239
+ goto out;
240
+ }
241
+
242
+ if (benchmark_output) {
243
+ /* Give the helpers time to clean up their act. */
244
+ uv_sleep(1000);
245
+ }
246
+
247
+ out:
248
+ /* Reap running processes except the main process, it's already dead. */
249
+ for (i = 0; i < process_count - 1; i++) {
250
+ process_terminate(&processes[i]);
251
+ }
252
+
253
+ if (process_count > 0 &&
254
+ process_wait(processes, process_count - 1, -1) < 0) {
255
+ FATAL("process_wait failed");
256
+ }
257
+
258
+ if (tap_output) {
259
+ if (status == 0)
260
+ LOGF("ok %d - %s\n", test_count, test);
261
+ else
262
+ LOGF("not ok %d - %s\n", test_count, test);
263
+ }
264
+
265
+ /* Show error and output from processes if the test failed. */
266
+ if (status != 0 || task->show_output) {
267
+ if (tap_output) {
268
+ LOGF("#");
269
+ } else if (status != 0) {
270
+ LOGF("\n`%s` failed: %s\n", test, errmsg);
271
+ } else {
272
+ LOGF("\n");
273
+ }
274
+
275
+ for (i = 0; i < process_count; i++) {
276
+ switch (process_output_size(&processes[i])) {
277
+ case -1:
278
+ LOGF("Output from process `%s`: (unavailable)\n",
279
+ process_get_name(&processes[i]));
280
+ break;
281
+
282
+ case 0:
283
+ LOGF("Output from process `%s`: (no output)\n",
284
+ process_get_name(&processes[i]));
285
+ break;
286
+
287
+ default:
288
+ LOGF("Output from process `%s`:\n", process_get_name(&processes[i]));
289
+ process_copy_output(&processes[i], fileno(stderr));
290
+ break;
291
+ }
292
+ }
293
+
294
+ if (!tap_output) {
295
+ LOG("=============================================================\n");
296
+ }
297
+
298
+ /* In benchmark mode show concise output from the main process. */
299
+ } else if (benchmark_output) {
300
+ switch (process_output_size(main_proc)) {
301
+ case -1:
302
+ LOGF("%s: (unavailable)\n", test);
303
+ break;
304
+
305
+ case 0:
306
+ LOGF("%s: (no output)\n", test);
307
+ break;
308
+
309
+ default:
310
+ for (i = 0; i < process_count; i++) {
311
+ process_copy_output(&processes[i], fileno(stderr));
312
+ }
313
+ break;
314
+ }
315
+ }
316
+
317
+ /* Clean up all process handles. */
318
+ for (i = 0; i < process_count; i++) {
319
+ process_cleanup(&processes[i]);
320
+ }
321
+
322
+ return status;
323
+ }
324
+
325
+
326
+ /* Returns the status code of the task part
327
+ * or 255 if no matching task was not found.
328
+ */
329
+ int run_test_part(const char* test, const char* part) {
330
+ task_entry_t* task;
331
+ int r;
332
+
333
+ for (task = TASKS; task->main; task++) {
334
+ if (strcmp(test, task->task_name) == 0 &&
335
+ strcmp(part, task->process_name) == 0) {
336
+ r = task->main();
337
+ return r;
338
+ }
339
+ }
340
+
341
+ LOGF("No test part with that name: %s:%s\n", test, part);
342
+ return 255;
343
+ }
344
+
345
+
346
+ static int compare_task(const void* va, const void* vb) {
347
+ const task_entry_t* a = va;
348
+ const task_entry_t* b = vb;
349
+ return strcmp(a->task_name, b->task_name);
350
+ }
351
+
352
+
353
+ static int find_helpers(const task_entry_t* task, const task_entry_t** helpers) {
354
+ const task_entry_t* helper;
355
+ int n_helpers;
356
+
357
+ for (n_helpers = 0, helper = TASKS; helper->main; helper++) {
358
+ if (helper->is_helper && strcmp(helper->task_name, task->task_name) == 0) {
359
+ *helpers++ = helper;
360
+ n_helpers++;
361
+ }
362
+ }
363
+
364
+ return n_helpers;
365
+ }
366
+
367
+
368
+ void print_tests(FILE* stream) {
369
+ const task_entry_t* helpers[1024];
370
+ const task_entry_t* task;
371
+ int n_helpers;
372
+ int n_tasks;
373
+ int i;
374
+
375
+ for (n_tasks = 0, task = TASKS; task->main; n_tasks++, task++);
376
+ qsort(TASKS, n_tasks, sizeof(TASKS[0]), compare_task);
377
+
378
+ for (task = TASKS; task->main; task++) {
379
+ if (task->is_helper) {
380
+ continue;
381
+ }
382
+
383
+ n_helpers = find_helpers(task, helpers);
384
+ if (n_helpers) {
385
+ printf("%-25s (helpers:", task->task_name);
386
+ for (i = 0; i < n_helpers; i++) {
387
+ printf(" %s", helpers[i]->process_name);
388
+ }
389
+ printf(")\n");
390
+ } else {
391
+ printf("%s\n", task->task_name);
392
+ }
393
+ }
394
+ }
@@ -0,0 +1,165 @@
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
+ #ifndef RUNNER_H_
23
+ #define RUNNER_H_
24
+
25
+ #include <stdio.h> /* FILE */
26
+
27
+
28
+ /*
29
+ * The maximum number of processes (main + helpers) that a test / benchmark
30
+ * can have.
31
+ */
32
+ #define MAX_PROCESSES 8
33
+
34
+
35
+ /*
36
+ * Struct to store both tests and to define helper processes for tasks.
37
+ */
38
+ typedef struct {
39
+ char *task_name;
40
+ char *process_name;
41
+ int (*main)(void);
42
+ int is_helper;
43
+ int show_output;
44
+ } task_entry_t, bench_entry_t;
45
+
46
+
47
+ /*
48
+ * Macros used by test-list.h and benchmark-list.h.
49
+ */
50
+ #define TASK_LIST_START \
51
+ task_entry_t TASKS[] = {
52
+
53
+ #define TASK_LIST_END \
54
+ { 0, 0, 0, 0, 0 } \
55
+ };
56
+
57
+ #define TEST_DECLARE(name) \
58
+ int run_test_##name(void);
59
+
60
+ #define TEST_ENTRY(name) \
61
+ { #name, #name, &run_test_##name, 0, 0 },
62
+
63
+ #define TEST_OUTPUT_ENTRY(name) \
64
+ { #name, #name, &run_test_##name, 0, 1 },
65
+
66
+ #define BENCHMARK_DECLARE(name) \
67
+ int run_benchmark_##name(void);
68
+
69
+ #define BENCHMARK_ENTRY(name) \
70
+ { #name, #name, &run_benchmark_##name, 0, 0 },
71
+
72
+ #define HELPER_DECLARE(name) \
73
+ int run_helper_##name(void);
74
+
75
+ #define HELPER_ENTRY(task_name, name) \
76
+ { #task_name, #name, &run_helper_##name, 1, 0 },
77
+
78
+ #define TEST_HELPER HELPER_ENTRY
79
+ #define BENCHMARK_HELPER HELPER_ENTRY
80
+
81
+ #define PATHMAX 1024
82
+ extern char executable_path[PATHMAX];
83
+
84
+ /*
85
+ * Include platform-dependent definitions
86
+ */
87
+ #ifdef _WIN32
88
+ # include "runner-win.h"
89
+ #else
90
+ # include "runner-unix.h"
91
+ #endif
92
+
93
+
94
+ /* The array that is filled by test-list.h or benchmark-list.h */
95
+ extern task_entry_t TASKS[];
96
+
97
+ /*
98
+ * Run all tests.
99
+ */
100
+ int run_tests(int timeout, int benchmark_output);
101
+
102
+ /*
103
+ * Run a single test. Starts up any helpers.
104
+ */
105
+ int run_test(const char* test,
106
+ int timeout,
107
+ int benchmark_output,
108
+ int test_count);
109
+
110
+ /*
111
+ * Run a test part, i.e. the test or one of its helpers.
112
+ */
113
+ int run_test_part(const char* test, const char* part);
114
+
115
+
116
+ /*
117
+ * Print tests in sorted order to `stream`. Used by `./run-tests --list`.
118
+ */
119
+ void print_tests(FILE* stream);
120
+
121
+
122
+ /*
123
+ * Stuff that should be implemented by test-runner-<platform>.h
124
+ * All functions return 0 on success, -1 on failure, unless specified
125
+ * otherwise.
126
+ */
127
+
128
+ /* Do platform-specific initialization. */
129
+ void platform_init(int argc, char** argv);
130
+
131
+ /* Invoke "argv[0] test-name [test-part]". Store process info in *p. */
132
+ /* Make sure that all stdio output of the processes is buffered up. */
133
+ int process_start(char *name, char* part, process_info_t *p, int is_helper);
134
+
135
+ /* Wait for all `n` processes in `vec` to terminate. */
136
+ /* Time out after `timeout` msec, or never if timeout == -1 */
137
+ /* Return 0 if all processes are terminated, -1 on error, -2 on timeout. */
138
+ int process_wait(process_info_t *vec, int n, int timeout);
139
+
140
+ /* Returns the number of bytes in the stdio output buffer for process `p`. */
141
+ long int process_output_size(process_info_t *p);
142
+
143
+ /* Copy the contents of the stdio output buffer to `fd`. */
144
+ int process_copy_output(process_info_t *p, int fd);
145
+
146
+ /* Return the name that was specified when `p` was started by process_start */
147
+ char* process_get_name(process_info_t *p);
148
+
149
+ /* Terminate process `p`. */
150
+ int process_terminate(process_info_t *p);
151
+
152
+ /* Return the exit code of process p. */
153
+ /* On error, return -1. */
154
+ int process_reap(process_info_t *p);
155
+
156
+ /* Clean up after terminating process `p` (e.g. free the output buffer etc.). */
157
+ void process_cleanup(process_info_t *p);
158
+
159
+ /* Move the console cursor one line up and back to the first column. */
160
+ void rewind_cursor(void);
161
+
162
+ /* trigger output as tap */
163
+ extern int tap_output;
164
+
165
+ #endif /* RUNNER_H_ */
@@ -0,0 +1,122 @@
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
+ #ifndef TASK_H_
23
+ #define TASK_H_
24
+
25
+ #include <stdio.h>
26
+ #include <stddef.h>
27
+ #include <stdlib.h>
28
+
29
+ #if defined(_MSC_VER) && _MSC_VER < 1600
30
+ # include "uv-private/stdint-msvc2008.h"
31
+ #else
32
+ # include <stdint.h>
33
+ #endif
34
+
35
+ #define TEST_PORT 9123
36
+ #define TEST_PORT_2 9124
37
+
38
+ #ifdef _WIN32
39
+ # define TEST_PIPENAME "\\\\.\\pipe\\uv-test"
40
+ # define TEST_PIPENAME_2 "\\\\.\\pipe\\uv-test2"
41
+ #else
42
+ # define TEST_PIPENAME "/tmp/uv-test-sock"
43
+ # define TEST_PIPENAME_2 "/tmp/uv-test-sock2"
44
+ #endif
45
+
46
+ #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
47
+
48
+ #define container_of(ptr, type, member) \
49
+ ((type *) ((char *) (ptr) - offsetof(type, member)))
50
+
51
+ typedef enum {
52
+ TCP = 0,
53
+ UDP,
54
+ PIPE
55
+ } stream_type;
56
+
57
+ /* Log to stderr. */
58
+ #define LOG(...) \
59
+ do { \
60
+ fprintf(stderr, "%s", __VA_ARGS__); \
61
+ fflush(stderr); \
62
+ } while (0)
63
+
64
+ #define LOGF(...) \
65
+ do { \
66
+ fprintf(stderr, __VA_ARGS__); \
67
+ fflush(stderr); \
68
+ } while (0)
69
+
70
+ /* Die with fatal error. */
71
+ #define FATAL(msg) \
72
+ do { \
73
+ fprintf(stderr, \
74
+ "Fatal error in %s on line %d: %s\n", \
75
+ __FILE__, \
76
+ __LINE__, \
77
+ msg); \
78
+ fflush(stderr); \
79
+ abort(); \
80
+ } while (0)
81
+
82
+ /* Have our own assert, so we are sure it does not get optimized away in
83
+ * a release build.
84
+ */
85
+ #define ASSERT(expr) \
86
+ do { \
87
+ if (!(expr)) { \
88
+ fprintf(stderr, \
89
+ "Assertion failed in %s on line %d: %s\n", \
90
+ __FILE__, \
91
+ __LINE__, \
92
+ #expr); \
93
+ abort(); \
94
+ } \
95
+ } while (0)
96
+
97
+ /* This macro cleans up the main loop. This is used to avoid valgrind
98
+ * warnings about memory being "leaked" by the main event loop.
99
+ */
100
+ #define MAKE_VALGRIND_HAPPY() \
101
+ uv_loop_delete(uv_default_loop())
102
+
103
+ /* Just sugar for wrapping the main() for a task or helper. */
104
+ #define TEST_IMPL(name) \
105
+ int run_test_##name(void); \
106
+ int run_test_##name(void)
107
+
108
+ #define BENCHMARK_IMPL(name) \
109
+ int run_benchmark_##name(void); \
110
+ int run_benchmark_##name(void)
111
+
112
+ #define HELPER_IMPL(name) \
113
+ int run_helper_##name(void); \
114
+ int run_helper_##name(void)
115
+
116
+ /* Pause the calling thread for a number of milliseconds. */
117
+ void uv_sleep(int msec);
118
+
119
+ /* Format big numbers nicely. WARNING: leaks memory. */
120
+ const char* fmt(double d);
121
+
122
+ #endif /* TASK_H_ */