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,64 @@
|
|
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
|
+
|
28
|
+
/* Actual benchmarks and helpers are defined in benchmark-list.h */
|
29
|
+
#include "benchmark-list.h"
|
30
|
+
|
31
|
+
|
32
|
+
/* The time in milliseconds after which a single benchmark times out. */
|
33
|
+
#define BENCHMARK_TIMEOUT 60000
|
34
|
+
|
35
|
+
static int maybe_run_test(int argc, char **argv);
|
36
|
+
|
37
|
+
|
38
|
+
int main(int argc, char **argv) {
|
39
|
+
platform_init(argc, argv);
|
40
|
+
|
41
|
+
switch (argc) {
|
42
|
+
case 1: return run_tests(BENCHMARK_TIMEOUT, 1);
|
43
|
+
case 2: return maybe_run_test(argc, argv);
|
44
|
+
case 3: return run_test_part(argv[1], argv[2]);
|
45
|
+
default:
|
46
|
+
LOGF("Too many arguments.\n");
|
47
|
+
return 1;
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
|
52
|
+
static int maybe_run_test(int argc, char **argv) {
|
53
|
+
if (strcmp(argv[1], "--list") == 0) {
|
54
|
+
print_tests(stdout);
|
55
|
+
return 0;
|
56
|
+
}
|
57
|
+
|
58
|
+
if (strcmp(argv[1], "spawn_helper") == 0) {
|
59
|
+
printf("hello world\n");
|
60
|
+
return 42;
|
61
|
+
}
|
62
|
+
|
63
|
+
return run_test(argv[1], BENCHMARK_TIMEOUT, 1, 1);
|
64
|
+
}
|
@@ -0,0 +1,159 @@
|
|
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 <errno.h>
|
23
|
+
#include <stdio.h>
|
24
|
+
#include <string.h>
|
25
|
+
|
26
|
+
#ifdef _WIN32
|
27
|
+
# include <io.h>
|
28
|
+
#else
|
29
|
+
# include <unistd.h>
|
30
|
+
#endif
|
31
|
+
|
32
|
+
#include "uv.h"
|
33
|
+
#include "runner.h"
|
34
|
+
#include "task.h"
|
35
|
+
|
36
|
+
/* Actual tests and helpers are defined in test-list.h */
|
37
|
+
#include "test-list.h"
|
38
|
+
|
39
|
+
/* The time in milliseconds after which a single test times out. */
|
40
|
+
#define TEST_TIMEOUT 5000
|
41
|
+
|
42
|
+
int ipc_helper(int listen_after_write);
|
43
|
+
int ipc_helper_tcp_connection(void);
|
44
|
+
int ipc_send_recv_helper(void);
|
45
|
+
int stdio_over_pipes_helper(void);
|
46
|
+
|
47
|
+
static int maybe_run_test(int argc, char **argv);
|
48
|
+
|
49
|
+
|
50
|
+
int main(int argc, char **argv) {
|
51
|
+
platform_init(argc, argv);
|
52
|
+
|
53
|
+
argv = uv_setup_args(argc, argv);
|
54
|
+
|
55
|
+
switch (argc) {
|
56
|
+
case 1: return run_tests(TEST_TIMEOUT, 0);
|
57
|
+
case 2: return maybe_run_test(argc, argv);
|
58
|
+
case 3: return run_test_part(argv[1], argv[2]);
|
59
|
+
default:
|
60
|
+
LOGF("Too many arguments.\n");
|
61
|
+
return 1;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
static int maybe_run_test(int argc, char **argv) {
|
67
|
+
if (strcmp(argv[1], "--list") == 0) {
|
68
|
+
print_tests(stdout);
|
69
|
+
return 0;
|
70
|
+
}
|
71
|
+
|
72
|
+
if (strcmp(argv[1], "ipc_helper_listen_before_write") == 0) {
|
73
|
+
return ipc_helper(0);
|
74
|
+
}
|
75
|
+
|
76
|
+
if (strcmp(argv[1], "ipc_helper_listen_after_write") == 0) {
|
77
|
+
return ipc_helper(1);
|
78
|
+
}
|
79
|
+
|
80
|
+
if (strcmp(argv[1], "ipc_send_recv_helper") == 0) {
|
81
|
+
return ipc_send_recv_helper();
|
82
|
+
}
|
83
|
+
|
84
|
+
if (strcmp(argv[1], "ipc_helper_tcp_connection") == 0) {
|
85
|
+
return ipc_helper_tcp_connection();
|
86
|
+
}
|
87
|
+
|
88
|
+
if (strcmp(argv[1], "stdio_over_pipes_helper") == 0) {
|
89
|
+
return stdio_over_pipes_helper();
|
90
|
+
}
|
91
|
+
|
92
|
+
if (strcmp(argv[1], "spawn_helper1") == 0) {
|
93
|
+
return 1;
|
94
|
+
}
|
95
|
+
|
96
|
+
if (strcmp(argv[1], "spawn_helper2") == 0) {
|
97
|
+
printf("hello world\n");
|
98
|
+
return 1;
|
99
|
+
}
|
100
|
+
|
101
|
+
if (strcmp(argv[1], "spawn_helper3") == 0) {
|
102
|
+
char buffer[256];
|
103
|
+
ASSERT(buffer == fgets(buffer, sizeof(buffer) - 1, stdin));
|
104
|
+
buffer[sizeof(buffer) - 1] = '\0';
|
105
|
+
fputs(buffer, stdout);
|
106
|
+
return 1;
|
107
|
+
}
|
108
|
+
|
109
|
+
if (strcmp(argv[1], "spawn_helper4") == 0) {
|
110
|
+
/* Never surrender, never return! */
|
111
|
+
while (1) uv_sleep(10000);
|
112
|
+
}
|
113
|
+
|
114
|
+
if (strcmp(argv[1], "spawn_helper5") == 0) {
|
115
|
+
const char out[] = "fourth stdio!\n";
|
116
|
+
#ifdef _WIN32
|
117
|
+
DWORD bytes;
|
118
|
+
WriteFile((HANDLE) _get_osfhandle(3), out, sizeof(out) - 1, &bytes, NULL);
|
119
|
+
#else
|
120
|
+
{
|
121
|
+
ssize_t r;
|
122
|
+
|
123
|
+
do
|
124
|
+
r = write(3, out, sizeof(out) - 1);
|
125
|
+
while (r == -1 && errno == EINTR);
|
126
|
+
|
127
|
+
fsync(3);
|
128
|
+
}
|
129
|
+
#endif
|
130
|
+
return 1;
|
131
|
+
}
|
132
|
+
|
133
|
+
if (strcmp(argv[1], "spawn_helper6") == 0) {
|
134
|
+
int r;
|
135
|
+
|
136
|
+
r = fprintf(stdout, "hello world\n");
|
137
|
+
ASSERT(r > 0);
|
138
|
+
|
139
|
+
r = fprintf(stderr, "hello errworld\n");
|
140
|
+
ASSERT(r > 0);
|
141
|
+
|
142
|
+
return 1;
|
143
|
+
}
|
144
|
+
|
145
|
+
if (strcmp(argv[1], "spawn_helper7") == 0) {
|
146
|
+
int r;
|
147
|
+
char *test;
|
148
|
+
/* Test if the test value from the parent is still set */
|
149
|
+
test = getenv("ENV_TEST");
|
150
|
+
ASSERT(test != NULL);
|
151
|
+
|
152
|
+
r = fprintf(stdout, "%s", test);
|
153
|
+
ASSERT(r > 0);
|
154
|
+
|
155
|
+
return 1;
|
156
|
+
}
|
157
|
+
|
158
|
+
return run_test(argv[1], TEST_TIMEOUT, 0, 1);
|
159
|
+
}
|
@@ -0,0 +1,328 @@
|
|
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 "runner-unix.h"
|
23
|
+
#include "runner.h"
|
24
|
+
|
25
|
+
#include <stdint.h> /* uintptr_t */
|
26
|
+
|
27
|
+
#include <errno.h>
|
28
|
+
#include <unistd.h> /* usleep */
|
29
|
+
#include <string.h> /* strdup */
|
30
|
+
#include <stdio.h>
|
31
|
+
#include <stdlib.h>
|
32
|
+
#include <sys/types.h>
|
33
|
+
#include <signal.h>
|
34
|
+
#include <sys/wait.h>
|
35
|
+
#include <sys/stat.h>
|
36
|
+
#include <assert.h>
|
37
|
+
|
38
|
+
#include <sys/select.h>
|
39
|
+
#include <pthread.h>
|
40
|
+
|
41
|
+
|
42
|
+
/* Do platform-specific initialization. */
|
43
|
+
void platform_init(int argc, char **argv) {
|
44
|
+
const char* tap;
|
45
|
+
|
46
|
+
tap = getenv("UV_TAP_OUTPUT");
|
47
|
+
tap_output = (tap != NULL && atoi(tap) > 0);
|
48
|
+
|
49
|
+
/* Disable stdio output buffering. */
|
50
|
+
setvbuf(stdout, NULL, _IONBF, 0);
|
51
|
+
setvbuf(stderr, NULL, _IONBF, 0);
|
52
|
+
strcpy(executable_path, argv[0]);
|
53
|
+
signal(SIGPIPE, SIG_IGN);
|
54
|
+
}
|
55
|
+
|
56
|
+
|
57
|
+
/* Invoke "argv[0] test-name [test-part]". Store process info in *p. */
|
58
|
+
/* Make sure that all stdio output of the processes is buffered up. */
|
59
|
+
int process_start(char* name, char* part, process_info_t* p, int is_helper) {
|
60
|
+
FILE* stdout_file;
|
61
|
+
const char* arg;
|
62
|
+
char* args[16];
|
63
|
+
int n;
|
64
|
+
|
65
|
+
stdout_file = tmpfile();
|
66
|
+
if (!stdout_file) {
|
67
|
+
perror("tmpfile");
|
68
|
+
return -1;
|
69
|
+
}
|
70
|
+
|
71
|
+
p->terminated = 0;
|
72
|
+
p->status = 0;
|
73
|
+
|
74
|
+
pid_t pid = fork();
|
75
|
+
|
76
|
+
if (pid < 0) {
|
77
|
+
perror("fork");
|
78
|
+
return -1;
|
79
|
+
}
|
80
|
+
|
81
|
+
if (pid == 0) {
|
82
|
+
/* child */
|
83
|
+
arg = getenv("UV_USE_VALGRIND");
|
84
|
+
n = 0;
|
85
|
+
|
86
|
+
/* Disable valgrind for helpers, it complains about helpers leaking memory.
|
87
|
+
* They're killed after the test and as such never get a chance to clean up.
|
88
|
+
*/
|
89
|
+
if (is_helper == 0 && arg != NULL && atoi(arg) != 0) {
|
90
|
+
args[n++] = "valgrind";
|
91
|
+
args[n++] = "--quiet";
|
92
|
+
args[n++] = "--leak-check=full";
|
93
|
+
args[n++] = "--show-reachable=yes";
|
94
|
+
args[n++] = "--error-exitcode=125";
|
95
|
+
}
|
96
|
+
|
97
|
+
args[n++] = executable_path;
|
98
|
+
args[n++] = name;
|
99
|
+
args[n++] = part;
|
100
|
+
args[n++] = NULL;
|
101
|
+
|
102
|
+
dup2(fileno(stdout_file), STDOUT_FILENO);
|
103
|
+
dup2(fileno(stdout_file), STDERR_FILENO);
|
104
|
+
execvp(args[0], args);
|
105
|
+
perror("execvp()");
|
106
|
+
_exit(127);
|
107
|
+
}
|
108
|
+
|
109
|
+
/* parent */
|
110
|
+
p->pid = pid;
|
111
|
+
p->name = strdup(name);
|
112
|
+
p->stdout_file = stdout_file;
|
113
|
+
|
114
|
+
return 0;
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
typedef struct {
|
119
|
+
int pipe[2];
|
120
|
+
process_info_t* vec;
|
121
|
+
int n;
|
122
|
+
} dowait_args;
|
123
|
+
|
124
|
+
|
125
|
+
/* This function is run inside a pthread. We do this so that we can possibly
|
126
|
+
* timeout.
|
127
|
+
*/
|
128
|
+
static void* dowait(void* data) {
|
129
|
+
dowait_args* args = data;
|
130
|
+
|
131
|
+
int i, r;
|
132
|
+
process_info_t* p;
|
133
|
+
|
134
|
+
for (i = 0; i < args->n; i++) {
|
135
|
+
p = (process_info_t*)(args->vec + i * sizeof(process_info_t));
|
136
|
+
if (p->terminated) continue;
|
137
|
+
r = waitpid(p->pid, &p->status, 0);
|
138
|
+
if (r < 0) {
|
139
|
+
perror("waitpid");
|
140
|
+
return NULL;
|
141
|
+
}
|
142
|
+
p->terminated = 1;
|
143
|
+
}
|
144
|
+
|
145
|
+
if (args->pipe[1] >= 0) {
|
146
|
+
/* Write a character to the main thread to notify it about this. */
|
147
|
+
ssize_t r;
|
148
|
+
|
149
|
+
do
|
150
|
+
r = write(args->pipe[1], "", 1);
|
151
|
+
while (r == -1 && errno == EINTR);
|
152
|
+
}
|
153
|
+
|
154
|
+
return NULL;
|
155
|
+
}
|
156
|
+
|
157
|
+
|
158
|
+
/* Wait for all `n` processes in `vec` to terminate. */
|
159
|
+
/* Time out after `timeout` msec, or never if timeout == -1 */
|
160
|
+
/* Return 0 if all processes are terminated, -1 on error, -2 on timeout. */
|
161
|
+
int process_wait(process_info_t* vec, int n, int timeout) {
|
162
|
+
int i;
|
163
|
+
process_info_t* p;
|
164
|
+
dowait_args args;
|
165
|
+
args.vec = vec;
|
166
|
+
args.n = n;
|
167
|
+
args.pipe[0] = -1;
|
168
|
+
args.pipe[1] = -1;
|
169
|
+
|
170
|
+
/* The simple case is where there is no timeout */
|
171
|
+
if (timeout == -1) {
|
172
|
+
dowait(&args);
|
173
|
+
return 0;
|
174
|
+
}
|
175
|
+
|
176
|
+
/* Hard case. Do the wait with a timeout.
|
177
|
+
*
|
178
|
+
* Assumption: we are the only ones making this call right now. Otherwise
|
179
|
+
* we'd need to lock vec.
|
180
|
+
*/
|
181
|
+
|
182
|
+
pthread_t tid;
|
183
|
+
int retval;
|
184
|
+
|
185
|
+
int r = pipe((int*)&(args.pipe));
|
186
|
+
if (r) {
|
187
|
+
perror("pipe()");
|
188
|
+
return -1;
|
189
|
+
}
|
190
|
+
|
191
|
+
r = pthread_create(&tid, NULL, dowait, &args);
|
192
|
+
if (r) {
|
193
|
+
perror("pthread_create()");
|
194
|
+
retval = -1;
|
195
|
+
goto terminate;
|
196
|
+
}
|
197
|
+
|
198
|
+
struct timeval tv;
|
199
|
+
tv.tv_sec = timeout / 1000;
|
200
|
+
tv.tv_usec = 0;
|
201
|
+
|
202
|
+
fd_set fds;
|
203
|
+
FD_ZERO(&fds);
|
204
|
+
FD_SET(args.pipe[0], &fds);
|
205
|
+
|
206
|
+
r = select(args.pipe[0] + 1, &fds, NULL, NULL, &tv);
|
207
|
+
|
208
|
+
if (r == -1) {
|
209
|
+
perror("select()");
|
210
|
+
retval = -1;
|
211
|
+
|
212
|
+
} else if (r) {
|
213
|
+
/* The thread completed successfully. */
|
214
|
+
retval = 0;
|
215
|
+
|
216
|
+
} else {
|
217
|
+
/* Timeout. Kill all the children. */
|
218
|
+
for (i = 0; i < n; i++) {
|
219
|
+
p = (process_info_t*)(vec + i * sizeof(process_info_t));
|
220
|
+
kill(p->pid, SIGTERM);
|
221
|
+
}
|
222
|
+
retval = -2;
|
223
|
+
|
224
|
+
/* Wait for thread to finish. */
|
225
|
+
r = pthread_join(tid, NULL);
|
226
|
+
if (r) {
|
227
|
+
perror("pthread_join");
|
228
|
+
retval = -1;
|
229
|
+
}
|
230
|
+
}
|
231
|
+
|
232
|
+
terminate:
|
233
|
+
close(args.pipe[0]);
|
234
|
+
close(args.pipe[1]);
|
235
|
+
return retval;
|
236
|
+
}
|
237
|
+
|
238
|
+
|
239
|
+
/* Returns the number of bytes in the stdio output buffer for process `p`. */
|
240
|
+
long int process_output_size(process_info_t *p) {
|
241
|
+
/* Size of the p->stdout_file */
|
242
|
+
struct stat buf;
|
243
|
+
|
244
|
+
int r = fstat(fileno(p->stdout_file), &buf);
|
245
|
+
if (r < 0) {
|
246
|
+
return -1;
|
247
|
+
}
|
248
|
+
|
249
|
+
return (long)buf.st_size;
|
250
|
+
}
|
251
|
+
|
252
|
+
|
253
|
+
/* Copy the contents of the stdio output buffer to `fd`. */
|
254
|
+
int process_copy_output(process_info_t *p, int fd) {
|
255
|
+
int r = fseek(p->stdout_file, 0, SEEK_SET);
|
256
|
+
if (r < 0) {
|
257
|
+
perror("fseek");
|
258
|
+
return -1;
|
259
|
+
}
|
260
|
+
|
261
|
+
ssize_t nwritten;
|
262
|
+
char buf[1024];
|
263
|
+
|
264
|
+
/* TODO: what if the line is longer than buf */
|
265
|
+
while (fgets(buf, sizeof(buf), p->stdout_file) != NULL) {
|
266
|
+
/* TODO: what if write doesn't write the whole buffer... */
|
267
|
+
nwritten = 0;
|
268
|
+
|
269
|
+
if (tap_output)
|
270
|
+
nwritten += write(fd, "#", 1);
|
271
|
+
|
272
|
+
nwritten += write(fd, buf, strlen(buf));
|
273
|
+
|
274
|
+
if (nwritten < 0) {
|
275
|
+
perror("write");
|
276
|
+
return -1;
|
277
|
+
}
|
278
|
+
}
|
279
|
+
|
280
|
+
if (ferror(p->stdout_file)) {
|
281
|
+
perror("read");
|
282
|
+
return -1;
|
283
|
+
}
|
284
|
+
|
285
|
+
return 0;
|
286
|
+
}
|
287
|
+
|
288
|
+
|
289
|
+
/* Return the name that was specified when `p` was started by process_start */
|
290
|
+
char* process_get_name(process_info_t *p) {
|
291
|
+
return p->name;
|
292
|
+
}
|
293
|
+
|
294
|
+
|
295
|
+
/* Terminate process `p`. */
|
296
|
+
int process_terminate(process_info_t *p) {
|
297
|
+
return kill(p->pid, SIGTERM);
|
298
|
+
}
|
299
|
+
|
300
|
+
|
301
|
+
/* Return the exit code of process p. */
|
302
|
+
/* On error, return -1. */
|
303
|
+
int process_reap(process_info_t *p) {
|
304
|
+
if (WIFEXITED(p->status)) {
|
305
|
+
return WEXITSTATUS(p->status);
|
306
|
+
} else {
|
307
|
+
return p->status; /* ? */
|
308
|
+
}
|
309
|
+
}
|
310
|
+
|
311
|
+
|
312
|
+
/* Clean up after terminating process `p` (e.g. free the output buffer etc.). */
|
313
|
+
void process_cleanup(process_info_t *p) {
|
314
|
+
fclose(p->stdout_file);
|
315
|
+
free(p->name);
|
316
|
+
}
|
317
|
+
|
318
|
+
|
319
|
+
/* Move the console cursor one line up and back to the first column. */
|
320
|
+
void rewind_cursor(void) {
|
321
|
+
fprintf(stderr, "\033[2K\r");
|
322
|
+
}
|
323
|
+
|
324
|
+
|
325
|
+
/* Pause the calling thread for a number of milliseconds. */
|
326
|
+
void uv_sleep(int msec) {
|
327
|
+
usleep(msec * 1000);
|
328
|
+
}
|
@@ -0,0 +1,36 @@
|
|
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 TEST_RUNNER_UNIX_H
|
23
|
+
#define TEST_RUNNER_UNIX_H
|
24
|
+
|
25
|
+
#include <sys/types.h>
|
26
|
+
#include <stdio.h> /* FILE */
|
27
|
+
|
28
|
+
typedef struct {
|
29
|
+
FILE* stdout_file;
|
30
|
+
pid_t pid;
|
31
|
+
char* name;
|
32
|
+
int status;
|
33
|
+
int terminated;
|
34
|
+
} process_info_t;
|
35
|
+
|
36
|
+
#endif /* TEST_RUNNER_UNIX_H */
|