~yolanda.robla/ubuntu/trusty/nodejs/add_distribution

« back to all changes in this revision

Viewing changes to deps/uv/test/test-counters-init.c

  • Committer: Package Import Robot
  • Author(s): Jérémy Lal
  • Date: 2013-08-14 00:16:46 UTC
  • mfrom: (7.1.40 sid)
  • Revision ID: package-import@ubuntu.com-20130814001646-bzlysfh8sd6mukbo
Tags: 0.10.15~dfsg1-4
* Update 2005 patch, adding a handful of tests that can fail on
  slow platforms.
* Add 1004 patch to fix test failures when writing NaN to buffer
  on mipsel.

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
 
#define UNIX (defined(__unix__) || defined(__POSIX__) || defined(__APPLE__))
22
 
#include "task.h"
23
 
#include "uv.h"
24
 
#include <fcntl.h>
25
 
 
26
 
#if UNIX
27
 
#include <unistd.h> /* unlink, rmdir, etc. */
28
 
#else
29
 
# include <direct.h>
30
 
# include <io.h>
31
 
# define unlink _unlink
32
 
# define rmdir _rmdir
33
 
# define stat _stati64
34
 
# define open _open
35
 
# define write _write
36
 
# define lseek _lseek
37
 
# define close _close
38
 
#endif
39
 
 
40
 
static char exepath[1024];
41
 
static size_t exepath_size = 1024;
42
 
static char* args[3];
43
 
static uv_fs_t open_req;
44
 
static uv_tcp_t tcp;
45
 
static uv_udp_t udp;
46
 
static uv_pipe_t uvpipe;
47
 
static uv_tty_t tty;
48
 
static uv_prepare_t prepare;
49
 
static uv_check_t check;
50
 
static uv_idle_t idle;
51
 
static uv_async_t async;
52
 
static uv_timer_t timer;
53
 
static uv_fs_event_t fs_event;
54
 
static uv_process_t process;
55
 
static uv_process_options_t options;
56
 
static uv_fs_t fs_req;
57
 
 
58
 
static void exit_cb(uv_process_t* process, int exit_status, int term_signal) {
59
 
  ASSERT(exit_status == 1);
60
 
  ASSERT(term_signal == 0);
61
 
  uv_close((uv_handle_t*)process, NULL);
62
 
}
63
 
 
64
 
static void init_process_options(char* test, uv_exit_cb exit_cb) {
65
 
  int r = uv_exepath(exepath, &exepath_size);
66
 
  ASSERT(r == 0);
67
 
  exepath[exepath_size] = '\0';
68
 
  args[0] = exepath;
69
 
  args[1] = test;
70
 
  args[2] = NULL;
71
 
  options.file = exepath;
72
 
  options.args = args;
73
 
  options.exit_cb = exit_cb;
74
 
}
75
 
 
76
 
static void create_dir(uv_loop_t* loop, const char* name) {
77
 
  int r;
78
 
  uv_fs_t req;
79
 
  r = uv_fs_rmdir(loop, &req, name, NULL);
80
 
  r = uv_fs_mkdir(loop, &req, name, 0755, NULL);
81
 
  ASSERT(r == 0);
82
 
  uv_fs_req_cleanup(&req);
83
 
}
84
 
 
85
 
static void create_cb(uv_fs_t* req) {
86
 
  ASSERT(req == &open_req);
87
 
  ASSERT(req->fs_type == UV_FS_OPEN);
88
 
  ASSERT(req->result != -1);
89
 
  uv_fs_req_cleanup(req);
90
 
  unlink("test_file");
91
 
}
92
 
 
93
 
