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

« back to all changes in this revision

Viewing changes to deps/uv/test/runner.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:
19
19
 * IN THE SOFTWARE.
20
20
 */
21
21
 
 
22
#include <stdio.h>
22
23
#include <string.h>
23
24
 
24
25
#include "runner.h"
25
26
#include "task.h"
 
27
#include "uv.h"
26
28
 
27
29
char executable_path[PATHMAX] = { '\0' };
28
30
 
29
 
 
30
 
static void log_progress(int total, int passed, int failed, const char* name) {
31
 
  LOGF("[%% %3d|+ %3d|- %3d]: %s", (passed + failed) / total * 100,
32
 
      passed, failed, name);
 
31
int tap_output = 0;
 
32
 
 
33
 
 
34
static void log_progress(int total,
 
35
                         int passed,
 
36
                         int failed,
 
37
                         int todos,
 
38
                         int skipped,
 
39
                         const char* name) {
 
40
  int progress;
 
41
 
 
42
  if (total == 0)
 
43
    total = 1;
 
44
 
 
45
  progress = 100 * (passed + failed + skipped + todos) / total;
 
46
  LOGF("[%% %3d|+ %3d|- %3d|T %3d|S %3d]: %s",
 
47
       progress,
 
48
       passed,
 
49
       failed,
 
50
       todos,
 
51
       skipped,
 
52
       name);
 
53
}
 
54
 
 
55
 
 
56
const char* fmt(double d) {
 
57
  static char buf[1024];
 
58
  static char* p;
 
59
  uint64_t v;
 
60
 
 
61
  if (p == NULL)
 
62
    p = buf;
 
63
 
 
64
  p += 31;
 
65
 
 
66
  if (p >= buf + sizeof(buf))
 
67
    return "<buffer too small>";
 
68
 
 
69
  v = (uint64_t) d;
 
70
 
 
71
#if 0 /* works but we don't care about fractional precision */
 
72
  if (d - v >= 0.01) {
 
73
    *--p = '0' + (uint64_t) (d * 100) % 10;
 
74
    *--p = '0' + (uint64_t) (d * 10) % 10;
 
75
    *--p = '.';
 
76
  }
 
77
#endif
 
78
 
 
79
  if (v == 0)
 
80
    *--p = '0';
 
81
 
 
82
  while (v) {
 
83
    if (v) *--p = '0' + (v % 10), v /= 10;
 
84
    if (v) *--p = '0' + (v % 10), v /= 10;
 
85
    if (v) *--p = '0' + (v % 10), v /= 10;
 
86
    if (v) *--p = ',';
 
87
  }
 
88
 
 
89
  return p;
33
90
}
34
91
 
35
92
 
36
93
int run_tests(int timeout, int benchmark_output) {
37
 
  int total, passed, failed;
 
94
  int total;
 
95
  int passed;
 
96
  int failed;
 
97
  int todos;
 
98
  int skipped;
 
99
  int current;
 
100
  int test_result;
38
101
  task_entry_t* task;
39
102
 
40
103
  /* Count the number of tests. */
45
108
    }
46
109
  }
47
110
 
 
111
  if (tap_output) {
 
112
    LOGF("1..%d\n", total);
 
113
  }
 
114
 
48
115
  /* Run all tests. */
49
116
  passed = 0;
50
117
  failed = 0;
 
118
  todos = 0;
 
119
  skipped = 0;
 
120
  current = 1;
51
121
  for (task = TASKS; task->main; task++) {
52
122
    if (task->is_helper) {
53
123
      continue;
54
124
    }
55
125
 
 
126
    if (!tap_output)
 
127
      rewind_cursor();
 
128
 
 
129
    if (!benchmark_output && !tap_output) {
 
130
      log_progress(total, passed, failed, todos, skipped, task->task_name);
 
131
    }
 
132
 
 
133
    test_result = run_test(task->task_name, timeout, benchmark_output, current);
 
134
    switch (test_result) {
 
135
    case TEST_OK: passed++; break;
 
136
    case TEST_TODO: todos++; break;
 
137
    case TEST_SKIP: skipped++; break;
 
138
    default: failed++;
 
139
    }
 
140
    current++;
 
141
  }
 
142
 
 
143
  if (!tap_output)
56
144
    rewind_cursor();
57
 
    if (!benchmark_output) {
58
 
      log_progress(total, passed, failed, task->task_name);
59
 
    }
60
 
 
61
 
    if (run_test(task->task_name, timeout, benchmark_output) == 0) {
62
 
      passed++;
63
 
    } else {
64
 
      failed++;
65
 
    }
66
 
  }
67
 
 
68
 
  rewind_cursor();
69
 
 
70
 
  if (!benchmark_output) {
71
 
    log_progress(total, passed, failed, "Done.\n");
 
145
 
 
146
  if (!benchmark_output && !tap_output) {
 
147
    log_progress(total, passed, failed, todos, skipped, "Done.\n");
72
148
  }
73
149
 
74
150
  return failed;
75
151
}
76
152
 
77
153
 
78
 
