summaryrefslogtreecommitdiff
path: root/deps/uv/test
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2013-05-10 15:30:53 -0700
committerisaacs <i@izs.me>2013-05-10 15:30:53 -0700
commitfede68fd68924117a46420c1ecfe42fe681b4ae3 (patch)
tree6ffe361d1b2896a3fd89ec881f7622893c20f142 /deps/uv/test
parentec576235f1f4d7f5873cf3c0118b28c022740ffe (diff)
downloadandroid-node-v8-fede68fd68924117a46420c1ecfe42fe681b4ae3.tar.gz
android-node-v8-fede68fd68924117a46420c1ecfe42fe681b4ae3.tar.bz2
android-node-v8-fede68fd68924117a46420c1ecfe42fe681b4ae3.zip
uv: Upgrade to 0.11.2
Diffstat (limited to 'deps/uv/test')
-rw-r--r--deps/uv/test/runner-unix.c28
-rw-r--r--deps/uv/test/runner-win.c40
-rw-r--r--deps/uv/test/runner.c94
-rw-r--r--deps/uv/test/runner.h5
-rw-r--r--deps/uv/test/task.h24
-rw-r--r--deps/uv/test/test-list.h9
-rw-r--r--deps/uv/test/test-osx-select.c82
-rw-r--r--deps/uv/test/test-ref.c12
8 files changed, 277 insertions, 17 deletions
diff --git a/deps/uv/test/runner-unix.c b/deps/uv/test/runner-unix.c
index eefb700835..b66df51b98 100644
--- a/deps/uv/test/runner-unix.c
+++ b/deps/uv/test/runner-unix.c
@@ -286,6 +286,34 @@ int process_copy_output(process_info_t *p, int fd) {
}
+/* Copy the last line of the stdio output buffer to `buffer` */
+int process_read_last_line(process_info_t *p,
+ char* buffer,
+ size_t buffer_len) {
+ char* ptr;
+
+ int r = fseek(p->stdout_file, 0, SEEK_SET);
+ if (r < 0) {
+ perror("fseek");
+ return -1;
+ }
+
+ buffer[0] = '\0';
+
+ while (fgets(buffer, buffer_len, p->stdout_file) != NULL) {
+ for (ptr = buffer; *ptr && *ptr != '\r' && *ptr != '\n'; ptr++);
+ *ptr = '\0';
+ }
+
+ if (ferror(p->stdout_file)) {
+ perror("read");
+ buffer[0] = '\0';
+ return -1;
+ }
+ return 0;
+}
+
+
/* Return the name that was specified when `p` was started by process_start */
char* process_get_name(process_info_t *p) {
return p->name;
diff --git a/deps/uv/test/runner-win.c b/deps/uv/test/runner-win.c
index 3aae1c3e9c..5d23259437 100644
--- a/deps/uv/test/runner-win.c
+++ b/deps/uv/test/runner-win.c
@@ -248,6 +248,46 @@ int process_copy_output(process_info_t *p, int fd) {
}
+int process_read_last_line(process_info_t *p,
+ char * buffer,
+ size_t buffer_len) {
+ DWORD size;
+ DWORD read;
+ DWORD start;
+ OVERLAPPED overlapped;
+
+ ASSERT(buffer_len > 0);
+
+ size = GetFileSize(p->stdio_out, NULL);
+ if (size == INVALID_FILE_SIZE)
+ return -1;
+
+ if (size == 0) {
+ buffer[0] = '\0';
+ return 1;
+ }
+
+ memset(&overlapped, 0, sizeof overlapped);
+ if (size >= buffer_len)
+ overlapped.Offset = size - buffer_len - 1;
+
+ if (!ReadFile(p->stdio_out, buffer, buffer_len - 1, &read, &overlapped))
+ return -1;
+
+ for (start = read - 1; start >= 0; start--) {
+ if (buffer[start] == '\n' || buffer[start] == '\r')
+ break;
+ }
+
+ if (start > 0)
+ memmove(buffer, buffer + start, read - start);
+
+ buffer[read - start] = '\0';
+
+ return 0;
+}
+
+
char* process_get_name(process_info_t *p) {
return p->name;
}
diff --git a/deps/uv/test/runner.c b/deps/uv/test/runner.c
index bda1080a18..d8e9ddeb01 100644
--- a/deps/uv/test/runner.c
+++ b/deps/uv/test/runner.c
@@ -31,12 +31,25 @@ char executable_path[PATHMAX] = { '\0' };
int tap_output = 0;
-static void log_progress(int total, int passed, int failed, const char* name) {
+static void log_progress(int total,
+ int passed,
+ int failed,
+ int todos,
+ int skipped,
+ const char* name) {
+ int progress;
+
if (total == 0)
total = 1;
- LOGF("[%% %3d|+ %3d|- %3d]: %s", (int) ((passed + failed) / ((double) total) * 100.0),
- passed, failed, name);
+ progress = 100 * (passed + failed + skipped + todos) / total;
+ LOGF("[%% %3d|+ %3d|- %3d|T %3d|S %3d]: %s",
+ progress,
+ passed,
+ failed,
+ todos,
+ skipped,
+ name);
}
@@ -78,7 +91,13 @@ const char* fmt(double d) {
int run_tests(int timeout, int benchmark_output) {
- int total, passed, failed, current;
+ int total;
+ int passed;
+ int failed;
+ int todos;
+ int skipped;
+ int current;
+ int test_result;
task_entry_t* task;
/* Count the number of tests. */
@@ -96,6 +115,8 @@ int run_tests(int timeout, int benchmark_output) {
/* Run all tests. */
passed = 0;
failed = 0;
+ todos = 0;
+ skipped = 0;
current = 1;
for (task = TASKS; task->main; task++) {
if (task->is_helper) {
@@ -106,13 +127,15 @@ int run_tests(int timeout, int benchmark_output) {
rewind_cursor();
if (!benchmark_output && !tap_output) {
- log_progress(total, passed, failed, task->task_name);
+ log_progress(total, passed, failed, todos, skipped, task->task_name);
}
- if (run_test(task->task_name, timeout, benchmark_output, current) == 0) {
- passed++;
- } else {
- failed++;
+ test_result = run_test(task->task_name, timeout, benchmark_output, current);
+ switch (test_result) {
+ case TEST_OK: passed++; break;
+ case TEST_TODO: todos++; break;
+ case TEST_SKIP: skipped++; break;
+ default: failed++;
}
current++;
}
@@ -121,13 +144,50 @@ int run_tests(int timeout, int benchmark_output) {
rewind_cursor();
if (!benchmark_output && !tap_output) {
- log_progress(total, passed, failed, "Done.\n");
+ log_progress(total, passed, failed, todos, skipped, "Done.\n");
}
return failed;
}
+void log_tap_result(int test_count,
+ const char* test,
+ int status,
+ process_info_t* process) {
+ const char* result;
+ const char* directive;
+ char reason[1024];
+
+ switch (status) {
+ case TEST_OK:
+ result = "ok";
+ directive = "";
+ break;
+ case TEST_TODO:
+ result = "not ok";
+ directive = " # TODO ";
+ break;
+ case TEST_SKIP:
+ result = "ok";
+ directive = " # SKIP ";
+ break;
+ default:
+ result = "not ok";
+ directive = "";
+ }
+
+ if ((status == TEST_SKIP || status == TEST_TODO) &&
+ process_output_size(process) > 0) {
+ process_read_last_line(process, reason, sizeof reason);
+ } else {
+ reason[0] = '\0';
+ }
+
+ LOGF("%s %d - %s%s%s\n", result, test_count, test, directive, reason);
+}
+
+
int run_test(const char* test,
int timeout,
int benchmark_output,
@@ -231,7 +291,7 @@ int run_test(const char* test,
}
status = process_reap(main_proc);
- if (status != 0) {
+ if (status != TEST_OK) {
snprintf(errmsg,
sizeof errmsg,
"exit code %d",
@@ -255,17 +315,17 @@ out:
FATAL("process_wait failed");
}
- if (tap_output) {
- if (status == 0)
- LOGF("ok %d - %s\n", test_count, test);
- else
- LOGF("not ok %d - %s\n", test_count, test);
- }
+ if (tap_output)
+ log_tap_result(test_count, test, status, &processes[i]);
/* Show error and output from processes if the test failed. */
if (status != 0 || task->show_output) {
if (tap_output) {
LOGF("#");
+ } else if (status == TEST_TODO) {
+ LOGF("\n`%s` todo\n", test);
+ } else if (status == TEST_SKIP) {
+ LOGF("\n`%s` skipped\n", test);
} else if (status != 0) {
LOGF("\n`%s` failed: %s\n", test, errmsg);
} else {
diff --git a/deps/uv/test/runner.h b/deps/uv/test/runner.h
index 8be9e39fcc..aa7f205407 100644
--- a/deps/uv/test/runner.h
+++ b/deps/uv/test/runner.h
@@ -143,6 +143,11 @@ long int process_output_size(process_info_t *p);
/* Copy the contents of the stdio output buffer to `fd`. */
int process_copy_output(process_info_t *p, int fd);
+/* Copy the last line of the stdio output buffer to `buffer` */
+int process_read_last_line(process_info_t *p,
+ char * buffer,
+ size_t buffer_len);
+
/* Return the name that was specified when `p` was started by process_start */
char* process_get_name(process_info_t *p);
diff --git a/deps/uv/test/task.h b/deps/uv/test/task.h
index de7c80ec3a..308201e579 100644
--- a/deps/uv/test/task.h
+++ b/deps/uv/test/task.h
@@ -119,4 +119,28 @@ void uv_sleep(int msec);
/* Format big numbers nicely. WARNING: leaks memory. */
const char* fmt(double d);
+/* Reserved test exit codes. */
+enum test_status {
+ TEST_OK = 0,
+ TEST_TODO,
+ TEST_SKIP
+};
+
+#define RETURN_OK() \
+ do { \
+ return TEST_OK; \
+ } while (0)
+
+#define RETURN_TODO(explanation) \
+ do { \
+ LOGF("%s\n", explanation); \
+ return TEST_TODO; \
+ } while (0)
+
+#define RETURN_SKIP(explanation) \
+ do { \
+ LOGF("%s\n", explanation); \
+ return TEST_SKIP; \
+ } while (0)
+
#endif /* TASK_H_ */
diff --git a/deps/uv/test/test-list.h b/deps/uv/test/test-list.h
index 30a2a0a28f..0822d7f151 100644
--- a/deps/uv/test/test-list.h
+++ b/deps/uv/test/test-list.h
@@ -128,6 +128,7 @@ TEST_DECLARE (pipe_ref2)
TEST_DECLARE (pipe_ref3)
TEST_DECLARE (pipe_ref4)
TEST_DECLARE (process_ref)
+TEST_DECLARE (has_ref)
TEST_DECLARE (active)
TEST_DECLARE (embed)
TEST_DECLARE (async)
@@ -221,6 +222,9 @@ TEST_DECLARE (we_get_signal)
TEST_DECLARE (we_get_signals)
TEST_DECLARE (signal_multiple_loops)
#endif
+#ifdef __APPLE__
+TEST_DECLARE (osx_select)
+#endif
HELPER_DECLARE (tcp4_echo_server)
HELPER_DECLARE (tcp6_echo_server)
HELPER_DECLARE (udp4_echo_server)
@@ -377,6 +381,7 @@ TASK_LIST_START
TEST_ENTRY (pipe_ref4)
TEST_HELPER (pipe_ref4, pipe_echo_server)
TEST_ENTRY (process_ref)
+ TEST_ENTRY (has_ref)
TEST_ENTRY (loop_handles)
TEST_ENTRY (walk_handles)
@@ -442,6 +447,10 @@ TASK_LIST_START
TEST_ENTRY (signal_multiple_loops)
#endif
+#ifdef __APPLE__
+ TEST_ENTRY (osx_select)
+#endif
+
TEST_ENTRY (fs_file_noent)
TEST_ENTRY (fs_file_nametoolong)
TEST_ENTRY (fs_file_loop)
diff --git a/deps/uv/test/test-osx-select.c b/deps/uv/test/test-osx-select.c
new file mode 100644
index 0000000000..5c2cbd4d93
--- /dev/null
+++ b/deps/uv/test/test-osx-select.c
@@ -0,0 +1,82 @@
+/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "uv.h"
+#include "task.h"
+
+#ifdef __APPLE__
+
+#include <sys/ioctl.h>
+#include <string.h>
+
+static int read_count;
+
+
+static uv_buf_t alloc_cb(uv_handle_t* handle, size_t size) {
+ static char buf[1024];
+
+ return uv_buf_init(buf, ARRAY_SIZE(buf));
+}
+
+
+static void read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) {
+ fprintf(stdout, "got data %d\n", ++read_count);
+
+ if (read_count == 3)
+ uv_close((uv_handle_t*) stream, NULL);
+}
+
+
+TEST_IMPL(osx_select) {
+ int r;
+ int fd;
+ size_t i;
+ size_t len;
+ const char* str;
+ uv_tty_t tty;
+
+ fd = open("/dev/tty", O_RDONLY);
+
+ ASSERT(fd >= 0);
+
+ r = uv_tty_init(uv_default_loop(), &tty, fd, 1);
+ ASSERT(r == 0);
+
+ uv_read_start((uv_stream_t*) &tty, alloc_cb, read_cb);
+
+ // Emulate user-input
+ str = "got some input\n"
+ "with a couple of lines\n"
+ "feel pretty happy\n";
+ for (i = 0, len = strlen(str); i < len; i++) {
+ r = ioctl(fd, TIOCSTI, str + i);
+ ASSERT(r == 0);
+ }
+
+ uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+
+ ASSERT(read_count == 3);
+
+ MAKE_VALGRIND_HAPPY();
+ return 0;
+}
+
+#endif /* __APPLE__ */
diff --git a/deps/uv/test/test-ref.c b/deps/uv/test/test-ref.c
index 9fc214ab60..37279ac89a 100644
--- a/deps/uv/test/test-ref.c
+++ b/deps/uv/test/test-ref.c
@@ -413,3 +413,15 @@ TEST_IMPL(process_ref) {
MAKE_VALGRIND_HAPPY();
return 0;
}
+
+
+TEST_IMPL(has_ref) {
+ uv_idle_t h;
+ uv_idle_init(uv_default_loop(), &h);
+ uv_ref((uv_handle_t*)&h);
+ ASSERT(uv_has_ref((uv_handle_t*)&h) == 1);
+ uv_unref((uv_handle_t*)&h);
+ ASSERT(uv_has_ref((uv_handle_t*)&h) == 0);
+ MAKE_VALGRIND_HAPPY();
+ return 0;
+}