TEST_IMPL(counters_init) {
94
 
  int r;
95
 
  uint64_t eio_init_prev;
96
 
  uint64_t req_init_prev;
97
 
  uint64_t handle_init_prev;
98
 
  uint64_t stream_init_prev;
99
 
  uint64_t tcp_init_prev;
100
 
  uint64_t udp_init_prev;
101
 
  uint64_t pipe_init_prev;
102
 
  uint64_t tty_init_prev;
103
 
  uint64_t prepare_init_prev;
104
 
  uint64_t check_init_prev;
105
 
  uint64_t idle_init_prev;
106
 
  uint64_t async_init_prev;
107
 
  uint64_t timer_init_prev;
108
 
  uint64_t process_init_prev;
109
 
  uint64_t fs_event_init_prev;
110
 
 
111
 
  /* req_init and eio_init test by uv_fs_open() */
112
 
  unlink("test_file");
113
 
  req_init_prev = uv_default_loop()->counters.req_init;
114
 
  eio_init_prev = uv_default_loop()->counters.eio_init;
115
 
  r = uv_fs_open(uv_default_loop(), &open_req, "test_file", O_WRONLY | O_CREAT,
116
 
                 S_IREAD | S_IWRITE, create_cb);
117
 
  ASSERT(r == 0);
118
 
  ASSERT(open_req.result == 0);
119
 
  ASSERT(uv_default_loop()->counters.req_init == ++req_init_prev);
120
 
#ifndef _WIN32
121
 
  ASSERT(uv_default_loop()->counters.eio_init == ++eio_init_prev);
122
 
#endif
123
 
 
124
 
  /* tcp_init, stream_init and handle_init test by uv_tcp_init() */
125
 
  tcp_init_prev = uv_default_loop()->counters.tcp_init;
126
 
  stream_init_prev = uv_default_loop()->counters.stream_init;
127
 
  handle_init_prev = uv_default_loop()->counters.handle_init;
128
 
  r = uv_tcp_init(uv_default_loop(), &tcp);
129
 
  ASSERT(r == 0);
130
 
  ASSERT(uv_default_loop()->counters.tcp_init == ++tcp_init_prev);
131
 
  ASSERT(uv_default_loop()->counters.stream_init == ++stream_init_prev);
132
 
  ASSERT(uv_default_loop()->counters.handle_init == ++handle_init_prev);
133
 
  uv_close((uv_handle_t*)&tcp, NULL);
134
 
 
135
 
  /* udp_init test by uv_udp_init() */
136
 
  udp_init_prev = uv_default_loop()->counters.udp_init;
137
 
  r = uv_udp_init(uv_default_loop(), &udp);
138
 
  ASSERT(r == 0);
139
 
  ASSERT(uv_default_loop()->counters.udp_init == ++udp_init_prev);
140
 
  uv_close((uv_handle_t*)&udp, NULL);
141
 
 
142
 
  /* pipe_init uv_pipe_init() */
143
 
  pipe_init_prev = uv_default_loop()->counters.pipe_init;
144
 
  uv_pipe_init(uv_default_loop(), &uvpipe, 0);
145
 
  ASSERT(r == 0);
146
 
  ASSERT(uv_default_loop()->counters.pipe_init == ++pipe_init_prev);
147
 
  uv_close((uv_handle_t*)&uvpipe, NULL);
148
 
 
149
 
  /* tty_init test by uv_tty_init()*/
150
 
  tty_init_prev = uv_default_loop()->counters.tty_init;
151
 
  r = uv_tty_init(uv_default_loop(), &tty, 1, 0);
152
 
  /* uv_tty_init() always returns -1 in run_test in Windows
153
 
     so that we avoid to check return value.
154
 
   */
155
 
#ifndef _WIN32
156
 
  ASSERT(r == 0);
157
 
  uv_close((uv_handle_t*)&tty, NULL);
158
 
#endif
159
 
  ASSERT(uv_default_loop()->counters.tty_init == ++tty_init_prev);
160
 
 
161
 
  /* prepare_init test by uv_prepare_init() */
162
 
  prepare_init_prev = uv_default_loop()->counters.prepare_init;
163
 
  r = uv_prepare_init(uv_default_loop(), &prepare);
164
 
  ASSERT(r == 0);
165
 
  ASSERT(uv_default_loop()->counters.prepare_init == ++prepare_init_prev);
166
 
  uv_close((uv_handle_t*)&prepare, NULL);
167
 
 
168
 
  /* check_init test by uv_check_init() */
169
 
  check_init_prev = uv_default_loop()->counters.check_init;
170
 
  r = uv_check_init(uv_default_loop(), &check);
171
 
  ASSERT(r == 0);
172
 
  ASSERT(uv_default_loop()->counters.check_init == ++check_init_prev);
173
 
  uv_close((uv_handle_t*)&check, NULL);
174
 
 
175
 
  /* idle_init test by uv_idle_init() */
176
 
  idle_init_prev = uv_default_loop()->counters.idle_init;
177
 
  r = uv_idle_init(uv_default_loop(), &idle);
178
 
  ASSERT(r == 0);
179
 
  ASSERT(uv_default_loop()->counters.idle_init == ++idle_init_prev);
180
 
  uv_close((uv_handle_t*)&idle, NULL);
181
 
 
182
 
  /* async_init test by uv_async_init() */
183
 
  async_init_prev = uv_default_loop()->counters.async_init;
184
 
  r = uv_async_init(uv_default_loop(), &async, NULL);
185
 
  ASSERT(r == 0);
186
 
  ASSERT(uv_default_loop()->counters.async_init == ++async_init_prev);
187
 
  uv_close((uv_handle_t*)&async, NULL);
188
 
 
189
 
  /* timer_init test by uv_timer_init() */
190
 
  timer_init_prev = uv_default_loop()->counters.timer_init;
191
 
  r = uv_timer_init(uv_default_loop(), &timer);
192
 
  ASSERT(r == 0);
193
 
  ASSERT(uv_default_loop()->counters.timer_init == ++timer_init_prev);
194
 
  uv_close((uv_handle_t*)&timer, NULL);
195
 
 
196
 
  /* process_init test by uv_spawn() */
197
 
  process_init_prev = uv_default_loop()->counters.process_init;
198
 
  init_process_options("spawn_helper1", exit_cb);
199
 
  r = uv_spawn(uv_default_loop(), &process, options);
200
 
  ASSERT(r == 0);
201
 
  ASSERT(uv_default_loop()->counters.process_init == ++process_init_prev);
202
 
  r = uv_run(uv_default_loop());
203
 
  ASSERT(r == 0);
204
 
 
205
 
  /* fs_event_init test by uv_fs_event_init() */
206
 
  create_dir(uv_default_loop(), "watch_dir");
207
 
  fs_event_init_prev = uv_default_loop()->counters.fs_event_init;
208
 
  r = uv_fs_event_init(uv_default_loop(), &fs_event, "watch_dir", NULL, 0);
209
 
  ASSERT(r == 0);
210
 
  ASSERT(uv_default_loop()->counters.fs_event_init == ++fs_event_init_prev);
211
 
  r = uv_fs_rmdir(uv_default_loop(), &fs_req, "watch_dir", NULL);
212
 
  ASSERT(r == 0);
213
 
  uv_fs_req_cleanup(&fs_req);
214
 
 
215
 
  return 0;
216
 
}