~james-page/ubuntu/precise/nodejs/0.6.x-merge

« back to all changes in this revision

Viewing changes to deps/uv/test/benchmark-spawn.c

  • Committer: James Page
  • Date: 2012-03-30 12:09:16 UTC
  • mfrom: (7.1.23 sid)
  • Revision ID: james.page@canonical.com-20120330120916-40hfu9o00qr5t87b
* Merge from Debian unstable:
  - New upstream release (LP: #892034).
  - This package is x86/arm only. Update control to match
  - d/patches/2009_increase_test_timeout.patch: Increased default test
    timeout from 60 to 120 seconds to support reliable execution of all
    tests on armhf/armel architectures.
  - d/patches/2005_expected_failing_tests.patch: 
    - Allow racey tests to fail: test-cluster-kill-workers,
      test-child-process-fork2 
    - Allow test-fs-watch to fail as LP buildd's don't support
      inotify.
    - Revert all other Ubuntu changes as no longer required.
* Update Standards-Version to 3.9.3.
* Patch wscript to enable build on mipsel arch, libv8 being available.
  Upstream does not support that arch, failure expected.
* test-cluster-kill-workers is expected to fail on armhf,
  Bug#660802 will be closed when test pass.
* test-buffer is expected to fail on armel,
  Bug#660800 will be closed when test pass.
* Add epoch to dependency on libev >= 1:4.11. Closes: bug#658441.
* Remove tools/doc because node-doc-generator has no license for now.
* Add copyright for doc/sh* files (shjs).
* source.lintian-overrides : source-contains-waf-binary tools/node-waf
  it is simply not the case here.
* test-stream-pipe-multi expected to timeout sometimes on busy builds. 
* New upstream release.
* Remove upstream patches.
* test-dgram-pingpong expected to timeout, the test itself is buggy.
* test-buffer expected to fail on armel, allow building package to make
  it easier to find the cause of the failure.
  Closes: bug#639636.
* Expect tests dgram-multicast and broadcast to fail.
  debian/patches/2005_expected_failing_tests.patch
* Drop dpkg-source local-options: Defaults since dpkg-source 1.16.1.
* New upstream release.
* Depend on libev-dev 4.11, see bug#657080.
* Bump dependency on openssl to 1.0.0g.
* Remove useless uv_loop_refcount from libuv,
  refreshed 2009_fix_shared_ev.patch.
* Apply to upstream patches landed after 0.6.10 release,
  to fix debugger repl and http client.
* New upstream release. Closes:bug#650661
* Repackage to remove non-dfsg font files ./deps/npm/html/*/*.ttf
* Remove unneeded bundled dependencies: lighter tarball,
  debian/copyright is easier to maintain.
* Drop unneeded build-dependency on scons.
* Depend on zlib1g, libc-ares, libev.
  Patches done to support building with those shared libs.
* Fix DEB_UPSTREAM_URL in debian/rules, and debian/watch.
* nodejs.pc file for pkgconfig is no more available.
* Build-depend on procps package, a test is using /bin/ps.
* Refreshed debian/patches/2005_expected_failing_tests.patch,
  only for tests that need networking.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
/* This benchmark spawns itself 1000 times. */
 
23
 
 
24
#include "task.h"
 
25
#include "uv.h"
 
26
 
 
27
static uv_loop_t* loop;
 
28
 
 
29
static int N = 1000;
 
30
static int done;
 
31
 
 
32
static uv_process_t process;
 
33
static uv_process_options_t options = { 0 };
 
34
static char exepath[1024];
 
35
static size_t exepath_size = 1024;
 
36
static char* args[3];
 
37
static uv_pipe_t out;
 
38
 
 
39
#define OUTPUT_SIZE 1024
 
40
static char output[OUTPUT_SIZE];
 
41
static int output_used;
 
42
 
 
43
static int process_open;
 
44
static int pipe_open;
 
45
 
 
46
 
 
47
static void spawn();
 
48
 
 
49
 
 
50
void maybe_spawn() {
 
51
  if (process_open == 0 && pipe_open == 0) {
 
52
    done++;
 
53
    if (done < N) {
 
54
      spawn();
 
55
    }
 
56
  }
 
57
}
 
58
 
 
59
 
 
60
static void process_close_cb(uv_handle_t* handle) {
 
61
  ASSERT(process_open == 1);
 
62
  process_open = 0;
 
63
  maybe_spawn();
 
64
}
 
65
 
 
66
 
 
67
static void exit_cb(uv_process_t* process, int exit_status, int term_signal) {
 
68
  ASSERT(exit_status == 42);
 
69
  ASSERT(term_signal == 0);
 
70
  uv_close((uv_handle_t*)process, process_close_cb);
 
71
}
 
72
 
 
73
 
 
74
uv_buf_t on_alloc(uv_handle_t* handle, size_t suggested_size) {
 
75
  uv_buf_t buf;
 
76
  buf.base = output + output_used;
 
77
  buf.len = OUTPUT_SIZE - output_used;
 
78
  return buf;
 
79
}
 
80
 
 
81
 
 
82
void pipe_close_cb(uv_handle_t* pipe) {
 
83
  ASSERT(pipe_open == 1);
 
84
  pipe_open = 0;
 
85
  maybe_spawn();
 
86
}
 
87
 
 
88
 
 
89
void on_read(uv_stream_t* pipe, ssize_t nread, uv_buf_t buf) {
 
90
  uv_err_t err = uv_last_error(loop);
 
91
 
 
92
  if (nread > 0) {
 
93
    ASSERT(pipe_open == 1);
 
94
    output_used += nread;
 
95
  } else if (nread < 0) {
 
96
    if (err.code == UV_EOF) {
 
97
      uv_close((uv_handle_t*)pipe, pipe_close_cb);
 
98
    }
 
99
  }
 
100
}
 
101
 
 
102
 
 
103
static void spawn() {
 
104
  int r;
 
105
 
 
106
  ASSERT(process_open == 0);
 
107
  ASSERT(pipe_open == 0);
 
108
 
 
109
  args[0] = exepath;
 
110
  args[1] = "spawn_helper";
 
111
  args[2] = NULL;
 
112
  options.file = exepath;
 
113
  options.args = args;
 
114
  options.exit_cb = exit_cb;
 
115
 
 
116
  uv_pipe_init(loop, &out, 0);
 
117
  options.stdout_stream = &out;
 
118
 
 
119
  r = uv_spawn(loop, &process, options);
 
120
  ASSERT(r == 0);
 
121
 
 
122
  process_open = 1;
 
123
  pipe_open = 1;
 
124
  output_used = 0;
 
125
 
 
126
  r = uv_read_start((uv_stream_t*) &out, on_alloc, on_read);
 
127
  ASSERT(r == 0);
 
128
}
 
129
 
 
130
 
 
131
BENCHMARK_IMPL(spawn) {
 
132
  int r;
 
133
  static int64_t start_time, end_time;
 
134
 
 
135
  loop = uv_default_loop();
 
136
 
 
137
  r = uv_exepath(exepath, &exepath_size);
 
138
  ASSERT(r == 0);
 
139
  exepath[exepath_size] = '\0';
 
140
 
 
141
  uv_update_time(loop);
 
142
  start_time = uv_now(loop);
 
143
 
 
144
  spawn();
 
145
 
 
146
  r = uv_run(loop);
 
147
  ASSERT(r == 0);
 
148
 
 
149
  uv_update_time(loop);
 
150
  end_time = uv_now(loop);
 
151
 
 
152
  LOGF("spawn: %.0f spawns/s\n",
 
153
       (double) N / (double) (end_time - start_time) * 1000.0);
 
154
 
 
155
  return 0;
 
156
}