summaryrefslogtreecommitdiff
path: root/deps/uv/test
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2012-10-10 02:17:32 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2012-10-10 02:17:32 +0200
commit5823290390ed8a65976778e055e35ac5e1d857f2 (patch)
tree7069789ce09af3e77e3645d5fdf2ac3dfa63627c /deps/uv/test
parent0ad005852c7bd7e896c9c94ae5284493aa35cb83 (diff)
downloadandroid-node-v8-5823290390ed8a65976778e055e35ac5e1d857f2.tar.gz
android-node-v8-5823290390ed8a65976778e055e35ac5e1d857f2.tar.bz2
android-node-v8-5823290390ed8a65976778e055e35ac5e1d857f2.zip
deps: upgrade libuv to cb03e3b
Diffstat (limited to 'deps/uv/test')
-rw-r--r--deps/uv/test/runner-win.c7
-rw-r--r--deps/uv/test/test-barrier.c98
-rw-r--r--deps/uv/test/test-condvar-consumer-producer.c137
-rw-r--r--deps/uv/test/test-list.h6
4 files changed, 247 insertions, 1 deletions
diff --git a/deps/uv/test/runner-win.c b/deps/uv/test/runner-win.c
index 111a6869d1..8f534bcdb7 100644
--- a/deps/uv/test/runner-win.c
+++ b/deps/uv/test/runner-win.c
@@ -24,7 +24,10 @@
#include <malloc.h>
#include <stdio.h>
#include <process.h>
-#include <crtdbg.h>
+#if !defined(__MINGW32__)
+# include <crtdbg.h>
+#endif
+
#include "task.h"
#include "runner.h"
@@ -44,8 +47,10 @@ void platform_init(int argc, char **argv) {
/* Disable the "application crashed" popup. */
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX |
SEM_NOOPENFILEERRORBOX);
+#if !defined(__MINGW32__)
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG);
+#endif
_setmode(0, _O_BINARY);
_setmode(1, _O_BINARY);
diff --git a/deps/uv/test/test-barrier.c b/deps/uv/test/test-barrier.c
new file mode 100644
index 0000000000..97df704c0e
--- /dev/null
+++ b/deps/uv/test/test-barrier.c
@@ -0,0 +1,98 @@
+/* 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"
+
+#include <string.h>
+#include <errno.h>
+
+typedef struct {
+ uv_barrier_t barrier;
+ int delay;
+ volatile int posted;
+} worker_config;
+
+
+static void worker(void* arg) {
+ worker_config* c = arg;
+
+ if (c->delay)
+ uv_sleep(c->delay);
+
+ uv_barrier_wait(&c->barrier);
+}
+
+
+TEST_IMPL(barrier_1) {
+ uv_thread_t thread;
+ worker_config wc;
+
+ memset(&wc, 0, sizeof(wc));
+
+ ASSERT(0 == uv_barrier_init(&wc.barrier, 2));
+ ASSERT(0 == uv_thread_create(&thread, worker, &wc));
+
+ uv_sleep(100);
+ uv_barrier_wait(&wc.barrier);
+
+ ASSERT(0 == uv_thread_join(&thread));
+ uv_barrier_destroy(&wc.barrier);
+
+ return 0;
+}
+
+
+TEST_IMPL(barrier_2) {
+ uv_thread_t thread;
+ worker_config wc;
+
+ memset(&wc, 0, sizeof(wc));
+ wc.delay = 100;
+
+ ASSERT(0 == uv_barrier_init(&wc.barrier, 2));
+ ASSERT(0 == uv_thread_create(&thread, worker, &wc));
+
+ uv_barrier_wait(&wc.barrier);
+
+ ASSERT(0 == uv_thread_join(&thread));
+ uv_barrier_destroy(&wc.barrier);
+
+ return 0;
+}
+
+
+TEST_IMPL(barrier_3) {
+ uv_thread_t thread;
+ worker_config wc;
+
+ memset(&wc, 0, sizeof(wc));
+
+ ASSERT(0 == uv_barrier_init(&wc.barrier, 2));
+ ASSERT(0 == uv_thread_create(&thread, worker, &wc));
+
+ uv_barrier_wait(&wc.barrier);
+
+ ASSERT(0 == uv_thread_join(&thread));
+ uv_barrier_destroy(&wc.barrier);
+
+ return 0;
+}
diff --git a/deps/uv/test/test-condvar-consumer-producer.c b/deps/uv/test/test-condvar-consumer-producer.c
new file mode 100644
index 0000000000..b2e8d3d9d9
--- /dev/null
+++ b/deps/uv/test/test-condvar-consumer-producer.c
@@ -0,0 +1,137 @@
+/* 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"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#define MAX_CONSUMERS 32
+#define MAX_LOOPS 1000
+
+struct buffer_s {
+ ngx_queue_t queue;
+ int data;
+};
+typedef struct buffer_s buffer_t;
+
+static ngx_queue_t queue;
+static uv_mutex_t mutex;
+static uv_cond_t empty;
+static uv_cond_t full;
+
+static volatile int finished_consumers = 0;
+
+
+static void produce(int value) {
+ buffer_t* buf;
+
+ buf = malloc(sizeof(*buf));
+ ngx_queue_init(&buf->queue);
+ buf->data = value;
+ ngx_queue_insert_tail(&queue, &buf->queue);
+}
+
+
+static int consume(void) {
+ ngx_queue_t* q;
+ buffer_t* buf;
+ int data;
+
+ ASSERT(!ngx_queue_empty(&queue));
+ q = ngx_queue_last(&queue);
+ ngx_queue_remove(q);
+
+ buf = ngx_queue_data(q, buffer_t, queue);
+ data = buf->data;
+ free(buf);
+
+ return data;
+}
+
+
+static void producer(void* arg) {
+ int i;
+
+ (void) arg;
+
+ for (i = 0; i < MAX_LOOPS * MAX_CONSUMERS; i++) {
+ uv_mutex_lock(&mutex);
+ while(!ngx_queue_empty(&queue))
+ uv_cond_wait(&empty, &mutex);
+ produce(i);
+ uv_cond_signal(&full);
+ uv_mutex_unlock(&mutex);
+ }
+
+ LOGF("finished_consumers: %d\n", finished_consumers);
+ ASSERT(finished_consumers == MAX_CONSUMERS);
+}
+
+
+static void consumer(void* arg) {
+ int i;
+ int value;
+
+ (void) arg;
+
+ for (i = 0; i < MAX_LOOPS; i++) {
+ uv_mutex_lock(&mutex);
+ while (ngx_queue_empty(&queue))
+ uv_cond_wait(&full, &mutex);
+ value = consume();
+ ASSERT(value < MAX_LOOPS * MAX_CONSUMERS);
+ uv_cond_signal(&empty);
+ uv_mutex_unlock(&mutex);
+ }
+
+ finished_consumers++;
+}
+
+
+TEST_IMPL(consumer_producer) {
+ int i;
+ uv_thread_t cthreads[MAX_CONSUMERS];
+ uv_thread_t pthread;
+
+ ngx_queue_init(&queue);
+ ASSERT(0 == uv_mutex_init(&mutex));
+ ASSERT(0 == uv_cond_init(&empty));
+ ASSERT(0 == uv_cond_init(&full));
+
+ for (i = 0; i < MAX_CONSUMERS; i++) {
+ ASSERT(0 == uv_thread_create(&cthreads[i], consumer, NULL));
+ }
+
+ ASSERT(0 == uv_thread_create(&pthread, producer, NULL));
+
+ for (i = 0; i < MAX_CONSUMERS; i++) {
+ ASSERT(0 == uv_thread_join(&cthreads[i]));
+ }
+
+ ASSERT(0 == uv_thread_join(&pthread));
+ uv_cond_destroy(&empty);
+ uv_cond_destroy(&full);
+ uv_mutex_destroy(&mutex);
+
+ return 0;
+}
diff --git a/deps/uv/test/test-list.h b/deps/uv/test/test-list.h
index 20c12e3e0a..28a13b2e23 100644
--- a/deps/uv/test/test-list.h
+++ b/deps/uv/test/test-list.h
@@ -22,6 +22,9 @@
TEST_DECLARE (platform_output)
TEST_DECLARE (callback_order)
TEST_DECLARE (run_once)
+TEST_DECLARE (barrier_1)
+TEST_DECLARE (barrier_2)
+TEST_DECLARE (barrier_3)
TEST_DECLARE (condvar_1)
TEST_DECLARE (condvar_2)
TEST_DECLARE (condvar_3)
@@ -214,6 +217,9 @@ TASK_LIST_START
TEST_ENTRY (callback_order)
#endif
TEST_ENTRY (run_once)
+ TEST_ENTRY (barrier_1)
+ TEST_ENTRY (barrier_2)
+ TEST_ENTRY (barrier_3)
TEST_ENTRY (condvar_1)
TEST_ENTRY (condvar_2)
TEST_ENTRY (condvar_3)