int run_test(const char* test, int timeout, int benchmark_output) {
 
154
void log_tap_result(int test_count,
 
155
                    const char* test,
 
156
                    int status,
 
157
                    process_info_t* process) {
 
158
  const char* result;
 
159
  const char* directive;
 
160
  char reason[1024];
 
161
 
 
162
  switch (status) {
 
163
  case TEST_OK:
 
164
    result = "ok";
 
165
    directive = "";
 
166
    break;
 
167
  case TEST_TODO:
 
168
    result = "not ok";
 
169
    directive = " # TODO ";
 
170
    break;
 
171
  case TEST_SKIP:
 
172
    result = "ok";
 
173
    directive = " # SKIP ";
 
174
    break;
 
175
  default:
 
176
    result = "not ok";
 
177
    directive = "";
 
178
  }
 
179
 
 
180
  if ((status == TEST_SKIP || status == TEST_TODO) &&
 
181
      process_output_size(process) > 0) {
 
182
    process_read_last_line(process, reason, sizeof reason);
 
183
  } else {
 
184
    reason[0] = '\0';
 
185
  }
 
186
 
 
187
  LOGF("%s %d - %s%s%s\n", result, test_count, test, directive, reason);
 
188
}
 
189
 
 
190
 
 
191
int run_test(const char* test,
 
192
             int timeout,
 
193
             int benchmark_output,
 
194
             int test_count) {
79
195
  char errmsg[1024] = "no error";
80
196
  process_info_t processes[1024];
81
197
  process_info_t *main_proc;
89
205
  main_proc = NULL;
90
206
  process_count = 0;
91
207
 
 
208
#ifndef _WIN32
 
209
  /* Clean up stale socket from previous run. */
 
210
  remove(TEST_PIPENAME);
 
211
#endif
 
212
 
92
213
  /* If it's a helper the user asks for, start it directly. */
93
214
  for (task = TASKS; task->main; task++) {
94
215
    if (task->is_helper && strcmp(test, task->process_name) == 0) {
109
230
 
110
231
    if (process_start(task->task_name,
111
232
                      task->process_name,
112
 
                      &processes[process_count]) == -1) {
 
233
                      &processes[process_count],
 
234
                      1 /* is_helper */) == -1) {
113
235
      snprintf(errmsg,
114
236
               sizeof errmsg,
115
237
               "Process `%s` failed to start.",
124
246
  uv_sleep(250);
125
247
 
126
248
  /* Now start the test itself. */
127
 
  for (main_proc = NULL, task = TASKS; task->main; task++) {
 
249
  for (task = TASKS; task->main; task++) {
128
250
    if (strcmp(test, task->task_name) != 0) {
129
251
      continue;
130
252
    }
135
257
 
136
258
    if (process_start(task->task_name,
137
259
                      task->process_name,
138
 
                      &processes[process_count]) == -1) {
 
260
                      &processes[process_count],
 
261
                      0 /* !is_helper */) == -1) {
139
262
      snprintf(errmsg,
140
263
               sizeof errmsg,
141
264
               "Process `%s` failed to start.",
168
291
  }
169
292
 
170
293
  status = process_reap(main_proc);
171
 
  if (status != 0) {
 
294
  if (status != TEST_OK) {
172
295
    snprintf(errmsg,
173
296
             sizeof errmsg,
174
297
             "exit code %d",
192
315
    FATAL("process_wait failed");
193
316
  }
194
317
 
 
318
  if (tap_output)
 
319
    log_tap_result(test_count, test, status, &processes[i]);
 
320
 
195
321
  /* Show error and output from processes if the test failed. */
196
 
  if (status != 0) {
197
 
    LOGF("\n`%s` failed: %s\n", test, errmsg);
 
322
  if (status != 0 || task->show_output) {
 
323
    if (tap_output) {
 
324
      LOGF("#");
 
325
    } else if (status == TEST_TODO) {
 
326
      LOGF("\n`%s` todo\n", test);
 
327
    } else if (status == TEST_SKIP) {
 
328
      LOGF("\n`%s` skipped\n", test);
 
329
    } else if (status != 0) {
 
330
      LOGF("\n`%s` failed: %s\n", test, errmsg);
 
331
    } else {
 
332
      LOGF("\n");
 
333
    }
198
334
 
199
335
    for (i = 0; i < process_count; i++) {
200
336
      switch (process_output_size(&processes[i])) {
214
350
        break;
215
351
      }
216
352
    }
217
 
    LOG("=============================================================\n");
 
353
 
 
354
    if (!tap_output) {
 
355
      LOG("=============================================================\n");
 
356
    }
218
357
 
219
358
  /* In benchmark mode show concise output from the main process. */
220
359
  } else if (benchmark_output) {
249
388
 */
250
389
int run_test_part(const char* test, const char* part) {
251
390
  task_entry_t* task;
 
391
  int r;
252
392
 
253
393
  for (task = TASKS; task->main; task++) {
254
 
    if (strcmp(test, task->task_name) == 0
255
 
        && strcmp(part, task->process_name) == 0) {
256
 
      return task->main();
 
394
    if (strcmp(test, task->task_name) == 0 &&
 
395
        strcmp(part, task->process_name) == 0) {
 
396
      r = task->main();
 
397
      return r;
257
398
    }
258
399
  }
259
400